disclaimer: this is alpha version, so things could still change
I am writing a little bigger Rye script (a concrete Telegram bot). So I started thinking about organizing the code, and there, various small details of a language become important. This is a series of blog-posts where I try to define them more clearly.
First class value
Scope (context) is a first class citizen in Rye. You can construct contexts in code, manipulate them, evaluate commands inside a specific context, define functions in and with specific contexts, use them to organize code, etc ...
Context is a dictionary with an optional parent context.
Search at the parent's house
If a word can't be found in the current context, Rye evaluator recursively searches the parent contexts to read a value.
It's the same with functions. Ordinary functions have their own contexts that they evaluate in. It's parent context is a current context at evaluation time.
Why is this needed? First, builtin and user functions are defined in the main context (they are normal Rye words with values). Without this you wouldn't be able to use "+" or any other function inside your functions.
You can also create isolated contexts, which are interesting. More about this later.
Very limited "write" access
Rebol, the language that Rye takes 80% of ideas from is brilliant if you ask me! But the way you were able to accidentally overwrite global(-er) words (variables) with set-words from within the function, if you didn't explicitly define them as /local was really something I didn't like.
Set-word is a word with colon on the right like a:
Set-word is a word with colon on the right like a:
Rye doesn't just change the default, Rye's set-words can't create or modify anything outside their context at all. Not in the parent contexts and not in any sub-context.
General rule with Rye and mutability is. If it doesn't seem really necessary, say no or make it very explicit.
We will continue with this in the next blogpost.
Follow Rye's development on Github.
Komentarji
Objavite komentar