GNU bug report logs -
#20087
'gensym' is not guaranteed to return a fresh symbol
Previous Next
Reported by: ludo <at> gnu.org (Ludovic Courtès)
Date: Wed, 11 Mar 2015 17:16:02 UTC
Severity: normal
Done: Andy Wingo <wingo <at> pobox.com>
Bug is archived. No further changes may be made.
Full log
Message #17 received at 20087 <at> debbugs.gnu.org (full text, mbox):
On 2016-03-22 05:24, Mark H Weaver wrote:
> ludo <at> gnu.org (Ludovic Courtès) writes:
>> ‘gensym’ returns interned symbols, but the algorithm to determine the
>> new symbol is simplistic and predictable.
>>
>> Thus, one can arrange to produce a symbol before ‘gensym’ does,
>> leading
>> ‘gensym’ to return a symbol that’s not fresh (in terms of ‘eq?’), as
>> is
>> the case with the second call to ‘gensym’ here:
>
> rain1 <at> openmailbox.org writes:
>> I agree, this goes against the main assumption people have about
>> gensym. I was able to reproduce the bug.
>>
>> Here's a patch to libguile/symbol.c which fixes this behavior by
>> incrementing the gensym counter in a loop until it creates a fresh
>> symbol.
>
> I've considered this idea in the past, but it only avoids collisions
> with symbols that have been interned before the gensym. It does not
> avoid collisions with symbols interned *after* the gensym. Obviously,
> there's no way to avoid such collisions.
Thanks for looking over the patch I sent!
One expects of gensym to create a fresh symbol, something not EQ? to any
symbol that already exists. It is an important property to be able to
rely on and this patch achieves that.
About symbols interned after, would that refer to something like this:
------------------------
scheme@(guile-user)> (define a (gensym "x"))
scheme@(guile-user)> a
$1 = x280
scheme@(guile-user)> (eq? a (string->symbol "x280"))
$2 = #t
------------------------
In most lisps gensym creates an uninterned symbol. I think that would
stop the previous giving #t. I could write a patch for this if wanted.
This bug report was last modified 9 years and 30 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.