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

Uniqueness of &rest arguments



    Date: Mon, 28 Oct 85 16:09 EST
    From: Guy Steele <gls@THINK-AQUINAS.ARPA>

	Date: 28 Oct 1985 15:32-EST
	From: OLDMAN@USC-ISI.ARPA

	Are &rest arguments guaranteed to be copied?  Consider the following:

	    (defmacro m (&rest args)
		 `',(nreverse args)        ; Destructive reverse
	    )
	    (setq x '(m a b c d))
	    (eval x)

	What is the final value of x?   I think that I would argue that
	it is undefined since args may or may not be a copy of the original
	form.   Is there anything in Cttl that clarifies this?

    I cannot find any place in the manual that addresses this point.  The
    text describing APPLY alludes to appending the last argument to APPLY to
    a list of all other arguments (except the function, of course), and so
    one might think, referring to the definition of APPEND, that the
    resulting list of arguments might contain actual cons cells from the
    list that is the last argument to APPLY.  However, nothing addresses
    whether a &REST argument might share with this list.

None of this applies to macros anyway, since they aren't invoked with APPLY.

    My own opinion is that indeed the args might not be a copy of the
    original form, but I regard this as a non-trivial clarification worthy
    of discussion.

I hope it doesn't take a whole lot of discussion.  It's pretty clear to me
that if the manual doesn't guarantee explicitly that the user can freely
bash the &rest argument, then the user can only sensibly assume that it is
not safe to bash it.  I also can't see any significant advantage to the user
to be gained requiring implementations to make copies of &rest arguments.
Note that if there are implementations that can't avoid making a copy (but
not for macros!), they can easily have a compiler optimizer to remove
calls to copy-list, so there can be no argument from efficiency.