6.6.0. Symbolic Constants
|
(lsh/libc/constants.lsh) |
header files of C libraries are often filled with large amounts of
#define directives that define numerical macros, flags and other
constants. Interfacing these libraries to Lush requires to turn those
constants into Lisp symbols. Lush contains a mechanism for defining such
constants without filling up the global variable name space and risquing
name clashes. Constants can be defined with the
(defconstant "constant-name" value) directive. Constants can
later be accessed using the @constant-name
macro or the @@constant-name macro.
The @ macro expands into a macro that
evaluates to the value, while @@
directly expands to the value at read time.
See: @ identifier
See: (defconstant identifier
val )
6.6.0.0. (defconstant identifier val)
|
(lsh/libc/constants.lsh) |
Defines a symbolic constant named identifier
and equal to val . Argument
identifier must be a string or a symbol. Argument
val must be a number or a string. These constant values are
not accessible as variables but are accessible using the |@|
macro-character.
6.6.0.1. @identifier @@identifier
|
(lsh/libc/constants.lsh) |
These macro-character expand to a expressions that retrieve the value of
the symbolic constant named identifier
. The @ form causes the retrieval to
occur at macro-expansion time. while the @@
form causes the retrieval to occur at read time. These macros are
particularly useful for using symbolic constants in compiled code.
Argument identifier must be a legal C
identifier name.
Compatibility notes:
- If identifier
has not been defined using defconstant
, the global value of the symbol named identifier
is used.
- If the macro-character |@| cannot
read a legal C identifier name, it reads a lisp expression and arranges
for that expression to be evaluated during the macro expansion time.
- The expansion of the @@ form
depends on the execution of the previous expressions, which may cause
discrepancies when loading tokenized files. However, the
@@ is more efficient in interpreted mode since the expansion
occurs in advance of execution.