From: Jérôme Benoit Date: Tue, 25 Apr 2017 08:17:20 +0000 (+0200) Subject: Add all course examples and tutorials X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=15c46339dbd746558fb5b82c2823e0ede2cc7bfd;p=TD_LISP.git Add all course examples and tutorials Signed-off-by: Jérôme Benoit --- diff --git a/course/functions.lsp b/course/functions.lsp new file mode 100755 index 0000000..f547702 --- /dev/null +++ b/course/functions.lsp @@ -0,0 +1,21 @@ +#!/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)) + +(println (let ((x 1) (y 2)) (+ x y))) +(println ((lambda (x y) (+ x y)) 1 2)) + +(setq x 3 y 4) +(println "x="x" y="y) +(println ((lambda (y) (setq x 5 y 6) (+ x y)) 1 2)) +(println "x="x" y="y) + +(exit) diff --git a/introduction.lsp b/course/introduction.lsp similarity index 100% rename from introduction.lsp rename to course/introduction.lsp diff --git a/course/lambda_lists.lsp b/course/lambda_lists.lsp new file mode 100755 index 0000000..5c446d3 --- /dev/null +++ b/course/lambda_lists.lsp @@ -0,0 +1,15 @@ +#!/usr/bin/env newlisp + +(define (f x y) (+ x y z)) +;(lambda (x y) (+ x y z)) +(println (first f)) +(println (last f)) +(setq z 2) +(println (f 1 3)) + +(setf (nth 1 f) '(+ x y z 1)) +(println (f 1 3)) + +(println (let ((z 2)) (expand f 'z))) + +(exit) diff --git a/lists.lsp b/course/lists.lsp similarity index 100% rename from lists.lsp rename to course/lists.lsp diff --git a/course/map.lsp b/course/map.lsp new file mode 100755 index 0000000..3a0676d --- /dev/null +++ b/course/map.lsp @@ -0,0 +1,19 @@ +#!/usr/bin/env newlisp + +(println (map eval '((+ 1) (+ 1 2 3) 11))) +;(println (list (+ 1) (+ 1 2 3) 11)) + +(println (map string? '(1 "Hello" 2 " World!"))) + +(println (map + '(1 2 3 4) '(4 5 6 7) '(8 9 10 11))) + +; fn = lambda +(println (map (fn (x) (= 0 (% x 2))) '(1 2 3 4))) + +(println (filter (fn (x) (= 0 (% x 2))) '(1 2 3 4))) + +(println (index (fn (x) (= 0 (% x 2))) '(1 2 3 4))) + +(println (apply + '(1 2 3))) + +(exit) diff --git a/functions.lsp b/functions.lsp deleted file mode 100755 index 79c4c55..0000000 --- a/functions.lsp +++ /dev/null @@ -1,13 +0,0 @@ -#!/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)