From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: Replacement for Common Lisp's GENSYM in Emacs Lisp Date: Sun, 07 Mar 2010 18:07:55 +1100 Organization: Unlimited download news at news.astraweb.com Message-ID: <87tysssj78.fsf@rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1272990304 5665 80.91.229.12 (4 May 2010 16:25:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 May 2010 16:25:04 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 04 18:25:03 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O9Kvb-0006ps-QA for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 18:25:00 +0200 Original-Received: from localhost ([127.0.0.1]:37039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9Kva-0002dM-6r for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 12:24:58 -0400 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!news.astraweb.com!border1.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.93 (gnu/linux) Cancel-Lock: sha1:bQBoqrsVwis7U5K5/FGV5CQ7LXw= Original-Lines: 32 Original-NNTP-Posting-Host: f7a5ab73.news.astraweb.com Original-X-Trace: DXC=SIhMb4; AC8[bnnNk7ne37PL?0kYOcDh@ZN2; X=hn^b@_M] List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:72925 Archived-At: Teemu Likonen 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