Skip to content

Latest commit

 

History

History
106 lines (89 loc) · 1.98 KB

README.md

File metadata and controls

106 lines (89 loc) · 1.98 KB

CamLisp (WIP)

A toy Lisp/Scheme interpreter in OCaml.

Getting Started

Make sure that you have dune and opam ready.

dune --version
# 3.7.1
opam --version
# 2.1.3

Install dependencies:

...

Run the binary:

dune exec camlisp

Test the REPL:

=> 1
1
=> (define x 1)
1
=> (+ x 1)
2
=> (define (fact n)
..   (if (= n 1)
..     1
..     (* n (fact (- n 1)))))
(lambda (n) (if (= n 1) 1 (* n (fact (- n 1)))))
=> (fact 5)
120
=> (define (fact-iter n)
..   (define (iter result n)
..     (if (= n 1)
..       result
..       (iter (* result n) (- n 1))))
..   (iter 1 n))
(lambda ...)
=> (fact-iter 5)
120

Run unit tests:

dune test

TODO

  • Implement +, -, *, and /
    • Redefine the underlying type to make the operators work for both int and float
    • Find a strategy to turn the operators into a "normal" Func?
  • Implement lambda
    • Add dot notation
  • Implement define
    • Add dot notation
  • Implement cons, car and cdr
  • Implement quote
  • Implement let and let* (done since let acts like let* in this case for the way env works)
  • Implement set!
  • Implement eval and apply
  • Research how to release/distribute the built binary
  • Improve error handling by separating user's error to internal evaluator error
  • Implement a "proper" CLI experience:
    • Interactive mode --interactive
    • Interactive mode with files preloading
    • Compiling
  • Add tests
    • Tokenizer.is_balance
    • Tokenizer.tokenize
    • Parser.parse_expr
    • Parser.parse_lambda
    • Parser.parse_define
    • Parser.parse_if
    • Parser.parse_let
    • Parser.parse_one
    • Parser.parse
    • Evaluator.compare_nodes
    • Evaluator.is_self_eval
    • Evaluator.try_eval_int
    • Evaluator.make_operator_handler
    • Evaluator.apply
    • Evaluator.eval