guile-user
[Top][All Lists]
Advanced

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

Question on mutability of argument lists


From: Niels Möller
Subject: Question on mutability of argument lists
Date: Wed, 19 Mar 2014 10:34:43 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (usg-unix-v)

Hi,

I discovered r7rs thanks to the recent guile release announcement. I
have one question (which likely applies also to earlier revisions). Not
sure what the right forum is, but I hope some of the guile people are
familiar with these things and if maybe even can push for some
clarification of the spec if needed. I tried mailing to
address@hidden, but that list seems to be
member's only).

When specifying the use of rest arguments for procedures (r7rs, sec
4.1.4), it seems to imply that the passed argument list is mutable? This
is convenient in some ways, e.g., I think the following definition of
the list procedure should be correct

  (define (list . args) args) 

However, for a natural implementation which evaluates arguments and
conses the results up to a list, this seems to require an extra copy of
the argument list, after all values are evaluated and before the list is
bound to the rest parameter. To see why, assume that evaluation of one
of the arguments captures its continuation and returns several times. If
this isn't the first argument evaluated, without the extra copying, one
gets several calls to the procedure with the rest argument sharing
structure, and if the shared part is mutated, things go bad. And since
I'd expect that the vast majority of function calls with rest arguments
to *not* need any mutability of the argument list, this extra copying
seems like an undesirable overhead.

On the other hand, if the argument is specified as immutable, then no
copying is needed in the common case (as far as I understand, consing up
the evaluated arguments will give the correct results no matter how many
times the evaluation of a particular argument returns), but instead, the
implementation of procedures like list must explicitly construct a
new mutable copy of the argument list.

It's not obvious if the general description "All objects created by the
other procedures listed in this report are mutable." (sec 3.4) applies
to the constructed argument lists, so if argument lists for rest
parameters really are intended to be mutable, then I think that could be
made clearer.

I guess the formal semantics section ought to answer the question on
whether or not one can get shared structure in argument lists in case
evaluation of an argument returns multiple times, but I haven't tried to
figure that out...

Regards,
/Niels Möller

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]