|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61501 - trunk/libs/spirit/example/scheme/example/scheme
From: joel_at_[hidden]
Date: 2010-04-22 23:58:10
Author: djowel
Date: 2010-04-22 23:58:09 EDT (Thu, 22 Apr 2010)
New Revision: 61501
URL: http://svn.boost.org/trac/boost/changeset/61501
Log:
cleanup
Removed:
trunk/libs/spirit/example/scheme/example/scheme/more_scheme.scm
trunk/libs/spirit/example/scheme/example/scheme/some_scheme.scm
Text files modified:
trunk/libs/spirit/example/scheme/example/scheme/factorial1.cpp | 39 ++++++++++++++++++++++-----------------
trunk/libs/spirit/example/scheme/example/scheme/factorial2.cpp | 6 ++++--
trunk/libs/spirit/example/scheme/example/scheme/scheme_error.scm | 13 ++++++-------
trunk/libs/spirit/example/scheme/example/scheme/scheme_test.cpp | 26 +++++++++++++++++---------
4 files changed, 49 insertions(+), 35 deletions(-)
Modified: trunk/libs/spirit/example/scheme/example/scheme/factorial1.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/factorial1.cpp (original)
+++ trunk/libs/spirit/example/scheme/example/scheme/factorial1.cpp 2010-04-22 23:58:09 EDT (Thu, 22 Apr 2010)
@@ -11,21 +11,8 @@
#include <iostream>
#include <fstream>
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int main()
+void ignore_bom(std::ifstream& in)
{
- char const* filename = "factorial.scm";
- std::ifstream in(filename, std::ios_base::in);
-
- if (!in)
- {
- std::cerr << "Error: Could not open input file: "
- << filename << std::endl;
- return 1;
- }
-
// Ignore the BOM marking the beginning of a UTF-8 file in Windows
char c = in.peek();
if (c == '\xef')
@@ -40,12 +27,30 @@
return 1;
}
}
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ char const* filename = "factorial.scm";
+ std::ifstream in(filename, std::ios_base::in);
+
+ if (!in)
+ {
+ std::cerr << "Error: Could not open input file: "
+ << filename << std::endl;
+ return -1;
+ }
+ ignore_bom(in);
using scheme::interpreter;
- using scheme::_1;
+ using scheme::function;
- scheme::interpreter program(in);
- std::cout << program["factorial"](10) << std::endl;
+ interpreter program(in);
+ function factorial = program["factorial"];
+ std::cout << factorial(10) << std::endl;
return 0;
}
Modified: trunk/libs/spirit/example/scheme/example/scheme/factorial2.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/factorial2.cpp (original)
+++ trunk/libs/spirit/example/scheme/example/scheme/factorial2.cpp 2010-04-22 23:58:09 EDT (Thu, 22 Apr 2010)
@@ -17,14 +17,16 @@
int main()
{
using scheme::interpreter;
+ using scheme::function;
using scheme::utree;
utree src =
"(define (factorial n) "
"(if (<= n 0) 1 (* n (factorial (- n 1)))))";
- scheme::interpreter program(src);
- std::cout << program["factorial"](10) << std::endl;
+ interpreter program(src);
+ function factorial = program["factorial"];
+ std::cout << factorial(10) << std::endl;
return 0;
}
Deleted: trunk/libs/spirit/example/scheme/example/scheme/more_scheme.scm
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/more_scheme.scm 2010-04-22 23:58:09 EDT (Thu, 22 Apr 2010)
+++ (empty file)
@@ -1,54 +0,0 @@
-(define (apply x f) (display (f x)))
-
-(apply 5 (lambda (x) (* x 5)))
-
-(display (quote (1 2 3 4 5)))
-
-(display (quote ()))
-
-
-(define for_each
- lambda (x f)
- f()
-
-
-(define (display-all . args)
- (display args))
-
-(display-all 123 456 999 666)
-
-(display (+ 1 2 3 4 5 6))
-
-(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)
-
-
-(define (foo x)
- (define (bar y z) (list x y z))
- (bar 9 (+ x 2)))
-
-(display (foo 100))
-
-; The hello-world for interpreters ;-)
-(define (factorial n)
- (if (<= n 0) 1
- (* n (factorial (- n 1)))))
-
-(display (factorial 10))
-
-
-
-(define (foo x)
- (define (bar y z) (list x y z))
- (bar 9 (+ x 2)))
-
-(define (main)
- (display (foo 100))) ; prints ( 100 9 102 )
\ No newline at end of file
Modified: trunk/libs/spirit/example/scheme/example/scheme/scheme_error.scm
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/scheme_error.scm (original)
+++ trunk/libs/spirit/example/scheme/example/scheme/scheme_error.scm 2010-04-22 23:58:09 EDT (Thu, 22 Apr 2010)
@@ -1,4 +1,4 @@
-blah ; blah not found
+(define what blah) ; blah not found
(define
(foo x)
@@ -8,14 +8,13 @@
(bar x)
(+ x y)) ; y not found
-(foo 123)
-(foo z) ; z not found
+(define (f1) (foo 123))
+(define (f2) (foo z)) ; z not found
(define foo 123) ; redefinition
-(foo 123 456) ; incorrect arity
-
-(bar 999) ; bar should not be found
-
+(define (f3) (foo 123 456)) ; incorrect arity
+(define (f4) (bar 999)) ; bar should not be found
+(define (main) ) ; no body
\ No newline at end of file
Modified: trunk/libs/spirit/example/scheme/example/scheme/scheme_test.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/scheme_test.cpp (original)
+++ trunk/libs/spirit/example/scheme/example/scheme/scheme_test.cpp 2010-04-22 23:58:09 EDT (Thu, 22 Apr 2010)
@@ -12,14 +12,8 @@
#include <utree/io.hpp>
#include <fstream>
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int main(int argc, char **argv)
+int check_file(std::ifstream& in, char const* filename)
{
- char const* filename = filename = argv[1];
- std::ifstream in(filename, std::ios_base::in);
-
if (!in)
{
std::cerr << filename << " not found" << std::endl;
@@ -35,14 +29,28 @@
s[3] = '\0';
if (s != std::string("\xef\xbb\xbf"))
{
- std::cerr << "unexpected characters in file" << std::endl;
+ std::cerr << "Error: Unexpected characters from input file: "
+ << filename << std::endl;
return -1;
}
}
+ return 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main(int argc, char **argv)
+{
+ char const* filename = filename = argv[1];
+ std::ifstream in(filename, std::ios_base::in);
+ if (check_file(in, filename) != 0)
+ return -1;
scheme::interpreter program(in, filename);
scheme::function main_ = program["main"];
- main_(); // call main
+ if (!main_.empty())
+ main_(); // call main
return 0;
}
Deleted: trunk/libs/spirit/example/scheme/example/scheme/some_scheme.scm
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/some_scheme.scm 2010-04-22 23:58:09 EDT (Thu, 22 Apr 2010)
+++ (empty file)
@@ -1,7 +0,0 @@
-; The hello-world for interpreters ;-)
-(define (factorial n)
- (if (<= n 0) 1
- (* n (factorial (- n 1)))))
-
-(define (main)
- (display (factorial 10)))
\ No newline at end of file
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