From 15c46339dbd746558fb5b82c2823e0ede2cc7bfd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 25 Apr 2017 10:17:20 +0200 Subject: [PATCH] Add all course examples and tutorials MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- course/functions.lsp | 21 +++++++++++++++++++++ introduction.lsp => course/introduction.lsp | 0 course/lambda_lists.lsp | 15 +++++++++++++++ lists.lsp => course/lists.lsp | 0 course/map.lsp | 19 +++++++++++++++++++ functions.lsp | 13 ------------- 6 files changed, 55 insertions(+), 13 deletions(-) create mode 100755 course/functions.lsp rename introduction.lsp => course/introduction.lsp (100%) create mode 100755 course/lambda_lists.lsp rename lists.lsp => course/lists.lsp (100%) create mode 100755 course/map.lsp delete mode 100755 functions.lsp 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) -- 2.34.1