Files
kraken/koka_bench/newlisp/newlisp-slow-fexpr-fib.nl
2022-11-08 22:49:43 -05:00

21 lines
863 B
Plaintext

#!/usr/bin/env newlisp
;;
;; fibonacci series
;; mostly from http://www.newlisp.org/syntax.cgi?benchmarks/fibo.newlisp.txt
;; modified slightly to match others
;;
(define (fib n)
(my-match (0 1)
(1 1)
(n (+ (fib (- n 1)) (fib (- n 2))))))
(define (my-match-helper x_sym cases i) (cond ((< i (- (length cases) 1)) (let (test__body_func (evaluate_case x_sym (cases i)))
(append (list (list (test__body_func 0) ((test__body_func 1) (cases (+ i 1))))) (my-match-helper x_sym cases (+ i 2)))))
(true '((true ("none matched"))))))
(define-macro (my-match x) (eval (list let (list '__MATCH_SYM x) (cons cond (my-match-helper '__MATCH_SYM (args) 0)))))
(println (fib (integer (main-args 2))))
(exit)