Discussion on the new Let block

We can optimize performance for multiple declarations by caching the setter once and repeatedly calling it, instead of reifying a new setter for each declaration tuple:

LET optimized script pic

This makes it somewhat faster...

Yes.
It's interesting that "this(caller)" degrades when contexts are embedded.
This is a microbenchmark result for

  1. "this( caller)"
  2. "run()"
  3. "run( this( caller))"

Reasonable result for case 3, as a straight composition of 1&3, should be 150-200 ms.
Of course it may be meanningles, as microbenchmark results fluctuate heavily.

Also, a full copy of the process at the start is very time-consuming. The same test with "Live coding..."

Jens’ new solution (let (2)) is, indeed, much faster than the original, e.g. for a let with 5 variables, as demonstrated below.

I found another quirk regarding run time, also demonstrated below: the library’s original let block takes more than linear extra runtime for each extra variable!

Edit
Initiallly I had the impression the new let was like Scheme's let*, i.e. something like variable creation benchmark script pic would work. Later I found it doesn't. Or perhaps I’ve been doing something wrong?

The issue you are having is that all inputs are evaluated before the block is run. This can be fixed by changing the second input type to "any (unevaluated)" and calling it in the block:
untitled script pic (1)

Great! Combining @mark4sisb’s brilliant (!) proposal with @jens’s post #21, and my own really simple version of let (working title: let-), we can now define the more efficient:

It may still be over 10 times slower than separate script variables + set but on the other hand it enables really compact, yet easily readable, code for declaring and initializing variables.

BTW definition of let-

Edit
… or is this actually even the equivalent of letrec*?

Can you do this with only one block (just a let block not let* & let-) ?

I think so
untitled script pic (69)

image

Note @qwe has a preferred approach to make things look neat and tidy so they are easier to understand :slight_smile:

Thk, i will test it soon

work perfectly, thk to both of you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.