Gruppen du sender innlegg til, er en Usenet-gruppe. E-postadressen til forfatteren av meldinger som legges inn i denne gruppen, vil vises for alle på Internett.
r...@zedat.fu-berlin.de (Stefan Ram) writes: > I could use »first component« and »second component«, but this > is a two-word term (compound term). I do not deem compound > terms to be appropriate for such fundamental concepts. For the > same reason, I prefer »pair« to »2-tuple«. A 2-tuple might > have a »first component« and a »second component«, but a pair > should have a CAR and a CDR (or some other single-word term).
On Jun 14, 9:47 pm, rwander...@rsw.digi.com.br wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes: > > I could use »first component« and »second component«, but this > > is a two-word term (compound term). I do not deem compound > > terms to be appropriate for such fundamental concepts. For the > > same reason, I prefer »pair« to »2-tuple«. A 2-tuple might > > have a »first component« and a »second component«, but a pair > > should have a CAR and a CDR (or some other single-word term).
On Jun 14, 1:34 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com> wrote:
> Head & Tail perhaps.
"Head" and "tail" are my favorites too. I like them better than "first" and "rest" because the latter terms are more abstract and could apply to sequences implemented in other ways than as lists. "Head" and "tail", on the other hand, seem to me to refer specifically to the structure of a list.
Of course I don't mind "car" and "cdr", but this is just from training :)
Scott Burson wrote: > On Jun 14, 1:34 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com> > wrote: >> Head & Tail perhaps.
> "Head" and "tail" are my favorites too. I like them better than > "first" and "rest" because the latter terms are more abstract and > could apply to sequences implemented in other ways than as lists. > "Head" and "tail", on the other hand, seem to me to refer specifically > to the structure of a list.
> Of course I don't mind "car" and "cdr", but this is just from > training :)
Cons cells can be used for things other than lists. For example, trees and just pairs.
Slobodan Blazeski <slobodan.blaze...@gmail.com> writes: > On Jun 14, 9:47 pm, rwander...@rsw.digi.com.br wrote: >> r...@zedat.fu-berlin.de (Stefan Ram) writes: >> > I could use »first component« and »second component«, but this >> > is a two-word term (compound term). I do not deem compound >> > terms to be appropriate for such fundamental concepts. For the >> > same reason, I prefer »pair« to »2-tuple«. A 2-tuple might >> > have a »first component« and a »second component«, but a pair >> > should have a CAR and a CDR (or some other single-word term).
>> What about just >>first<< and >>second<<?
> Head & Tail perhaps.
Head and Tail are asymetric and presuppose a list structure. First and Second expect a Third and Fourth and so on.
CAR and CDR are agnostic.
Alternatives would be: Top and Bottom, Up and Down, Left and Right, Charm and Strange, Yin and Yang, etc. but they're all overloaded. At least CAR and CDR are specific to computer pairs.
On Jun 14, 10:47 pm, rwander...@rsw.digi.com.br wrote:
> r...@zedat.fu-berlin.de (Stefan Ram) writes: > > I could use »first component« and »second component«, but this > > is a two-word term (compound term). I do not deem compound > > terms to be appropriate for such fundamental concepts. For the > > same reason, I prefer »pair« to »2-tuple«. A 2-tuple might > > have a »first component« and a »second component«, but a pair > > should have a CAR and a CDR (or some other single-word term).
> What about just >>first<< and >>second<<?
> Rodrigo
As noted many times before, car & cdr have a good property of nesting: caar, cadar and even cadadar :)
You can try fst & rst: frst, frrst,-- for that as well. But it as well (like car/cdr) requires getting used to.
Scott Burson <FSet....@gmail.com> writes: > On Jun 14, 1:34 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com> > wrote:
>> Head & Tail perhaps.
> "Head" and "tail" are my favorites too. I like them better than > "first" and "rest" because the latter terms are more abstract and > could apply to sequences implemented in other ways than as lists. > "Head" and "tail", on the other hand, seem to me to refer specifically > to the structure of a list.
I'm not 100% sure on this, but I'd say that the shortcuts of the composed forms were of importance as well (if not greater importance given the number of shortcuts defined in the standard). For example:
(car (cdr x))
can be rewritten as a single function
(cadr x).
I know the shortcuts are somewhat frowned upon now, but perhaps there is time in lisp's history when the shortcuts may have been common practice. Take all this with a grain of salt. Part of me has always wondered why they were even specified in the standard way down to CDDDDR. Can someone enlighten me?
I wish I had the neurons and synapses that allowed me to navigate my data structures using CADAAR and CADADR! Maybe the coffee was much better in the past.
Mark Cox <markco...@gmail.com> wrote: +--------------- | I wish I had the neurons and synapses that allowed me | to navigate my data structures using CADAAR and CADADR! +---------------
The one place I find myself frequently using CDD*R is in destructuring lists by "gulps" in LOOP, e.g.:
> (defun group-by-triples (list) (loop for (a b c) on list by #'cdddr collect (list a b c)))
Note: Whether sublist (12 NIL NIL) is the "correct" result or a "bug" depends upon your application. Adjusting the function so that the last sublist is (12) is left as an exercise for the reader. ;-} ;-}
-Rob
----- Rob Warnock <r...@rpw3.org> 627 26th Avenue <URL:http://rpw3.org/> San Mateo, CA 94403 (650)572-2607
> Scott Burson wrote: > > On Jun 14, 1:34 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com> > > wrote: > >> Head & Tail perhaps.
> > "Head" and "tail" are my favorites too. I like them better than > > "first" and "rest" because the latter terms are more abstract and > > could apply to sequences implemented in other ways than as lists. > > "Head" and "tail", on the other hand, seem to me to refer specifically > > to the structure of a list.
> > Of course I don't mind "car" and "cdr", but this is just from > > training :)
> Cons cells can be used for things other than lists. For example, trees > and just pairs.
True. But CL itself defines `first' and `rest' as synonyms of `car' and `cdr'. I was just explaining why I like `head' and `tail' better.
Personally, I tend to use `car' and `cdr', and I agree that there are situations where these semantically unloaded terms are the only ones that really work. But for those who would like to use more semantically loaded terms in the extremely common case that the conses form a list, I recommend `head' and `tail'.
On Jun 14, 2:28 pm, p...@informatimago.com (Pascal J. Bourguignon) wrote:
> Alternatives would be: Top and Bottom, Up and Down, Left and Right, > Charm and Strange, Yin and Yang, etc. but they're all overloaded. At > least CAR and CDR are specific to computer pairs.
* (Rob Warnock) <_qudnZGHoOhXUajXnZ2dnUVZ_tmdn...@speakeasy.net> : Wrote on Sun, 14 Jun 2009 23:23:38 -0500: | | The one place I find myself frequently using CDD*R is in destructuring | lists by "gulps" in LOOP, e.g.: | | > (defun group-by-triples (list) | (loop for (a b c) on list by #'cdddr | collect (list a b c))) | | GROUP-BY-TRIPLES | > (group-by-triples '(0 1 2 3 4 5 6 7 8 9 10 11 12)) | | ((0 1 2) (3 4 5) (6 7 8) (9 10 11) (12 NIL NIL)) | > | | Note: Whether sublist (12 NIL NIL) is the "correct" result or a "bug" | depends upon your application. Adjusting the function so that the last | sublist is (12) is left as an exercise for the reader. ;-} ;-}
You clearly don't want (12) in the output list because then you have a situation where the accursed recursive solution is preferable over using our glorious LOOP:
(defun group-by-triples (list &optional ret) (if (some (lambda (x) (endp (funcall x list))) '(cdddr cddr cdr)) (nreconc ret (list list)) (group-by-triples (cdddr list) (cons (ldiff list (cdddr list)) ret))))
And of course, if you are the inveterate CADDARing aesthete, the
Scott Burson wrote: > On Jun 14, 2:20 pm, Pascal Costanza <p...@p-cos.net> wrote: >> Scott Burson wrote: >>> On Jun 14, 1:34 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com> >>> wrote: >>>> Head & Tail perhaps. >>> "Head" and "tail" are my favorites too. I like them better than >>> "first" and "rest" because the latter terms are more abstract and >>> could apply to sequences implemented in other ways than as lists. >>> "Head" and "tail", on the other hand, seem to me to refer specifically >>> to the structure of a list. >>> Of course I don't mind "car" and "cdr", but this is just from >>> training :) >> Cons cells can be used for things other than lists. For example, trees >> and just pairs.
> True. But CL itself defines `first' and `rest' as synonyms of `car' > and `cdr'. I was just explaining why I like `head' and `tail' better.
> Personally, I tend to use `car' and `cdr', and I agree that there are > situations where these semantically unloaded terms are the only ones > that really work. But for those who would like to use more > semantically loaded terms in the extremely common case that the conses > form a list, I recommend `head' and `tail'.
Scott Burson <FSet....@gmail.com> writes: > On Jun 14, 2:20 pm, Pascal Costanza <p...@p-cos.net> wrote: >> Scott Burson wrote: >> > On Jun 14, 1:34 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com> >> > wrote: >> >> Head & Tail perhaps.
>> > "Head" and "tail" are my favorites too. I like them better than >> > "first" and "rest" because the latter terms are more abstract and >> > could apply to sequences implemented in other ways than as lists. >> > "Head" and "tail", on the other hand, seem to me to refer specifically >> > to the structure of a list.
>> > Of course I don't mind "car" and "cdr", but this is just from >> > training :)
>> Cons cells can be used for things other than lists. For example, trees >> and just pairs.
> True. But CL itself defines `first' and `rest' as synonyms of `car' > and `cdr'.
It's an error to believe that first and rest are synonymous to car and cdr. There's a big difference: first and rest apply on lists, while car and cdr apply on cons cells.
> I was just explaining why I like `head' and `tail' better.
> Personally, I tend to use `car' and `cdr', and I agree that there are > situations where these semantically unloaded terms are the only ones > that really work.
Yes.
> But for those who would like to use more > semantically loaded terms in the extremely common case that the conses > form a list, I recommend `head' and `tail'.
Not in lisp, where the traditionnal way to decompose lists is by first and rest.
Notice that a tail doesn't start from the head, but from the end of the body. If you had head, body, tail, then perhaps head and tail could be used (along with body).
(defun head (x) (first x)) (defun body (x) (rest (butlast x))) (defun tail (x) (first (last x)))
On 2009-06-14 17:28:58 -0400, p...@informatimago.com (Pascal J. Bourguignon) said:
> Alternatives would be: Top and Bottom, Up and Down, Left and Right, > Charm and Strange, Yin and Yang, etc. but they're all overloaded. At > least CAR and CDR are specific to computer pairs.
On Jun 14, 5:28 pm, p...@informatimago.com (Pascal J. Bourguignon) wrote: [...]
> Alternatives would be: Top and Bottom, Up and Down, Left and Right, > Charm and Strange, Yin and Yang, etc. but they're all overloaded. At > least CAR and CDR are specific to computer pairs.
The publishers of the venerable /Car and Driver/ magazine only half agree. ;)
> > On Jun 14, 2:20 pm, Pascal Costanza <p...@p-cos.net> wrote: > >> Scott Burson wrote: > >> > On Jun 14, 1:34 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com> > >> > wrote: > >> >> Head & Tail perhaps.
> >> > "Head" and "tail" are my favorites too. I like them better than > >> > "first" and "rest" because the latter terms are more abstract and > >> > could apply to sequences implemented in other ways than as lists. > >> > "Head" and "tail", on the other hand, seem to me to refer specifically > >> > to the structure of a list.
> >> > Of course I don't mind "car" and "cdr", but this is just from > >> > training :)
> >> Cons cells can be used for things other than lists. For example, trees > >> and just pairs.
> > True. But CL itself defines `first' and `rest' as synonyms of `car' > > and `cdr'.
> It's an error to believe that first and rest are synonymous to car and > cdr. There's a big difference: first and rest apply on lists, while > car and cdr apply on cons cells.
Not so. Cons cells and lists are not distinct in Lisp. The standard *defines* FIRST to be synonymous with CAR and REST to be synonymous with CDR. It may be a good idea to keep the two concepts distinct, but Common Lisp doesn't enforce -- or even support -- any distinction. Some people consider this a feature.
wrote: > On 2009-06-14 17:28:58 -0400, p...@informatimago.com (Pascal J. > Bourguignon) said:
> > Alternatives would be: Top and Bottom, Up and Down, Left and Right, > > Charm and Strange, Yin and Yang, etc. but they're all overloaded. At > > least CAR and CDR are specific to computer pairs.
I'm personally a fan of FST and RST, but if you really want something concise that doesn't evoke lists I'd suggest SEL and SER for SElect Left and SElect Right. These are also composable in the obvious way. Or if you don't like Left and Right, you can do SEA/SEB, or SEX/SEY, SEA/SEZ, or SEA/SEO (for Alpha and Omega). If you have a unicode-aware Lisp you can even put real alpha and omega characters in there.
>> > On Jun 14, 2:20 pm, Pascal Costanza <p...@p-cos.net> wrote: >> >> Scott Burson wrote: >> >> > On Jun 14, 1:34 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com> >> >> > wrote: >> >> >> Head & Tail perhaps.
>> >> > "Head" and "tail" are my favorites too. I like them better than >> >> > "first" and "rest" because the latter terms are more abstract and >> >> > could apply to sequences implemented in other ways than as lists. >> >> > "Head" and "tail", on the other hand, seem to me to refer specifically >> >> > to the structure of a list.
>> >> > Of course I don't mind "car" and "cdr", but this is just from >> >> > training :)
>> >> Cons cells can be used for things other than lists. For example, trees >> >> and just pairs.
>> > True. But CL itself defines `first' and `rest' as synonyms of `car' >> > and `cdr'.
>> It's an error to believe that first and rest are synonymous to car and >> cdr. There's a big difference: first and rest apply on lists, while >> car and cdr apply on cons cells.
> Not so. Cons cells and lists are not distinct in Lisp. The standard > *defines* FIRST to be synonymous with CAR and REST to be synonymous with > CDR. It may be a good idea to keep the two concepts distinct, but > Common Lisp doesn't enforce -- or even support -- any distinction. Some > people consider this a feature.
And I have the regret to inform you that you are not distinct from your mass of lead. Same number of quarks, same forces. The universe doesn't enforce any distinction here either. And yes, it's a feature too :-)
Pillsy <pillsb...@gmail.com> writes: > On Jun 14, 5:28 pm, p...@informatimago.com (Pascal J. Bourguignon) > wrote: > [...] >> Alternatives would be: Top and Bottom, Up and Down, Left and Right, >> Charm and Strange, Yin and Yang, etc. but they're all overloaded. At >> least CAR and CDR are specific to computer pairs.
> The publishers of the venerable /Car and Driver/ magazine only half > agree. ;)
Notice the difference between CAR and car. The former is a TLA standing for Content of Address Register part, the later is a word derived from latin carrum designating a celtic two-wheeled war chariot.
Long life to case sensitivity! -- __Pascal Bourguignon__
r...@zedat.fu-berlin.de (Stefan Ram) writes: > I was searching for a word referring to the »x« and > »y« in the relation »R(x,y)«. Assume, for a moment, > the word would be »alpha« and »beta«, respectively, > then I would like to write this explanation of "is a":
> "is a" > the relation, where the alpha is an instance of the beta
> I looked up these web pages to find common, simple words for > the placeholders »alpha« and »beta«:
Well, I would expect that the most standard mathemtical terminology would use "domain" and "range" for those concepts.
This meets your desire (below) of not having multiple word terms. Otherwise I would use "argument 1" and "argument 2". These could be abbreviated as arg1 and arg2, which would parallel the standard mathematical notation of tuples (which is what relations are) of using a sequence like
<a1, ... , aN>
> I could use »first component« and »second component«, but this > is a two-word term (compound term). I do not deem compound > terms to be appropriate for such fundamental concepts. For the > same reason, I prefer »pair« to »2-tuple«. A 2-tuple might > have a »first component« and a »second component«, but a pair > should have a CAR and a CDR (or some other single-word term).
-- Thomas A. Russ, USC/Information Sciences Institute
Slobodan Blazeski <slobodan.blaze...@gmail.com> writes: > On Jun 14, 9:47 pm, rwander...@rsw.digi.com.br wrote: > > r...@zedat.fu-berlin.de (Stefan Ram) writes: > > > I could use »first component« and »second component«, but this > > > is a two-word term (compound term). I do not deem compound > > > terms to be appropriate for such fundamental concepts. For the > > > same reason, I prefer »pair« to »2-tuple«. A 2-tuple might > > > have a »first component« and a »second component«, but a pair > > > should have a CAR and a CDR (or some other single-word term).
> > What about just >>first<< and >>second<<?
> Head & Tail perhaps.
The problem that I see with HEAD and TAIL is that they make me think of two different types of structures. Granted, they are isomorphic to CAR and CDR, but on reflection that really just points up a problem with the original formulation. The proper terms would really be CAR and CADR (paralleling FIRST and SECOND).
-- Thomas A. Russ, USC/Information Sciences Institute
> >> > On Jun 14, 2:20 pm, Pascal Costanza <p...@p-cos.net> wrote: > >> >> Scott Burson wrote: > >> >> > On Jun 14, 1:34 pm, Slobodan Blazeski <slobodan.blaze...@gmail.com> > >> >> > wrote: > >> >> >> Head & Tail perhaps.
> >> >> > "Head" and "tail" are my favorites too. I like them better than > >> >> > "first" and "rest" because the latter terms are more abstract and > >> >> > could apply to sequences implemented in other ways than as lists. > >> >> > "Head" and "tail", on the other hand, seem to me to refer specifically > >> >> > to the structure of a list.
> >> >> > Of course I don't mind "car" and "cdr", but this is just from > >> >> > training :)
> >> >> Cons cells can be used for things other than lists. For example, trees > >> >> and just pairs.
> >> > True. But CL itself defines `first' and `rest' as synonyms of `car' > >> > and `cdr'.
> >> It's an error to believe that first and rest are synonymous to car and > >> cdr. There's a big difference: first and rest apply on lists, while > >> car and cdr apply on cons cells.
> > Not so. Cons cells and lists are not distinct in Lisp. The standard > > *defines* FIRST to be synonymous with CAR and REST to be synonymous with > > CDR. It may be a good idea to keep the two concepts distinct, but > > Common Lisp doesn't enforce -- or even support -- any distinction. Some > > people consider this a feature.
> And I have the regret to inform you that you are not distinct from > your mass of lead. Same number of quarks, same forces. The universe > doesn't enforce any distinction here either. And yes, it's a feature > too :-)
That's a very bad analogy. The universe does enforce many distinctions between me and a block of lead, or even between a block of lead and a block of gold, to the dismay of many an alchemist. In fact, it is precisely those distinctions that make it possible to distinguish between lead and gold.
The distinction between cons cells and lists in Lisp, by way of contrast, is purely one of convention. If I give you a block of metal that is either lead or gold and ask you which it is you'll have no trouble answering. On the other hand, if I give you a data structure returned by the CONS function and ask you if it's a list or a cons cell there's no way for you to tell. There *is* no "right answer".