Constants

There are a lot of constants in Idio and, indeed, several kinds of constants although most users are only going to use a small number.

The usual constants are:

#f

The boolean value for false.

This is the only value that is tested for. Any other value is considered to be true.

#t

The boolean value for true. In fact, as any non-#f value is regarded as true (that is, it isn’t #f) then #t is entirely redundant. It is, however, a useful non-#f value to return from a predicate.

#n

The null value.

The most useful use of this value is for marking the end of a chain of pairs – commonly known as a list.

Other Constants

Most other constants do not have constructors for use in source code, they exist in machina. Their printed form is always unacceptable to the reader.

Other constants that may appear include:

#<unspec>

No useful value.

Most functions that set something return #<unspec>.

Scholars (and laymen) disagree on what the result of the computation to modify memory should be in which case none shall be correct.

Printing also returns #<unspec> for similarly arcane reasons.

#<undef>

The undefined value.

No value a user sees should be undefined!

It is used internally for concomitantly defined values and shouldn’t escape.

#<void>

The result of no computation!

There are several instances of no computation:

  1. a conditional statement where the condition is false and there is no alternate clause:

    Idio> if #f #f
    #<void>
    
  2. a begin clause with no expressions:

    Idio> (begin)
    #<void>
    
  3. a cond or case expression where no match exists and there is no else clause

In all cases, something must be returned.

#<eof>

A flag indicating that a read has reached end of file (or string!).

See also

eof? and eof-handle?.

Other Kinds of Constants

Where possible, Idio uses constants internally for other purposes, rather than C integers per se.

The are groups of constants for:

  • reader tokens as source code is being read in and converted to an Abstract Syntax Tree

  • generalized intermediate code from the evaluator to the code generator

  • unicode is a distinct set of constants as is its (deprecated) predecessor “character” type

Constant Predicates

function boolean? o

test if o is a boolean

Param o:

object to test

Return:

#t if o is a boolean

function null? o

test if o is #n

Param o:

object to test

Return:

#t if o is #n, #f otherwise

function void? o

test if o is void (#<void>)

Param o:

object to test

Return:

#t if o is #<void>, #f otherwise

function undef? o

test if o is undef (#<undef>)

Param o:

object to test

Return:

#t if o is #<undef>, #f otherwise

function eof? o

Is o the end-of-file value?

Param o:

value to test

Return:

#t if o is the end-of-file value, #f otherwise

Rtype:

boolean

Constant Functions

function void
Return:

#<void>

Somewhat disingenuous as the act of calling a function cannot be no computation…

function undef
Return:

#<undef>

The use of undef may result in unexpected errors.

Last built at 2024-12-21T07:10:45Z+0000 from 62cca4c (dev) for Idio 0.3.b.6