# FENCE!'s Higher Calling: WRAP

**URL:** <https://revolt.metaeducation.com/forum/t/fence-s-higher-calling-wrap/2613>\
**Category:** Datatypes\
**Tags:** historic\
**Created:** [December 24, 2025, 10:48pm UTC](https://revolt.metaeducation.com/forum/t/fence-s-higher-calling-wrap/2613 "2025-12-24T22:48:07Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [December 24, 2025, 10:48pm UTC](https://revolt.metaeducation.com/forum/t/fence-s-higher-calling-wrap/2613/1 "2025-12-24T22:48:07Z")

</div>

Since FENCE! came out I've been reluctant to use it directly in source as MAKE OBJECT!... wondering if there was some higher calling.

I suggested it might be better to have it be **[the CONSTRUCT dialect](https://revolt.metaeducation.com/forum/t/construct-dialect-for-objects-maps/2569)**, for instance. And that _seemed_ smarter:

```
>> {x y (1020) ~z~}
== &[object! [
    x: ~null~
    y: 1020
    z: ~
]] ; ... maybe this is useful? :-/

```

## But Then... I Looked at WRAP in Branches...

> [@Why Not Allow non-BLOCK! (and non-QUOTED!) Branches?](https://revolt.metaeducation.com/forum/t/why-not-allow-non-block-and-non-quoted-branches/476/9):
>
> ```plaintext
> >> if 1 = 1 (wrap [x: 10 print [x]]) else (wrap [x: 20 print [x]])
> 10
> 
> >> if 1 = 2 (wrap [x: 10 print [x]]) else (wrap [x: 20 print [x]])
> 20
> 
> ```

When I looked at that I thought "well, branches **[take their argument literally](https://revolt.metaeducation.com/forum/t/soft-literal-branching-light-elegant-fast/1020)**, WHY NOT USE FENCE! and have it mean WRAP?"

```
>> if 1 = 1 {x: 10 print [x]} else {x: 20 print [x]}
10

>> if 1 = 2 {x: 10 print [x]} else {x: 20 print [x]}
20

```

## EUREKA

🌩

With these seen, I realized it wasn't just branches. The best... most cross-cutting application of the new FENCE! type under _non-dialected evaluation_... would be for wrapping code in contexts... and returning the wrapped BLOCK!:

```
>> {x: 10 print [x]}
== [x: 10 print [x]] ; bound (to a context with X in it!)

```

_(Note that WRAP in Redbol lore has sometimes been evaluating and sometimes not...but the more useful form here is "make the block bound into the object, but don't run it, just return it.")_

I don't think it will become the _default_ code block choice. Because it gathers all the top-level SET-WORD!s and you have to be more careful, to use `$foo:` for any assignments you want to refer to outer-"scoped" things:

```
x: 10
y: 20
assert [1324 = all {
    x: 1020

    [$y]: 304 ; [$y]: today means "ignore Y as field of WRAP'd context" 
    set $y 304 ; alternative trick (more like historical trick)
    (y: 304) ; yet another historical trick to dodge wrapping Y

    x + y
}]
assert [x = 10, y = 304]

```

So don't expect to see people reaching for this _every_ time they make a code block. Brackets will remain king, especially since LET gives you a nice-enough tool most of the time if you need to create a new variable in mid-block.

But this makes it more terse if you are doing an evaluation where you're creating more variables than you are assigning outside the scope.

## FENCE Function Body: "Make Top-Level Assigns Locals"

```
foo: func [x y] {
   local: 10
   if x [
      not-local: 20
      ...
   ]
   ...
}

```

Mechanically speaking, this requires FUNC body to be taken literally. But it can build the locals into the FRAME!, and use its knowledge of what's already in the frame so that it doesn't create locals for arguments...

We see that now you have the power you always needed... _to make a choice of scope establishment at each level_, since it makes little sense to make it deeply when you don't know what dialect might be in effect:

```
foo: func [x y] {
   local: 10
   if x {
      new-variable: 20 ; not a FRAME! local, but new to this scope
      x: 30 ; would be creating a new variable (vs. $x:)
      ...
   }
   y: 40 ; wouldn't create new variable? (FUNC got FENCE!, can filter)
   ...
}

```

There's a bit of nuance here with a difference between the logic of the outermost scope vs. the inner ones, but I think that nuance is learnable. (Don't like it? Don't use FENCE!, use BLOCK! and LET... and be a little wordier and less efficient. This just helps the efficiency-hounds have a pithier way of saying what they want.)

It's a really high-leverage choice, and I think it stands out visually well enough... especially when you are in the rhythm of expecting to see BLOCK!, making the choice all the more powerful.

## {{...}} Probably Should Be Boring ☹

It's a little risky to carve something out of a generic evaluative tool to give {{...}} as some special meaning (CONSTRUCT, etc). Generative code might get bitten. It thinks it's inserting scoped code somewhere, which is also scoped, and you get a wacky composite behavior.

_(Though **`^{...}`** could be argued as a pretty cool way of asking for the OBJECT! that was generated by the WRAP, vs. the evaluative product. Will have to think about that.)_

But there's a plus to having {{...}} and ((...)) being largely meaningless in the evaluator. Since you wouldn't have a good reason to write them as they do the same thing as **{...}** and **(...)** generally, they make good callouts for COMPOSE or similar to do templating/etc.

I think CONSTRUCT might just be CONSTRUCT, and then in some contexts **[you might use RebindableSyntax](https://revolt.metaeducation.com/forum/t/evaluator-hooking-rebindablesyntax/2443)** to say "the {...} or {{...}} I use here are constructs" (for instance, that's what it is in locals in function specs, probably other places...)

Sky's the limit here.

---

<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:** [December 25, 2025, 7:57pm UTC](https://revolt.metaeducation.com/forum/t/fence-s-higher-calling-wrap/2613/2 "2025-12-25T19:57:09Z")

</div>

> [@hostilefork](#):
>
> ```plaintext
> foo: func [x y] {
> local: 10
> if x [
> not-local: 20
> ...
> ]
> ...
> }
> 
> ```
> 
> Mechanically speaking, this requires FUNC body to be taken literally.

There's a little bit of an issue with using WRAP on things like loop bodies that are taken by value, because they _may or may not run_.

```
 data: []

 for-each 'item data {
     var: ...
     ...
 }

```

If the behavior of FENCE! is to wrap and create an object, and bind the list to it and give it back as a BLOCK!, you'd be creating an object even when you weren't going to need it... because there'd be no iteration.

**[Branching code handles this by using literal arguments.](https://revolt.metaeducation.com/forum/t/soft-literal-branching-light-elegant-fast/1020)**

**It seems to me that for that reason, loops should follow branch rules, and take their bodies as literals... so that you only pay if the loop runs at least once.**

It's good for FENCE!, and it's good for synthesized bodies via GROUP!:

```
 data: []

 code: '[item mold print]

 for-each 'item data (
     print "don't want to run this when data is empty"
     reverse code ; would turn code to [print mold item]
 )

```

...and for that matter, it's arguably good even for plain old BLOCK! (because you're not gluing a binding into a block evaluating it, leaving that reference for the GC to clean up).

Anyway...loop bodies _are_ basically branches, taken repeatedly.

So this is probably where things were going, anyway.

---

<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:** [December 26, 2025, 2:57pm UTC](https://revolt.metaeducation.com/forum/t/fence-s-higher-calling-wrap/2613/3 "2025-12-26T14:57:50Z")

</div>

So I implemented this, and it's pretty amazing... I only had one little thought...

## It's A Little Hard To See

One might argue that lots of languages have different behaviors for braces and brackets, and we're expected to see the difference (or if we have a hard time seeing the difference, change our fonts or syntax coloring to help us discern).

But what's a bit weird here is that the braces are sitting in slots that are contextually not special; your eye can miss it.

For instance, here's some code with braces:

```
valid: ["~abc~" "~a|b~"]
for-each 'str valid {
    word: parse str [/to-word between '~ '~]
    bad: transcode:one str
    assert [quasi? bad]
    assert [word = unquasi bad]
}

```

Were it brackets:

```
valid: ["~abc~" "~a|b~"]
for-each 'str valid [
    word: parse str [/to-word between '~ '~]
    bad: transcode:one str
    assert [quasi? bad]
    assert [word = unquasi bad]
]

```

**How natural is it for your brain to "see" that these are different?** Or is it easy to overlook?

The same could be said perhaps of parentheses:

```
valid: ["~abc~" "~a|b~"]
for-each 'str valid (
    word: parse str [/to-word between '~ '~]
    bad: transcode:one str
    assert [quasi? bad]
    assert [word = unquasi bad]
)

```

But for some reason I feel the parentheses stand out more. (It does depend on the font.)

One could perhaps argue that this means the WRAP construct should be {{...}} instead:

```
valid: ["~abc~" "~a|b~"]
for-each 'str valid {{
    word: parse str [/to-word between '~ '~]
    bad: transcode:one str
    assert [quasi? bad]
    assert [word = unquasi bad]
}}

```

Then you could say "well, that frees up {...} for other things, like CONSTRUCT"

---

<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:** [December 26, 2025, 4:00pm UTC](https://revolt.metaeducation.com/forum/t/fence-s-higher-calling-wrap/2613/5 "2025-12-26T16:00:27Z")

</div>

> [@hostilefork](#):
>
> ```plaintext
> valid: ["~abc~" "~a|b~"]
> for-each 'str valid {
> word: parse str [/to-word between '~ '~]
> bad: transcode:one str
> assert [quasi? bad]
> assert [word = unquasi bad]
> }
> 
> ```

It also occurs to me... _since the loop is taking the branch literally, it could scan it and omit loop variables from the object_.

```
valid: ["~abc~" "~a|b~"]
for-each 'str valid {
    str: reverse str ; WRAP won't consider STR for the object
    word: parse str [/to-word between '~ '~]
    bad: transcode:one str
    assert [quasi? bad]
    assert [word = unquasi bad]
}

```

This is bonkers. But pretty amazing.

😵‍💫

---

<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:** [November 11, 2026, 3:12pm UTC](https://revolt.metaeducation.com/forum/t/fence-s-higher-calling-wrap/2613/6 "2026-11-11T15:12:47Z")

</div>

> [@hostilefork](#):
>
> It also occurs to me... _since the loop is taking the branch literally, it could scan it and omit loop variables from the object_.
> 
> ```plaintext
> valid: ["~abc~" "~a|b~"]
> for-each 'str valid {
> str: reverse str ; WRAP won't consider STR for the object
> word: parse str [/to-word between '~ '~]
> bad: transcode:one str
> assert [quasi? bad]
> assert [word = unquasi bad]
> }
> 
> ```
> 
> ...
> 
> This is bonkers. But pretty amazing.

In trying to implement these ideas, I began to face a kind of **[Cliffs of Complexity](https://revolt.metaeducation.com/forum/t/the-cliffs-of-complexity-how-much-is-too-much/1241)** question, because while _ **I** _ might be able to assemble all these semantic pieces together, I'm not sure anyone building on top of them could easily offer the same invariants. And this ability to abstract and have your own constructs behave just as cleanly as the system is paramount in Revolt.

Think about what such a loop has to do:

- It receives its arguments: the loop variables, the data to loop over, and a literal argument (FENCE! for wrapped code, BLOCK! for ordinary code, GROUP! for code that may evaluate... to a FENCE! or a BLOCK!... and maybe even a GROUP! depending on how tolerant you wish to be in leaving room for infinite loops).

- Some cases of the data will have nothing to iterate (empty block, for example). A decision has to be made if these cases evaluate a GROUP! body or not, or if at least one iteration is required. Opting out with a VOID would hopefully not evaluate a group.

- If it's decided that the body will be evaluated (and possibly have its variables wrapped), it must be transformed... _but only once_. The job of the transformation is to give you the code to execute. So something like a FOR-BOTH that receives a GROUP! that evaluates to a FENCE! needs to do the GROUP! evaluation and then the wrap to produce a BLOCK! and then pass that BLOCK! into two separate FOR-EACH instead of passing the GROUP! to the two FOR-EACH so it evaluates and wraps twice.

- If we're going to consider the idea that the wrapping process can be conscious of the loop variables, then that adds a twist in that the wrap step must fold the variables in.

Let's look at what this does to something like FOR-BOTH. Initially it was this:

```plaintext
  for-both: lambda [@(vars) data1 data2 body] [
      all [
          ^ for-each (vars) data1 body then lift/
          ^ for-each (vars) data2 body then lift/
      ] then unlift/
  ]

```

The parameter convention `@(var)` means "give me this literally as-is at the callsite, but evaluate any GROUP!s". So you get your variable definitions. The body was previously not taken literally, but imagine if we use the same rule:

```plaintext
  for-both: lambda [@(vars) data1 data2 @(body)] [
      all [
          ^ for-each (vars) data1 (body) then lift/
          ^ for-each (vars) data2 (body) then lift/
      ] then unlift/
  ]

```

We had to parenthesize the body when passing to the FOR-EACHes, so it evaluates the variable instead of trying to pass the word body to the now-literal body argument of FOR-EACH.

Okay, but what if body evaluates to a FENCE!? We're now paying to wrap it twice. The only way we can avoid that is with some kind of generic tool that does a variable-aware wrapping:

```plaintext
  for-both: lambda [@(vars) data1 data2 @(body)] [
      if fence? body [
          body: wrap:with (as block! body) vars
      ]
      all [
          ^ for-each (vars) data1 (body) then lift/
          ^ for-each (vars) data2 (body) then lift/
      ] then unlift/
  ]

```

We might imagine that wrapping service being offered as a loop-specific helper that does just that:

```plaintext
  for-both: lambda [@(vars) data1 data2 @(body)] [
      body: loop-wrap body vars
      all [
          ^ for-each (vars) data1 (body) then lift/
          ^ for-each (vars) data2 (body) then lift/
      ] then unlift/
  ]

```

Or in the "mutable arguments" alternative convention I've been designing:

```plaintext
  for-both: lambda [@(vars) data1 data2 @(body)] [
      loop-wrap $body vars
      all [
          ^ for-each (vars) data1 (body) then lift/
          ^ for-each (vars) data2 (body) then lift/
      ] then unlift/
  ]

```

But note that this doesn't have the property of not wrapping or evaluating a GROUP! if the data is empty.

```
>> for-both item [] [] (print "This runs and wraps" {x: item, x + 1020})
This runs and wraps ; you paid for the eval and the wrapping
== \~\ ; antiform (void!)

```

It's actually worse than this, because since you're using the "group evaluation" mode voids can't opt out either. All the parameters are evaluated before the voids opt out. To get past that, you can't use the escapable literal trick:

```plaintext
  for-both: lambda [@(vars) data1 data2 @body] [ ; @body not @(body)
      loop-wrap $body vars ; must handle GROUP! now
      all [
          ^ for-each (vars) data1 (body) then lift/
          ^ for-each (vars) data2 (body) then lift/
      ] then unlift/
  ]

```

So here we have it that the GROUP! is passed literally, meaning that voids passed as blk1 and blk2 can opt out. But wait... we can't use the opt out parameter convention because that would mean _either_ void could opt out of the whole operation. 🙄 Not only that, we reserve NULL to signal loop breaking, so loops never use the opt out convention anyway (that produces NULL on void input).

Hence we have to manually ensure both data1 and data2 opt out, and do so before the LOOP-WRAP

```plaintext
  for-both: lambda [@(vars) ^data1 ^data2 @body] [
      all [void? ^data1, void? ^data2] then [return ^void]
      loop-wrap $body vars ; won't eval GROUP! if both data opt out
      all [
          ^ for-each (vars) ^data1 (body) then lift/
          ^ for-each (vars) ^data2 (body) then lift/
      ] then unlift/
  ]

```

## Madness or Genius?

Well, it's not completely clear. But what I do know is: **I just can't accept the idea of this getting any more complicated.**

Our hands get tied on policy when we analyze the difficulty of writing higher level composition. Detecting empty iterations adds too much conditional behavior. If you want to opt out you need some kind of "turn empty things to void".

SO... If you pass NON-VOID as the data to a loop to iterate over, detecting its emptiness and the fact that it won't actually iterate over anything **does not save you the GROUP! evaluation of a body argument, nor the wrapping of any FENCE!**. It's your job to turn empty data into void at the callsite if you really want to dodge that.

## Of Course, It's Your Call How "Perfect" To Be...

Getting it _exactly right_ is something a metaprogramming specialist does.

I'm not concerned about a quick-and-dirty solution that works well enough for your case having defects. **I'm concerned about it being impossible to write the right answer, or there not being an obvious through-line of logical thinking that lets you see what the issues you're facing are.**

---

<div class="post-metadata">

**Author:** ![claude](https://revolt.metaeducation.com/forum/user_avatar/revolt.metaeducation.com/claude/32/512_2.png) [@claude](https://revolt.metaeducation.com/forum/u/claude)\
**Post date:** [November 11, 2026, 3:42pm UTC](https://revolt.metaeducation.com/forum/t/fence-s-higher-calling-wrap/2613/7 "2026-11-11T15:42:38Z")

</div>

Reading over this thread, three rules fall out. **None of them is about efficiency, even though that's how they were first argued.**

### 1. A FENCE! decides _when variables are born_

`{...}` makes a fresh set of variables for the top-level assignments inside it. The only question is how often:

| Where the `{...}` is | New variables are made... |
| --- | --- |
| FUNC body | once per call |
| Branch (`if`, `else`, ...) | once each time the branch is taken |
| Loop body | once per loop, _not_ once per iteration |

The loop row is a choice. It means variables persist across iterations:

```
for-each 'item [1 2 3] {
    total: default [0] ; set on the first pass only
    total: total + item
}

```

It also means a variable you only assign _sometimes_ still holds its value from the previous pass, and functions created in the body all share the same variables. If you want fresh-per-iteration, use LET.

### 2. If you build a loop from other loops, wrap once yourself

Because of rule 1, wrapping twice isn't a slower version of the same program. It's a different program, where state resets halfway through. So a FOR-BOTH has to turn the body into a BLOCK! one time and hand that same block to both FOR-EACHes:

```
for-both: func [@(vars) ^data1 ^data2 @body] [
    all [void? ^data1, void? ^data2] then [return ^void]
    loop-wrap $body vars
    return all [
        ^ for-each (vars) ^data1 (body) then lift/
        ^ for-each (vars) ^data2 (body) then lift/
    ] then unlift/
]

```

(This is a FUNC, not a LAMBDA as posted earlier: a LAMBDA has no RETURN of its own.)

### 3. Only VOID data skips the body's setup

If you pass a GROUP! or FENCE! as a body, it gets evaluated and wrapped whenever the data is non-void, even if the data is empty and the body never runs.

This is not an oversight. A loop can't always know in advance that there is nothing to iterate, and a composed loop can't share a "do it lazily on first use" body across its sub-loops. So the rule is the simple one: **if you want to skip everything, pass void**.
