'replace' will except
anything as the first parameter and then look it up in the list or string following.
As a rule all functions will evaluate their parameters. Only this way it is possible to pass parameters in variables:
In this case the variable symbol 'key' has to be evaluated to find out whats inside, which could be a number, string list-expression or anything else to be looked up inside whats in the second varable 'list-or-string'.
For 'key' this could be a symbol itself:
Code: Select all
(set 'key 'x)
(replace key '(a b x d e f) 'c) => (a b c d e f)
There are functions which deviate from the rule to evaluate all parameters and these are called
special forms. For example in newLISP flow contructs like 'case', 'dotimes', 'dolist' and 'for' are all special forms, in:
the function 'dotimes' has at least two parameters: '(i N)' and one or more expressions 'exp'. The first '(i N)' is not evaluates, but instead the 'dotimes' function looks inside and evalautes 'N' to find out how often to iterate over the exp1,exp2 .... and evaluate them over and over again, N times.
Another examples is 'setq', which does evaluate only its second parameter, but not the first:
Code: Select all
(set 'x 'y)
(setq y 123)
(set 'y 123)
(set x 123)
x => y
Y => 123
The 'setq' and 2 following 'set' statements do all the same, setting the contents of the symbol 'y' to 123. 'setq' is a special form with special evaluation rules, 'set' is not.
Lutz