chickadee » chicken » keyword

Module (chicken keyword)

Keywords are written like symbols, but prefixed with #:. They evaluate to themselves. While they behave a lot like symbols in that they are interned when read and can be compared in constant time with eq?, they are a distinct type. In particular, they have no plist, they cannot be bound or assigned to and aren't eq? to a symbol with the same spelling. Procedures can use keywords to accept optional named parameters in addition to normal required parameters.

The parameter keyword-style and the compiler/interpreter option -keyword-style can be used to allow an additional keyword syntax, either compatible to Common LISP, or to DSSSL. As long as this parameter is set to #:suffix, CHICKEN conforms to SRFI-88.

There is also a srfi-88 or (srfi 88) module which only includes the standard procedures from the SRFI document, without the CHICKEN extensions. (chicken keyword) offers the complete set of procedures, both CHICKEN-specific and standard SRFI-88.

get-keyword

get-keyword KEYWORD ARGLIST #!optional THUNKprocedure

Returns the argument from ARGLIST specified under the keyword KEYWORD. If the keyword is not found, then the zero-argument procedure THUNK is invoked and the result value is returned. If THUNK is not given, #f is returned.

(define (increase x . args)
  (+ x (get-keyword #:amount args (lambda () 1))) )
(increase 123)                                      ==> 124
(increase 123 #:amount 10)                          ==> 133

keyword?

keyword? Xprocedure

Returns #t if X is a keyword, or #f otherwise.

keyword->string

keyword->string KEYWORDprocedure

Transforms KEYWORD into a string.

string->keyword

string->keyword STRINGprocedure

Returns a keyword with the name STRING.


Previous: Module (chicken irregex)

Next: Module (chicken load)

Contents »