From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Using Emacs Lisp for script writing Date: Tue, 22 Dec 2009 16:36:56 +0100 Organization: Informatimago Message-ID: <87637zrpev.fsf@hubble.informatimago.com> References: <87hbrrrl3c.fsf@Traian.DecebalComp> <87vdg09ls9.fsf@Traian.DecebalComp> <878wcw53mj.fsf@lion.rapttech.com.au> <87pr677s4z.fsf@Traian.DecebalComp> <874onj5jxu.fsf@lion.rapttech.com.au> <87ljgv3ymp.fsf@Traian.DecebalComp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1261496523 24017 80.91.229.12 (22 Dec 2009 15:42:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Dec 2009 15:42:03 +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 Dec 22 16:41:56 2009 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.50) id 1NN6ry-0005Yi-0J for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Dec 2009 16:41:54 +0100 Original-Received: from localhost ([127.0.0.1]:52217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NN6ry-0002JD-33 for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Dec 2009 10:41:54 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 70 Original-X-Trace: individual.net +fnvUznfHWzg90+IeFMHBgbTEI8a/EnjdGtv5IHOD1OS0BXHK5 Cancel-Lock: sha1:ZTUyYzY5MzU5ODc5N2IzZGU4MGI3YzYzZTg5ODBlNzgxNGEwMDQ1Yg== sha1:sRubPuitOBksKEvP5brSZhriZro= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux) Original-Xref: news.stanford.edu gnu.emacs.help:175728 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor 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:70802 Archived-At: Cecil Westerhof writes: > I'll try to keep that in mind. But compiling the regular expression made > a big difference. Also, I remember someone telling me that lists are not > very efficient. See? This is what we meant when we told you that you need to know more before trying to optimize things out! Adding an element to a list or removing one is O(1) (when it's the first element of the list). Doing the same with a vector is O(n). With a tree it'll be O(log(n)), and with a hash-table, it will be O(1) amortized, that is, the constant factors will kill you. Now of course if your algorithm is not adding or removing the first element of the data structure, the time complexities and constant factors will be different. So either you have a partial memory, or the someone who told you that lists are not very efficient did the same error most people do, that is forgetting the conditions of application. > What should I use instead? Or will I found that out in > Practical Common Lisp? Practical Common Lisp is only the first step. There is a lot of literature to read and programs to write to learn what has to be learnt. Browse the cliki: http://cliki.net/Education http://cliki.net/Online%20Tutorial http://cliki.net/Lisp%20books > Another question. The BBDB and also the example in Practical Common Lisp > use lists for the database. Is this not inefficient? No, not in those conditions of application. > Would a real database not be better. Not that I want to burn me at > the moment on databases. ;-) A real database would be overkill to store five records. Just "opening" the database would takes hundreds times more of cycles than pushing onto a list, and don't you know the speed differential between memory write and disk writes? Remember this is a "simple database", a small example given to give a taste of lisp before even introducing the Syntax of lisp! But the most important thing you should have learnt from this chapter, is not that it used lists to store the records, but that the storing of the records was abstracted away with a add-record function. That means that all the programs presented in this chapter will work the same once you hook a disk based database under add-record instead of the simple list (See SICP). -- __Pascal Bourguignon__ http://www.informatimago.com/ "Specifications are for the weak and timid!"