hyperfiddle

2025-03-10T19:33:59.009029Z

I’m going through the v3 tutorial, currently looking at the e/amb section. I have a question — not sure if it’s interesting or just revealing a lack of understanding on my part… There’s this example…

(e/as-vec
 (let [x (e/amb 1 2 3)]
   (if (odd? x)
     x
     (e/amb))))
=> [1 2 3 1 2 3]
…and an explanation that mentions that Electric if’s current implementation interacts badly with product semantics That got me thinking, and I tried this:
(e/as-vec
 (let [x (e/amb 1 2 3)]
   [x x]))
=> [[1 1] [1 2] [1 3] [2 1] [2 2] [2 3] [3 1] [3 2] [3 3]]
I might have expected [[1 1] [2 2] [3 3]] for the [x x] example, expecting the two xs to be the same in each case. Would that make sense? Wouldn’t “unifying” the two xs make the if example behave more intuitively? Would it break something else?

Dustin Getz (Hyperfiddle) 2025-03-10T19:35:24.623619Z

I agree that unifying could make sense, we're still debating it internally

Dustin Getz (Hyperfiddle) 2025-03-10T19:35:41.992689Z

Verse's if performs similar scope narrowing

2025-03-10T19:36:12.668159Z

OK; thanks. Interesting