summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md101
1 files changed, 52 insertions, 49 deletions
diff --git a/README.md b/README.md
index d193110..cb99cfc 100644
--- a/README.md
+++ b/README.md
@@ -51,23 +51,26 @@ mind. What you write, becomes part of who you are.
### Numeric operations
-lali supports the five arithmetic operations `+`, `-`, `*`, `/`, `%` (with `%` the
-operands are automatically converted to integer) as well as the relational
+For lali to recognize numbers, numbers have to be prefixed or by `+` (for positive
+numbers) or by `-` (for negative numbers).
+
+There is support for the five arithmetic operations `+`, `-`, `*`, `/`, `%` (with
+`%` the operands are automatically converted to integer) as well as the relational
operations `!` (different), `<`, `>`:
- (- 5) ; -5
- (- 5 3.2 .6) ; 1.2
- (< 2 4 6.8) ; t
- (> 4 8) ; f
- (! 4 4) ; f
+ (- +5) ; -5
+ (- +5 +3.2 +.6) ; +1.2
+ (< +2 +4 +6.8) ; t
+ (> +4 +8) ; f
+ (! +4 +4) ; f
#### Random number operation
`(random [number])` takes no or one number argument, returns a random number below
`number` until 0.
- (random) ; 2.1442e+09
- (random 2) ; returns 0 or 1
+ (random) ; +747528572
+ (random 2) ; returns +0 or +1
### Processing operations
@@ -93,19 +96,19 @@ do something at the beginning, because other cons cells should never have `()` i
`(list ...)` returns a list containing the supplied arguments:
(list) ; ()
- (list 1 2 3) ; (1 2 3)
- (list 1 2 (+ 1 2)) ; (1 2 3)
+ (list +1 +2 +3) ; (+1 +2 +3)
+ (list +1 +2 (+ +1 +2)) ; (+1 +2 +3)
`(cons x y)` creates a new cons cell, the `car` of which is `x` and the `cdr` of
which is `y`:
- (cons 1 2) ; (1 . 2)
- (cons 1 '(2)) ; (1 2)
+ (cons +1 +2) ; (+1 . +2)
+ (cons +1 '(+2)) ; (+1 +2)
`(car x)`, `(cdr x)` return the `car` and `cdr` of a list respectively:
- (car '(1 2 3)) ; 1
- (cdr '(1 2 3)) ; (2 3)
+ (car '(a b c)) ; a
+ (cdr '(a b c)) ; (b c)
### Predicates
@@ -113,62 +116,62 @@ which is `y`:
numbers with different values, or if they are string objects with different
contents:
- (dif 1 1) ; f
- (dif 1 2) ; t
+ (dif +1 +1) ; f
+ (dif +1 +2) ; t
(dif 'a 'a) ; f
(dif 'a 'b) ; t
(dif t t) ; f
(dif t f) ; t
- (dif '(1 2) '(1 2)) ; t
+ (dif '(a b) '(a b)) ; t
`(differ x y)` returns `t` if `x` and `y` are objects of different structure and
each of their elements satisfy the `dif` predicate, otherwise `f`:
- (differ '(1 2) '(1)) ; t
- (differ '(1 2) '(1 2)) ; f
+ (differ '(a b) '(a)) ; t
+ (differ '(a b) '(a b)) ; f
`(space x)` returns `t` if `x` is an empty list `()`, otherwise `f`:
(space ()) ; t
- (space 1) ; f
+ (space +1) ; f
(space t) ; f
- (space '(1 2)) ; f
+ (space '(a b)) ; f
`(ap x)` returns `t` if `x` is "an existing thing" (not an empty list `()`),
otherwise `f`:
(ap ()) ; f
- (ap 1) ; t
+ (ap +1) ; t
(ap t) ; t
- (ap '(1 2)) ; t
+ (ap '(a b)) ; t
`(atom x)` returns `t` if `x` is an atom (and not an empty list `()`), otherwise
`f`:
(atom ()) ; f
- (atom 1) ; t
+ (atom +1) ; t
(atom t) ; t
- (atom '(1 2)) ; f
+ (atom '(a b)) ; f
`(listp x)` returns `t` if `x` is either an empty list `()`, or a list with
atom(s), otherwise `f`:
(listp ()) ; t
- (listp 1) ; f
+ (listp +1) ; f
(listp t) ; f
- (listp '(1 2)) ; t
+ (listp '(a b)) ; t
`(consp x)` returns `t` if `x` is a list with atom(s), otherwise `f`:
(consp ()) ; f
- (consp 1) ; f
+ (consp +1) ; f
(consp t) ; f
- (consp '(1 2)) ; t
+ (consp '(a b)) ; t
`(zerop x)` returns `t` if `x` is the number zero, otherwise `f`:
- (zerop 0) ; t
- (zerop 1) ; f
+ (zerop +0) ; t
+ (zerop +1) ; f
(zerop t) ; error: t is not a number
### Logical operations
@@ -182,16 +185,16 @@ arguments. Otherwise, it returns the value produced by evaluating its last
argument. If no arguments are supplied, `and` returns `t`:
(and) ; t
- (and 1 2 3) ; 3
- (and 1 f 3) ; f
+ (and +1 +2 +3) ; +3
+ (and +1 f +3) ; f
`(or ...)` evaluates its arguments one at a time from left to right. As soon as
any argument does not evaluate to `f`, `or` returns its value without evaluating
the remaining arguments. Otherwise, it returns `f`:
(or) ; f
- (or 1 2 3) ; 1
- (or f f 3) ; 3
+ (or +1 +2 +3) ; +1
+ (or f f +3) ; +3
### Conditionals
@@ -255,10 +258,10 @@ evaluation of further expressions and returning the symbol of the evaluation of
the symbol of `expr-var-A` evaluated. More than one `expr-var`-`expr-val` pair can
be given. `set` returns the value bound to the last symbol:
- (set 'a 1
- 'b 2) ; 2
- a ; 1
- b ; 2
+ (set 'a +1
+ 'b +2) ; +2
+ a ; +1
+ b ; +2
### Defining functions
@@ -270,18 +273,18 @@ variable number of arguments:
((lambda ()
'Hello)) ; Hello
((lambda (a b)
- (+ a b)) 1 2) ; 3
+ (+ a b)) +1 +2) ; +3
((lambda (a b . c)
- c) 1 2 3 4 5) ; (3 4 5)
+ c) +1 +2 +3 +4 +5) ; (+3 +4 +5)
((lambda args
- args) 1 2 3 4 5) ; (1 2 3 4 5)
+ args) +1 +2 +3 +4 +5) ; (+1 +2 +3 +4 +5)
`(defun name params expr...)` creates a function and binds it to the symbol
`name`:
(defun plus1 (x)
- (+ x 1)) ; #<Lambda (x)>
- (plus1 2) ; 3
+ (+ x +1)) ; #<Lambda (x)>
+ (plus1 +2) ; +3
### Defining macros
@@ -297,9 +300,9 @@ returning a new expression as output.
Imagine we want to implement `(when test expr...)`:
- (set 'x '(1 2 3)) ; (1 2 3)
+ (set 'x '(+1 +2 +3)) ; (+1 +2 +3)
(when (consp x)
- (car x)) ; 1
+ (car x)) ; +1
(set 'x 'hello)
(when (consp x)
(car x)) ; n
@@ -312,7 +315,7 @@ would be evaluated as soon as `when` is called:
(car x)) ; error: Hello is not a list
However, we can implement `when` as a macro that wraps `expr...` in a call to
-`if`:
+`cond`:
(defmacro when (test . expr)
(list cond (list test (cons 'prog expr))))
@@ -361,7 +364,7 @@ outputting them without the initial/ending parenthesis:
`(time)` gives a timestamp in (sec minute hour day month year dow dst utcoff).
- (time) ; (23 54 17 13 5 2025 2 t 3600)
+ (time) ; (+34 +22 +17 +29 +5 +2025 +4 t +3600)
## Copyright