Weird Lisp interpreter.
https://dawdmaow.github.io/lisp/
- OOP-like object types
- Enum types for type-safe constants
- Exception handling with try/catch/finally blocks
- Template system with unquote and unquote-splicing
- Table/dictionary data structures with key-value storage
- Functions with type-checked parameters
- Variable scoping with block-level scope management
- Syntax highlighting powered by Ace Editor with Clojure mode
- Real-time code evaluation with immediate feedback
nimble install
nimble build
./server.sh;; Numbers
(x := 42)
(pi := 3.14159)
;; Strings
(name := "Hello, World!")
;; Booleans
(flag := true)
(other := false);; Define a 2D vector type
(vec2 := (object-type ((x number) (y number))))
;; Create an instance
(v := (vec2 ((x 10) (y 20))))
;; Access fields
(echo v.x) ;; prints 10
(echo v.y) ;; prints 20;; Define an enum for chess pieces
(PieceKind := (enum-type "pawn" "rook" "knight" "bishop" "queen" "king"))
;; Use the enum
(piece := (PieceKind "queen"));; Untyped function
(add := (\ (a b) any (a + b)))
;; Typed function with type checking
(multiply := (\ ((x number) (y number)) number (x * y)))
;; Call functions
(result := (add 5 3)) ;; 8
(product := (multiply 4 7)) ;; 28;; Conditional expressions
(result := (if (> x 0) "positive" "non-positive"))
;; Exception handling
(try
(risky-operation)
(except
(echo "An error occurred")
)
(finally
(cleanup)
)
);; Define a template for conditional execution
(unless := (template (cond body)
(if (not ^unquote cond)
(block
^unquote-splicing body
)
)
))
;; Use the template
(unless false ((echo "This will run")));; Create a table
(colors := (table ("red" "#FF0000") ("green" "#00FF00") ("blue" "#0000FF")))
;; Access values
(red-color := (colors "red")) ; "#FF0000"# Build for JavaScript/Web
nim js -d:release src/lisp.nim
# Build for native execution
nim c -d:release src/lisp.nim