Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61360 - in trunk/libs/spirit/example/scheme: scheme utree/detail
From: joel_at_[hidden]
Date: 2010-04-18 11:18:27


Author: djowel
Date: 2010-04-18 11:18:26 EDT (Sun, 18 Apr 2010)
New Revision: 61360
URL: http://svn.boost.org/trac/boost/changeset/61360

Log:
fix arity checking for lambda
Text files modified:
   trunk/libs/spirit/example/scheme/scheme/compiler.hpp | 30 ++++++++++++++++++++++++------
   trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp | 1 -
   2 files changed, 24 insertions(+), 7 deletions(-)

Modified: trunk/libs/spirit/example/scheme/scheme/compiler.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/scheme/compiler.hpp (original)
+++ trunk/libs/spirit/example/scheme/scheme/compiler.hpp 2010-04-18 11:18:26 EDT (Sun, 18 Apr 2010)
@@ -181,7 +181,7 @@
         {
             fragments.push_back(function());
             function& f = fragments.back();
- env.define(name, external_function(f), 0);
+ env.define(name, external_function(f), args.size());
             f = make_lambda(args, body);
             return f;
         }
@@ -212,6 +212,16 @@
                     {
                         // (define f ...body...)
                         fname = get_symbol(*i++);
+
+ // (define f (lambda (x) ...body...))
+ if (i->which() == utree_type::list_type
+ && get_symbol((*i)[0]) == "lambda")
+ {
+ utree const& arg_names = (*i)[1];
+ Iterator ai = arg_names.begin();
+ while (ai != arg_names.end())
+ args.push_back(get_symbol(*ai++));
+ }
                     }
 
                     return define_function(fname, args, *i);
@@ -240,8 +250,16 @@
                             compile(*i, env, fragments, line, source_file));
 
                     // Arity check
- if (r.second != -1 && int(flist.size()) < r.second)
- throw incorrect_arity();
+ if (r.second < 0) // non-fixed arity
+ {
+ if (int(flist.size()) < -r.second)
+ throw incorrect_arity();
+ }
+ else // fixed arity
+ {
+ if (int(flist.size()) != r.second)
+ throw incorrect_arity();
+ }
                     return (*r.first)(flist);
                 }
 
@@ -304,9 +322,9 @@
         env.define("if", if_, 3);
         env.define("<", less_than, 2);
         env.define("<=", less_than_equal, 2);
- env.define("+", plus, -1);
- env.define("-", minus, -1);
- env.define("*", times, -1);
+ env.define("+", plus, -2);
+ env.define("-", minus, -2);
+ env.define("*", times, -2);
     }
 
     ///////////////////////////////////////////////////////////////////////////

Modified: trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp (original)
+++ trunk/libs/spirit/example/scheme/utree/detail/utree_detail2.hpp 2010-04-18 11:18:26 EDT (Sun, 18 Apr 2010)
@@ -773,7 +773,6 @@
         }
     }
 
-
     template <typename T>
     inline void utree::insert(iterator pos, std::size_t n, T const& val)
     {


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk