RandomSoup / sack

A modern take on an interpreted scripting language
12 stars 0 forks source link

Function closures supported? #20

Open lemorage opened 3 months ago

lemorage commented 3 months ago

I am wondering if there is any chance we can use function closures here, like JavaScript does, and what is the formal way to do it?

nobody5050 commented 3 months ago

Well this is certainly an interesting question! I read through the MDN's explanation of closures, and some of the examples. I have to say my gut is telling me that Sack's rules on scope make these impossible currently (https://github.com/RandomSoup/sack/tree/1.0.0?tab=readme-ov-file#scope), and porting some of the examples over to Burlap, the reference implementation of Sack indeed did error on the definition of a functi inside of another functi.

However, closures definitely seem very powerful, especially when paired with the lack of classes. If you have any ideas for how they could work, please do feel free to suggest them!