Skip to content, Skip to search

Changes

Clojure Scripting

1 byte added, 04:43, 7 February 2009
m
no edit summary
* The backquote ` quotes the next expression, as defined by: `( <any code here> ). Which means the code block is <b>not</b> evaluated. But, unlike simple quote ', the backquote enables evaluation of expressions within the block when tagged with a ~ (a tilde).
* The ~ (tilde) evaluates the immediate expression. Can only be used in the context of a backquoted code block.
* The ~@ means <i>evaluate and expand</i>, which has the efect of placing the elements of a list as if they where declared in the code, without the list enclosure. So: `(~@(str "this" "that")) results in: "thisthat". In the example above, we expand the <i>& args</i>, which is a list containing all arguments given to the exec macro beyond the first and second (which are bound to <i>cmd</i> and <i>pred</i>, respectively). In this way, we lay down the proper function call of the <i>pred</i>, which is expected to be a function name (a predicate); the reason we use ~ on it is to evaluate <i>pred</i> so that it renders the pointer to the function itself. That <i>pred</i>function, by design, must accept a lazy sequence of text lines and any number of arguments afterwards.* The # tagged at the end of a word name expands to (gensym name), which results in creating a uniquely named symbol, to avoid name collisions.
* Any code present outside the backquote (none, in the case above) will be executed at macro read time, not at code execution time (aka run time)! So any precomputations are possible before laying down the code that will be executed at run time.
Emailconfirmed, uploaders
653
edits