Re: Adding to the end of a list
- From: "Brian Hulley" <brianh@xxxxxxxxxxxx>
- Date: 14 May 2005 12:41:35 -0700
Bill Spight wrote:
> Dear Brian,
>
> Brian Hulley wrote:
> >
> > Anders Lindén wrote:
> > > (Just like you add to a list in the beginning with [A|List]?
> >
> > No - [A|List] is a new list whose head is A and whose tail is List
> > (nothing is added to List)
>
> That depends upon your definition of 'add'. E. g., if you add 1 to 2
you
> get 3. However, 2 remains the same, it does not become 3 when you add
1
> to it. Similarly, when you add Head to Tail to get [Head | Tail],
Tail
> remains the same.
Yes (also in reply to Torkel's post) thanks for pointing these things
out. I posted the comment because I thought that perhaps the original
question (by Anders) might have been due to a misconception that
[A|List] was some syntax for destructively modifying a list in the same
way that List.push_front(A) in STL would add A to the head of List in
C++ for example, because if so you would then expect an equally neat
equivalent for push_back.
Given that this may not have been the motivating thought for the
question, a better answer from me to Anders might have been that a list
is not a flat structure like an array with two ends, but is rather a
nested structure which has an outside and an inside.
ie a list has the form [a, [b, [c, [d, [..... []]]]]]
Clearly you can "add" something outside (by including this list in a
bigger enclosing list) but you can't add anything inside because
there's no space to add anything there (but difference lists (Torkel's
post) give you this "inner space")
Hence the asymmetry between "adding at the beginning" and "adding at
the end"
Regards, Brian.
.
- Follow-Ups:
- Re: Adding to the end of a list
- From: Brian Hulley
- Re: Adding to the end of a list
- References:
- Adding to the end of a list
- From: Anders Lindén
- Re: Adding to the end of a list
- From: Brian Hulley
- Re: Adding to the end of a list
- From: Bill Spight
- Adding to the end of a list
- Prev by Date: Re: Adding to the end of a list
- Next by Date: Re: Adding to the end of a list
- Previous by thread: Re: Adding to the end of a list
- Next by thread: Re: Adding to the end of a list
- Index(es):
Relevant Pages
|
|