Could you perhaps summarise how contexts work in Rye? On the Ren-C forum we’ve recently been discussing binding a lot, and I’d be interested to learn how Rye does it.
Could you perhaps summarise how contexts work in Rye? On the Ren-C forum we’ve recently been discussing binding a lot, and I’d be interested to learn how Rye does it.
Context is just a namespace of "word: value"-s and an optional link to a parent context. When a word is being searched it looks in the current context and if it's not found it goes up to parent, etc.
One interesting things about contexts are what I called "isolates", a context that is isolated from anything else, but can hold a set of functions specialized for a certain task. Or you can construct and string together custom contexts to create a desired environment for certain code.
When you have a context, you can evaluate code in context, you can call functions in context from outside, you can create functions that are evaluated is a specified context or with a specified parent context, etc ...
You can also move through contexts and list them in Rye console like you would through directories.
I don't know if I answered your question well ... I'm maybe better at showing than explaining. I'm preparing an asciinema demo called "contextplay".
One difference with Rebol around scopes is that setwords only set values in current context. A function (or any other context) can't change anything outside directly, and also not in subcontext, so there is not context/word: "value".
You can only call functions in sub or parent contexts.
There are few functions that change words in-place and all end with !, they accept lit-word (in Rebol terms) that they should change in place. So this word is seeked in same manner as in general words are, also through parents, but it's very visible and explicit.
You might be interested in this description, then: https://adv-r.hadley.nz/environments.html