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

Definitions can be used as expressions #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shawwn
Copy link
Contributor

@shawwn shawwn commented Oct 4, 2018

In Arc, afn is used to create a recursive function:

arc> ((afn (n)
        (if (< n 2) n
            (+ (self (- n 1))
               (self (- n 2)))))
      8)
21

This PR lowers definitions as expressions, achieving the same thing in a natural way:

diff --git a/test.l b/test.l
index 80b089a..e71f09c 100755
--- a/test.l
+++ b/test.l
@@ -581,7 +581,13 @@ c"
   (test= 42 (f))
   ((fn ()
      (define f () 38)
-     (test= 38 (f))))
+     (test= 38 (f))
+     (test= 21 ((define f (n)
+                  (if (< n 2) n
+                    (+ (f (- n 1))
+                       (f (- n 2)))))
+                8))
+     (test= 21 (f 8))))
   (test= 42 (f)))

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 this pull request may close these issues.

1 participant