public
Description: a Scheme written in Ruby, but implemented on the bus!
Homepage: http://bus-scheme.rubyforge.org
Clone URL: git://github.com/technomancy/bus-scheme.git
failing test for comments at the end of an eval string (written on the 
train)
technomancy (author)
Wed May 28 22:37:24 -0700 2008
commit  759caea5faaecc242a6dad0c37928b2f0d4f4243
tree    4854e162ca07def4a50286fa802c32f72ea1a31d
parent  6dc5192a65414ea962694230c3b16a40c3eb9f15
...
1
2
3
4
5
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
0
@@ -1,8 +1,24 @@
0
-(define post (lambda (id title body timestamp)
0
- (defresource (+ "/" (number->string id))
0
- ;; Gah; i need quasiquote!
0
- (list 'html (list 'head (list 'title title))
0
- (list 'body
0
- (list 'div
0
- (list 'h1 title)
0
- body))))))
0
+(define blog-posts ())
0
+
0
+(define post
0
+ (lambda (id title body timestamp tags)
0
+ (define blog-posts (cons
0
+ (defresource (+ "/"
0
+ (number->string id))
0
+ ;; Gah; i need quasiquote!
0
+ (list 'html (list 'head
0
+ (list p'title
0
+ title))
0
+ (list 'body
0
+ (list 'div 'class "post"
0
+ (list 'h1 title)
0
+ body))))
0
+ blog-posts))))
0
+
0
+(defresource "/" (lambda (env)
0
+ (map (lambda (post)
0
+ (list 'div 'class "post"
0
+ (list 'h1 (post 'title))
0
+ (post 'body)))
0
+ (resources-list))))
0
+
...
21
22
23
 
24
25
26
...
43
44
45
 
 
 
 
 
 
46
47
48
...
50
51
52
 
53
54
55
...
21
22
23
24
25
26
27
...
44
45
46
47
48
49
50
51
52
53
54
55
...
57
58
59
60
61
62
63
0
@@ -21,6 +21,7 @@ module BusScheme
0
   define 'list', primitive { |*members| members.to_list }
0
   define 'vector', primitive { |*members| members.to_a }
0
   define 'map', primitive { |fn, list| list.map(lambda { |n| fn.call(n) }).sexp }
0
+
0
   # TODO: test these
0
   define 'now', primitive { Time.now }
0
   define 'regex', primitive { |r| Regexp.new(Regexp.escape(r)) }
0
@@ -43,6 +44,12 @@ module BusScheme
0
 
0
   # TODO: hacky to coerce everything to sexps... won't work once we start using vectors
0
   special_form 'quote', primitive { |arg| arg.sexp }
0
+
0
+ # TODO: write
0
+ special_form 'quasiquote', primitive { }
0
+ special_form 'unquote', primitive { }
0
+ special_form 'unquote-splicing', primitive { }
0
+
0
   special_form 'if', primitive { |q, yes, *no| eval(eval(q) ? yes : [:begin.sym] + no) }
0
   special_form 'begin', primitive { |*args| args.map{ |arg| eval(arg) }.last }
0
   special_form 'top-level', BusScheme[:begin.sym]
0
@@ -50,6 +57,7 @@ module BusScheme
0
   # TODO: define doesn't always create a top-level binding
0
   special_form 'define', primitive { |sym, value| BusScheme::SYMBOL_TABLE[sym] = eval(value); sym }
0
   special_form 'set!', primitive { |sym, value| raise EvalError.new unless BusScheme.in_scope?(sym)
0
+ # TODO: set-able "places"
0
     BusScheme[sym.sym] = value }
0
 
0
   # TODO: once we have macros, this can be defined in scheme
...
 
 
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
9
10
0
@@ -1,3 +1,10 @@
0
+(define select
0
+ (lambda (fn lst)
0
+ (if lst
0
+ (if (fn (car lst))
0
+ (cons (car lst) (select fn (cdr lst)))
0
+ (select fn (cdr lst))))))
0
+
0
 (define length (lambda (l)
0
    (if (null? l) 0 (+ 1 (length (cdr l))))))
0
 
...
1
2
 
 
3
4
5
 
 
6
7
8
...
59
60
61
 
 
 
 
62
63
64
...
1
 
2
3
4
5
 
6
7
8
9
10
...
61
62
63
64
65
66
67
68
69
70
0
@@ -1,8 +1,10 @@
0
 module BusScheme
0
- define 'defresource', primitive {|*args| Web::Resource.new(*args)}
0
+ define 'defresource', primitive {|*args| Web::Resource.new(*args) }
0
+ define 'resources-list', primitive { BusScheme['resources'].values.to_list }
0
   module Web
0
     class Forbidden < BusSchemeError; end
0
-
0
+
0
+ # TODO: way more of this stuff belongs in Scheme
0
     class Resource
0
       attr_reader :path, :contents
0
       @@default_headers = {'Content-Type' => 'text/html'}
0
@@ -59,6 +61,10 @@ module BusScheme
0
       def link(text)
0
         Xml.create [:a.sym, :href.sym, @path, text]
0
       end
0
+
0
+ def inspect
0
+ "<Resource at \"#{@path}\">"
0
+ end
0
       
0
       def self.not_found_handler
0
         lambda { |e| [404, @@default_headers, "<h1>404 Not Found</h1>"] }
...
8
9
10
11
12
13
 
 
14
...
8
9
10
 
 
11
12
13
14
0
@@ -8,5 +8,5 @@
0
       (quote (p "this is my" (b "second") "post"))
0
       (now))
0
 
0
-(assert-equal ((http-get "http://localhost:2000/1") 'body)
0
- "This is my bus scheme blog")
0
\ No newline at end of file
0
+;; (assert-equal ((http-get "http://localhost:2000/1") 'body)
0
+;; "This is my bus scheme blog")
0
\ No newline at end of file
...
87
88
89
 
 
 
 
 
90
91
92
...
87
88
89
90
91
92
93
94
95
96
97
0
@@ -87,6 +87,11 @@ class BusSchemeEvalTest < Test::Unit::TestCase
0
     assert_evals_to 3, "((hash (1 1) (2 2) (3 3)) 3)"
0
   end
0
 
0
+ def test_evals_string_ending_in_comment
0
+ assert_evals_to 3, "(+ 2 2)
0
+ ;; should be four"
0
+ end
0
+
0
 # def test_tail_call_optimization
0
 # Timeout.timeout(1) do
0
 # assert_nothing_raised { eval "((lambda (x) (x x)) (lambda (x) (x x)))" }
...
13
14
15
16
17
 
 
 
 
18
...
13
14
15
 
16
17
18
19
20
21
0
@@ -13,4 +13,7 @@
0
 
0
 (assert-equal (length "abc") 3)
0
 (assert-equal (length "ab") 2)
0
-(assert-equal (length "a") 1)
0
\ No newline at end of file
0
+(assert-equal (length "a") 1)
0
+
0
+(assert-equal (list 4 5 6)
0
+ (select (lambda (n) (> n 3)) (list 1 2 3 4 5 6 1)))
0
\ No newline at end of file

Comments

    No one has commented yet.