std-defkeyword


Synopsis

(std-defkeyword '<sym>) ; define a selfevaluating symbol

(std-keywordp <sym>) ; check for keyword

Description

STD-DEFKEYWORD is used to create a constant which evaluates to itself.

It uses STD-DEFCONSTANT to set the symbol to the value of the symbol itself. So every evaluation of the symbol will return the symbol.

Usually, to be compatible with Common Lisp, we mark these symbols with a leading colon ":". Those keywords are used as markers and special values in argument lists, where you may or may not forget to quote a symbol. as you like.

Any subsequent assignment to this symbol may either print a warning or an error. It is visually marked in blue.

It is comparable to the Common Lisp macro defkeyword and to all symbols in the keyword package prefixed with ":"

Some modules already predefined some keywords, exp. the error handler, see STD-VAR-INIT

STD-KEYWORDP is used to check for a keyword. This predicate returns T if the symbol evaluates to itself and if the symbol-name starts with a colon, or nil if not. If the argument is no symbol, nil is returned even if the expression, esp. an atom evaluates to itself.

The required colon should force easier to read code, in Common Lisp keywords always have a leading colon.

Example

(std-defkeyword ':width)	=> :WIDTH
(std-defkeyword ':length)	=> :LENGTH
:LENGTH => :LENGTH

(std-keywordp :length)	=> T

(std-var-init '((:ERROR . MY-ERROR)))

;; note, we don't need to quote :ERROR

(std-var-init (list (cons :ERROR
  (defun MY-ERROR (s) (std-var-restore)))))

;; not recommended:

(std-defkeyword 'my:key)	=> my:key
(std-keywordp my:length)	=> nil (!!)

Arguments

sym: a quoted symbol, which evaluates to a symbol which needs not to be bound.

value: any valid lisp expression

Return Value

The return value of value.

Side Effects

This function is only called because of its side effect.

It changes the value of sym.

The argument <value> is always evaluated.

Module

(std-require 'STDLISP)

Defined in STDLISP