bel icon indicating copy to clipboard operation
bel copied to clipboard

Add a test to capture the fact that 'some' returns a lexical variable and can't be used for modifying the tail of the input list

Open masak opened this issue 3 years ago • 1 comments

Language::Bel 0.63 -- darwin.
> (set L '(1 2 3 4 5))
(1 2 3 4 5)
> (some (is 3) L)
(3 4 5)
> (set (some (is 3) L) '(10 20 30))
(10 20 30)
> L
(1 2 3 4 5)

Expected that last one to be (1 2 10 20 30).

Seems not only is this one busted, but maybe we also don't have a test for something like this.

masak avatar Oct 07 '22 13:10 masak

Not a bug. The final (1 2 3 4 5) is correct.

It would be nice if (set (some ...) ...) worked like that, but it simply doesn't. Recall the definition:

(def some (f xs)
  (if (no xs)      nil
      (f (car xs)) xs
                   (some f (cdr xs))))

Note in particular the xs being returned in the second branch. That's a parameter, so it's a lexical variable. That's the thing that gets modified by set later; it happens (which is why there's no error) but it's not visible.

The fastfunc implementation substantiates this. It's correct.

Seems not only is this one busted, but maybe we also don't have a test for something like this.

It's not busted, it turns out. But I agree with OP that a test for this would be better. Going to rename the issue to reflect this.

The originally-expected behavior for some feels like it could have been useful. I wonder if it can be implemented to do that.

masak avatar Oct 09 '22 01:10 masak