Bracketlang

A lisp-like interpreter for the web :)

How To Use

Basic Syntax

Lisp follows a basic syntax of (FUNCTION ARGUMENTS). For instance, if you wanted to add 3 and 5, you could write (+ 3 5).

To define a variable, you can use the def! function, like so:

=> (def! x 3)
3
=> x
3

For control flow, there is an if statment with the syntax (if CONDITION TRUE_PATH FALSE_PATH). false and nil are false, everything else is true.

=> (if true "hello" "world")
"hello"
=> (if false "hello" "world")
"world"

For creating functions, you can use fn*:

=> (def! addone (fn* (x) (+ x 1)))
Closure(0x?????)
=> (addone 3)
4

You can also create variadic arguments using &:

=> (def! test (fn* (& x) (cons "hello" x)))
Closure(0x?????)
=> (test 3 2 3)
("hello" 3 2 3)

For creating loops... don't. Use recursion instead.

Data Types

Useful Functions

Add, subtract, multiply, divide, gt, lt, gte, lte, equals all work as expected. Other than those basics, there is also:

More Control Flow

This language also has try/catch/throw functionality:

=> (try* (throw "whoops") (fn* (error) (prn error)))
whoops

The let* special form lets you temporarily set variables

=> (let* (c 3) (+ c 1))
4

The do special form lets you run multiple blocks of code, only returning the last one.

=> (do 1 2 (prn "hello") 3 4)
hello
4

Macros and Metaprogramming

Now for the fun part.



...and thats all there is to it! Enjoy!