Stefan Ram wrote:
> I have seen several ways to annotate S-expressions with
> "attributes":
>
> (example (name "value") (name1 "value1"))
> (example (name -> "value") (name1 -> "value1"))
> (example ((name "value") (name1 "value1")))
> (example '((name "value")(name1 "value1")))
> (example '(name "value" name1 "value1"))
> (example name: "value" name1: "value1" )
> (example :name "value" :name1 "value1" )
> (example 'name "value" 'name1 "value1")
>
> The following question might be related more to culture than
> to technology: Which of the above (or not of the above) is the
> usual - most common - way to write attributes?
Association lists (alists) and property (plists) lists are pretty
common. They both have their respective advantages. With association
lists, it's easier to see whether an element is actually associated to
something or not, because assoc returns the cons cell, and not just the
associated value. With property lists, you have the advantage that you
can APPLY functions on them which can use keyword arguments to pick out
the right values. I find the latter very handy.
Therefore, I have often seen keywords (:name, :name1, etc.) seen in
conjunction with property lists. I have never seen name: or -> with
either alists or plists. Something like name: probably doesn't even work
in Common Lisp.
Consider using objects for representing information. Writing macros that
expand into applications of make-instance is pretty straightforward, and
you get some added benefits beyond mere alists and plists.
> Actually I believe that property lists would be the feature
> corresponding most closely to attributes, but then they can
> not be used in anonymous list, but only with symbols?
They can also be used with anonymous lists. Check out GETF.
--
OOPSLA'05 tutorial on generic functions & the CLOS Metaobject Protocol
++++ see http://p-cos.net/oopsla05-tutorial.html for more details ++++
On Thu, 11 Aug 2005 17:34:38 +0200, Pascal Costanza wrote:
> [...]
> Therefore, I have often seen keywords (:name, :name1, etc.) seen in
> conjunction with property lists. I have never seen name: or -> with
> either alists or plists. Something like name: probably doesn't even work
> in Common Lisp.
DSSL uses 'name:' but it's a Scheme dialect and hence doesn't need to
honor CL's package notation (which would croak on name:).
Cheers Ralf Mattes