Could we have the library let block be made a primitive

..but hidden behind a relabel option for

untitled script pic (16)

I like using the let block (as its neater than declaring a var and then setting it) but I end up debating with myself - should I spend time importing a lib just to get it as its not worth it for just one use

Do you mean as a "Relabel..." option?

Yes- edited

I definitely agree. Also the LET should have multiple variable support.

Agreed. This should be in Snap!

My feeling is that if we have it at all, it shouldn't be hidden.

As for multiple variables, that's a big ask because it requires variadic upvars. And to do it right, it requires variadic input groups, so we can have
untitled script pic
I don't think we'd go for two separate variadic inputs, one for upvars and one for values.

Anyway, for sure not in v7; we'll think about this for later.

So the text inputs just automatically update with the upvars?
Edit: I like that idea.

The whole point of the LET syntax is to put each name next to its value, so you don't have to look back and forth, and run the risk of miscounting. Otherwise you could just say


with the rest of the code inside the lambda.

Hmm. Maybe, although it introduces one more notation for people to learn.

untitled script pic (93)
untitled script pic (94)
Even
untitled script pic (95)
Declaration at first use
untitled script pic (97)

Could you show your definition of LET that uses your : block? Thanks.

:slight_smile:
letbe. script pic (1)
:slight_smile:

Update of the block
letbe. script pic

Playground project (a bit cluttered)

Cool. On my "someday" list.

You actually have a "to add someday" list?

Very nice :slight_smile:

One suggestion ....

image

I think it's more the Snap! way to use words rather than symbols

Just great minds thinking alike :slight_smile:

Yes. Mind you, there's no guarantee that Jens will agree to anything on the list, let alone everything! It used to just be a "features I want" list, but there's been a flurry of forum feature requests (that I like) recently so I (just yesterday) added a "from the forum" category within it.

The trouble with BE is that that block can be used by itself, setting and using a script variable all at once, and in that context, without "let," BE sounds weird. So I'm afraid it has to be ←, which everyone understands to mean assignment.

Good point - so something like

image

It was primarily intended as a part of blocks resembling some useful JS construct:
Object literal px = {r:255, g:0, b:0, a:100}
Destruct/spread [r,g,b,a] = ...px
let be.2 script pic (2)

let be.2 script pic (3)

BTW: with the "Variables" library and slight parameters tinkering it can work without external variables declaration.