Strings, Arrays, and Objects

Strings

Strings can be created using the usual syntax with single quotes, double quotes,and backticks. Note that double quotes can be used for multiline strings. If you need a double quote inside the string, escape it with \". Elfenben also supports string interpolation using the same syntax as ES6:

(var text "World")

`Hello ${text}`

Produces Hello World

You can also concatenate strings using: (str "hello " "world")

Arrays

You can create arrays in a number of ways. You can use the built in functions/macros of the language. For example:

(array elem1 elem2 ....)

You can also create an array using the Javascript literal notation like [1, 2, 3, 4] however there is a difference. The literal notation is evaluated in the Javascript context, and will work in most cases except when you want some Elfenben code evaluated, like when one of the elements is a Elfenben anonymous function. And unlike Javascript "new Array" a single integer passed will still create a proper array with the int as the first element.

Create a Javascript Array of length length, with all elements initialized to initialVal(arrayInit 5 null) => [null, null, null, null, null]

(arrayInit length initialVal)

Create a Javascript Array of length outerLength, with all elements initialized to arrays of length innerLength, and all elements of inner arrays initialized to initialVal (arrayInit2d 2 3 null) => [[null, null, null], [null, null, null]

(arrayInit2d outerLength innerLength initialVal)

Objects

Create a Javascript Object. Note that you can also use the javascript syntax to create objects for example:{ a: 1, b: 2 }

(object a 1 b 2 c 3) => {a: 1, b:2, c:3}

(object key1 val1 key2 val2 ....)

Instantiate a new Javascript Object.

(new Classname arg1 arg2 ....)

(new Date)

(new Date "October 13, 1975 11:13:00")

results matching ""

    No results matching ""