From: Jérôme Benoit Date: Mon, 24 Apr 2017 10:06:37 +0000 (+0200) Subject: Add more TD code snippets X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b610b3081e928e5b67a5b03704f899f0411ba317;p=TD_LISP.git Add more TD code snippets Signed-off-by: Jérôme Benoit --- diff --git a/functions.lsp b/functions.lsp new file mode 100755 index 0000000..79c4c55 --- /dev/null +++ b/functions.lsp @@ -0,0 +1,13 @@ +#!/usr/bin/env newlisp + +; function addition +(define (f x y) (+ x y)) +(println (f 1 2)) + +(define f (lambda (x y) (+ x y))) +(setq f (lambda (x y) (+ x y))) +;(set 'f (lambda (x y) (+ x y))) +(println (f 1 2)) +(println ((lambda (x y) (+ x y)) 1 2)) + +(exit) diff --git a/lists.lsp b/lists.lsp index e11271c..432d9c7 100755 --- a/lists.lsp +++ b/lists.lsp @@ -12,10 +12,34 @@ ;(println (last '())) (define (list-length a-list) - (if a-list - (+ 1 (list-length (rest a-list))) - 0)) + (if a-list + (+ 1 (list-length (rest a-list))) + 0)) (println (list-length L)) +(println (length L)) + +type list ::= empty-list | first * list + +(setq x 1) +(println (+ x 1)) + +(set 'x 1 'y 2) +(let ((x 3) (y 4)) + (println x) + (println (list x y))) +(println "x="x" y="y) + +(setq x 3 y 4) +(let ((x 1) (y 2)) + (println "x="x" y="y)) +(println "x="x" y="y) + +(setq x 3 y 4) +(let ((y 2)) + (setq x 5 y 6) + (println "x="x" y="y)) +(println "x="x" y="y) + (exit)