/another-lisp

personal pet project to teach myself Rust PL.

Primary LanguageRust

another-lisp

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.

Abilities

  1. Basic arithmetic: +, -, * ,/
  2. Basic logic : >, <, =, >=, <=, !, &&, ||
  3. Output : print
    Prints all passed arguments. Compute it, if required.
  4. If : if
    If condition is true, then compute first expression,
    unless try to compute the second one, if it exists.
  5. Variable (re)definition : def
    Takes 2 arguments: name and value
  6. 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")
  1. List operations:

head

returns first element of list.

(print
    (head (1 2 4) )
)

result: 1

tail

returns all list elements, except the first one.

(print
    (tail (1 2 4) )
)

result:(2 4)

concat

unites different value into the list.

(print
    (concat (1 2 'hey' True (False 645)) )
)

result:(1 2 'hey' True False 645)

get

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

  1. Type checking
    To find out the type of value you can use type operation.

Example 1:

(print (type 1))

result:'Number'

Example 2:

(print (type (1 4 True)))

result:'List'

Example 3:

(print (type 1 'hey' False))

result:('Number' 'String' 'Bool)

  1. Repeat
    It is pretty experimental feature, but
    it works in the same way, as cycle does.

Example:

(
    defn test (fn (a)
                (print a)
                (def a (+ a 1))
                (if (< a 10) repeat)
              )
              
)