From b610b3081e928e5b67a5b03704f899f0411ba317 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Apr 2017 12:06:37 +0200 Subject: [PATCH] Add more TD code snippets MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- functions.lsp | 13 +++++++++++++ lists.lsp | 30 +++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100755 functions.lsp 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) -- 2.34.1