~ chicken-core (chicken-5) /manual/Module (chicken keyword)
Trap1[[tags: manual]]2[[toc:]]34== Module (chicken keyword)56Keywords are written like symbols, but prefixed with {{#:}}. They7evaluate to themselves. While they behave a lot like symbols in that8they are interned when read and can be compared in constant time with9{{eq?}}, they are a distinct type. In particular, they have no plist,10they cannot be bound or assigned to and aren't {{eq?}} to a symbol11with the same spelling. Procedures can use keywords to accept12optional named parameters in addition to normal required parameters.1314The parameter {{keyword-style}} and the compiler/interpreter option15{{-keyword-style}} can be used to allow an additional keyword syntax,16either compatible to Common LISP, or to DSSSL. As long as this17parameter is set to {{#:suffix}}, CHICKEN conforms to18[[http://srfi.schemers.org/srfi-88/srfi-88.html|SRFI-88]].1920There is also a {{srfi-88}} or {{(srfi 88)}} module which only21includes the standard procedures from the SRFI document, without the22CHICKEN extensions. {{(chicken keyword)}} offers the complete set of23procedures, both CHICKEN-specific and standard SRFI-88.2425==== get-keyword2627<procedure>(get-keyword KEYWORD ARGLIST [THUNK])</procedure>2829Returns the argument from {{ARGLIST}} specified under the keyword30{{KEYWORD}}. If the keyword is not found, then the zero-argument31procedure {{THUNK}} is invoked and the result value is returned. If32{{THUNK}} is not given, {{#f}} is returned.3334<enscript highlight=scheme>35(define (increase x . args)36 (+ x (get-keyword #:amount args (lambda () 1))) )37(increase 123) ==> 12438(increase 123 #:amount 10) ==> 13339</enscript>4041==== keyword?4243<procedure>(keyword? X)</procedure>4445Returns {{#t}} if {{X}} is a keyword, or {{#f}} otherwise.464748==== keyword->string4950<procedure>(keyword->string KEYWORD)</procedure>5152Transforms {{KEYWORD}} into a string.535455==== string->keyword5657<procedure>(string->keyword STRING)</procedure>5859Returns a keyword with the name {{STRING}}.606162---63Previous: [[Module (chicken irregex)]]6465Next: [[Module (chicken load)]]