Preamble This is continuing a serious discussion started in the topic "Multiple upvars". The original topic was closed by (@)jens "as it has degenerated from the original question into - yet another - frenzy about boasting speculative JavaScript fantasies". I have no opinion on that, but LET's keep this discussion on-topic anyway.
Body
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).
Recap
What I suggest is a modification of , such that it will support initialization of variables, perhaps something like: .
P.S.
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.
i don't like the multibranch library either, both of these for similar reasons:
the let block doesn't do anything with the BE inputs put into it, reporters should report
the block isn't symmetrical, with the first BE standing out
the let block is still a variadic that does nothing, except for the first item
the BE block is still unclear
nothing really implies well that these blocks are meant to be used together and only together
you can't take out the first BE to put somewhere else, but you can take out the others to set a position with it like in the third reporter of that image
it's a hassle to use because you need to expand the variadic before you can place the BE
for the multibranch library, the ELSE block doesn't even report anything