LispTick Wiki

LispTick Syntax

Atoms

LispTick has nine types of Atoms: ints, floats, strings, chars, bools, datetimes, durations, dataorigins, and symbols. The following are different kinds of literal syntax for these atoms.

Note that semicolons are used for single-line comments. The syntax for symbols is quite flexible. Any non-whitespace character other than ' or # can be used in a symbol.

Lists

Lists are just cons-cell lists like in other LISP dialects and are delimited by parentheses

You can also just describe plain pairs (cons-cells in which the tail is not necessarily a list) using the dotted syntax.

Arrays

Arrays correspond to Go slices and are delimited by square braces.

Hashes

LispTick has mutable hashmaps which use Go maps internally. The literal syntax uses curly braces

The hash above maps a to 3 and b to 2. Hash keys can only be integers, strings, chars, or symbols.

Quoting

The quote symbol ' indicates that the following expression should be interpreted literally. This is useful for declaring symbols and lists.

Functions

An anonymous function can be declared in LispTick like so

A function can be declared with a name using defn.

Note that like in Clojure, the argument list is given in an array instead of a list.

Bindings

A binding can be added in the current scope using def. You can also create a new scope and declare bindings in it using let or let*.

The difference between let and let* is that let creates bindings all at once, so you will not be able to access earlier bindings in later bindings. The let* form creates bindings one by one, so each binding can access bindings declared before it.

Calling functions

Functions can be called in the regular way.

They can also be called indirectly using apply.

This works exactly the same with anonymous functions

Conditionals

LispTick has only a single conditional statement, cond. The syntax is as follows.

The cond statement will check the conditions in order. If the condition is true, it will return the result of the corresponding expression. If not, it will move on the next condition. If none of the conditions are true, it will return the result of the default expression. The default expression is the only required portion of this statement. The way to think of this is that the first condition/expression pair is an if statement, the second is an else if statement, and the default is the else statement.

LispTick also provides the short-circuit boolean operators and and or. The and expression will return the first "falsy" sub-expression or, if all sub-expressions are "truthy", the last sub-expression is returned. The or expression is the opposite, returning the first "truthy" expression or the last expression.

The boolean false, the null value (empty list), the integer 0, and the null character are considered "falsy". All other values are considered "truthy".

Sequencing

The begin statement is used to sequence expressions. It will run all sub-expressions and return the result of the final expression. The top-level, function bodies, and let-statement bodies have implicit begin statements.

Builtin Functions

The following builtin functions are provided by the language runtime.

Integer shift operations

  • sll (shift-left logical)
  • sra (shift-right arithmetic)
  • srl (shift-right logical)

Bitwise operations

  • bit-and
  • bit-or
  • bit-xor
  • bit-not (one's complement)

Boolean operations

  • not

Arithmetic, applicable on timeserie

  • +
  • -
  • *
  • /
  • max
  • min
  • mod (modulo, not for timeserie)
  • abs
  • exp
  • log
  • log10
  • round
  • sqr
  • sqrt

Comparisons

  • <
  • >
  • <=
  • >=
  • =
  • not=

Type Introspection

  • zero? (returns true only for 0, 0.0, and null character)
  • null? (returns true only for ())
  • empty? (returns true only for (), [], and {})
  • list?
  • array?
  • number? (int, char, or float)
  • int?
  • float?
  • char?
  • string?
  • symbol?
  • hash?
  • time? (returns true if date or time)
  • duration? (returns true for difference of time for example)
  • timeserie? (returns true for any timeserie)

Printing

  • println
  • print

Array Functions

The array function can be used to construct an array. It is identical to the square brace literal syntax.

The make-array function creates an array of a given length. By default, the items in the array are intialized to null.

The aget function indexes into an array.

The aset! function modifies the value in the array at the given index

So yes, arrays are mutable in LispTick.

List Functions

The list, cons, first, and rest functions operate the same as in other LISP dialects. Note, however, that first and rest can also work on arrays.

String Functions

The sget function is similar to the aget function, except it operates on characters of a string instead of elements of a list.

The functions contains, has-prefix and has-suffix allows to check if a susbtring is part, start or end of a string.

Hashmap functions

The hget function retrieves a value from the hashmap by key.

You can give the hget function a third argument, which is the default value that will be returned if the key is not found. If no default is given and the key is not found, a runtime error will occur.

The hset! function works similar to aset! but using a key instead of an index.

The hdel! function takes a hash and a key and deletes the given key from the hash.

Generic Container Operations

The append function can append an expression to the end of an array or a character onto the end of a list.

The concat function can concatenate two arrays, two strings, or two lists

The len function returns the number of elements in an array or number of characters in a string.