You are browsing as a guest. Sign up (or log in) to start making projects!

6h 13m 32s logged

Lambdas

I added lambdas to Scratcher!
They allow you to write more expressive code like map(list, a -> a + 1), which literally adds 1 to every element of list
I also allow using outer variables within lambdas

int a = ...;    
map(list, b -> {    
     a++;    
     b + a    
});

I allow this through boxing, the local variables become boxes and the lambdas get the local variable’s box, this makes lambdas more powerful than most languages as this allows for variables to be shared mutable state across lambdas, this also allows the local variables to get garbage collected.

Of course, scratch doesn’t support this natively, so lambdas are 100% compiler sugar and just lowers to regular functions and uses function references(which is also 100% compiler sugar).

void lambda::defunc@lambad@0(LambdaCaptures c, args...) {  
  ...  
}
0
38

Comments 0

No comments yet. Be the first!