Maybe

is a data type to represent optional values. It has two constructors, (Just <value>) and Nothing, and provides many functions to wrap and unwrap values.

=

defn

(Fn [(Ref (Maybe a) b), (Ref (Maybe a) b)] Bool)

                        (= a b)
                    

equality is defined as the equality of both the constructor and the contained value, i.e. (Just 1) and (Just 1) are the same, but (Just 1) and (Just 2) are not.

Just

template

(Fn [a] (Maybe a))

creates a Just.

Nothing

template

(Fn [] (Maybe a))

creates a Nothing.

apply

defn

(Fn [(Maybe a), (Ref (Fn [a] b c) d)] (Maybe b))

                        (apply a f)
                    

applies a function to the value inside a if it is a Just, and wraps it up again. If it is Nothing, it is just returned.

copy

template

(Fn [(Ref (Maybe a) b)] (Maybe a))

copies a Maybe.

delete

template

(Fn [(Maybe a)] ())

deletes a Maybe. This should usually not be called manually.

from

defn

(Fn [(Maybe a), a] a)

                        (from a dflt)
                    

is an unwrapper that will get the value from a Just, or a default value if a Nothing is passed.

from-ptr

defn

(Fn [(Ptr a)] (Maybe a))

                        (from-ptr a)
                    

Creates a (Maybe a) from a (Ptr a). If the Ptr was NULL, this function will return Nothing.

get-tag

instantiate

(Fn [(Ref (Maybe a) b)] Int)

Gets the tag from a Maybe.

just?

defn

(Fn [(Ref (Maybe a) b)] Bool)

                        (just? a)
                    

checks whether the given value a is a Just.

It is the inverse of nothing?.

nothing?

defn

(Fn [(Ref (Maybe a) b)] Bool)

                        (nothing? a)
                    

checks whether the given value a is a Nothing.

It is the inverse of just?.

or-zero

defn

(Fn [(Maybe a)] a)

                        (or-zero a)
                    

is an unwrapper that will get the value from a Just, or build a value using zero if a Nothing is passed.

prn

template

(Fn [(Ref (Maybe a) b)] String)

converts a Maybe to a string.

str

template

(Fn [(Ref (Maybe a) b)] String)

converts a Maybe to a string.

to-result

defn

(Fn [(Maybe a), b] (Result a b))

                        (to-result a error)
                    

is a function that will convert a Maybe to a Result, where a Just becomes a Success and a Nothing becomes an Error.

You’ll also need to provide an error message error that is given to the Error constructor if necessary.

unsafe-from

defn

(Fn [(Maybe a)] a)

                        (unsafe-from a)
                    

is an unsafe unwrapper that will get the value from a Just. If a is Nothing, a runtime error will be generated.

unsafe-ptr

defn

(Fn [(Ref (Maybe a) b)] (Ptr a))

                        (unsafe-ptr a)
                    

Creates a (Ptr a) from a (Maybe a). If the Maybe was Nothing, this function will return a NULL value.

zero

defn

(Fn [] (Maybe a))

                        (zero)
                    

returns Nothing.

zip

macro

Macro

                        (zip f :rest args)
                    

zip-

dynamic

Dynamic

                        (zip- f args names)