From 7ceb3e8700795a6414fe2e4cfc96c85a54599b2a Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 6 Jul 2009 14:54:12 +0000 Subject: [PATCH] Added concat function --- chaiscript/chaiscript_prelude.hpp | 12 +++++++++++- dispatchkit/bootstrap.hpp | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/chaiscript/chaiscript_prelude.hpp b/chaiscript/chaiscript_prelude.hpp index 8a5d6f3..46cca52 100644 --- a/chaiscript/chaiscript_prelude.hpp +++ b/chaiscript/chaiscript_prelude.hpp @@ -8,7 +8,7 @@ const char *chaiscript_prelude = " \ def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\ \"<\" + x.first.to_string() + \", \" + x.second.to_string() + \">\"\n\ }\n\ -def to_string(x) : call_exists(range, x) && !is_type(\"string\", x){ \n\ +def to_string(x) : call_exists(range, x) && !x.is_type(\"string\"){ \n\ \"[\" + x.join(\", \") + \"]\"\n\ }\n\ def to_string(x) { \n\ @@ -52,6 +52,16 @@ def foldl(container, func, initial) : call_exists(range, container){ \n\ } \n\ def sum(container) { foldl(container, `+`, 0.0) } \n\ def product(container) { foldl(container, `*`, 1.0) } \n\ +def concat(x, y) : call_exists(clone, x) { \n\ + var retval = x; \n\ + var len = y.size(); \n\ + var i = 0; \n\ + while (i < len) { \n\ + retval.push_back(y[i]); \n\ + ++i; \n\ + } \n\ + retval; \n\ +} \n\ def take(container, num) : call_exists(range, container) { \n\ var r = range(container); \n\ var i = num; \n\ diff --git a/dispatchkit/bootstrap.hpp b/dispatchkit/bootstrap.hpp index e19e8fa..dd42c8c 100644 --- a/dispatchkit/bootstrap.hpp +++ b/dispatchkit/bootstrap.hpp @@ -526,7 +526,7 @@ namespace dispatchkit s.register_function(boost::function(boost::bind(&dump_system, boost::ref(s))), "dump_system"); s.register_function(boost::function(boost::bind(&dump_object, _1)), "dump_object"); - s.register_function(boost::function(boost::bind(&is_type, boost::ref(s), _1, _2)), + s.register_function(boost::function(boost::bind(&is_type, boost::ref(s), _2, _1)), "is_type"); s.add_object("_", Placeholder_Object());