Overview

In Elfenben we write Javascript in a tree structure. If you know Javascript and a Lisp like language, then using Elfenben will be a breeze. Even if you don't know a Lisp Language, all you need to learn is to write code in a tree structure.

Hello World

(console.log "Hello Elfenben!")

An Elfenben program is made up of expressions in parenthesis. The first element in the expression is a function or an Elfenben keyword. The rest of the elements (separated by space characters) are the arguments to the function. As you can see above we can directly access javascript functions from Elfenben.

A more intricate Hello World!

(if (undefined? window)

(console.log "Hello Elfenben!")

(alert "Hello Elfenben!"))

You can have expressions within expressions.

Elfenben is Javascript!

All Javascript functions, objects and literals can be used in Elfenben. Elfenben also exposes javascript keywords such as let, const, and so on.

Variables

Declaring Variables

(var myVar "This is myVar!")

(let blockScopedVariable [1,2,3,4])

(const cannotBeChangedVariable 9001)

You may also declare multiple variables at once

(var name1 value1 name2 value2 ...)

Setting variables

(set myVar "This is Sparta!")

Functions

Named function.

(function sayHello (name) (console.log (str "Hello " name)))

An anonymous function.

(function (x) (* x x))

The first element in an expression can be an anonymous function.

((function (x) (* x x)) 2)

That was the anonymous function above evaluated immediately with argument 2.

Functions return the last expression evaluated within the function.

You can set a variable name to a function.

(let square (function (x) (* x x))) (console.log (square 10))

Comments

Comments in Elfenben start with a ; and span the rest of the line.

results matching ""

    No results matching ""