Skip to content

Definitions can be used as expressions - #210

Open
shawwn wants to merge 1 commit into
sctb:masterfrom
shawwn:2018-10-03/lower-definition
Open

Definitions can be used as expressions#210
shawwn wants to merge 1 commit into
sctb:masterfrom
shawwn:2018-10-03/lower-definition

Conversation

@shawwn

@shawwn shawwn commented Oct 4, 2018

Copy link
Copy Markdown
Contributor

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