unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: rain1@openmailbox.org
To: 20087@debbugs.gnu.org
Subject: bug#20087: gensym
Date: Tue, 22 Mar 2016 11:21:05 +0000	[thread overview]
Message-ID: <d25c385d3db69db4c23edb7312bef96d@openmailbox.org> (raw)
In-Reply-To: <87twjzytit.fsf@netris.org>

On 2016-03-22 05:24, Mark H Weaver wrote:
> ludo@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@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.






  parent reply	other threads:[~2016-03-22 11:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-11 17:15 bug#20087: 'gensym' is not guaranteed to return a fresh symbol Ludovic Courtès
2016-03-18 17:03 ` bug#20087: gensym rain1
2016-03-22  5:24   ` Mark H Weaver
2016-03-22  7:58     ` Ludovic Courtès
2016-03-23 17:55       ` Mark H Weaver
2016-03-24  8:45         ` Ludovic Courtès
2016-06-23 13:48           ` Andy Wingo
2016-06-23 14:13             ` Ludovic Courtès
2016-06-23 16:05               ` Andy Wingo
2016-03-22 11:21     ` rain1 [this message]
2016-03-22 18:06       ` Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d25c385d3db69db4c23edb7312bef96d@openmailbox.org \
    --to=rain1@openmailbox.org \
    --cc=20087@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).