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

While function should allow arbitrary body #21

Closed
skx opened this issue Oct 5, 2022 · 0 comments · Fixed by #23
Closed

While function should allow arbitrary body #21

skx opened this issue Oct 5, 2022 · 0 comments · Fixed by #23
Assignees

Comments

@skx
Copy link
Owner

skx commented Oct 5, 2022

I wrote a quick fibonacci generator like so:

(set! fib (fn* (n)
               (if (<= n 1)
                   n
                 (+ (fib (- n 1)) (fib (- n 2))))))

(let* (n 0)
  (while (<= n 10)
    (do
        (print (fib n))
        (set! n (+ n 1) true))))

That (do .. )feels like it shouldn't be necessary.

(Also the scoping issue requiring the fixed set! call is really starting to get on my nerves; both should be resolved I think - reported separately in #22.)

@skx skx self-assigned this Oct 5, 2022
skx added a commit that referenced this issue Oct 9, 2022
This now allows the use of an arbitrary body, as can be seen
in the following test:

```
(set! p 4)

(while (<= p 10)
    (print "Pxx: %s" p)
    (set! p (+ p 1) true)
)
```

The new approach defines a local lambda, with a random name, and
calls that recursively when the conditional is true.

This closes #21, though we still need to use the three-argument
form of (set!) as our scoping/environment is confused - that is
tracked in #22.
@skx skx closed this as completed in #23 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

Successfully merging a pull request may close this issue.

1 participant