From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.help Subject: Re: How to describe something in Lisp? Date: Tue, 03 Feb 2009 17:24:21 +0100 Message-ID: <87tz7bbia2.fsf@tux.homenetwork> References: <929ccd880902030623t1ccb3567weecce35deb378f73@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1233678705 18324 80.91.229.12 (3 Feb 2009 16:31:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 3 Feb 2009 16:31:45 +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:33:00 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 1LUOCh-0006MA-Bg for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Feb 2009 17:32:51 +0100 Original-Received: from localhost ([127.0.0.1]:37854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUOBN-0004Cp-V3 for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Feb 2009 11:31:29 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUOB5-0004Cc-3U for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:31:11 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUOB2-0004CQ-No for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:31:09 -0500 Original-Received: from [199.232.76.173] (port=36886 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUOB2-0004CN-IU for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:31:08 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:52338 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LUOB2-0005sx-5b for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:31:08 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1LUOAy-0008EB-Pj for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 16:31:04 +0000 Original-Received: from 90.211.85-79.rev.gaoland.net ([79.85.211.90]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Feb 2009 16:31:04 +0000 Original-Received: from thierry.volpiatto by 90.211.85-79.rev.gaoland.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 03 Feb 2009 16:31:04 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 75 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 90.211.85-79.rev.gaoland.net User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.90 (gnu/linux) Cancel-Lock: sha1:un3SoYMLbiFaHLwTqZ5c+3u3gPQ= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:61879 Archived-At: Hi, Johan Andersson writes: > 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! Does that help? ,---- | ELISP> (defstruct People name age) | People | ELISP> (defvar P (make-People :name "thierry" :age "45")) | P | ELISP> (People-name P) | "thierry" | ELISP> (People-age P) | "45" | ELISP> (setf (People-age P) "46") | "46" | ELISP> (People-age P) | "46" `---- -- A + Thierry Volpiatto Location: Saint-Cyr-Sur-Mer - France