[Top][All Lists]

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

Re: Guile: What's wrong with this?

From: Mark H Weaver
Subject: Re: Guile: What's wrong with this?
Date: Thu, 05 Jan 2012 17:42:51 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Bruce Korb <address@hidden> writes:
> Anyway, such a concept should be kept
> very simple:  functions that modify their argument make copies of
> any input argument that is read only.  Any other SCM's lying about
> that refer to the unmodified object continue referring to that
> same unmodified object.  No mind reading required.
>    (define a "hello")
>    (define b a)
>    (string-upcase! a)
>    b

I suspect that what you really want is for `define' (and maybe some
other things) to automatically do a deep copy instead of merely making a
new reference to an existing object.

For example, you seem to want (define a "hello") to make a fresh copy of
the string literal, and for (define b a) to make another copy so that
changes to the string referenced by `b' do not affect the string
referenced by `a'.

You seem to not want to think about aliasing issues.  Indeed, it would
be more intuitive if we always copied everything deeply, but that would
be strictly less powerful, not to mention far less efficient, especially
when handling large structures.

`define' merely makes a new reference to an existing object.  If you
want a copy, you must explicitly ask for one (though this could be
hidden by custom syntax).  It would not be desirable for the language to
make copies automatically as part of the core `define' syntax.  For one
thing, sometimes you don't want a copy.  Sometimes you want shared
mutable objects.

Even if you do want to copy, there are different kinds of copies.  How
deeply do you want to copy?  If it's a hierarchical list, do you want to
copy only the first level of the list, or do you want to recurse?
Suppose this hierarchical list contains strings.  Do you want to copy
the strings too, or just the list structure?  I could go on and on.
There's no good universal copier; it depends on your purposes.

If you want an abbreviated way to both `define' and `copy', then you'll
need to make new syntax to do that.  Guile provides all the power you
need to do this.


reply via email to

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