help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Replacement for Common Lisp's GENSYM in Emacs Lisp


From: Tim X
Subject: Re: Replacement for Common Lisp's GENSYM in Emacs Lisp
Date: Tue, 04 May 2010 15:41:47 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.93 (gnu/linux)

Teemu Likonen <tlikonen@iki.fi> writes:

> In Common Lisp GENSYM function generates unique symbol names. It seems
> that Emacs Lisp does not have similar function (unless with CL
> extension). In plain Emacs Lisp code and macros, what would you suggest
> as a replacement for GENSYM? Just some very unlikely names?
>
>

This is actually a non-trivial problem. Best approach would probably be
to do something similar to how they generate universally unique IDs. 

I'd probably use some combination of letters/name and a random number.
Once generated, I'd look to see if the symbol by that name is already
interned and if it was, increment the number and try again. 

Other approaches I've seen use name/letters and the date as seconds
since epoch plus a cuple of random digits. 

The solution that is best really depends on what the criteria is for
correctness. A large lisp implementation that runs a flight control
centre in a busy airport probalby has a higher correctness criteria than
a bit of elisp that uses gensyms in a macro that handles address records
for a address book.

In reality, I'd just use (require 'cl)

Tim


-- 
tcross (at) rapttech dot com dot au


reply via email to

[Prev in Thread] Current Thread [Next in Thread]