[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to describe something in Lisp?

From: Johan Andersson
Subject: Re: How to describe something in Lisp?
Date: Tue, 3 Feb 2009 17:44:47 +0100

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 <address@hidden> wrote:
Andreas Politz <address@hidden> 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

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__

reply via email to

[Prev in Thread] Current Thread [Next in Thread]