unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp
       [not found] ` <20170912151315.C449D2087D@vcs0.savannah.gnu.org>
@ 2017-09-12 16:48   ` Stefan Monnier
  2017-09-12 17:21     ` Mark Oteiza
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2017-09-12 16:48 UTC (permalink / raw)
  To: emacs-devel; +Cc: Mark Oteiza

> +(defun gensym (&optional prefix)
> +  "Return a new uninterned symbol.
> +The name is made by appending `gensym-counter' to PREFIX.
> +PREFIX can be a string, and defaults to \"G\".
> +If PREFIX is a number, it replaces the value of `gensym-counter'."

I understand that Common-Lisp has that "PREFIX is a number"
functionality, but I could never find a use-case for it, so I wonder why
we carry over that baggage to Elisp?


        Stefan



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp
  2017-09-12 16:48   ` [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp Stefan Monnier
@ 2017-09-12 17:21     ` Mark Oteiza
  2017-09-12 17:35       ` Mark Oteiza
  2017-09-12 18:28       ` Stefan Monnier
  0 siblings, 2 replies; 9+ messages in thread
From: Mark Oteiza @ 2017-09-12 17:21 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 12/09/17 at 12:48pm, Stefan Monnier wrote:
> > +(defun gensym (&optional prefix)
> > +  "Return a new uninterned symbol.
> > +The name is made by appending `gensym-counter' to PREFIX.
> > +PREFIX can be a string, and defaults to \"G\".
> > +If PREFIX is a number, it replaces the value of `gensym-counter'."
> 
> I understand that Common-Lisp has that "PREFIX is a number"
> functionality, but I could never find a use-case for it, so I wonder why
> we carry over that baggage to Elisp?

It was just simpler to not duplicate the code for such a small
historical tidbit.  I have no problem with the idea of dropping it.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp
  2017-09-12 17:21     ` Mark Oteiza
@ 2017-09-12 17:35       ` Mark Oteiza
  2017-09-12 18:28       ` Stefan Monnier
  1 sibling, 0 replies; 9+ messages in thread
From: Mark Oteiza @ 2017-09-12 17:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 12/09/17 at 01:21pm, Mark Oteiza wrote:
> On 12/09/17 at 12:48pm, Stefan Monnier wrote:
> > > +(defun gensym (&optional prefix)
> > > +  "Return a new uninterned symbol.
> > > +The name is made by appending `gensym-counter' to PREFIX.
> > > +PREFIX can be a string, and defaults to \"G\".
> > > +If PREFIX is a number, it replaces the value of `gensym-counter'."
> > 
> > I understand that Common-Lisp has that "PREFIX is a number"
> > functionality, but I could never find a use-case for it, so I wonder why
> > we carry over that baggage to Elisp?
> 
> It was just simpler to not duplicate the code for such a small
> historical tidbit.  I have no problem with the idea of dropping it.

Is this what you mean? (I lowered the prefix for good measure)

diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi
index 2d9ec6fda3..cda5f1c40f 100644
--- a/doc/lispref/symbols.texi
+++ b/doc/lispref/symbols.texi
@@ -276,8 +276,7 @@ Creating Symbols
 @defun gensym &optional prefix
 This function returns a symbol using @code{make-symbol}, whose name is
 made by appending @code{gensym-counter} to @var{prefix}.  The prefix
-defaults to @code{"G"}.  If @var{prefix} is a number, it replaces the
-value of the counter.
+defaults to @code{"g"}.
 @end defun
 
 @defun intern name &optional obarray
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index eee5953882..3405c92e8d 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -161,9 +161,16 @@ cl--expr-depends-p
 
 ;;; Symbols.
 
-(defvaralias 'cl--gensym-counter 'gensym-counter)
+(defvar cl--gensym-counter 0)
 ;;;###autoload
-(cl--defalias 'cl-gensym 'gensym)
+(defun cl-gensym (&optional prefix)
+  "Generate a new uninterned symbol.
+The name is made by appending a number to PREFIX, default \"G\"."
+  (let ((pfix (if (stringp prefix) prefix "G"))
+	(num (if (integerp prefix) prefix
+	       (prog1 cl--gensym-counter
+		 (setq cl--gensym-counter (1+ cl--gensym-counter))))))
+    (make-symbol (format "%s%d" pfix num))))
 
 (defvar cl--gentemp-counter 0)
 ;;;###autoload
diff --git a/lisp/subr.el b/lisp/subr.el
index ebb8b53b50..52d4e190e7 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -286,13 +286,10 @@ gensym-counter
 (defun gensym (&optional prefix)
   "Return a new uninterned symbol.
 The name is made by appending `gensym-counter' to PREFIX.
-PREFIX can be a string, and defaults to \"G\".
-If PREFIX is a number, it replaces the value of `gensym-counter'."
-  (let ((pfix (if (stringp prefix) prefix "G"))
-        (num (if (integerp prefix) prefix
-               (prog1 gensym-counter
-                 (setq gensym-counter (1+ gensym-counter))))))
-    (make-symbol (format "%s%d" pfix num))))
+PREFIX is a string, and defaults to \"g\"."
+  (let ((num (prog1 gensym-counter
+               (setq gensym-counter (1+ gensym-counter)))))
+    (make-symbol (format "%s%d" prefix num))))
 
 (defun ignore (&rest _ignore)
   "Do nothing and return nil.



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp
  2017-09-12 17:21     ` Mark Oteiza
  2017-09-12 17:35       ` Mark Oteiza
@ 2017-09-12 18:28       ` Stefan Monnier
  2017-09-12 18:51         ` Mark Oteiza
  2017-09-13  3:48         ` Alex
  1 sibling, 2 replies; 9+ messages in thread
From: Stefan Monnier @ 2017-09-12 18:28 UTC (permalink / raw)
  To: Mark Oteiza; +Cc: emacs-devel

> It was just simpler to not duplicate the code for such a small
> historical tidbit.

Damn!  So still no explanation for that weird functionality.


        Stefan



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp
  2017-09-12 18:28       ` Stefan Monnier
@ 2017-09-12 18:51         ` Mark Oteiza
  2017-09-13  3:48         ` Alex
  1 sibling, 0 replies; 9+ messages in thread
From: Mark Oteiza @ 2017-09-12 18:51 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 12/09/17 at 02:28pm, Stefan Monnier wrote:
> > It was just simpler to not duplicate the code for such a small
> > historical tidbit.
> 
> Damn!  So still no explanation for that weird functionality.

Nope, the best answer I have is what the CL spec says :(



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp
  2017-09-12 18:28       ` Stefan Monnier
  2017-09-12 18:51         ` Mark Oteiza
@ 2017-09-13  3:48         ` Alex
  2017-09-13 12:40           ` Stefan Monnier
  1 sibling, 1 reply; 9+ messages in thread
From: Alex @ 2017-09-13  3:48 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Mark Oteiza, emacs-devel

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> It was just simpler to not duplicate the code for such a small
>> historical tidbit.
>
> Damn!  So still no explanation for that weird functionality.
>
>
>         Stefan

According to [1] (page 53), MACLISP didn't have a visible
gensym-counter, and instead used an integer argument to gensym to allow
programs to set an internal counter. According to [2], it was only
decided in 1989 to have *gensym-counter* in CL, so before then having an
integer argument made sense if you wanted to manipulate the gensym
state.

I don't think an integer argument makes much sense when there's a
visible counter available. Checking it only in cl-gensym and not in
gensym is a nice idea, but I wonder if people who use an integer
argument here are the type of people to use `cl' instead of `cl-lib'.

Footnotes: 
[1]  http://www.softwarepreservation.org/projects/LISP/MIT/Moon-MACLISP_Reference_Manual-Apr_08_1974.pdf

[2]  https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node110.html




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp
  2017-09-13  3:48         ` Alex
@ 2017-09-13 12:40           ` Stefan Monnier
  2017-09-13 12:50             ` Mark Oteiza
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2017-09-13 12:40 UTC (permalink / raw)
  To: Alex; +Cc: Mark Oteiza, emacs-devel

> According to [1] (page 53), MACLISP didn't have a visible
> gensym-counter, and instead used an integer argument to gensym to allow
> programs to set an internal counter. According to [2], it was only
> decided in 1989 to have *gensym-counter* in CL, so before then having an
> integer argument made sense if you wanted to manipulate the gensym
> state.

An integer arg that lets you set the internal counter makes some
sense, yes.  But the integer arg implements in cl-lib.el (and in clisp,
FWIW) does not affect the internal counter.

> but I wonder if people who use an integer argument here are the type
> of people to use `cl' instead of `cl-lib'.

I think using the plural here is rather optimistic.  I'd already be
surprised if there's even just one user of that functionality.


        Stefan



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp
  2017-09-13 12:40           ` Stefan Monnier
@ 2017-09-13 12:50             ` Mark Oteiza
  2017-09-28  7:05               ` Alex
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Oteiza @ 2017-09-13 12:50 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Alex, emacs-devel

On 13/09/17 at 08:40am, Stefan Monnier wrote:
> > According to [1] (page 53), MACLISP didn't have a visible
> > gensym-counter, and instead used an integer argument to gensym to allow
> > programs to set an internal counter. According to [2], it was only
> > decided in 1989 to have *gensym-counter* in CL, so before then having an
> > integer argument made sense if you wanted to manipulate the gensym
> > state.

Thanks for digging that up.

> > but I wonder if people who use an integer argument here are the type
> > of people to use `cl' instead of `cl-lib'.
> 
> I think using the plural here is rather optimistic.  I'd already be
> surprised if there's even just one user of that functionality.

Only one way to find out! I suppose I'll apply the patch I sent earlier.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp
  2017-09-13 12:50             ` Mark Oteiza
@ 2017-09-28  7:05               ` Alex
  0 siblings, 0 replies; 9+ messages in thread
From: Alex @ 2017-09-28  7:05 UTC (permalink / raw)
  To: Mark Oteiza; +Cc: emacs-devel

Mark Oteiza <mvoteiza@udel.edu> writes:

> On 13/09/17 at 08:40am, Stefan Monnier wrote:
>> > According to [1] (page 53), MACLISP didn't have a visible
>> > gensym-counter, and instead used an integer argument to gensym to allow
>> > programs to set an internal counter. According to [2], it was only
>> > decided in 1989 to have *gensym-counter* in CL, so before then having an
>> > integer argument made sense if you wanted to manipulate the gensym
>> > state.
>
> Thanks for digging that up.
>
>> > but I wonder if people who use an integer argument here are the type
>> > of people to use `cl' instead of `cl-lib'.
>> 
>> I think using the plural here is rather optimistic.  I'd already be
>> surprised if there's even just one user of that functionality.
>
> Only one way to find out! I suppose I'll apply the patch I sent earlier.

It doesn't really matter, but wouldn't it be a bit nicer if cl-gensym
and gensym shared the same counter and default prefix?



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-09-28  7:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20170912151313.7686.92637@vcs0.savannah.gnu.org>
     [not found] ` <20170912151315.C449D2087D@vcs0.savannah.gnu.org>
2017-09-12 16:48   ` [Emacs-diffs] master 35c893d 2/2: Move gensym to core Elisp Stefan Monnier
2017-09-12 17:21     ` Mark Oteiza
2017-09-12 17:35       ` Mark Oteiza
2017-09-12 18:28       ` Stefan Monnier
2017-09-12 18:51         ` Mark Oteiza
2017-09-13  3:48         ` Alex
2017-09-13 12:40           ` Stefan Monnier
2017-09-13 12:50             ` Mark Oteiza
2017-09-28  7:05               ` Alex

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).