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

Re: Bug & co



Lauri Alanko:

> The semantics of reverse! are not _completely_ obvious, especially not
> to someone who's used to, say, arrays. For example, the original poster
> _might_ have expected reverse! to simple rearrange the _elements_ in the
> list without modifying the structure, like this:
> 
> (define (reverse! l)
>   (define (aux curr)
   ... etc. : a 1-level deep copy.

> Of course this is inefficient and generally a bad idea, but still, it's
> not "elementary", and certainly not obvious from the description "list
> is destructively reversed".

RRight. It *might* work differently. I protested as I did for two reasons:

1. Manuel Giraud didn't ask *why*, he said that this is a *bug*, and it was
   followed by a reasoning which was not addressing this problem. But this
   is a standard cliché, covered by textbooks for at least 30 years. 
   So I was surprised, but I sincerely regret having reacted theatrically.

2. "Elementary" is the fact that when you have update'able data structures,
   and call by value protocol, the variable which points to this structure
   may, and usually will have everything invalidated, so you cannot draw a
   conclusion that a massacre of l constitutes a bug, or anything. In fact
   you have no right to assume anything, and if I were an implementor of
   a Scheme-like language, I would try - if possible - to put at the address
   containing a structure which gets masticated a kind of special-undefined-
   object-which-will-scream-bloody-murder-and-prevent-you-from-doing-anything-
   with.


Jerzy Karczmarczuk