1
votes

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 ?

1
In Common Lisp, all functions evaluate their arguments. If arguments aren't to be evaluated, then you need a macro or special form that doesn't evaluate its arguments.Joshua Taylor
Perhaps you could implement cond which does not evaluate its arguments like a function. Maybe you could implement some other special forms for control flow. Maybe you could implement defun.Dan Robertson
Why tag common-lisp? Are you making a dual namespace lisp? lexically scoped of dynamicly scoped? I would have decided on those two before deciding on which special forms to implement besides if which is a slam dunk.Sylwester

1 Answers

4
votes

The need for deferred evaluation

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 ...

  1. check whether we are under attack
  2. print Peace!
  3. launch the missiles
  4. if we were under attack, return 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?

My recommendation for implementation is: