[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

non-list arguments



    I haven't checked the manuals for T or Scheme but it was certainly the
    intent that the list passed to APPLY is unrelated to the list that a
    rest-parameter gets bound to.  The rest-list should always be freshly
    consed, so e.g. the procedure LIST is equivalent to (LAMBDA X X).  The
    last argument to APPLY must be a proper list.  I think Common Lisp takes
    the same stance.

A quick scan of the Common Lisp book leaves the question unresolved;
maybe Guy Steele could comment.  However, I have seen object-oriented
programs where this would probably lead to less than the most efficient
implementation.  Suppose we represent objects by procedures and call
them using the general form

	(<object> <key> <other stuff>)

where the <key> indicates the operation to be performed on <object> and
<other stuff> (possibly empty) consists of operation-dependent
parameters.  One way to code up such an object is as

	(lambda (key . rest)
	  (cond ((eq? key 'foo) (apply f1 rest))
		((eq? key 'bar) (apply f2 (cons 'barbar rest)))
		...))

where we use the key to pick a function (or new object) to forward the
request to, on the assumption that somebody at the end of the chain will
actually use the rest of the original arguments.  Putting an extra list
copy in at each forwarding step seems mildly expensive and somewhat
unnecessary.  I don't think that LAMBDA should be prohibited from
checking that its argument is a true list, or from copying it over, but
I also don't think it should be required to.  Why is it important for
the list of rest arguments to be copied over when we don't, for example,
expect quoted lists to be copied over every time an expression '(...) is
evaluated?

To summarize, I think it should be permissible for

	(eq? ((lambda x x) l) l)

to return true, but it should not be a requirement.  Furthermore, it
should be permissible for an implementation to report an error if l in
the above expression is not a true list, but an implementation should
not be required to do so.  Of course, it would still be true that

	((lambda x x) 3 4 5)

would return a freshly consed list, just like (list 3 4 5).  An
interesting question:  do people expect (apply list l) to return a
top-level copy of l?					-b.