Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #432

Open
masak opened this issue Oct 7, 2022 · 1 comment

Comments

@masak
Copy link
Owner

masak commented Oct 7, 2022

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
Copy link
Owner Author

masak commented Oct 9, 2022

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 masak changed the title Trouble with '(set (some ...) ...)' 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 Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant