Re: [sawfish] Re: The dark corners of rep

On May 20, Timo Korvola wrote:
> Eli Barzilay <eli barzilay org> writes:
> > In any case, that's another rep difference from Scheme -- it
> > provides both `rplaca'/`rplacd' and `setcar'/`setcdr' -- the
> > difference seems to be the return value.
> The names and return values of setc[ad]r seem to stem from Emacs
> Lisp.  The return values of rplac[ad] are as in Common Lisp.

Yes, I forgot to include the conclusion -- rep provides all four like
elisp, but with different semantics for the latter two like Lisp.

> (Scheme has set-c[ad]r! with undefined return values.)


> > (Using such mutation is a bad idea anyway,
> Sometimes it is useful for performance but care is required not to
> mutate objects referenced from code that expects them to stay
> constant.  And most code expects that.

Right.  This is why in PLT Scheme there are boxes (similar to
one-value cons cells) that are intended for mutation, and why you can
define your own struct with mutable fields.  (The same philosophy goes
in CLtL, as the part I quoted shows.)

> > and using the result of a side-effect function is also a bad
> > idea.)
> Only when the return value is undefined.  E.g., not using the result
> of nreverse would be kind of strange.

If the return value is unspecified (as it is in Scheme), then using
the result is impossible.  (At least not for portable code.)  My point
was that even if it is defined, it's a bad idea to have functions that
both perform some side-effect and return some value.  What usually
happens with most scheme implementations (where there is some specific
"unspecified" value that you get back) is that the property of
side-effect-ness tends to propagate -- a function that prints stuff
will in most cases return that unspecified value since its last
expression will be a print call; a function that mutates stuff will
also return the unspecified value for similar reasons.  This avoids
silently hiding bugs in that code that is supposed to do side effects
is not usually mixed and confused with code that is computing some

The flip side of this is making things a little inconvenient when you
want to chain assignments -- but that's a really lame argument for
encouraging sloppy coding style for that benefit.  It was even a
common argument at some point that allowing `x = y = z = 0' in C is
good because it allows the compiler to optimize the code.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                         Maze is Life!

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