here's a programming language construct I'd like to see: a locals barrier

i.e., a way to define a block where after the end of the block, all local variables that were not defined inside that block are gone

@halcy i take it these pieces of code are too small to justify extracting them to separate functions?

hm! that's an interesting idea~ a little anti-lexical zone to save yourself from footguns

i wonder how hard it would be to write a macro that created like...a function with a random name in the global scope (to break out of your lexixal one) and to call it (so it isn't extra work to do this inline wherever you wanted it)

· · Web · 1 · 0 · 0

@halcy update: so, as expected, the simple case doesn't work in common lisp, clojure, or scheme

that means that this would need to probably be done inside a special let form that would replace all names inside those blocks with gensym'd ones instead, so they can only be resolved locally, and the ones that don't would just fail

hee, i've never tried to avoid making a closure before!

@halcy alright! i have a naive version of this working!

basically the anti-scope macro is a let form that makes random names for the things you bind to it, and then replaces all the symbols in the body to be those random names. if it can't find a name, it looks in the namespace, or errors out failing that

so! of the two let forms at the bottom, only the first one works because a wasn't brought into the scope

the second pic is what the first test expands to so you can see what's happening~

Sign in to participate in the conversation
Awoo Space

Awoo.space is a Mastodon instance where members can rely on a team of moderators to help resolve conflict, and limits federation with other instances using a specific access list to minimize abuse.

While mature content is allowed here, we strongly believe in being able to choose to engage with content on your own terms, so please make sure to put mature and potentially sensitive content behind the CW feature with enough description that people know what it's about.

Before signing up, please read our community guidelines. While it's a very broad swath of topics it covers, please do your best! We believe that as long as you're putting forth genuine effort to limit harm you might cause – even if you haven't read the document – you'll be okay!