Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weird Lisp interpreter.

Online

https://dawdmaow.github.io/lisp/

Features

  • 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

Web Interface

  • Syntax highlighting powered by Ace Editor with Clojure mode
  • Real-time code evaluation with immediate feedback

Building

nimble install
nimble build
./server.sh

Language Syntax

Basic Types

;; Numbers
(x := 42)
(pi := 3.14159)

;; Strings
(name := "Hello, World!")

;; Booleans
(flag := true)
(other := false)

Object Types

;; 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

Enums

;; Define an enum for chess pieces
(PieceKind := (enum-type "pawn" "rook" "knight" "bishop" "queen" "king"))

;; Use the enum
(piece := (PieceKind "queen"))

Functions

;; 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

Control Flow

;; Conditional expressions
(result := (if (> x 0) "positive" "non-positive"))

;; Exception handling
(try
    (risky-operation)
    (except
        (echo "An error occurred")
    )
    (finally
        (cleanup)
    )
)

Macros and Templates

;; 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")))

Tables (Key-Value Storage)

;; Create a table
(colors := (table ("red" "#FF0000") ("green" "#00FF00") ("blue" "#0000FF")))

;; Access values
(red-color := (colors "red"))  ; "#FF0000"

Targets

# Build for JavaScript/Web
nim js -d:release src/lisp.nim

# Build for native execution
nim c -d:release src/lisp.nim

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages