Value goes unbound oddly

(#knock provides light)
    (current room $Room)
    (log) { room1: $Room }
    {
        (#emergency-lights is on)
        (log) { room2: $Room }
        (tower vicinity $Room)
    }
    (or)
    {
        (#headlights is on)
        (log) { room3: $Room }
        (in range of headlights $Room)
    }

yields:

> (#knock provides light)
| | | QUERY (#knock provides light)
| | | | ENTER (#knock provides light) src/light.dg:15
| | | | QUERY (current room $) src/light.dg:16
| | | | FOUND (current room #open-desert) src/light.dg:16
room1: #open-desert
| | | | QUERY (#emergency-lights is off) src/light.dg:19
| | | | FOUND (#emergency-lights is off) src/light.dg:19
| | | | QUERY (#headlights is off) src/light.dg:25
room3: $
| | | | QUERY (in range of headlights $) src/light.dg:27
| | | | | ENTER (in range of headlights $) src/light.dg:3
| | | | | QUERY *($ is one of [#middle-of-nowhere #backtracking #crumbling-concrete #base-of-tower #staging-area]) src/light.dg:3
| | | | | FOUND (#middle-of-nowhere is one of [#middle-of-nowhere #backtracking #crumbling-concrete #base-of-tower #staging-area]) src/light.dg:3
| | | | FOUND (in range of headlights #middle-of-nowhere) src/light.dg:27
| | | FOUND (#knock provides light)
Query succeeded: (#knock provides light)
> 

So it looks like $Room is getting unbound on entry to the (or). I feel like I’m missing something basic.

1 Like

Found it; needed to enclose the disjunction:


(#knock provides light)
    (current room $Room)
    {
        {
            (#emergency-lights is on)
            (tower vicinity $Room)
        }
        (or)
        {
            (#headlights is on)
            (in range of headlights $Room)
        }
    }
1 Like

Indeed, the reach of (or) extends as far as possible, both before and after the keyword. But this makes the inner braces unnecessary, so the following should also work:

(#knock provides light)
    (current room $Room)
    {
        (#emergency-lights is on)
        (tower vicinity $Room)
    (or)
        (#headlights is on)
        (in range of headlights $Room)
    }