personal pet project to teach myself Rust PL.
Also the purpose is to write full lisp intereter.
I followed this https://stopa.io/post/222 to write the several parts of interpeter
Future goal is to create language to use
instead of bash and its analogues.
- Basic arithmetic:
+
,-
,*
,/
- Basic logic :
>
,<
,=
,>=
,<=
,!
,&&
,||
- Output :
print
Prints all passed arguments. Compute it, if required. - If :
if
If condition is true, then compute first expression,
unless try to compute the second one, if it exists. - Variable (re)definition :
def
Takes 2 arguments: name and value - Lambdas:
(fn (a) (+ a 1))
Also you can execute it:
(print
(fn (a) (+ a 1) 2)
)
You can define it to use somewhere else:
(defn lmd
(fn (arg) (print arg))
)
(lmd! (2))
7)One line comment:
#(print "it won't never be printed")
- List operations:
returns first element of list.
(print
(head (1 2 4) )
)
result: 1
returns all list elements, except the first one.
(print
(tail (1 2 4) )
)
result:(2 4)
unites different value into the list.
(print
(concat (1 2 'hey' True (False 645)) )
)
result:(1 2 'hey' True False 645)
return the list element or None if it is out of borders.
(def list (1 2.55 'hello'))
(get 1 list)
result:(if you use it with print) 2.55
- Type checking
To find out the type of value you can usetype
operation.
(print (type 1))
result:'Number'
(print (type (1 4 True)))
result:'List'
(print (type 1 'hey' False))
result:('Number' 'String' 'Bool)
- Repeat
It is pretty experimental feature, but
it works in the same way, as cycle does.
(
defn test (fn (a)
(print a)
(def a (+ a 1))
(if (< a 10) repeat)
)
)