From 2853156a2bce535bcaa440c37cf872916f76c03b Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Thu, 3 Jan 2013 08:10:25 +0000 Subject: Refactoring, rename isNil to isNull. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1428206 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/kernel/list.hpp | 68 +++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'sca-cpp/trunk/kernel/list.hpp') diff --git a/sca-cpp/trunk/kernel/list.hpp b/sca-cpp/trunk/kernel/list.hpp index 02df2c2dc5..753b33b6a0 100644 --- a/sca-cpp/trunk/kernel/list.hpp +++ b/sca-cpp/trunk/kernel/list.hpp @@ -120,9 +120,9 @@ public: inline const bool operator==(const list& p) const noexcept { if(this == &p) return true; - if(isNil(cdr)) - return isNil(p.cdr); - if(isNil(p.cdr)) + if(isNull(cdr)) + return isNull(p.cdr); + if(isNull(p.cdr)) return false; if(!(car == p.car)) return false; @@ -134,9 +134,9 @@ public: inline const bool operator<(const list& p) const noexcept { if(this == &p) return false; - if (isNil(cdr)) - return !isNil(p.cdr); - if (isNil(p.cdr)) + if (isNull(cdr)) + return !isNull(p.cdr); + if (isNull(p.cdr)) return false; if (car < p.car) return true; @@ -148,9 +148,9 @@ public: inline const bool operator>(const list& p) const noexcept { if(this == &p) return false; - if (isNil(cdr)) + if (isNull(cdr)) return false; - if (isNil(p.cdr)) + if (isNull(p.cdr)) return true; if (car > p.car) return true; @@ -173,7 +173,7 @@ private: string watch; #endif - template friend const bool isNil(const list& p) noexcept; + template friend const bool isNull(const list& p) noexcept; template friend const X car(const list& p) noexcept; template friend const list cdr(const list& p) noexcept; @@ -188,7 +188,7 @@ private: * to watch than the list itself in a debugger. */ template inline const string watchList(const list& p) noexcept { - if(isNil(p)) + if(isNull(p)) return "()"; odebugstream os; os << "(" << car(p) << " ...)"; @@ -200,22 +200,22 @@ template inline const string watchList(const list& p) noexcept { /** * Returns true if the given list is nil. */ -template inline const bool isNil(const list& p) noexcept { - return isNil(p.cdr); +template inline const bool isNull(const list& p) noexcept { + return isNull(p.cdr); } /** * Write a list to an output stream. */ template inline ostream& writeHelper(ostream& out, const list& l) noexcept { - if (isNil(l)) + if (isNull(l)) return out; out << " " << car(l); return writeHelper(out, cdr(l)); } template inline ostream& operator<<(ostream& out, const list& l) noexcept { - if(isNil(l)) + if(isNull(l)) return out << "()"; out << "(" << car(l); writeHelper(out, cdr(l)); @@ -294,7 +294,7 @@ template inline const list mklist(const T& a, const T& b, const T */ template inline const T car(const list& p) noexcept { // Abort if trying to access the car of a nil list - assertOrFail(!isNil(p.cdr)); + assertOrFail(!isNull(p.cdr)); return p.car; } @@ -401,7 +401,7 @@ template inline const list cdddddddr(const list& p) noexcept { */ template inline const size_t length(const list& p) noexcept { const lambda&)> lengthRef = [&lengthRef](const size_t c, const list& p) -> const size_t { - if(isNil(p)) + if(isNull(p)) return c; return lengthRef(c + 1, cdr(p)); }; @@ -412,7 +412,7 @@ template inline const size_t length(const list& p) noexcept { * Appends a list and a lambda function returning a list. */ template inline const list append(const list&a, const lambda()>& fb) noexcept { - if(isNil(a)) + if(isNull(a)) return fb(); return cons(car(a), [a, fb]() { return append(cdr(a), fb); }); } @@ -439,7 +439,7 @@ template const list inline operator+(const list& l * Run a map lambda function on a list. */ template inline const list map(const lambda& f, const list& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list (); return cons(f(car(p)), map(f, cdr(p))); } @@ -449,7 +449,7 @@ template inline const list map(const lambda inline const R reduce(const lambda& f, const R& initial, const list& p) noexcept { const lambda&p)> reduceAccumulate = [f, &reduceAccumulate](const R& acc, const list& p) -> R { - if(isNil(p)) + if(isNull(p)) return acc; return reduceAccumulate(f(acc, car(p)), cdr(p)); }; @@ -458,7 +458,7 @@ template inline const R reduce(const lambda inline const R reduceRight(const lambda& f, const R& initial, const list& p) noexcept { const lambda&p, const R&)> reduceRightAccumulate = [f, &reduceRightAccumulate](const list& p, const R& acc) -> R { - if(isNil(p)) + if(isNull(p)) return acc; return reduceRightAccumulate(cdr(p), f(car(p), acc)); }; @@ -469,7 +469,7 @@ template inline const R reduceRight(const lambda inline const list filter(const lambda& f, const list& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list (); if(f(car(p))) { const lambda(const lambda, const list)> ff(filter); @@ -482,7 +482,7 @@ template inline const list filter(const lambda inline const list member(const T& t, const list& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list (); if(t == car(p)) return p; @@ -493,7 +493,7 @@ template inline const list member(const T& t, const list& p) n * Reverse a list. */ template inline const list reverseIter(const list& acc, const list& p) noexcept { - if(isNil(p)) + if(isNull(p)) return acc; return reverseIter(cons(car(p), acc), cdr(p)); } @@ -528,7 +528,7 @@ template inline const T listRef(const list& l, const size_t i) no template inline const list listTail(const list& l, const size_t k) noexcept { if(k == 0) return l; - if(isNil(l)) + if(isNull(l)) return l; return listTail(cdr(l), k - 1); } @@ -537,7 +537,7 @@ template inline const list listTail(const list& l, const size_ * Substitute elements in a list. */ template inline const list subst(const T& o, const T& n, const list& p) noexcept { - if(isNil(p)) + if(isNull(p)) return p; if(o == car(p)) return cons(n, subst(o, n, cdr(p))); @@ -548,7 +548,7 @@ template inline const list subst(const T& o, const T& n, const li * Returns the first pair matching a key from a list of key value pairs. */ template inline const list assoc(const T& k, const list >& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list(); if(k == car(car(p))) return car(p); @@ -560,7 +560,7 @@ template inline const list assoc(const T& k, const list > * Requires T to support isList and cast to list. */ template inline const list assoc(const T& k, const list& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list(); const T c = car(p); if(isList(c) && k == car(c)) @@ -572,7 +572,7 @@ template inline const list assoc(const T& k, const list& p) no * Returns a list of lists containing elements from two input lists. */ template inline const list > zip(const list& a, const list& b) noexcept { - if (isNil(a) || isNil(b)) + if (isNull(a) || isNull(b)) return list >(); return cons >(mklist(car(a), car(b)), zip(cdr(a), cdr(b))); } @@ -581,13 +581,13 @@ template inline const list > zip(const list& a, const lis * Converts a list of key value pairs to a list containing the list of keys and the list of values. */ template inline const list unzipKeys(const list >& l) noexcept { - if (isNil(l)) + if (isNull(l)) return list(); return cons(car(car(l)), unzipKeys(cdr(l))); } template inline const list unzipValues(const list >& l) noexcept { - if (isNil(l)) + if (isNull(l)) return list(); return cons(cadr(car(l)), unzipValues(cdr(l))); } @@ -600,7 +600,7 @@ template inline const list > unzip(const list >& l) * Delete assocs matching a key from a list of assocs. */ template inline const list > delAssoc(const T& k, const list >& p) noexcept { - if(isNil(p)) + if(isNull(p)) return p; if(k == car(car(p))) return delAssoc(k, cdr(p)); @@ -612,7 +612,7 @@ template inline const list > delAssoc(const T& k, const list * Requires T to support isList, isAssoc, and cast to list. */ template inline const list delAssoc(const T& k, const list& p) noexcept { - if(isNil(p)) + if(isNull(p)) return p; const T c = car(p); if(isList(c) && k == car(c)) @@ -624,7 +624,7 @@ template inline const list delAssoc(const T& k, const list& p) * Substitute assocs with matching keys in a list of assocs. */ template inline const list > substAssoc(const T& k, const list& n, const list >& p, const bool add = false) noexcept { - if(isNil(p)) + if(isNull(p)) return add? mklist >(n) : p; if(k == car(car(p))) return cons >(n, substAssoc(k, n, cdr(p), false)); @@ -636,7 +636,7 @@ template inline const list > substAssoc(const T& k, const li * Requires T to support isList, isAssoc, and cast to list. */ template inline const list substAssoc(const T& k, const list& n, const list& p, const bool add = false) noexcept { - if(isNil(p)) + if(isNull(p)) return add? mklist(n) : p; const T c = car(p); if(isList(c) && k == car(c)) -- cgit v1.2.3