# Rebol And Scopes: Well, Why Not?

**URL:** <https://revolt.metaeducation.com/forum/t/rebol-and-scopes-well-why-not/1751>\
**Category:** Binding\
**Tags:** best-of\
**Created:** [October 27, 2021, 3:57am UTC](https://revolt.metaeducation.com/forum/t/rebol-and-scopes-well-why-not/1751 "2021-10-27T03:57:01Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![hostilefork](https://revolt.metaeducation.com/forum/user_avatar/revolt.metaeducation.com/hostilefork/32/421_2.png) [@hostilefork](https://revolt.metaeducation.com/forum/u/hostilefork)\
**Post date:** [January 25, 2024, 1:36am UTC](https://revolt.metaeducation.com/forum/t/rebol-and-scopes-well-why-not/1751/11 "2024-01-25T01:36:55Z")

</div>

> [@hostilefork](#):
>
> I think the proposals have evolved to where the answers are clear enough to make a prototype to explore further.

Here we are a mere two weeks later, and I have managed to put together **"Pure Virtual Binding II"**. It actually didn't take but a couple of days to get it booting. But this time, I've pushed through getting it to run a non-trivial set of things:

- UPARSE (now with a LET combinator!)
- the Whitespace Interpreter (including the Redbol emulated old version)
- the ODBC dialect
- @rgchris's HTTPD Server
- @BlackATTR's Query dialect
- bootstrap via Rebmake

Changes were needed to the usermode code. But most of the time taken was more about figuring out what to change. The total number of edits needed were actually smaller than I would have thought.

## What's Different This Time

- **No attempt to propagate binding through structural operations.**

- **QUOTED! values lose a quote level under evaluation, but their binding is not affected.**

- **Strings don't carry binding (but you can--for instance--wrap them in a block).**

## Put Another Way...

1. **The system only does "automatic" binding inheritance in evaluated code** _(PICKs and such do not count)_

2. **Once a binding is on something, the system won't override it except at clearly specified points** _(something has to BIND or UNBIND things, typically immutably)_

3. **Even when evaluated, quoted material retains whatever binding it had** _(which the majority of the time means it will be unbound)_

Let me be clear: coding within this new model is not trivial. It requires writing dialects that perform composition with a conscious awareness of binding at each step.

**But it's much better than spraying meaningless bindings on code...in the hopes that a meaningful one will ultimately "win" as deep walks of mutable binding are applied in waves.**

Not finding yourself in a situation where it's too late for you to bind code is empowering across the board. Again: I don't have all the answers, but it makes about as much sense as I think this can make.

## Overall Impression: It's The Way Forward

I've said before that this is important, because it offers means for things people have always wanted to do. Like looking up variables to do string interpolation. Or more generally: _"treat this unbound code as if it had been written here"_.

But a crucial aspect is that **this has much more of a feeling of things being under control**.

There is a sanity and a logic to diagnosing binding problems. You have the compounded binding environment in your hands, in the moment. Previously you could only sift through the scattershot results of however many binding waves that happened before.

It does require a new way of thinking about what you're doing, but _at least you can think_.

## Performance Is An Issue

Historical binding did have one thing going for it: gluing the binding onto things meant you knew where to look up words without having to search through a linked list of objects every time.

But we're talking about bound values only coming into existence under evaluation. This means that the entire body of a function is effectively unbound at the start of each run.

I haven't done any optimization yet, and empirically it seems to be about 25% slower. That's actually not bad considering that I haven't put any attention on performance...but I do feel like there's going to be limits to how good it can be.

UPDATE: Adding the optimization of caching in function bodies [whether a word is in that function or not](https://revolt.metaeducation.com/forum/t/semantics-and-optimization-of-copying-function-bodies/2119/2) brings it more to approximately 10%. Lots more to look at, but that's encouraging.

## Working Through A Few Things Before Committing This

I'm aiming to commit this to GitHub soon-ish. But I have a few more things to look at:

- The tests. I got the test runner to work, and it ran to the end without crashing. But there were still 300 failures, after I'd just gotten that number down to like a dozen after facing a similar number of issues in the year-of-isotopes. I felt like looking at real code first...and I'll probably be pushing this out before all the minutiae of thought experiments get rethought.

- Get some more clarity on [attachment binding](https://revolt.metaeducation.com/forum/t/caching-binding-lookup-and-attachment-binding/2128/5). It's a sketchy concept, but is required for the system to run at the moment. It's bothersome because it creates a "neither bound nor unbound" state that complicates code that wants a more definitive answer on whether words are bound or unbound--that doesn't change out from ounder them.

- Cleanup old unnecessary code, e.g. the code for propagating bindings through structural operations (which is still there, just deactivated).

- Do at least a little bit of looking into what can be done about performance.

But overall, it feels about as right as I think it's going to feel. So that's a win!

---

_[View the full topic](https://revolt.metaeducation.com/forum/t/rebol-and-scopes-well-why-not/1751)._
