I often find myself writing code that looks a bit like this:
f[x_Integer] :=
With[
{
range = Range[2] + x
},
With[
{
a = range[[1]],
b = range[[2]],
c = g[range]
},
h[a,b,c]
]
];
It would be nice if I could avoid With
s and just write
f[x_Integer] :=
Let[
range = Range[2] + x,
{a,b} = range,
c = g[range]
,
h[a,b,c]
];
which would then automatically expand to the above at definition time.
What I'm asking is a bit similar to this questionthis question. There are additional requirements however. The new scoping construct (Let
in the above) should:
- Group sequential disjoint assignments into single
With
s. - Thread over
List
assignments.
Of course, it should not evaluate the left-hand-sides and the right-hand-sides of the assignments while expanding to With
s.
Any proposals for such a scoping construct? (I'll post my version soon).