From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Johan Andersson Newsgroups: gmane.emacs.help Subject: Re: How to describe something in Lisp? Date: Tue, 3 Feb 2009 17:44:47 +0100 Message-ID: <929ccd880902030844h77859033q9a1c359595a0ece2@mail.gmail.com> References: <1233676167.44903@arno.fh-trier.de> <7cprhz3259.fsf@pbourguignon.anevia.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0015174c3f4ca686030462066332 X-Trace: ger.gmane.org 1233679536 21276 80.91.229.12 (3 Feb 2009 16:45:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 3 Feb 2009 16:45:36 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Pascal J. Bourguignon" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 03 17:46:50 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 1LUOPy-0003ma-Ih for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Feb 2009 17:46:34 +0100 Original-Received: from localhost ([127.0.0.1]:38218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUOOf-0000ma-G3 for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Feb 2009 11:45:13 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUOOI-0000lz-Ly for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:44:50 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUOOH-0000lj-KM for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:44:49 -0500 Original-Received: from [199.232.76.173] (port=48408 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUOOH-0000lg-Ed for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:44:49 -0500 Original-Received: from mail-ew0-f20.google.com ([209.85.219.20]:35707) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LUOOG-0007SZ-TE for help-gnu-emacs@gnu.org; Tue, 03 Feb 2009 11:44:49 -0500 Original-Received: by ewy13 with SMTP id 13so2757691ewy.18 for ; Tue, 03 Feb 2009 08:44:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=yqUwLPeFFnzaq4Un2k69bvvIlOkX/uAXDrvp4CaOEN4=; b=kluS1b8IJKZs/A2zh4TgLdcSRnaKwJF3QCGRGW2wCTZUJIfp3eLn6KpWR0YMqsnqv8 T6STtObaV89JPip+OtHxKKfbDllRpno5fl0VaTjx1wI1lIMwQw82FCJtgNj9yqKhxSgq aM/Lrkp/Btwbydsedgh8yv9ifbUL2164hGScY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=mkQ4oaA4SQT5FbRBFfKMXt//1Mx2hYVe347Ja0CFQtR8CI07wSt0nXyPwjN4imqmQg z7Nx21yHz0DJfu4LSSJar2R/XxFEc9Nn8joamnRoU1d5goH1pMjMM2nQ6StkuI9FH6x+ wG46NbH3s5P0hVa8iMjQoJp56ajBXS+fE33KQ= Original-Received: by 10.210.67.4 with SMTP id p4mr1994006eba.92.1233679488025; Tue, 03 Feb 2009 08:44:48 -0800 (PST) In-Reply-To: <7cprhz3259.fsf@pbourguignon.anevia.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:61883 Archived-At: --0015174c3f4ca686030462066332 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thanks all for your answers. All of your examples will work fine in my case. But is it "accepted" by Emacs users to code a mode using these structures? I've never seen them before. On Tue, Feb 3, 2009 at 5:40 PM, Pascal J. Bourguignon wrote: > Andreas Politz writes: > > > 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: > >> [...] > >> 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 > > [...] > > There is also EIEIO which is an implementation of CLOS, the Common > Lisp Object System, adapted for emacs. > > You can find it part of http://cedet.sourceforge.net/ > > Then you can define your objects: > > (require 'eieio) > > (defclass person > ((name :type string :initarg :name :accessor name) > (birthdate :type date :initarg :birthdate :accessor birthdate)) > (status :type marital-status :initarg :martial-status :accessor > martial-status) > (sex :type (member :male :female) :initarg :sex :accessor sex)) > > (defmethod age ((p person)) > (date- (now) (birthdate p))) > > ... > > -- > __Pascal Bourguignon__ > --0015174c3f4ca686030462066332 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks all for your answers.

All of your examples will work fine in = my case. But is it "accepted" by Emacs users to code a mode using= these structures? I've never seen them before.

On Tue, Feb 3, 2009 at 5:40 PM, Pascal J. Bourguignon <= ;pjb@informatimago.com> wrote:
Andreas Politz <politza@fh-trier.de> writes:

> 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 perso= n, 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<= br> >> datastructure (which kind of is the problem). And on save, the fil= e would be
>> updated. For me it's obvious to represent a person with a clas= s:
>> [...]
>>  I read something about object orientat= ion in lisp, but I have never
>> seen this be used in Emacs. So my question is basically: What is t= he best
>> way to model something in lisp, that you in an object oriented lan= guage
>> would model with a class.
>> Thanks!
>
> (defstruct person
> [...]

There is also EIEIO which is an implementation of CLOS, the Common
Lisp Object System, adapted for emacs.

You can find it part of http://cedet.sourceforge.net/

Then you can define your objects:

(require 'eieio)

(defclass person
 ((name       :type string :initarg :name    = ;  :accessor name)
  (birthdate  :type date   :initarg :birthdate :accessor bi= rthdate))
  (status     :type marital-status :initarg  :martial-= status :accessor martial-status)
  (sex        :type (member :male :female) :inita= rg :sex :accessor sex))

(defmethod age ((p person))
 (date- (now) (birthdate p)))

...

--
__Pascal Bourguignon__

--0015174c3f4ca686030462066332--