defmacro added, doc improvements

This commit is contained in:
vaclavt
2022-01-29 15:35:42 +01:00
parent 249af03f60
commit f1d102130f
9 changed files with 155 additions and 97 deletions

View File

@@ -28,6 +28,7 @@
|`(do a b c ...)`|`do` takes a list of s-expressions and evaluates them in the order they were given (in the current scope), and then returns the result of the last s-expression.|This special form allows lambda functions to have multi-step bodies.|Language|
|`(scope a b c ...)`|`scope` takes a list of s-expressions and evaluates them in the order they were given _in a new scope_, and then returns the result of the last s-expression.|This special form allows the user to evaluate blocks of code in new scopes.|Language|
|`(defn name params body)`|`defn` evaluates none of its arguments.|This special form allows the user to conveniently define functions.|Language|
|`(defmacro name params body)`|`defmacro` evaluates none of its arguments.|This special form allows the user to conveniently define macros.|Language|
|`(def name value)`|`def` evaluates the `value` argument, which is then assigned to `name` in the current scope.|This special form allows the user to bind atoms to values in a scope.|Language|
|`(lambda params body)`|`lambda` evaluates none of its arguments.|This special form allows the user to define anonymous functions.|Language|
|`(quote x)`|`quote` evaluates none of its arguments.|This is equivalent to the `'expr` syntactic sugar.|Language|
@@ -36,6 +37,7 @@
|`(and ...)`|`and` evaluates logical and on its list argument.|`and` evaluates only until its true, it stops when becomes false.|Language|
|`(or ...)`|`or` evaluates logical or on its list argument.|`or` evaluates while its false, it stops when becomes true.|Language|
|`(benchmark msg_string ...)`|`benchmark` takes a list of s-expressions and evaluates them in the order they were given (in the current scope), and then returns the result of the last s-expression and prints msg_string and timing info.||Language|
|`(set! x)`|`set!` ...|....|Language|
## Library
|Signature|Description|Return values|Section|
@@ -68,7 +70,9 @@
|`(flatten list)`|Flattens a list to single level|`>>> (flatten '(1 (2 2) 3)) => (1 2 2 3)`|List manipulation|
|`(take list count)`|Returns sublist with count element of list|`>>> (take '(1 2 3 4) 3) => (1 2 3)`|List manipulation|
|`(make-list len)`|Return list with len nil elements|`(make-list 3) => (nil nil nil)`|List manipulation|
|`(make-list-of len value)`|Return list with len value elements||List manipulation|
|`(make-list-of size value)`|Makes list with size elements of values|`>>> (make-list-of 5 0) => (0 0 0 0 0)`|List manipulation|
|`(concat-lists seq1 seq2)`|Appends all elements from seq2 to seq1|`>>> (concat-lists '(1 2 3) '(4 5 6)) => (1 2 3 4 5 6)`|List manipulation|
|`(take lst size)`|Makes sublist of a lst with size length|`>>> (take '(1 2 3 4 5 6) 3) => (1 2 3)`|List manipulation|
|`(map ..)`|Returns list that is the result of executing lambda on its elements|`(map (lambda (x) (+ x 10)) '(1 2 3 4 5 6)) => (11 12 13 14 15 16)`|List manipulation|
|`(filter lambda list)`|Returns list with elements for which passed lambda returns true|`(filter (lambda (x) (> x 2)) '(1 2 3 4 5)) => (3 4 5)`|List manipulation|
|`(reduce lambda acumulator list)`|Reduces list|`>>> (reduce (lambda (x y) (+ (* x 10) y)) 0 '(1 2 3 4)) => 1234`|List manipulation|
@@ -133,20 +137,31 @@
|`(string value)`|Cast int or float item to a string|`>>> (string 3.14) => "3.14"`|Type casting|
|`(eval <exp>)`|Eval returns the value of the second evaluation|`>>> (eval '(+ 1 2)) => 3`|Language|
|`(type e)`|Returns data type of e|`>>> (type (+ 1 2)) => "int"`|Type casting|
|`(list? e)`|Returns true if type of e is list|`>>> (list? 12) => nil >>> (list? '(1 2)) => #t`|Type casting|
|`(empty-list? e)`|Returns true if type of e is empty list|`>>> (empty-list? '(1 2)) => nil >>> (empty-list? '()) => #t`|Type casting|
|`(string? e)`|Returns true if type of e is string|`>>> (string? "str") => #t`|Type casting|
|`(int? e)`|Returns true if type of e is integer|`>>> (int? "str") => nil >>> (int? 9) => #t`|Type casting|
|`(float? e)`|Returns true if type of e is float|`>>> (float? 9) => nil >>> (float? 9.0) => #t`|Type casting|
|`(nil? e)`|Returns true if type of e is nil|`>>> (nil? 9.0) => nil >>> (nil? nil) => #t >>> (nil? '()) => nil`|Type casting|
|`(true? e)`|Returns true if type of e is #t||Type casting|
|`(parse ..)`|Parses string to be evaluated|`>>> (eval (first (parse "(+ 1 2)"))) => 3`|Language|
|`(make-list-of size value)`|Makes list with size elements of values|`>>> (make-list-of 5 0) => (0 0 0 0 0)`|List manipulation|
|`(make-list size)`|Makes list of nil values with size length|`>>> (make-list 5) => (nil nil nil nil nil)`|List manipulation|
|`(empty-list? lst)`|Return true is lst is list with zero elements|`>>> (empty-list? '()) => 1`|Type casting|
|`(quick-sort-by list cmp)`|Returns list sorted by comparsion function||Language|
|`(quick-sort list)`|Return sorted list|`>>> (quick-sort '(2 4 6 1 7 3 3 9 5)) => (1 2 3 3 4 5 6 7 9)`|Language|
|`(quick-sort-reverse list)`|Return reverse sorted list|`>>> (quick-sort-reverse '(2 4 6 1 7 3 3 9 5)) => (9 7 6 5 4 3 3 2 1)`|Language|
|`(not c)`|Logical NOT of c|`>>> (not 1) => nil`|Logical|
|`(not c)`|Logical NOT of c|`>>> (not 1) => nil`|Language|
|`(neg n)`|Negates number|`>>> (neg -5) => 5`|Language|
|`(is-pos? n)`|Returns true if n is positive number||Language|
|`(is-neg? n)`|Returns true if n is negative number||Language|
|`(dec n)`|Return n decremented by 1|`>>> (dec 5) => 4`|Language|
|`(inc n)`|Return n incremented by 1|`>>> (inc 5) => 6`|Language|
|`(sleep time)`|Pauses execution for time interval of seconds||System|
|`(function? e)`|Returns true if type of e is lambda, macro or builtin|`>>> (function? index) => #t`|Language|
|`(unless test v)`|If test is not truthy then v is evaluated. This is macro.|`>>> (unless (> 1 2) "1 < 2") => "1 < 2"`|Language|
|`(dotimes v n body)`|Evaluates body n-times. For each eveluation v is set to value between 0 and n minus one|`(dotimes i 10 (print "i :" i))`|Language|
|`(doc::man "func_name")`|Prints short help for func_name||Language|
|`(doc::appropos "string")`|Looks for functions to be related passed string. String can be more words separated by space||Language|
|`(doc::look "string")`|Alias for appropos||Language|
|`(doc::lookup "string")`|Alias for appropos||Language|
|`(get-env var)`|Return environment variable var|`>>> (get-env "HOME") => "/Users/vaclavt"`|System|
|`(second list)`|Returns second element of list|`>>> (second '(1 2 3 4 5 6 7)) => 2`|List manipulation|
|`(third list)`|Returns third element of list|`>>> (third '(1 2 3 4 5 6 7)) => 3`|List manipulation|
@@ -160,5 +175,4 @@
|`(thread-sleep milisecons)`|Sleeps thread for given amount of miliseconds||Threading|
|`(threads-join)`|Wait for all running threads to finish||Threading|
|`(try block catch_block [finally_block])`|Evaluates block and if an exception is thrown, evaluates catch_block.Eventually in both cases evals finally_block. Return evaluated last expression from block if no exception or last expression from catch_block, if exception is thrown from block. Variable ml-exception in catch block is available with astring describing exception||Exceptions|
|`(throw-exception exp_desc)`|Throws an exception with exp_desc describing what happened ||Exceptions|
|`(xx ..)`|Desc|example|section|
|`(throw-exception exp_desc)`|Throws an exception with exp_desc describing what happened ||Exceptions|