Palet Scripting Reference

This manual describes the complete overview of the palet scripting language.

Palet is an anagram-acronym of the words: (A)uto-(E)ditor's (T)iny (P)rocedural (L)anguage

Basic Syntax

Syntax

(define id expr)

Set id to the result of expr.

Syntax

(set! id expr)

Set the result of expr to id if id is already defined. If id is not defined, raise an error.

Syntax

(lambda / λ args body)

Produces a procedure that accepts args arguments and runs body when called.

Syntax

(if test-expr then-expr else-expr)

Evaluates test-expr. If #t then evaluate then-expr else evaluate else-expr. An error will be raised if evaluated test-expr is not a boolean?.

Syntax

(when test-expr body)

Evaluates test-expr. If #t then evaluate body else do nothing. An error will be raised if evaluated test-expr is not a boolean?.

Loops

Syntax

(for ([id seq-expr] ...) body)

Loop over seq-expr by setting the variable id to the nth item of seq-expr and evaluating body.

Syntax

(for/vector ([id seq-expr] ...) body)

Like for but returns a vector with the last evaluated elements of body.

Equality

Procedure

(equal? v1 v2) → boolean?

 v1 : any

 v2 : any

Returns #t if v1 and v2 are the same type and have the same value, #f otherwise.

Procedure

(eq? v1 v2) → boolean?

 v1 : any

 v2 : any

Returns #t if v1 and v2 refer to the same object in memory, #f otherwise.

Booleans

Procedure

(boolean? v) → boolean?

 v : any

Returns #t if v is #t or #f, #f otherwise.

Value

true  : boolean?

An alias for #t.

Value

false  : boolean?

An alias for #f.

Number Predicates

Procedure

(number? v) → boolean?

 v : any

Returns #t if v is a number, #f otherwise.

Procedure

(real? v) → boolean?

 v : any

Returns #t if v is a real number, #f otherwise.

Procedure

(integer? v) → boolean?

 v : any

Returns #t if v is an integer, #f otherwise.

Procedure

(nonnegative-integer? v) → boolean?

 v : any

Returns #t if v is an integer and v is greater than -1, #f otherwise.

Procedure

(zero? v) → boolean?

 v : real?

Returns #t if v is equal to 0, #f otherwise.

Procedure

(positive? v) → boolean?

 v : real?

Returns #t if v is greater than 0, #f otherwise.

Procedure

(negative? v) → boolean?

 v : real?

Returns #t if v is less than 0, #f otherwise.

Numbers

Procedure

(+ z ...) → number?

 z : number?

Return the sum of zs. Add from left to right. If no arguments are provided, the result is 0.

Procedure

(- z w ...) → number?

 z : number?

 w : number?

When no ws are applied, return (- 0 z). Otherwise, return the subtraction of ws of z.

Procedure

(* z ...) → number?

 z : number?

Return the product of zs. If no zs are supplied, the result is 1.

Procedure

(/ z w ...) → number?

 z : number?

 w : number?

When no ws are applied, return (/ 1 z). Otherwise, return the division of ws of z.

Procedure

(mod n m) → integer?

 n : integer?

 m : integer?

Return the modulo of n and m.

Procedure

(modulo n m) → real?

 n : real?

 m : real?

Clone of mod.

Procedure

(add1 z) → number?

 z : number?

Returns (+ z 1).

Procedure

(sub1 z) → number?

 z : number?

Returns (- z 1).

Procedure

(= z w ...) → boolean?

 z : number?

 w : number?

Returns #t if all arguments are numerically equal, #f otherwise.

Procedure

(< x y) → boolean?

 x : real?

 y : real?

Returns #t if x is less than y, #f otherwise.

Procedure

(<= x y) → boolean?

 x : real?

 y : real?

Returns #t if x is less than or equal to y, #f otherwise.

Procedure

(> x y) → boolean?

 x : real?

 y : real?

Returns #t if x is greater than y, #f otherwise.

Procedure

(>= x y) → boolean?

 x : real?

 y : real?

Returns #t if x is greater than or equal to y, #f otherwise.

Procedure

(abs x) → real?

 x : real?

Returns the absolute value of x.

Procedure

(max x ...) → real?

 x : real?

Returns largest value of the xs.

Procedure

(min x ...) → real?

 x : real?

Returns smallest value of the xs.

Procedure

(pow z w) → real?

 z : real?

 w : real?

Returns z raised to the w power.

Vectors

Procedure

(vector? v) → boolean?

 v : any

Returns #t if v is a vector, #f otherwise.

Procedure

(vector v ...) → vector?

 v : any

Returns a new vector with the v args filled with its slots in order.

Procedure

(make-vector size [v]) → vector?

 size : nonnegative-integer?

 v : any = 0

Returns a new vector with size slots, all filled with vs.

Procedure

(vector-pop! vec) → any

 vec : vector?

Remove the last element of vec and return it.

Procedure

(vector-add! vec v)

 vec : vector?

 v : any

Append v to the end of vec.

Procedure

(vector-set! vec pos v)

 vec : vector?

 pos : integer?

 v : any

Set slot pos of vec to v.

Procedure

(vector-extend! vec vec2 ...)

 vec : vector?

 vec2 : vector?

Append all elements of vec2 to the end of vec in order.

Arrays

Procedure

(array? v) → boolean?

 v : any

Returns #t if v is an array, #f otherwise.

Procedure

(array dtype v ...) → array?

 dtype : symbol?

 v : any

Returns a freshly allocated array with dtype as its datatype and the v args as its values filled in order.

Procedure

(array-splice! arr v [start] [stop]) → array?

 arr : array?

 v : real?

 start : integer? = 0

 stop : integer? = (length arr)

Modify arr by setting start to stopto v.

Procedure

(margin left [right] arr) → bool-array?

 left : integer?

 right : integer? = left

 arr : bool-array?

Returns a new bool-array? with left andright margin applied.

Pairs and Lists

Procedure

(pair? v) → boolean?

 v : any

Returns #t if v is a pair, #f otherwise.

Procedure

(null? v) → boolean?

 v : any

Returns #t if v is an empty list, #f otherwise.

Procedure

(cons a d) → pair?

 a : any

 d : any

Returns a newly allocated pair where the first item is set to a and the second item set to d.

Procedure

(car p) → any?

 p : pair?

Returns the first element of the pair p.

Procedure

(cdr p) → any?

 p : pair?

Returns the second element of the pair p.

Procedure

(list? v) → boolean?

 v : any

Returns #t if v is an empty list or a pair whose second element is a list.

Procedure

(list v ...) → list?

 v : any

Returns a list with v in order.

Procedure

(list-ref lst pos) → any

 lst : list?

 pos : nonnegative-integer?

Returns the element of lst at position pos.

Ranges

Procedure

(range? v) → boolean?

 v : any

Returns #t if v is a range object, #f otherwise.

Procedure

(range start stop [step]) → range?

 start : integer?

 stop : integer?

 step : integer? = 1

Returns a range object.

Generic Sequences

Procedure

(iterable? v) → boolean?

 v : any

Returns #t if v is a vector, array, string, hash, pair, or range, #f otherwise.

Procedure

(sequence? v) → boolean?

 v : any

Returns #t if v is a vector, array, string, pair, or range, #f otherwise.

Procedure

(length seq) → nonnegative-integer?

 seq : iterable?

Returns the length of seq.

Procedure

(ref seq pos) → any

 seq : iterable?

 pos : integer?

Returns the element of seq at position pos, where the first element is at position0. For sequences other than pair?, negative positions are allowed.

Procedure

(slice seq start [stop] [step]) → sequence?

 seq : sequence?

 start : integer?

 stop : integer? = (length seq)

 step : integer? = 1

Returns the elements of seq from start inclusively to stop exclusively. If step is negative, then stop is inclusive and start is exclusive.

Procedure

(reverse seq) → sequence?

 seq : sequence?

Returns seq in reverse order.

Hashmaps

Procedure

(hash? v) → boolean?

 v : any

Returns #t if v is a hash table, #f otherwise.

Procedure

(hash key val ...) → hash?

 key : any

 val : any

Returns a newly contructed hash map from key-value pairs.

Procedure

(has-key? hash key) → boolean?

 hash : hash?

 key : any

Returns #t if key is in the hash map, #f otherwise.

Input / Output

Procedure

(display datum) → void?

 datum : any

Display datum to stdout.

Procedure

(displayln datum) → void?

 datum : any

Display datum, to stdout with a newline character.

Procedure

(print datum) → void?

 datum : any

Display datum, like REPL does.

Syntax

(with-open (file-binding file-path file-mode) body-expr)

In the block, the file object to file-binding .(with-open (file "todo.txt" 'a) ((. file write) "buy milk"))

Objects

Syntax

(. obj attr)

Returns the specified attribute on the object.

Misc. Predicates

Procedure

(any v) → boolean?

 v : any

Returns #t regardless of the value of v.