* Generating an unique symbol in elisp
@ 2010-12-03 21:19 Alin Soare
2010-12-03 21:30 ` Edward O'Connor
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Alin Soare @ 2010-12-03 21:19 UTC (permalink / raw)
To: Emacs Dev
[-- Attachment #1: Type: text/plain, Size: 522 bytes --]
A very useful function for generating private environments is the
(gensym&optional x) in common lisp. It can replace in some places the
closures.
In Clisp it is defined in C something like this:
char*
gensym (char *x)
{
static int x;
char a[100];
snprintf(a, 100, "%s%d", x? x:"G", x++);
return strdup (a);
}
Does this function already exist in elisp ? I looked in the manual and did
not find it...
Alin
*
---
*
Wenn ich 'Kultur' höre, nehme ich meine Pistole
Hermann Göring
*
*
[-- Attachment #2: Type: text/html, Size: 620 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Generating an unique symbol in elisp
2010-12-03 21:19 Generating an unique symbol in elisp Alin Soare
@ 2010-12-03 21:30 ` Edward O'Connor
2010-12-03 21:33 ` Alin Soare
2010-12-03 21:41 ` Andreas Schwab
2010-12-03 22:34 ` Stefan Monnier
2 siblings, 1 reply; 11+ messages in thread
From: Edward O'Connor @ 2010-12-03 21:30 UTC (permalink / raw)
To: Alin Soare; +Cc: Emacs Dev
> Does this function already exist in elisp ? I looked in the manual and did
> not find it...
`make-symbol' creates uninterned symbols.
Ted
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Generating an unique symbol in elisp
2010-12-03 21:30 ` Edward O'Connor
@ 2010-12-03 21:33 ` Alin Soare
2010-12-03 22:03 ` Edward O'Connor
0 siblings, 1 reply; 11+ messages in thread
From: Alin Soare @ 2010-12-03 21:33 UTC (permalink / raw)
To: Edward O'Connor; +Cc: Emacs Dev
[-- Attachment #1: Type: text/plain, Size: 273 bytes --]
> Does this function already exist in elisp ? I looked in the manual and did
> > not find it...
>
> `make-symbol' creates uninterned symbols.
>
The name is the problem. Does it generate an uninexistent name, or have I
write a function to generate the uninexistent name ?
[-- Attachment #2: Type: text/html, Size: 518 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Generating an unique symbol in elisp
2010-12-03 21:33 ` Alin Soare
@ 2010-12-03 22:03 ` Edward O'Connor
2010-12-03 22:12 ` Alin Soare
0 siblings, 1 reply; 11+ messages in thread
From: Edward O'Connor @ 2010-12-03 22:03 UTC (permalink / raw)
To: Alin Soare; +Cc: Emacs Dev
> The name is the problem. Does it generate an uninexistent name, or have I
> write a function to generate the uninexistent name ?
The name isn't the problem. You can (make-symbol "foo") a bunch of
times, and you'll have a bunch of different symbols. That's what it
means for them to be uninterned.
Ted
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Generating an unique symbol in elisp
2010-12-03 22:03 ` Edward O'Connor
@ 2010-12-03 22:12 ` Alin Soare
2010-12-03 22:23 ` Drew Adams
2010-12-03 22:46 ` Stefan Monnier
0 siblings, 2 replies; 11+ messages in thread
From: Alin Soare @ 2010-12-03 22:12 UTC (permalink / raw)
To: Edward O'Connor; +Cc: Emacs Dev
[-- Attachment #1: Type: text/plain, Size: 634 bytes --]
2010/12/4 Edward O'Connor <hober0@gmail.com>
> > The name is the problem. Does it generate an uninexistent name, or have I
> > write a function to generate the uninexistent name ?
>
> The name isn't the problem. You can (make-symbol "foo") a bunch of
> times, and you'll have a bunch of different symbols. That's what it
> means for them to be uninterned.
>
Good.
Can you bind a value in variable field/ evaluate a symbol as a variable if
it is not interned ?
Otherwise, can you create an obarray (different of main obarr) and intern
within it only a few symbols (in this case the matter ), and evaluate within
that environment ?
[-- Attachment #2: Type: text/html, Size: 981 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: Generating an unique symbol in elisp
2010-12-03 22:12 ` Alin Soare
@ 2010-12-03 22:23 ` Drew Adams
2010-12-03 22:38 ` Alin Soare
2010-12-03 22:46 ` Stefan Monnier
1 sibling, 1 reply; 11+ messages in thread
From: Drew Adams @ 2010-12-03 22:23 UTC (permalink / raw)
To: 'Alin Soare', 'Edward O'Connor'; +Cc: 'Emacs Dev'
> can you create an obarray (different of main obarr) and intern
> within it only a few symbols (in this case the matter ), and
> evaluate within that environment ?
Yes. That's the idea behind having separate obarrays.
There are no doubt examples of this in the Lisp sources.
If not, here is one: http://www.emacswiki.org/emacs/synonyms.el.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Generating an unique symbol in elisp
2010-12-03 22:12 ` Alin Soare
2010-12-03 22:23 ` Drew Adams
@ 2010-12-03 22:46 ` Stefan Monnier
1 sibling, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2010-12-03 22:46 UTC (permalink / raw)
To: Alin Soare; +Cc: Edward O'Connor, Emacs Dev
> Can you bind a value in variable field/ evaluate a symbol as a variable if
> it is not interned ?
Yes. The fact that it's interned or not only affects the Lisp reader,
not the interpreter.
> Otherwise, can you create an obarray (different of main obarr) and intern
> within it only a few symbols (in this case the matter ),
Yes.
> and evaluate within that environment ?
Elisp does not have such a notion, no.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Generating an unique symbol in elisp
2010-12-03 21:19 Generating an unique symbol in elisp Alin Soare
2010-12-03 21:30 ` Edward O'Connor
@ 2010-12-03 21:41 ` Andreas Schwab
2010-12-03 21:44 ` Alin Soare
2010-12-03 22:34 ` Stefan Monnier
2 siblings, 1 reply; 11+ messages in thread
From: Andreas Schwab @ 2010-12-03 21:41 UTC (permalink / raw)
To: Alin Soare; +Cc: Emacs Dev
Alin Soare <as1789@gmail.com> writes:
> Does this function already exist in elisp ? I looked in the manual and did
> not find it...
gensym is a compiled Lisp function in `cl-macs.el'.
(gensym &optional PREFIX)
Generate a new uninterned symbol.
The name is made by appending a number to PREFIX, default "G".
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Generating an unique symbol in elisp
2010-12-03 21:19 Generating an unique symbol in elisp Alin Soare
2010-12-03 21:30 ` Edward O'Connor
2010-12-03 21:41 ` Andreas Schwab
@ 2010-12-03 22:34 ` Stefan Monnier
2 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2010-12-03 22:34 UTC (permalink / raw)
To: Alin Soare; +Cc: Emacs Dev
> A very useful function for generating private environments is the
> (gensym&optional x) in common lisp. It can replace in some places the
> closures.
> Does this function already exist in elisp ? I looked in the manual and did
> not find it...
It's called make-symbol.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2010-12-03 22:46 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-03 21:19 Generating an unique symbol in elisp Alin Soare
2010-12-03 21:30 ` Edward O'Connor
2010-12-03 21:33 ` Alin Soare
2010-12-03 22:03 ` Edward O'Connor
2010-12-03 22:12 ` Alin Soare
2010-12-03 22:23 ` Drew Adams
2010-12-03 22:38 ` Alin Soare
2010-12-03 22:46 ` Stefan Monnier
2010-12-03 21:41 ` Andreas Schwab
2010-12-03 21:44 ` Alin Soare
2010-12-03 22:34 ` Stefan Monnier
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).