My request for Snap! is an equivalent of Scheme's LET special form. LET creates and initializes a local variable. In Snap!, since doesn't support variable initialization, the closest equivalent of LET is:
... which is quite a bit more verbose.
I tried to write a LET-function myself, with an upvar and a C-shape command,
as defined: ; as used:
This DIY-LET has three downsides though (compared to Scheme's LET):
It can't create any number of variables (if one wants two variables a 2-variable version of LET needs to be written, etc.)
The scope of the upvar is not restricted to the ACTION inside the C-shape. This is a general characteristic of upvars, and it is applicable to the SCRIPT VARIABLES special form too; I feel this ought to be reconsidered (I'll create a separate topic on this).
When one moves a reporter or variable anywhere near the C-shape and its contents, a rectangular white veil will appear; if one accidentally releases the left mouse button, the reporter / variable will nestle itself inside the C-shape, throwing out the existing contents. This is a general characteristic of C-shapes within custom blocks, which IMO deserves reconsideration as well (another separate topic to come).
What I suggest is a modification of , such that it will support initialization of variables, perhaps something like: .
I'm well aware that @joecooldoo created a LET-function earlier, with its own limitations and complicated underlying code: [[Multiple Input LET VAR BE Block]], as did @sarpnt in the aforementioned topic on "Multiple upvars". IMO these examples only show that there is a demand for a LET-like special form to be incorporated into Snap!
the create variable library makes some VERY weird script variables. they break all sorts of scoping rules since they're created in a custom block, but need to be outside that block. iirc they go into other blocks and don't stay in environments like other variables.
i don't like the "let" block here, the block seems like it's just a variadic that does nothing.
this would also be extremely confusing in the pallete, since neither make sense by themselves.
i'd rather a reporter (let ((x)) = ) that returns the value put into it, an IGNORE control block with a variadic anything input, and the LET block i've made before.
the reporter can be put into any expression to get the variable from it easily, possibly for debugging or to grab part of a conditional in a loop.
the IGNORE block is already used in many libraries for various reasons.
the LET block i've made is a single block in the pallete, and allows splitting a list into many named variables.