From 9f187b46ae761e8275362d6c1533e9fe79028c7b Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sun, 1 Nov 2009 05:24:54 +0000 Subject: Improved memory management using APR memory pools, changed frame allocation in eval library to support forward references and fixed memory leak in XML parsing code. Also simplified a bit the printing of lists to make them easier to read. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@831639 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/sca/kernel/list.hpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'cpp/sca/kernel/list.hpp') diff --git a/cpp/sca/kernel/list.hpp b/cpp/sca/kernel/list.hpp index 62c5d91150..deb4414d98 100644 --- a/cpp/sca/kernel/list.hpp +++ b/cpp/sca/kernel/list.hpp @@ -144,7 +144,7 @@ template std::ostream& operator<<(std::ostream& out, const list& ml = cdr(ml); if (isNil(ml)) break; - out << ", "; + out << " "; } return out << ")"; } @@ -163,6 +163,17 @@ template const list cons(const T& car, const list& cdr) { return list (car, result(cdr)); } +/** + * Cons variations for use with the reduce and reduceRight functions. + */ +template const list lcons(const list& cdr, const T& car) { + return cons(car, cdr); +} + +template const list rcons(const T& car, const list& cdr) { + return cons(car, cdr); +} + /** * Construct a list from a single value. */ @@ -350,6 +361,22 @@ template const R reduce(const lambda& f, const return reduceAccumulate (f)(initial, p); } +template struct reduceRightAccumulate { + const lambda f; + reduceRightAccumulate(const lambda& f) : + f(f) { + } + R operator()(const list& p, const R& acc) const { + if(isNil(p)) + return acc; + return (*this)(cdr(p), f(car(p), acc)); + } +}; + +template const R reduceRight(const lambda& f, const R& initial, const list& p) { + return reduceRightAccumulate (f)(p, initial); +} + /** * Run a filter lambda function on a list. */ -- cgit v1.2.3