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

undef

Creating and inspecting undefined values.

undef.from

undef.from value -> Undefined

Returns an undefined value that carries value, for example a message that explains the error. The whole argument is wrapped, even a tuple. Its description is Custom undefined value: , followed by a short value as you would write it, or by its type for any other value.

err = undef.from "not found"
type err             # => "Undefined"
(undef.inspect err).val        # => "not found"
(undef.inspect (undef.from {a: 1})).description    # => "Custom undefined value: a namespace"

undef.inspect

undef.inspect u -> Namespace

Returns a namespace that describes the undefined value u. Its type member names the kind of error, and description gives the error in plain words. The other members depend on the type:

typeMembersMeaning
UnaryOperationop, val, posoperation op failed on the operand val
BinaryOperationop, lhv, rhv, posoperation op failed on lhv and rhv
Terminationexpected, posthe expression ended before the closing bracket expected
Tokentoken, posa token is in the wrong place
Nameposa name was expected
Valuevalcreated by undef.from
HostErrorerror, posa function of the host failed, with the text of its error

In a document, pos is the position of the error in bytes from the start of the document, and uri is the location of that document; an error made by a built-in function has the position of its call. In code run with parse, pos counts from the start of that code and there is no uri. A value made by undef.from has neither. Operands that are themselves undefined are described in the same way. If u is not undefined, the result is Undefined.

e = undef.inspect ([1] - 1)
e.type               # => "BinaryOperation"
e.description        # => "cannot subtract the number `1` from a list"
e.op                 # => "subtraction"
(e.lhv, e.rhv)       # => ([1], 1)
(undef.inspect (text.size 1)).(op, val)  # => ("text.size", 1)