Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

core

List of symbols:

euid, last-command, last-status, uid, =, apply, back-quote, block, comp-time, dec!, def, defmacro, defn, do, doc, doc-raw, dotimes, dotimes-i, dump-globals, dyn, env, err, eval, exit, expand-macro, fn, gensym, get-error, get-globals, get-prop, identity, inc!, is-noop, len, let, let-while, load, load-rc, loop, macro, mk-err, noop, noop-fn, not=, not==, nsubstitute!, occurs, on-raised-error, platform, quote, recur, set!, set-env, set-prop, sizeof-heap-object, sizeof-value, substitute, to-list, to-vec, un-noop-fn, unset-env, usage

euid

Usage: (prn euid)

Namespace: root

Return effective system uid as a String.

Example:

#t

last-command

Usage: (prn last-command)

Namespace: root

Return last run command as a String.

Example:

#t

last-status

Usage: (prn last-status)

Namespace: root

Return last exit code as an Int.

Example:

#t

uid

Usage: (prn uid)

Namespace: root

Return system uid as a String.

Example:

#t

=

Usage: (= val0 val1)

Namespace: root

Test equality, works for most value types where it makes sense, not just primitives.

Example:

(test::assert-false (= "aab" "aaa"))
(test::assert-true (= "aaa" "aaa"))
(test::assert-true (= "aaa" "aaa" "aaa"))
(test::assert-false (= "aaa" "aaaa" "aaa"))
(test::assert-false (= "ccc" "aab" "aaa"))
(test::assert-false (= "aaa" "aab"))
(test::assert-true (= (get-error (/ 1 0)) (get-error (/ 1 0))))

apply

Usage: (apply function arg* list)

Namespace: root

Call the provided function with the supplied arguments, if last is a list or vector then it will be "spread" as arguments. For instance (apply pr 1 2 3 [4 5 6]) is equivalent to (pr 1 2 3 4 5 6).

Example:

(def test-apply-one (apply str "O" "NE"))
(test::assert-equal "ONE" test-apply-one)
(test::assert-equal 10 (apply + 1 2 7))
(test::assert-equal 10 (apply + 1 [2 7]))
(test::assert-equal 10 (apply + 1 '(2 7)))
(test::assert-equal 10 (apply + [1 2 7]))
(test::assert-equal 10 (apply + '(1 2 7)))
(def test-apply-fn1 (fn (& args) (apply + args)))
(test::assert-equal 10 (apply test-apply-fn1 1 2 7))
(test::assert-equal 10 (apply test-apply-fn1 1 [2 7]))
(test::assert-equal 10 (apply test-apply-fn1 1 '(2 7)))
(test::assert-equal 10 (apply test-apply-fn1 [1 2 7]))
(test::assert-equal 10 (apply test-apply-fn1 '(1 2 7)))
(def test-apply-fn2 (fn (x y z) (+ x y z)))
(test::assert-equal 10 (apply test-apply-fn2 1 2 7))
(test::assert-equal 10 (apply test-apply-fn2 1 [2 7]))
(test::assert-equal 10 (apply test-apply-fn2 1 '(2 7)))
(test::assert-equal 10 (apply test-apply-fn2 [1 2 7]))
(test::assert-equal 10 (apply test-apply-fn2 '(1 2 7)))

back-quote

Usage: `expression -> expression

Namespace: root

Return expression without evaluation. Always use the ` reader macro or expansion will not work (i.e. (back-quote expression) will not do , expansion).

Backquote (unlike quote) allows for symbol/form evaluation using , or ,@.

Example:

(test::assert-equal (list 1 2 3) `(1 2 3))
(test::assert-equal `(1 2 3) '(1 2 3))
(def test-bquote-one 1)
(def test-bquote-list '(1 2 3))
(test::assert-equal (list 1 2 3) `(~test-bquote-one 2 3))
(test::assert-equal (list 1 2 3) `(~@test-bquote-list))

block

Usage: (get-error exp0 ... expN) -> pair

Namespace: root

Evaluate each form (like do) but on error return (:error msg backtrace) instead of aborting. On success return (:ok . expN-result).

If there is no error will return the value of the last expression as the cdr of the pair. Always returns a pair with the first value either being :ok or :error.

Example:

(let (get-error-t1 (get-error (err (mk-err :string (str "Some Error")))))
    (test::assert-equal :error (car get-error-t1))
    (test::assert-equal "error [string]: \"Some Error\"" (str (cdr get-error-t1))))
(test::assert-equal "Some String" (get-error "Some String"))
(test::assert-equal "Some Other String" (get-error (let (test-get-error "Some ") (str test-get-error "Other String"))))

comp-time

Usage: (comp-time sexp+)

Namespace: root

Compile and execute sexp+ at compile time. The result of the final sexp will then be compiled into the current module being compiled (produce nil to avoid this).

Example:

(with-ns test-out
    (comp-time '(def ttf (fn () '(1 2 3))))
    (comp-time (def ttf2 (fn () '(1 2 3))) nil)
    (test::assert-equal '(1 2 3) (ttf))
    (test::assert-equal '(1 2 3) (test-out::ttf))
    (test::assert-equal '(1 2 3) (ttf2))
    (test::assert-equal '(1 2 3) (test-out::ttf2)))

dec!

Usage: (dec! symbol [number]) -> new value

Namespace: root

Decrement the value in symbol by one or the optional number

Example:

(def *dec-test* 5)
(test::assert-equal 4 (dec! *dec-test*))
(test::assert-equal 4 *dec-test*)
(test::assert-equal 1 (dec! *dec-test* 3))
(test::assert-equal 1 *dec-test*)
(let (dec-test 5)
  (test::assert-equal 4 (dec! dec-test))
  (test::assert-equal 4 dec-test)
  (test::assert-equal 1 (dec! dec-test 3))
  (test::assert-equal 1 dec-test))

def

Usage: (def symbol doc_string? expression) -> expression

Namespace: root

Adds an expression to the current namespace. Return the expression that was defined. Symbol is not evaluated. Can take an option doc string (docstrings can only be set on namespaced (global) symbols).

Example:

(def test-do-one nil)
(def test-do-two nil)
(def test-do-three (do (set! test-do-one "One")(set! test-do-two "Two")"Three"))
(test::assert-equal "One" test-do-one)
(test::assert-equal "Two" test-do-two)
(test::assert-equal "Three" test-do-three)
(let (test-do-one nil)
    ; Add this to the let's scope (shadow the outer test-do-two).
    (test::assert-equal "Default" (def test-do-four "Default"))
    ; set the currently scoped value.
    (set! test-do-one "1111")
    (set! test-do-two "2222")
    (test::assert-equal "1111" test-do-one)
    (test::assert-equal "2222" test-do-two)
    (test::assert-equal "Default" test-do-four))
; Original outer scope not changed.
(test::assert-equal "One" test-do-one)
(test::assert-equal "Default" test-do-four)

defmacro

Usage: (defmacro name argument_list body)

Namespace: root

Create a macro and bind it to a symbol in the current scope.

Example:

(defmacro test-mac (x) `(inc! ~x))
(def test-mac-x 2)
(test-mac test-mac-x)
(test::assert-equal 3 test-mac-x)
(defmacro test-mac (x) `(set! ~x 15))
(test-mac test-mac-x)
(test::assert-equal 15 test-mac-x)

defn

Usage: (defn name args body)

Namespace: root

Define a named function in the current namespace.

Example:

(defn defn-test (x y) (+ x y))
(test::assert-equal 5 (defn-test 2 3))
(defn defn-test (x y) (set! x (* x 2)) (+ x y))
(test::assert-equal 7 (defn-test 2 3))
(defn defn-test (x y) nil)
(test::assert-false (defn-test 2 3))
(defn defn-test (x y) #t)
(test::assert-true (defn-test 2 3))

do

Usage: (do exp0 ... expN) -> expN

Namespace: root

Evaluate each form and return the last.

Example:

(def test-do-one nil)
(def test-do-two nil)
(def test-do-three (do (set! test-do-one "One") (set! test-do-two "Two") "Three"))
(test::assert-equal "One" test-do-one)
(test::assert-equal "Two" test-do-two)
(test::assert-equal "Three" test-do-three)

doc

Usage: (doc sym)

Namespace: root

Print the documentation for provided symbol.

No Examples

doc-raw

Usage: (doc-raw sym [SCRATCH] [SCRATCH] docs has-usage)

Namespace: root

Return the documentation for provided symbol as a string.

No Examples

dotimes

Usage: (dotimes times body [SCRATCH] [SCRATCH] i-name)

Namespace: root

Evaluate body a number of times equal to times' numerical value.

Example:

(def i 0)
(dotimes 11 (set! i (+ 1 i)))
(test::assert-equal 11 i)

dotimes-i

Usage: (dotimes-i idx-bind times body)

Namespace: root

Evaluate body a number of times equal to times' numerical value. Includes an incrementing reference binding, idx-bind, accessible in body.

Example:

(def i 0)
(def i-tot 0)
(dotimes-i idx 11 (do (set! i-tot (+ idx i-tot))(set! i (+ 1 i))))
(test::assert-equal 11 i)
(test::assert-equal 55 i-tot)

dump-globals

Usage: (dump-globals)

Namespace: root

Prints the global variables to stdout.

Example:

#t

dyn

Usage: (dyn key value expression) -> result_of_expression

Namespace: root

Creates a dynamic binding for key, assigns value to it and evals expression under it. Note that if key must be a symbol and is not evaluated.

The binding is gone once the dyn form ends. This is basically a set! on the binding in an unwind protect to reset it when done. When used on a global will set the first binding found and reset it when done. Calls to dyn can be nested and previous dynamic values will be restored as interior dyn's exit.

Example:

(def *dyn-test* 1)
(defn test-dyn-fn (val) (str *dyn-test* val))
(def out (dyn *dyn-test* 11 (test-dyn-fn 101)))
(test::assert-equal "11101" (str out))
;; when file handling works
;;(defn test-dyn-fn () (prn "Print dyn out"))
;;(dyn *stdout* (open "/tmp/sl-sh.dyn.test" :create :truncate) (test-dyn-fn))
;;(test::assert-equal "Print dyn out" (read-line (open "/tmp/sl-sh.dyn.test" :read)))

env

Usage: (env "NAME_OF_ENVIRONMENT_VARIABLE")

Namespace: root

Takes a string (tries to treat all values like strings), and checks the environment to see if that string is a valid environment variable and returns the value as a string, otherwise returns Nil.

Example:

#t

err

Usage: (err :keyword value)

Namespace: root

Raises an error with keyword and value. By default this will break into the debugger like a runtime error (use get-error to avoid this).

Example:

(let (error (get-error (err :test "Test error")))
    (test::assert-equal :test (car error))
    (test::assert-equal "Test error" (cdr error))
    (test::assert-true (err? error)))

eval

Usage: (eval expression)

Namespace: root

Evaluate the provided expression. If expression is a list it will be compiled and executed and the result returned other values will just be returned (i.e. (eval 1) = 1, (eval "test") = "test", (eval [1 2 3]) = [1 2 3], etc).

Note eval is a function not a special form, the provided expression will be evaluated as part of a call.

Example:

(test::assert-equal "ONE" (eval "ONE"))
(test::assert-equal 10 (eval 10))
(test::assert-equal [1 2 3] (eval [1 2 3]))
(test::assert-equal 10 (eval '(+ 1 2 7)))
(test::assert-equal 10 (eval '(apply + 1 2 7)))
(test::assert-equal 10 (eval '(apply + 1 '(2 7))))
(test::assert-equal 10 (eval '(apply + '(1 2 7))))
(test::assert-equal 10 (eval '(apply + 1 [2 7])))
(test::assert-equal 10 (eval '(apply + [1 2 7])))

exit

Usage: (exit int)

Namespace: root

Exit shell with provided exit code.

Example:

#t

expand-macro

Usage: (expand-macro 'code)

Namespace: root

Output code, any macro invocation will be replaced with the code it would generate. This is particularly useful for introspection when debugging macros.

Example:

#t

fn

Usage: (fn (param*) expr*) -> exprN

Namespace: root

Create a function (lambda).

Example:

(def test-fn1 nil)
(def test-fn2 nil)
(def test-fn3 nil)
(def test-fn-empty ((fn () nil)))
(test::assert-false test-fn-empty)
((fn () (set! test-fn1 1)))
(test::assert-equal 1 test-fn1)
((fn () (set! test-fn1 10)(set! test-fn2 2)))
(test::assert-equal 10 test-fn1)
(test::assert-equal 2 test-fn2)
((fn () (set! test-fn1 11)(set! test-fn2 20)(set! test-fn3 3)))
(test::assert-equal 11 test-fn1)
(test::assert-equal 20 test-fn2)
(test::assert-equal 3 test-fn3)
(test::assert-equal 63 ((fn (x y z) (set! test-fn1 x)(set! test-fn2 y)(set! test-fn3 z)(+ x y z)) 12 21 30))
(test::assert-equal 12 test-fn1)
(test::assert-equal 21 test-fn2)
(test::assert-equal 30 test-fn3)

gensym

Usage: (gensym)

Namespace: root

Used to make macros hygenic by creating a random symbol name to be used in code output by a macro to avoid conflicting variable names.

Example:

#t

get-error

Usage: (get-error exp0 ... expN) -> pair

Namespace: root

Evaluate each form (like do) but on error return (:error msg backtrace) instead of aborting. On success return (:ok . expN-result).

If there is no error will return the value of the last expression as the cdr of the pair. Always returns a pair with the first value either being :ok or :error.

Example:

(let (get-error-t1 (get-error (err (mk-err :string (str "Some Error")))))
    (test::assert-equal :error (car get-error-t1))
    (test::assert-equal "error [string]: \"Some Error\"" (str (cdr get-error-t1))))
(test::assert-equal "Some String" (get-error "Some String"))
(test::assert-equal "Some Other String" (get-error (let (test-get-error "Some ") (str test-get-error "Other String"))))

get-globals

Usage: (get-globals)

Namespace: root

Return a vector containing all the symbols currently defined globally.

No Examples

get-prop

Usage: (get-prop 'a-symbol :a-property))

Namespace: root

Read property that maps to given keyword for provided-symbol. Most forms have a :doc-string property that returns the docstring for the symbol.

Example:

#t

identity

Usage: (identity arg)

Namespace: root

Identity function.

Example:

(test::assert-equal 0 (identity 0))

inc!

Usage: (inc! symbol [number]) -> new value

Namespace: root

Increment the value in symbol by one or the optional number

Example:

(def *inc-test* 1)
(test::assert-equal 2 (inc! *inc-test*))
(test::assert-equal 2 *inc-test*)
(test::assert-equal 5 (inc! *inc-test* 3))
(test::assert-equal 5 *inc-test*)
(let (inc-test 1)
  (test::assert-equal 2 (inc! inc-test))
  (test::assert-equal 2 inc-test)
  (test::assert-equal 5 (inc! inc-test 3))
  (test::assert-equal 5 inc-test))

is-noop

Usage: (is-noop 'fn-to-test)

Namespace: root

Report whether or not the provided function is currently set to do nothing. When called with the 'noop function always returns true.

Example:

(test::assert-true (is-noop 'noop))
(test::assert-false (is-noop 'fs-meta))

len

Usage: (len expression) -> int

Namespace: root

Return length of supplied expression. The length of an atom is 1.

Example:

(test::assert-equal 0 (len nil))
(test::assert-equal 5 (len "12345"))
; Note the unicode symbol is only one char even though it is more then one byte.
(test::assert-equal 6 (len "12345Σ"))
(test::assert-equal 3 (len '(1 2 3)))
(test::assert-equal 3 (len [1 2 3]))
(test::assert-equal 3 (len (list 1 2 3)))
(test::assert-equal 3 (len (vec 1 2 3)))
(test::assert-equal 1 (len 100))
(test::assert-equal 1 (len 100.0))
(test::assert-equal 1 (len \tab))

let

Usage: (let vals &rest let-body)

Namespace: root

Takes list, vals, of form ((binding0 sexp0) (binding1 sexp1) ...) and evaluates let-body with all values of binding bound to the result of the evaluation of sexp.

Example:

(def test-do-one "One1")
(def test-do-two "Two1")
(def test-do-three (let (test-do-one "One") (set! test-do-two "Two")(test::assert-equal "One" test-do-one)"Three"))
(test::assert-equal "One1" test-do-one)
(test::assert-equal "Two" test-do-two)
(test::assert-equal "Three" test-do-three)
((fn (idx) (let (v2 (+ idx 2) v3 (+ idx 3))
    (test::assert-equal (+ idx 2) v2)
    (test::assert-equal (+ idx 3) v3)
    (if (< idx 5) (recur (+ idx 1)))))0)
((fn (idx) (let (v2 (+ idx 2) v3 (+ idx 3))
    (test::assert-equal (+ idx 2) v2)
    (test::assert-equal (+ idx 3) v3)
    (if (< idx 5) (this-fn (+ idx 1)))))0)

let-while

Usage: (let-while (initial-bindings) (loop bindings) condition & let-body)

Namespace: root

Takes list of initial bindings (done once before loop) of form (binding0 sexp0, binding1 sexp1, ...), and a list of loop bindings (done at the start of each iteration including the first) and evaluates let-body with all values of binding bound to the result of the evaluation of both bindings while condition is true.

Example:

; both of these examples create a vector and iterate to print all the elements
; use traditional lisp structure
(def test-res [])
(let-while (l [1 2 3]) (done (empty? l), f (first l),  l (rest l)) (not done)
  (prn f)
  (vec-push! test-res f))
(let ([x y z] test-res)
  (test::assert-equal 1 x)
  (test::assert-equal 2 y)
  (test::assert-equal 3 z))
; same thing using destructuring
(def test-res [])
(let-while (l [1 2 3]) (done (empty? l), [% f & l] l) (not done)
  (prn f)
  (vec-push! test-res f))
(let ([x y z] test-res)
  (test::assert-equal 1 x)
  (test::assert-equal 2 y)
  (test::assert-equal 3 z))

load

Usage: (load path) -> [last form value]

Namespace: root

Read and eval a file (from path- a string). The load special form executes at compile time. This means it's parameter must resolve at compile time. Most of the time you will want to use this in conjunction with 'with-ns' to namespace the contents. Note: on it's own does nothing with namespaces.

Example:

(comp-time (def test-temp-file (get-temp-file)) nil)
(defer (fs-rm test-temp-file))
(let (tst-file (fopen test-temp-file :create))
    (defer (fclose tst-file))
    (fprn tst-file "(with-ns test-load")
    (fprn tst-file "    (defn test-fn () '(1 2 3)))"))
(load test-temp-file) ; put stuff in it's own namespace
(test::assert-equal '(1 2 3) (test-load::test-fn))


(with-ns test-out2
    (comp-time
        (def test-temp-file (get-temp-file))
        (let (tst-file (fopen test-temp-file :create))
            (defer (fclose tst-file))
            (fprn tst-file "(defn test-fn () '(1 2 3))"))
        nil)
    (defer (fs-rm test-temp-file))
    (load test-temp-file) ; put new stuff in current namespace
    (test::assert-equal '(1 2 3) (test-fn))
    (test::assert-equal '(1 2 3) (test-out2::test-fn)))

load-rc

Usage: (load-rc) | (load-rc "init.slosh)

Namespace: root

Read and eval user's rc file, by default "init.slosh" or a user provided file path found in '$HOME/.config/slosh/'.

No Examples

loop

Usage: (loop params bindings body)

Namespace: root

Binds bindings to parameters in body. Use recur with desired bindings for subsequent iteration. Within the loop the lambda 'break' will end the loop, break can take an option argument that is what the loop produces (nil if no argument).

Example:

(def tot 0)
(loop (idx) (3) (do
    (set! tot (+ tot 1))
    (if (> idx 1) (recur (- idx 1)))))
(test::assert-equal 3 tot)
(def tot 0)
(loop (idx) (0)
    (set! tot (+ tot 1))
    (when (not (= idx 2))
        (recur (+ idx 1))))
(test::assert-equal 3 tot)
(test::assert-equal 11 (loop (idx) (0)
    (if (= idx 2) (break 11))
    (recur (+ idx 1))))
(test::assert-false (loop (idx) (0)
    (if (= idx 2) (break nil))
    (recur (+ idx 1))))
(test::assert-error (loop (idx) (0)
    (if (= idx 2) (break 1 3))
    (recur (+ idx 1))))

macro

Usage: (macro (args) `(apply + ,@args))

Namespace: root

Define an anonymous macro.

Example:

(def test-macro1 nil)
(def test-macro2 nil)
(def test-macro-empty (macro () nil))
(test::assert-false (test-macro-empty))
(def test-mac nil)
(def mac-var 2)
(let (mac-var 3)
  (set! test-mac (macro (x) (set! test-macro2 100) (test::assert-equal 3 mac-var) (* mac-var x))))
(set! test-macro1 (test-mac 10))
(test::assert-equal 30 test-macro1)
(test::assert-equal 100 test-macro2)

mk-err

Usage: (mk-err :keyword value)

Namespace: root

Create an error object. This does not raise the error but merely creates it. Can use car/cdr to extract the keyword and value.

Example:

(let (error (mk-err :test "Test error"))
    (test::assert-equal :test (car error))
    (test::assert-equal "Test error" (cdr error))
    (test::assert-true (err? error)))

noop

Usage: (noop any*)

Namespace: root

Takes any number of arguments and always returns nil.

Example:

(test::assert-equal nil (noop 'noop))
(test::assert-equal nil (noop "foo" :bar 'baz))
(test::assert-equal nil (noop))

noop-fn

Usage: (noop-fn 'fn-to-noop)

Namespace: root

Alter the runtime so that the provided function is a no-operation (no-op or noop) that does nothing and returns nil for the provided function. Any future call to this function will do nothing, regardless of the arguments it is given.

Example:

#t

not=

Usage: (not= arg1 arg2)

Namespace: root

Test if two values are not equal using =

Example:

(test::assert-true (not= 0 1))
(test::assert-true (not= 1 1.0))
(test::assert-false (not= 2 2))
(test::assert-false (not= 0.0 -0.0))

not==

Usage: (not== arg1 arg2)

Namespace: root

Test if two values are not numerically equal using ==

Example:

(test::assert-true (not== 0 1))
(test::assert-false (not== 1 1.0))
(test::assert-false (not== 0.0 -0.0))
(test::assert-false (not== 2 2))

nsubstitute!

Usage: (nsubstitute! lst old-item new-item mods [SCRATCH] [SCRATCH] early-return)

Namespace: root

Replaces all instances of old-item in lst with new-item. If last argument passed in is keyword :first only the first instance of old-item will be replaced.

Example:

(let (lst (list 1 2 3 4 5))
    (test::assert-equal (list 1 2 2 4 5) (nsubstitute! lst 3 2))
    (test::assert-equal (list 1 2 2 4 5) lst)
    (test::assert-equal (list 1 3 2 4 5) (nsubstitute! lst 2 3 :first)))

occurs

Usage: (occurs (list 1 2 ...) 7)

Namespace: root

Counts instances of item in sequence.

Example:

(test::assert-equal 1 (occurs (list 1 3 5 2 4 8 2 4 88 2 1) 8))
(test::assert-equal 3 (occurs (list 1 3 5 2 4 10 2 4 88 2 1) 2))
(test::assert-equal 0 (occurs (list 1 3 5 2 4 10 2 4 88 2 1) 42))

on-raised-error

Usage: (on-raised-error (fn (error) ...))

Namespace: root

Low level (consider this unstable) interface to the raised error machinery. Useful for building higher level error handling (get-error for instance). It takes either Nil or a callable with one parameter. That parameter will be the error that was raised. The entire running "chunk" of code will be displaced for the installed handler. Probably best to use this with a continuation or a function that ends in a continuation call otherwise it may be difficult to reason about...

Will return the previously installed handler or Nil if one is not installed. Calling with Nil will return the old handler and clear it (no handler installed).

This special form will override breaking into the debugger when an error is raised.

Example:

(defmacro get-error-test (& body)
`(let (old-error (on-raised-error nil))
    (defer (on-raised-error old-error))
    (call/cc (fn (k) (on-raised-error (fn (err) (k (cons (car err)(cdr err)))))
                (cons :ok (do ~@body))))))

(test::assert-equal (cons :ok 6) (get-error-test (let (x 1, y 5) (+ x y))))
(test::assert-equal '(:test . "error") (get-error-test (let (x 1, y 5) (err :test "error")(+ x y))))

platform

Usage: (platform)

Namespace: root

Returns a string representing the platform.

Example:

#t

quote

Usage: 'expression -> expression

Namespace: root

Return expression without evaluation. The reader macro 'expression will expand to (quote expression).

Example:

(test::assert-equal (list 1 2 3) (quote (1 2 3)))
(test::assert-equal (list 1 2 3) '(1 2 3))
(test::assert-equal '(1 2 3) (quote (1 2 3)))

recur

Usage: (recur &rest)

Namespace: root

Recursively call the enclosing function with the given parameters. Recur uses tail call optimization and must be in the tail position or it is an error. For a named function it would be equivalent to a normal recursive call in a tail position but it requires a tail position and does not need a name (a normal recursive call would work in a non-tail position but could blow the stack if it is to deep- unlike a recur or tail position recursive call). NOTE: potential footgun, the let macro expands to a lambda (fn) and a recur used inside the let would bind with the let not the enclosing lambda (this would apply to any macro that also expands to a lambda- this is by design with the loop macro but would be unexpected with let).

Example:

(def tot 0)
(loop (idx) (3) (do
    (set! tot (+ tot 1))
    (if (> idx 1) (recur (- idx 1)))))
(test::assert-equal 3 tot)
(set! tot 0)
((fn (idx) (do
    (set! tot (+ tot 1))
    (if (> idx 1) (recur (- idx 1)))))5)
(test::assert-equal 5 tot)

set!

Usage: (set! symbol expression) -> expression

Namespace: root

Sets an existing expression in the current scope(s). Return the expression that was set. Symbol is not evaluated.

Set will set the first binding it finds starting in the current scope and then trying enclosing scopes until exhausted.

Example:

(def test-do-one nil)
(def test-do-two nil)
(def test-do-three (do (set! test-do-one "One")(set! test-do-two "Two")"Three"))
(test::assert-equal "One" test-do-one)
(test::assert-equal "Two" test-do-two)
(test::assert-equal "Three" test-do-three)
(let (test-do-one nil)
    ; set the currently scoped value.
    (test::assert-equal "1111" (set! test-do-one "1111"))
    (test::assert-equal "1111" test-do-one))
; Original outer scope not changed.
(test::assert-equal "One" test-do-one)

set-env

Usage: (set-env "NAME_OF_ENVIRONMENT_VARIABLE" "Value variable should be assigned")

Namespace: root

Takes two strings the first is the name of an environment variable, and the second is the value it should bind.

Example:

#t

set-prop

Usage: (set-prop 'a-symbol :a-property a-value)

Namespace: root

Write property with value for the given symbol.

Example:

(def foo #t)
(set-prop 'foo :bar "baz")
(test::assert-equal "baz" (get-prop 'foo :bar))

sizeof-heap-object

Usage: (sizeof-heap-object)

Namespace: root

Returns the default size of a heap object by the current runtime in bytes.

Example:

(test::assert-equal 16 (sizeof-heap-object))

sizeof-value

Usage: (sizeof-value)

Namespace: root

Returns the default size of a value by the current runtime in bytes. Optimized to be 8 bytes so that a given primitve or pointer to a head object fits in one word on a 64 bit machine.

Example:

(test::assert-equal 8 (sizeof-value))

substitute

Usage: (substitute lst old-item new-item mods)

Namespace: root

Replaces all instances of old-item in copy of lst with new-item. If last argument passed in is keyword :first only the first instance of old-item will be replaced.

Example:

(let (lst (list 1 2 3 4 3)
      olst (list 1 2 3 4 3)
       lst2 (list 1 2 3 3 3 4 5)
      olst2 (list 1 2 3 3 3 4 5))
     (test::assert-equal (list 1 2 10 4 10) (substitute lst 3 10))
     (test::assert-equal (list 1 2 10 4 3) (substitute lst 3 10 :first))
     (test::assert-equal olst lst)
     (test::assert-equal (list 1 2 4 4 4 4 5) (substitute lst2 3 4))
     (test::assert-equal (list 1 2 4 3 3 4 5) (substitute lst2 3 4 :first))
     (test::assert-equal olst2 lst2))

to-list

Usage: (to-list any)

Namespace: root

Turns any one value into a list. If that value or if it was a sequence a new sequence with the same values.

No Examples

to-vec

Usage: (to-list any)

Namespace: root

Turns any one value into a vector. If that value or if it was a sequence a new sequence with the same values.

No Examples

un-noop-fn

Usage: (un-noop-fn 'fn-to-un-noop)

Namespace: root

If the runtime was previously altered for the provided function (to make it do nothing) swap the old function back in so the previous behavior is restored and the function behaves as normal.

Example:

#t

unset-env

Usage: (unset-env "NAME_OF_ENVIRONMENT_VARIABLE")

Namespace: root

Takes a string, checks the environment to see if the string is a valid environment variable and if it is it unsets it.

Example:

#t

usage

Usage: (usage 'symbol)

Namespace: root

Provides usage information derived from the bytecode. Documentation can also have it's own usage string provided in the doc string but this function returns what the actual function's compiled code provides.

No Examples