about:compile-time-vs-run-time-values
A symbol can have two values: a compile-time value and a run-time value.
Run-time values are functions, numbers, strings and other objects. Compile-time values are special forms, macros and compiler macros.
When a symbol is referenced in the first position of a form, its compile-time value is considered before its run-time value. In any other position only the run-time value is considered.
do is a special form equivalent to a {...} block in other languages. It has
a compile-time value but no run-time value:
make-html > (do (print-line 1) (print-line 1))
1
1
make-html > do
Undefined variable: lisp:do
+ is a function. It has a no compile-time value but only a run-time value:
make-html > (+ 3 4)
it: 7
make-html > +
it: #<Function Name="Kiezel.Runtime.Add">
make-html > (map + '(1 2) '(3 4))
it: (4 6)
or is a special form and a function. It has a compile-time value and a
run-time value:
make-html > (or (number? (do (print-line 123) 123))
(string? (do (print-line "abc") "abc")))
123
it: true
make-html > or
it: #<Function Name="Kiezel.Runtime.LogicalOr">
make-html > (map or '(true false) '(true true))
it: (true true)
Depending on the actual arguments, calls to the following functions can be made faster by some Dynamic Language Runtime trickery.
Only special forms can implement the short-circuiting behaviour of these functions, but the equivalent functions are nice to have.
Kiezellisp compiler macros are similar to Common Lisp compiler macros. Use a compiler macro to optimize special cases of a function call.
make-html > (defun ++ (&rest numbers)
(apply + numbers))
it: ++
make-html > (define-compiler-macro ++ (&rest numbers &whole original-form)
(if (and (= (length numbers) 2)
(number? (second numbers))
(= (second numbers) 1))
`(inc ,(first numbers))
original-form))
it: ++
make-html > (macroexpand '(++ a b c))
it: (++ a b c)
make-html > (macroexpand '(++ a 1))
it: (inc a)
The special forms def, defun, defun*, defconstant, defonce, defmulti
and defmethod set a symbol's run-time value while erasing its
compile-time value.
The special forms defmacro and define-symbol-macro set a symbol's compile-time
value while erasing its run-time value.
The special form define-compiler-macro sets a symbol's compile-time value and
requires its current run-time value to be a function.