Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I had a look at the readme but don't see the "first class scope" part.


> Every function call receives its own scope

Which you can also see here [0], in the interpreter, or here[1] for the "let" example. Everything gets it's own scope, with only "global!" and "set!" being able to escape that. (And all the usual flow control like "if", "cond", "for", etc. are just ordinary function calls.)

[0] https://git.sr.ht/~shakna/scriptlang/tree/master/item/script...

[1] https://git.sr.ht/~shakna/scriptlang/tree/master/item/exampl...


Sorry, maybe I'm ignorant, but I still don't see it.

What I see is: The scope is not a first-class object. You can't "touch" it.

I see variable shadowing. And I think something that's called "dynamic scope"—or maybe it's just references, not sure.

I'm not 100% sure even what "first-class" scope would look like. I don't know any language that claims having it. I have a few ideas but would like to see some more to find out whether this idea make any sense at all. It's not in the ballpark of "first-class comments" and could be even useful. Maybe. But to know that we would need to have some language to play with.


If I'm understanding what you're calling first-class scope, then Lua's environments would count as a well-developed language with first class scope. Sandboxing Lua (outside of Luajit) is trivial, for example, because you just bind a given environment to a given function. [0]

Scope in my scripting language is also similar - you can definently touch it. That's how "set!" allows you to create a variable, for example. Assignment isn't special. set! is reaching into the scope above itself to place the variable, otherwise it wouldn't be accessible after the set! call. But it is just a function call. (And there's a couple other things like scopedepth to help you index a given scope).

[0] https://www.lua.org/pil/14.html


Thank you for the pointer to Lua! Will have a look.

Yes, "scope" is in the end the evaluation environment of some funktion. Usually it's not a first-class object in a particular language, and only available implicitly.

Having it first-class would mean being able to directly manipulate and pass function environments.

Like I said, I'm not sure this makes sense at all. But maybe it could open up some possibilities.

(I came up with the general idea when thinking about what the "implicit scope" in Scala is, or could be seen as).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: