From: Jérôme Benoit Date: Mon, 24 Apr 2017 09:32:28 +0000 (+0200) Subject: Add introduction to LISP and list manipulation in LISP code X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=679ae8f3a1de255be56edd9ac79370d15d59378b;p=TD_LISP.git Add introduction to LISP and list manipulation in LISP code Signed-off-by: Jérôme Benoit --- 679ae8f3a1de255be56edd9ac79370d15d59378b diff --git a/introduction.lsp b/introduction.lsp new file mode 100755 index 0000000..7e6a7c8 --- /dev/null +++ b/introduction.lsp @@ -0,0 +1,52 @@ +#!/usr/bin/env newlisp + +(println "Hello World!") + +(println '(println "Hello World!")) + +(println (eval (quote (println "Hello World!")))) + +(if true (println "Hello") (println "Goodbye")) + +(set 'hello "Hello") +(set 'world " World!") + +(println hello world) + +(println hello) +(println world) + +(println (eval 'z)) + +(set 'y 'x) +(set y 1) +(println "x="x) +(println "y="y) + +(setq y 1) +(println "y="y) + +(define y 2) +(println "y="y) + +(set 'x 1 'y 2) +(println "x="x) +(println "y="y) + +(setq x 3 y 4) +(println "x="x) +(println "y="y) + +(println '((x 1) (y 2))) + +(println (first '(x 1))) +(println (last '(x 1))) + +(println (first '((x 1) (y 2)))) + +(println "assoc:") +(println (assoc 'x '((x 1) (y 2) (x 3)))) +(println "lookup:") +(println (lookup 'x '((x 1) (y 2) (x 3)))) + +(exit) diff --git a/lists.lsp b/lists.lsp new file mode 100755 index 0000000..e11271c --- /dev/null +++ b/lists.lsp @@ -0,0 +1,21 @@ +#!/usr/bin/env newlisp + +(setq L '(1 2 3)) +(println (first L)) ; le premier élément +(println (rest L)) ; la liste privée du premier élément +(println (last L)) ; le dernier élément + +(println (rest '(1))) +(println (rest '())) +; return an error: empty list +;(println (first '())) +;(println (last '())) + +(define (list-length a-list) + (if a-list + (+ 1 (list-length (rest a-list))) + 0)) + +(println (list-length L)) + +(exit)