help-gnu-emacs
[Top][All Lists]
Advanced

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

How to describe something in Lisp?


From: Johan Andersson
Subject: How to describe something in Lisp?
Date: Tue, 3 Feb 2009 15:23:10 +0100

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!

reply via email to

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