From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.help Subject: Re: How to describe something in Lisp? Date: Tue, 03 Feb 2009 16:48:24 +0100 Organization: FH-Trier Message-ID: <1233676167.44903@arno.fh-trier.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1233679259 20259 80.91.229.12 (3 Feb 2009 16:40:59 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 3 Feb 2009 16:40:59 +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 Feb 03 17:42:13 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 1LUOLl-0001oR-27 for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Feb 2009 17:42:13 +0100 Original-Received: from localhost ([127.0.0.1]:46950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUOKS-0007Rx-Ap for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Feb 2009 11:40:52 -0500 Original-Path: news.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!t-online.de!news-2.dfn.de!news.uni-stuttgart.de!news.belwue.de!news.uni-kl.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 76 Original-NNTP-Posting-Host: 143-93-54-11.arno.fh-trier.de Original-X-Trace: news.uni-kl.de 1233676237 28968 143.93.54.11 (3 Feb 2009 15:50:37 GMT) Original-X-Complaints-To: usenet@news.uni-kl.de Original-NNTP-Posting-Date: Tue, 3 Feb 2009 15:50:37 +0000 (UTC) User-Agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018) In-Reply-To: Cache-Post-Path: arno.fh-trier.de!unknown@dslb-088-068-219-008.pools.arcor-ip.net X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) Original-Xref: news.stanford.edu gnu.emacs.help:166564 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:61880 Archived-At: Johan Andersson wrote: > Hi! > > As a Java and Ruby programmer I sometimes find it hard to code Lisp. Right > now I'm working on a minor mode for which the structure would obvious for me > in Java or Ruby, but in Lisp is a riddle. > > I will not describe the mode itself, but give a description of the problem. > Say I want to store a list of people in a file. And for each person, also > some information on them in the format: > name|age|married|sex > > Each time I start the mode, that file should be parsed in to some > datastructure (which kind of is the problem). And on save, the file would be > updated. For me it's obvious to represent a person with a class: > class Person > var name, age, married, sex > > methods... > end > > Then I could easy update attributes on the objects, remove and add people > and then update the file. > > I tried with a couple of solutions for this in Lisp: > > 1) One list named people: > ( > (name age married sex) > ... > ) > > 2) Multiple lists named name, age, married and sex where the index decides > the connection between the lists: > (name1 name2) > (age1 age2) > (married1 married2) > (sex1 sex2) > > 3) Same as two, but with arrays: > [name1 name2] > [age1 age2] > [married1 married2] > [sex1 sex2] > > > Each way above has their disadvantages and I think none of them is good > enough. I read something about object orientation in lisp, but I have never > seen this be used in Emacs. So my question is basically: What is the best > way to model something in lisp, that you in an object oriented language > would model with a class. > > Thanks! > (defstruct person name age married sex) (person-name (make-person :name "Hans")) You most likely can read about it here: (info "(cl)Top") Other possibilities include association lists (info "(elisp)Association List Type") and property lists (info "(elisp)Property Lists") . -ap