Schript

JS designed for Macros.


Project maintained by mattneary Hosted on GitHub Pages — Theme by mattgraham

Schript

Schript will be a JavaScript dialect made more uniform, like Scheme. This allows for user-defined macros to work in a natural way; this is the primary motivation of the project.

Syntax

Definitions

defun(fact, n) {
    if(n) {
        *(n,fact(n-1))
    } {
        return(1)
    }
}
define(x, 5)

Invocation

write("Hello, World")

Macros

Macros have been implemented to allow syntax definition within programs. The following defines a let macro which will serve to define a variable over the scope of a block.

defmacro(let, name, val, expr) {
    defun(tmp, `name) {
        return(`expr)
    }
    tmp(`val)
}
let(a, 56) {
    write(a)
}

Note the back-tick notation which denotes an expression as a value to be inserted into the returned syntax; all other expressions are evaluated upon invocation of the macro.