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

type

List of symbols:

->float, ->int, callable?, char?, err?, io?, list?, nil?, ok?, pair?, seq?, string?, symbol?, vec?

->float

Usage: (->float ?float) -> float

If string or other value is a valid representation of a float return that float. Error if not.

Example:

(test::assert-equal 0.0 (->float "0"))
(test::assert-equal 11.0 (->float 11))
(test::assert-equal 10.0 (->float "10.0"))
(test::assert-equal 13.0 (->float :13))
(test::assert-equal 10.5 (->float "10.5"))
(test::assert-equal 101.0 (->float "101"))
(test::assert-equal -101.95 (->float "-101.95"))
(test::assert-error (->float "not int"))
(test::assert-error (->float "--10"))
;; for some reason this ->sym test case must be last or else there's an error w/ load
(test::assert-equal 12.0 (->float (->sym 12)))

->int

Usage: (->int ?int) -> int

If string or other value is a valid representation of an integer return that int. Error if not.

Note, if value is a float (or is a string that casts initially to a float) and it is NaN, +/- infinity, < i56::MIN, or > i56::MAX the function will error.

Example:

(test::assert-equal 0 (->int "0"))
(test::assert-equal 101 (->int "101"))
(test::assert-equal 1101 (->int :1101))
(test::assert-equal 8 (->int 8.1))
(test::assert-equal -111 (->int "-111"))
(test::assert-equal 10 (->int "10.0"))
(test::assert-error (->int "not int"))
(test::assert-error (->int "--10"))
;; for some reason this ->sym test case must be last or else there's an error w/ load
(test::assert-equal 1102 (->int (->sym 1102)))

callable?

Usage: (callable? v [SCRATCH] [SCRATCH] t)

Usage: (callable? to-test)

No Examples

char?

Usage: (char? expression)

True if the expression is a char, false otherwise.

Example:

(test::assert-true (char? \a))
(test::assert-false (char? 1))
(test::assert-false (char? "a"))

err?

Usage: (err? expression)

True if the expression is an error, false otherwise.

Example:

(test::assert-true (err? (mk-err :arr "test")))
(test::assert-false (err? nil))

io?

Usage: (io? expression)

True if the expression is an IO object (file), false otherwise.

Example:

(def iotst (fopen "/tmp/iotst" :create))
(test::assert-true (io? iotst))
(test::assert-false (io? 1))
(test::assert-false (io? '(1 2 3)))
(test::assert-false (io? (list)))

list?

Usage: (list? expression)

True if the expression is a list, false otherwise.

Example:

(test::assert-true (list? '(1 2 3)) "reader macro")
(test::assert-true (list? (list 1 2 3)) "list")
(test::assert-false (list? 1))
(test::assert-false (list? [1 2 3]))
(test::assert-false (list? []))
(test::assert-false (list? '(1 . 2)))

nil?

Usage: (nil? v)

True if the expression is nil, false otherwise

Example:

(test::assert-true (nil? ()))
(test::assert-true (nil? '()))
(test::assert-true (nil? nil))
(test::assert-true (nil? (list)))
(test::assert-false (nil? #f))

ok?

Usage: (ok? expression)

True if the expression is NOT an error, false if it is an error.

Example:

(test::assert-false (ok? (mk-err :arr "test")))
(test::assert-true (ok? nil))

pair?

Usage: (pair? expression)

True if the expression is a pair, false otherwise.

Example:

(test::assert-true (pair? '(1 . 2)) "reader macro")
(test::assert-true (pair? (cons 1 2)) "cons")
(test::assert-true (pair? '(1 2)))
(test::assert-false (pair? 1))
(test::assert-false (pair? [1 2 3]))
(test::assert-false (pair? (vec)))

seq?

Usage: (seq? expression)

True if expression is a list or vector, false otherwise.

Example:

(test::assert-true (seq? '(1 2 3)))
(test::assert-true (seq? [1 2 3]))
(test::assert-true (seq? []))
(test::assert-false (seq? "aaa"))
(test::assert-false (seq? 1))

string?

Usage: (string? expression)

True if the expression is a string, false otherwise.

Example:

(test::assert-true (string? "string"))
(test::assert-false (string? 1))

symbol?

Usage: (symbol? expression)

True if the expression is a symbol, false otherwise.

Example:

(test::assert-true (symbol? 'symbol))
(test::assert-false (symbol? 1))

vec?

Usage: (vec? expression)

True if the expression is a vector, false otherwise.

Example:

(test::assert-true (vec? [1 2 3]) "reader macro")
(test::assert-true (vec? (make-vec)) "make-vec")
(test::assert-true (vec? (vec 1 2 3)) "vec")
(test::assert-false (vec? 1))
(test::assert-false (vec? '(1 2 3)))
(test::assert-false (vec? (list)))