From 3868a32168a02be60477a2ff8a2f5212764bb886 Mon Sep 17 00:00:00 2001 From: VaclavT Date: Tue, 2 Mar 2021 23:11:57 +0100 Subject: [PATCH] nth function added to stdlib, doc updates --- Readme.md | 5 +++++ debug.lsp | 27 --------------------------- doc/Doc.md | 16 +++++++++------- stdlib/stdlib.lsp | 3 +++ 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/Readme.md b/Readme.md index cc0eacd..2ec0c7d 100644 --- a/Readme.md +++ b/Readme.md @@ -85,3 +85,8 @@ https://stackoverflow.com/questions/478898/how-do-i-execute-a-command-and-get-th https://www.skysilk.com/cloud/pricing/#classId=Standard§ion=2 https://contabo.com/en/ https://www.hetzner.com/de/ + +#### Editor +https://viewsourcecode.org/snaptoken/kilo/07.syntaxHighlighting.html +http://antirez.com/news/108 +https://github.com/antirez/kilo diff --git a/debug.lsp b/debug.lsp index 5c9aeaf..8862f80 100644 --- a/debug.lsp +++ b/debug.lsp @@ -1,32 +1,5 @@ (print "Debug starts") -; add support for () -(print "(member '(1 2 3) 1:" (member '(1 2 3) 1)) -(print "(member '(1 2 3) 3:" (member '(1 2 3) 3)) -(print "(member '(1 2 3) 30:" (member '(1 2 3) 30)) - - -(print "result of (and (> 2 1) (> 2 1)): " (and (> 2 1) (> 2 1))) -(print "result of (or (> 2 1) (> 2 1)): " (or (> 2 1) (> 2 1))) -(print "result of (and (> 2 1) (> 1 2)): " (and (> 2 1) (> 1 2))) -(print "result of (or (> 2 1) (> 1 2)): " (or (> 2 1) (> 1 2))) -(print "result of (and (> 1 1) (> 1 2)): " (and (> 1 1) (> 1 2))) -(print "result of (or (> 1 1) (> 2 1)): " (or (> 1 1) (> 1 2))) - -;; (print (member '(1 2 3) 1)) -;; (print (member '(1 2 3) 10)) - - - -(print (string-rpad "rpad0123456789" 10 "x")) -(print (string-rpad "rpad " 10 "x")) - -(print (string-lpad "lpad" 10 "x")) - -(print nil) -(print ()) - -(print (make-list 5)) (print "Debug ends") diff --git a/doc/Doc.md b/doc/Doc.md index a6eb331..b68934e 100644 --- a/doc/Doc.md +++ b/doc/Doc.md @@ -34,16 +34,18 @@ |`(remove list index)`|Remove a value at an index from a list|List with element removed| |`(len list)`|Get the length of a list|list length| |`(push list element)`|Add an item to the end of a list|new list with element added| -|`(pop ..)`||| +|`(pop list)`|Returns last element of list|Last element| |`(head list)`|Returns first element of a list|First element| |`(tail list)`|Return all elements of list except first one|List without first element| -|`(first ..)`||| -|`(last ..)`||| -|`(range ..)`||| +|`(first list)`|Returns first element of a list|First element| +|`(last list)`|Returns last element of list|Last element| +|`(range low high)`|Returns list with elements in range low .. high|`(range 1 5) => (1 2 3 4)`| |`(member list item)`||| -|`(map ..)`||| -|`(filter ..)`|`(filter (lambda (x) (> x 2)) '(1 2 3 4 5)) => (3 4 5)`|| -|`(reduce ..)`||| +|`(make-list len)`|Return list with len nil elements|`(make-list 3) => (nil nil nil)`| +|`(make-list-of len value)`||| +|`(map ..)`||`(map (lambda (x) (+ x 10)) '(1 2 3 4 5 6)) => (11 12 13 14 15 16)`| +|`(filter lambda list)`||`(filter (lambda (x) (> x 2)) '(1 2 3 4 5)) => (3 4 5)`| +|`(reduce lambda acumulator list)`||`>>> (reduce (lambda (x y) (+ (* x 10) y)) 0 '(1 2 3 4)) => 1234`| |`(exit ..)`||| |`(quit ..)`||| |`(print ..)`||| diff --git a/stdlib/stdlib.lsp b/stdlib/stdlib.lsp index c1ed474..6b84c49 100644 --- a/stdlib/stdlib.lsp +++ b/stdlib/stdlib.lsp @@ -49,6 +49,9 @@ ; return fifth element of list (defun fifth (l) (index l 4)) +; return nth element of list, indexing from 0 +(defun nth (i l) (index l i)) + ; return 1 when list contains item otherwise 0 (defun member (lst itm) (do