Reputation: 31
For my homework, I have a small List interpreter written in C with few functions already coded : set
, cons
, car
, cdr
and quote
.
And I have to add 6 another functions of my choice. 3 with argument evaluation, and 3 without argument evaluation.
With evaluation, I choose : eq
, +
and -1
,
but I don't have any idea for the 3 next, what kind of Lisp function is useful without argument evaluation ?
Upvotes: 1
Views: 767
Reputation: 60014
All arguments to lisp functions are always evaluated.
This is not the case
for macros
and special operators,
one of which, quote
,
you have already implemented.
The standard example when deferred evaluation is useful is:
(if (under-attack-p)
(launch-missiles)
(print "Peace!"))
I the arguments of if
were evaluated,
then we would ...
print
Peace!
Peace!
(the value returned by
print
), otherwise return the value of launch-missiles
However, the special operator if
evaluates its first argument and
decides which of the other two argument to evaluate based on that value.
See also How does `if` not evaluate all its arguments?
Upvotes: 4