Arc Forumnew | comments | leaders | submitlogin
1 point by waterhouse 4761 days ago | link | parent

> Association lists could be (x 1 y 2) instead of ((x 1) (y 2))

Nice, I never consciously realized that. (I suppose we've been seeing it all along in replacing (let ((a 1) (b 2))) with (with (a 1 b 2)), but I never thought about remaking alists that way.) I think the single drawback of actually doing that is that O(n) lookup is now O(2n). [Obviously, if lookup time is a bottleneck, you probably should replace the alists with something else, like... tables! or AVL trees.]



1 point by Pauan 4761 days ago | link

It's an old concept, known as plists[1]. Common Lisp has them, and uses the same syntax that I'm proposing.

By the way, one benefit of alists is that you can iterate over them easier:

  (each '(k v) '((a 1) (b 2) (c 3))
    ...)
Compared to the following, with a plist:

  (each '(k v) (pair '(a 1 b 2 c 3))
    ...)
Which, incidentally, uses `pair` to create an alist, then iterate over that... I was thinking about how to solve this, and figured a form of destructuring might help:

  (each :(k v) '(:a 1 :b 2 :c 3)
    ...)

  ; or this...?

  (each (:k v) '(:a 1 :b 2 :c 3)
    ...)
But that's still kinda up in the air at this point.

---

* [1]: http://www.gigamonkeys.com/book/practical-a-simple-database....

http://www.ida.liu.se/imported/cltl/clm/node108.html

http://www.augustana.ab.ca/~mohrj/courses/common/csc370/lect...

(Search for "property" to jump to the relevant portions.)

-----