Keyword Type

Keywords are very similar to symbols but serve a slightly different purpose. Like symbols they are a word but must begin with a :, U+003A (COLON).

They exist as semantic flags – rather than as symbols’ programmatic flags – to be used to identify optional arguments to functions. Think of a function with many possible optional arguments and if you only want to set the foo optional parameter you might invoke:

func formals :foo arg

There is a constraint on the possible keywords in that in order to avoid clashing with the definition operators, := etc., then the characters of a keyword after the : must not start with a punctuation character, (through ispunct(3)).

So :foo=bar is fine but :=bar is not – and will be interpreted as a symbol.

Keyword Predicates

function keyword? o

test if o is an keyword

Param o:

object to test

Return:

#t if o is an keyword, #f otherwise

Keyword Constructors

function make-keyword s

create a keyword from s

Param s:

keyword

Type s:

symbol or string

Return:

keyword

Rtype:

keyword

Keyword Functions

function keywords

return a list of all keywords

Return:

list

Keyword Tables

Keyword tables are hash tables indexed by keywords.

They are used primarily as property tables.

function make-keyword-table [size]

used for constructing property tables

Param size:

size of underlying hash table

Type size:

integer, optional

Return:

keyword table

function keyword-ref kt kw [default]

return the value indexed by keyword kw in keyword table kt

Param kt:

keyword table

Type kt:

keyword table

Param kw:

keyword index

Type kw:

keyword

Param default:

a default value to return if kw not found

Type default:

value, optional

Return:

value

Raises ^rt-keyword-error:

if key is not found and no default is supplied

function keyword-set! kt kw v

set the index of kw in keyword table kt to v

Param kt:

keyword table

Type kt:

keyword table

Param kw:

keyword index

Type kw:

keyword

Param v:

value

Type v:

a value

Return:

#<unspec>

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