[Xpath-ng] List constructor syntax

Jeni Tennison jeni at jenitennison.com
Mon Dec 2 09:47:58 MST 2002


Hi David,

> If I have a list of lists
>
> (list (list 1 2)  (list 3 4))
>
> Then I can make a list of all their first elements, something like
>
> (mapcar 'car (list (list 1 2)  (list 3 4)))
> (1 3)
>
> (It's useful if your mail client has a built in lisp system:-)
>
> But how's the (mapcar 'car function supposed to work if one of the
> child lists was a singleton, it gets automatically flattened and
> then presumably errors as you can't apply car to a non list.

Let me play devil's advocate. You're making the assumption that you
can't apply car to a non list. The point, I think, of making singleton
lists equivalent to single values, is that the reverse is true a
single value *is* a singleton list. So:

> So a simpler example: Is
>
> (car (list 1))
>
> which I'd expect to be 1
>
> the same as 
>
> (car 1)

Yes, they both return 1.

In other words, all values are lists; all functions return lists and
accept lists as arguments (though some functions might enforce a
restriction that the lists they accept are singleton lists).

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/




More information about the Xpath-ng mailing list