diff --git a/koka_bench/newlisp/newlisp-macro-fib-let.nl b/koka_bench/newlisp/newlisp-macro-fib-let.nl new file mode 100644 index 0000000..bf69a96 --- /dev/null +++ b/koka_bench/newlisp/newlisp-macro-fib-let.nl @@ -0,0 +1,24 @@ +#!/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 (let (a (fib (- n 1)) + b (fib (- n 2)) + ) (+ a b))))) + +(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")))))) + +(macro (my-match X) X) +(constant 'my-match (lambda-macro (X) (expand (list let (list '__MATCH_SYM 'X) (cons cond (my-match-helper '__MATCH_SYM (args) 0))) 'X))) + +(println (fib (integer (main-args 2)))) + +(exit) diff --git a/koka_bench/newlisp/newlisp-macro-fib.nl b/koka_bench/newlisp/newlisp-macro-fib.nl new file mode 100644 index 0000000..115d524 --- /dev/null +++ b/koka_bench/newlisp/newlisp-macro-fib.nl @@ -0,0 +1,22 @@ +#!/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")))))) + +(macro (my-match X) X) +(constant 'my-match (lambda-macro (X) (expand (list let (list '__MATCH_SYM 'X) (cons cond (my-match-helper '__MATCH_SYM (args) 0))) 'X))) + +(println (fib (integer (main-args 2)))) + +(exit) diff --git a/koka_bench/newlisp/newlisp-slow-fexpr-fib-let.nl b/koka_bench/newlisp/newlisp-slow-fexpr-fib-let.nl new file mode 100644 index 0000000..542bde3 --- /dev/null +++ b/koka_bench/newlisp/newlisp-slow-fexpr-fib-let.nl @@ -0,0 +1,22 @@ +#!/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 (let (a (fib (- n 1)) + b (fib (- n 2)) + ) (+ a b))))) + +(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) diff --git a/koka_bench/newlisp/newlisp-slow-fexpr-fib.nl b/koka_bench/newlisp/newlisp-slow-fexpr-fib.nl new file mode 100644 index 0000000..45dee2c --- /dev/null +++ b/koka_bench/newlisp/newlisp-slow-fexpr-fib.nl @@ -0,0 +1,20 @@ +#!/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) diff --git a/koka_bench/picolisp/picolisp-fib-let.l b/koka_bench/picolisp/picolisp-fib-let.l index 76bc72e..22faeab 100755 --- a/koka_bench/picolisp/picolisp-fib-let.l +++ b/koka_bench/picolisp/picolisp-fib-let.l @@ -8,7 +8,7 @@ exec pil $0 $1 (de fib (N) (cond ((= 0 N) 1) ((= 1 N) 1) - (1 (let (A (fib (- N 1)) + (T (let (A (fib (- N 1)) B (fib (- N 2)) ) (+ A B))))) diff --git a/koka_bench/picolisp/picolisp-fib.l b/koka_bench/picolisp/picolisp-fib.l index 2b3977f..948d25f 100755 --- a/koka_bench/picolisp/picolisp-fib.l +++ b/koka_bench/picolisp/picolisp-fib.l @@ -8,6 +8,6 @@ exec pil $0 $1 (de fib (n) (cond ((= 0 n) 1) ((= 1 n) 1) - (1 (+ (fib (- n 1)) (fib (- n 2)))))) + (T (+ (fib (- n 1)) (fib (- n 2)))))) (bye (println (fib (car (str (opt)))))) diff --git a/koka_bench/picolisp/picolisp-nqueens.l b/koka_bench/picolisp/picolisp-nqueens.l new file mode 100644 index 0000000..35f8a5d --- /dev/null +++ b/koka_bench/picolisp/picolisp-nqueens.l @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +#{ +# Thanks to http://rosettacode.org/wiki/Multiline_shebang#PicoLisp +exec pil $0 $1 +# }# + +(de safe (Q D S) (let (C (car S)) + (case C + (NIL T) + (T (and (<> Q C) (<> Q (+ C D)) (<> Q (- C D)) (safe Q (+ D 1) (cdr S)) )) + ) + ) +) + +(de appendS (Q S X) (cond ((<= Q 0) X) + ((safe Q 1 S) (appendS (- Q 1) S (cons (cons Q S) X))) + (T (appendS (- Q 1) S X) ) + ) + +) + +(de extendS (Q A X) (let (S (car X)) + (case S + (NIL A) + (T (extendS Q (appendS Q S A) (cdr X))) + ) + ) +) + +(de findS (N Q) (cond ((= 0 Q) (cons (cons NIL NIL) NIL)) + (T (extendS N NIL (findS N (- Q 1)))))) + +(de nqueens (N) (length (findS N N))) + +(bye (println (nqueens (car (str (opt)))))) + +