From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#20087: gensym Date: Tue, 22 Mar 2016 14:06:13 -0400 Message-ID: <87bn66wfoq.fsf@netris.org> References: <87a8zjxxpl.fsf@gnu.org> <87twjzytit.fsf@netris.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1458670108 31223 80.91.229.3 (22 Mar 2016 18:08:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Mar 2016 18:08:28 +0000 (UTC) Cc: 20087@debbugs.gnu.org To: rain1@openmailbox.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Tue Mar 22 19:08:18 2016 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aiQj1-0005Of-3l for guile-bugs@m.gmane.org; Tue, 22 Mar 2016 19:08:15 +0100 Original-Received: from localhost ([::1]:38749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiQj0-0000Ai-2U for guile-bugs@m.gmane.org; Tue, 22 Mar 2016 14:08:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiQir-00006i-K4 for bug-guile@gnu.org; Tue, 22 Mar 2016 14:08:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiQio-00054b-8u for bug-guile@gnu.org; Tue, 22 Mar 2016 14:08:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34952) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiQio-00054U-5B for bug-guile@gnu.org; Tue, 22 Mar 2016 14:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1aiQio-0004dD-2G for bug-guile@gnu.org; Tue, 22 Mar 2016 14:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 22 Mar 2016 18:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20087 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 20087-submit@debbugs.gnu.org id=B20087.145867002617721 (code B ref 20087); Tue, 22 Mar 2016 18:08:02 +0000 Original-Received: (at 20087) by debbugs.gnu.org; 22 Mar 2016 18:07:06 +0000 Original-Received: from localhost ([127.0.0.1]:60308 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aiQhu-0004bl-Cy for submit@debbugs.gnu.org; Tue, 22 Mar 2016 14:07:06 -0400 Original-Received: from world.peace.net ([50.252.239.5]:55171 ident=hope4) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aiQhs-0004bc-Os for 20087@debbugs.gnu.org; Tue, 22 Mar 2016 14:07:05 -0400 Original-Received: from [10.1.10.68] (helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aiQhC-0002Ep-3h; Tue, 22 Mar 2016 14:06:22 -0400 In-Reply-To: (rain1@openmailbox.org's message of "Tue, 22 Mar 2016 11:21:05 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.92 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7995 Archived-At: rain1@openmailbox.org writes: > On 2016-03-22 05:24, Mark H Weaver wrote: >> ludo@gnu.org (Ludovic Court=C3=A8s) writes: >>> =E2=80=98gensym=E2=80=99 returns interned symbols, but the algorithm to= determine the >>> new symbol is simplistic and predictable. >>> >>> Thus, one can arrange to produce a symbol before =E2=80=98gensym=E2=80= =99 does, >>> leading >>> =E2=80=98gensym=E2=80=99 to return a symbol that=E2=80=99s not fresh (i= n terms of =E2=80=98eq?=E2=80=99), >>> as is >>> the case with the second call to =E2=80=98gensym=E2=80=99 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. Can you give a (non-contrived) example of an application that requires the property you stated above, but does not rely on avoiding collisions with symbols interned after the gensym? I=E2=80=99m open to the idea that such applications exist, but at the momen= t I cannot think of one :) > About symbols interned after, would that refer to something like this: > > ------------------------ > scheme@(guile-user)> (define a (gensym "x")) > scheme@(guile-user)> a > $1 =3D x280 > scheme@(guile-user)> (eq? a (string->symbol "x280")) > $2 =3D #t > ------------------------ Right. Another example would be using =E2=80=98read=E2=80=99 after the gen= sym, on input that contains a symbol of the same name. > In most lisps gensym creates an uninterned symbol. I think that would > stop the previous giving #t. Indeed, it would solve this problem, but we cannot change the behavior of Guile's =E2=80=98gensym=E2=80=99 in this way, since it would break a lot= of existing code. By the way, I looked at our manual entry for =E2=80=98gensym=E2=80=99, and = it includes the following text: The symbols generated by =E2=80=98gensym=E2=80=99 are _likely_ to be u= nique, since their names begin with a space and it is only otherwise possible to generate such symbols if a programmer goes out of their way to do so. Uniqueness can be guaranteed by instead using uninterned symbols (*noteSymbol Uninterned::), though they can=E2=80=99t be usefully written= out and read back in. We have =E2=80=98make-symbol=E2=80=99 for creating uninterned symbols, alth= ough you must provide the exact name of the returned symbol. > I could write a patch for this if wanted. It would be nice to have another procedure, maybe =E2=80=98uninterned-gensy= m=E2=80=99 (I=E2=80=99m not sure what to call it, names are hard :) which would be like =E2=80=98gensym=E2=80=99 but would return an uninterned symbol, and thus re= liably avoid collisions. If you=E2=80=99d like to contribute such a procedure, that would be welcome. It is our policy to ask contributors to assign copyright to the Free Software Foundation. Would you be willing to do this? Mark