argumentcomputer / lurk-lisp

Lisp implementation of Lurk.
MIT License
67 stars 6 forks source link

Add example translated from Go. #22

Closed porcuquine closed 2 years ago

porcuquine commented 2 years ago

@whyrusleeping Asked me to translate a Go function to Lurk as an example. He did a good job of making it nasty. Might as well check it in for future reference.

Output is as expected.

➜  lurk git:(example) make repl 
Lurk REPL [API].
:help for help.

API> :load "example/from-go.lurk"
Read from example/from-go.lurk: (LET* ((FOO
                                             (LAMBDA (A B)
                                              (LETREC*
                                               ((AUX
                                                 (LAMBDA (I A X)
                                                  (IF (= I B) X
                                                   (LET* ((X (+ X A))
                                                          (A (+ A (* B 2))))
                                                     (AUX (+ I 1) A X))))))
                                               (LET* ((X (+ (* A B) 4)))
                                                 (AUX 0 A X))))))
                                       (CURRENT-ENV))

API> (foo 10 6)
304