[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: lisp style question
From: |
Erik Winkels |
Subject: |
Re: lisp style question |
Date: |
03 Dec 2010 12:59:32 GMT |
User-agent: |
slrn/0.9.8.1 (FreeBSD) |
On 2010-12-03, Katalin Sinkov <lispstylist@gmail.com> wrote:
> On Dec 2, 12:50 am, "Frode V. Fjeld" <fr...@netfonds.no> wrote:
>> Katalin Sinkov <lispstyl...@gmail.com> writes:
>> > In the {} world I would return a small table like
>>
>> > width 1
>> > height 2
>> > weight 3
>>
>> Typically in Lisp you'd return either a property or association list.
>>
>> I.e: (WIDTH 1 HEIGHT 2 WEIGHT 3) with accessor GETF,
>>
>> or ((WIDTH . 1) (HEIGHT . 2) (WEIGHT . 3)) with accessor ASSOC.
>
> Of all the four or five replies, I found yours most helpful although
> brief. This is perhaps due to me being a beginner, although the
> replies seem very promising and I am desirous of understanding them. I
> have just read the paper by McCarthy and the micro manual.
>
> assoc. and pair. are the most elementary of the functions, although
> not primitive and used in evaluator for working the symbol table.
>
> but beyond this, i could not understand your post.
I'm very fond of using plists when exploratory programming and find
alists to be a little more verbose. Here's a small example (I always
use keywords as indicators: they stand out a little more and avoid
package troubles):
CL-USER(2): (defun plist-example (width height weight)
(list :width width :height height :weight weight))
PLIST-EXAMPLE
CL-USER(3): (defparameter plist (plist-example 1 2 3))
PLIST
CL-USER(4): plist
(:WIDTH 1 :HEIGHT 2 :WEIGHT 3)
CL-USER(5): (getf plist :height)
2
CL-USER(6): (setf (getf plist :height) 4)
4
CL-USER(8): plist
(:WIDTH 1 :HEIGHT 4 :WEIGHT 3)