Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-12-12 14:44:19


From: "David Abrahams" <david.abrahams_at_[hidden]>
> From: "Peter Dimov" <pdimov_at_[hidden]>
>
> > Because it's not a push_back.
> >
> > push_back(c, v) is a mutating operation on c. After it c has one
> additional
> > element pushed to its back, v.
>
> Okay, I see your point. There arer indeed some strange non-correspondences
> between MPL functions and their STL counterparts. For example, copy, which
> takes two input sequences and adds the elements of the first to the end of
> the second.

Actually there are two levels of non-correspondence. The first level is when
the algorithms perform a different operation - like the "copy" you just
mentioned. In STL "copy" takes one sequence as input and "returns" a result
into the second, output, sequence.

The second level is that in pure functional languages (and C++ templates are
a pure functional language) there are _no_ mutating operations, while in
(non-meta) C++ mutating operations are essential. The STL follows the
procedural idiom, while a metaprogramming library must, out of necessity,
follow the pure functional idiom.

> > append(a, b) is a pure function that returns the concatenation of a and
b.
> >
> > I might be wrong, though; it's been a while since I looked at anything
> > Lisp-related.
>
> In elisp, the docs say:
>
> Concatenate all the arguments and make the result a list.
> The result is a list whose elements are the elements of all the arguments.
> Each argument may be a list, vector or string.
> The last argument is not copied, just used as the tail of the new list.

Yep. Mostly what I had in mind.

append(A.B, C) :- A.append(B, C);
append(nil, C) :- C;

> So I guess that would be a better name for what MPL calls copy.

Agreed.

BTW a "functional" push_back(l, v) is simply append(l, cons(v, nil)).
push_front(l, v) is cons(v, l) (a fundamental operation.)

--
Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk