Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61483 - in trunk/libs/spirit/example/scheme: example/scheme scheme
From: joel_at_[hidden]
Date: 2010-04-22 08:14:48


Author: djowel
Date: 2010-04-22 08:14:46 EDT (Thu, 22 Apr 2010)
New Revision: 61483
URL: http://svn.boost.org/trac/boost/changeset/61483

Log:
blocks and scopes
Text files modified:
   trunk/libs/spirit/example/scheme/example/scheme/more_scheme.scm | 7 +++++++
   trunk/libs/spirit/example/scheme/example/scheme/some_scheme.scm | 6 ++++--
   trunk/libs/spirit/example/scheme/scheme/compiler.hpp | 28 +++++++++++++++++-----------
   3 files changed, 28 insertions(+), 13 deletions(-)

Modified: trunk/libs/spirit/example/scheme/example/scheme/more_scheme.scm
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/more_scheme.scm (original)
+++ trunk/libs/spirit/example/scheme/example/scheme/more_scheme.scm 2010-04-22 08:14:46 EDT (Thu, 22 Apr 2010)
@@ -21,4 +21,11 @@
 
 (define (display-all first . rest) (display first) (display rest))
 
+(display-all 123 456 999 666)
+
+
+(define (display-all first . rest)
+ (display first)
+ (display (begin 1 2 rest)))
+
 (display-all 123 456 999 666)
\ No newline at end of file

Modified: trunk/libs/spirit/example/scheme/example/scheme/some_scheme.scm
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/some_scheme.scm (original)
+++ trunk/libs/spirit/example/scheme/example/scheme/some_scheme.scm 2010-04-22 08:14:46 EDT (Thu, 22 Apr 2010)
@@ -1,3 +1,5 @@
-(define (display-all first . rest) (display first) (display rest))
+(define (foo x)
+ (define (bar y z) (list x y z))
+ (bar 9 x))
 
-(display-all 123 456 999 666)
\ No newline at end of file
+(display (foo 100))
\ No newline at end of file

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-22 08:14:46 EDT (Thu, 22 Apr 2010)
@@ -244,20 +244,25 @@
                     local_env.define(args[i], boost::bind(arg, i), 0, false);
             }
 
- if (body.size() == 1)
+ actor_list flist;
+ BOOST_FOREACH(utree const& item, body)
             {
- return protect(compile(body[0], local_env, fragments, line, source_file));
+ function f = compile(item, local_env, fragments, line, source_file);
+ if (!is_define(item))
+ flist.push_back(f);
             }
- else
- {
- actor_list flist;
- BOOST_FOREACH(utree const& item, body)
- {
- flist.push_back(
- compile(item, local_env, fragments, line, source_file));
- }
+ if (flist.size() > 1)
                 return protect(block(flist));
- }
+ else
+ return protect(flist.front());
+ }
+
+ bool is_define(utree const& item) const
+ {
+ if (item.which() != utree_type::list_type ||
+ item.begin()->which() != utree_type::symbol_type)
+ return false;
+ return get_symbol(*item.begin()) == "define";
         }
 
         function define_function(
@@ -491,6 +496,7 @@
     {
         env.define("if", if_, 3, true);
         env.define("begin", block, 1, false);
+ env.define("list", list, 1, false);
         env.define("display", display, 1, true);
         env.define("front", front, 1, true);
         env.define("back", back, 1, true);


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