Types and type predicates
Every type below is bound under its name in every module, and a
predicate named after it with a ? suffix is bound beside it. The type
is callable as a constructor and usable with instance?.
Type predicates
Syntax: (NAME? VALUE)
Return True when VALUE is an instance of the type bound as
NAME, False otherwise. (NAME? x) is (instance? x NAME), so
an instance of a subclass passes.
(tuple? #(1 2)) ; True
(tuple? #[1 2]) ; False
(list? #[1 2]) ; True
(list? '(1 2)) ; False -- a quoted list is a pair chain
(str? "abc") ; True
(str? 'abc) ; False -- a symbol
(int? True) ; True -- bool is a subclass of int
(bool? 1) ; False
A predicate is an ordinary one-argument function:
(list (filter str? #[1 "a" 2 "b"])) ; #["a" "b"]
(list (map int? #[1 "a" True])) ; #[True False True]
Defining a class binds only the class name. No predicate is created
for it; test with instance?.
Numbers
Name |
Type |
|---|---|
|
|
|
Integers |
|
Floating point numbers |
|
Complex numbers |
|
Decimal fixed point numbers, |
|
Rational numbers, |
Also: macro bool.
(float? 7) ; False
(decimal? (decimal "1.5")) ; True
(decimal? 1.5) ; False
(fraction? (fraction 1 3)) ; True
(str (+ (fraction 1 3) (fraction 1 6))) ; "1/2"
Text and bytes
Name |
Type |
|---|---|
|
Strings |
|
Immutable byte strings |
|
Mutable byte strings |
|
Views over a byte buffer |
(bytes? (bytes 3)) ; True
(bytes? (bytearray 3)) ; False
Collections
Name |
Type |
|---|---|
|
Lists, |
|
Tuples, |
|
Dicts, |
|
Mutable sets |
|
Immutable sets |
|
Integer ranges |
|
Slice objects |
list, tuple, set, and frozenset take one iterable; the #
builders on Functions take the
elements as arguments.
Also: macro slice.
(set? (set #[1 2])) ; True
(set? (frozenset #[1])) ; False
(sorted (frozenset #[3 1 3])) ; #[1 3]
(dict? #{"a": 1}) ; True
Objects and classes
Name |
Type |
|---|---|
|
The base of every value |
|
Classes |
|
Properties; accepts Koskari accessor functions directly |
|
Class method wrappers |
|
Static method wrappers |
Also: special form
type.
(type? int) ; True
(type? 5) ; False
(object? None) ; True -- every value is an object
(is? (type 5) int) ; True
Pairs and symbols
Name |
Type |
|---|---|
|
Cons cells, and |
|
Symbols, such as |
|
Keywords, such as |
|
Values wrapped with a source position |
nil passes pair?. Use nil? to test for the empty list, and test
it before pair? when the two cases differ.
Also: macro datum.
(pair? '(1 2)) ; True
(pair? nil) ; True -- nil is the empty pair
(pair? #[1 2]) ; False
(symbol? 'abc) ; True
(keyword? 'abc:) ; True
(keyword? 'abc) ; False
Functions and results
Name |
Values |
|---|---|
|
Partial applications, from |
|
Callables that run their function on the demand path |
|
Callables that always return one value |
|
Multiple results, from |
|
Single-shot held work, from |
See Functions for each constructor.
(partial? (partial + 1)) ; True
(partial? +) ; False
(values? (values 1 2)) ; True
Iterators
Name |
Type |
|---|---|
|
Lazy iterators that accept Koskari functions; see map and filter |
|
Python’s |
The two families are distinct types, and each predicate accepts only its own:
(map? (map str #[1])) ; True
(map? (py-map str #[1])) ; False
(py-map? (py-map str #[1])) ; True
(py-zip? (zip #[1] #[2])) ; False
Refs
Name |
Ref |
|---|---|
|
Every ref; the base of the kinds below |
|
A subscript, from |
|
An attribute, from |
|
Getter and setter functions, from |
|
A value that refuses stores, from |
|
A getter called once on first deref, from |
|
A parameter, from |
ref? is the same predicate as Ref?. See ref.
var xs #[1 2 3]
(ref? &xs) ; True
(ItemRef? (ref (item xs 0))) ; True
(ConstantRef? (ref (constant 5))) ; True
(ref? 5) ; False
Processes
ProcessResult is the result of run-process; see
Functions. Its predicate is ProcessResult?.
Exceptions
Every exception type is bound by name, Koskari’s and Python’s. The Koskari exception classes and their hierarchy are on the Error guide.