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
second airplane commit! got some more predicates
technomancy (author)
Mon Feb 25 18:29:50 -0800 2008
commit  ab22cb87eb7253adc4dc50e5fac3210a6e5235f7
tree    728712fd2c31ae254dbb834d6f7eea1c237fc3d1
parent  51b7e3d518cd3147059108dd06773ddc9b59a1ad
...
2
3
4
5
6
7
 
 
 
 
 
 
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
 
 
 
 
 
 
 
 
 
57
58
59
60
61
...
2
3
4
 
 
 
5
6
7
8
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
13
14
15
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
0
@@ -2,60 +2,29 @@
0
 
0
 == Parsing
0
 
0
-"a sequence of letters, digits, and "extended alphabetic characters
0
-that begins with a character that cannot begin a number is an
0
-identifier"
0
+Unsupported:
0
+* Quasiquote, unquote, unquote-splice
0
+* Backslash in strings
0
+* Character literals
0
+* Alternate-base numbers
0
+* Alternate define lambda forms
0
 
0
-Extended chars:
0
-! $ % & * + - . / : < = > ? @ ^ _ ~
0
-
0
-Quasiquote, unquote, unquote-splice
0
-
0
-Backslash in strings
0
-
0
-[]{}| - reserved
0
-
0
-Character literals
0
-
0
-Alternate-base numbers
0
-
0
-Alternate lambda forms
0
+* []{}| should be reserved
0
 
0
 == Functions
0
 
0
 === Basic
0
-read
0
-cond
0
-case
0
-let*
0
-letrec
0
-do
0
-delay
0
-
0
-=== Predicates
0
-boolean?
0
-symbol?
0
-char?
0
-vector?
0
-procedure?
0
-pair?
0
-number?
0
-string?
0
-port?
0
-
0
-== Errors
0
-
0
-Mutating constant values
0
-Using invalid identifiers
0
-
0
-== Macros
0
-
0
-...
0
-
0
-== Other
0
-
0
+Unsupported:
0
+* cond
0
+* case
0
+* let*
0
+* letrec
0
+* do
0
+* delay
0
+* read - uses Ruby's gets
0
+
0
+== General
0
 Tail-recursion
0
 
0
 Continuations
0
 
0
-Gone through the doc through section 4
...
13
14
15
16
 
 
 
 
 
17
18
19
...
13
14
15
 
16
17
18
19
20
21
22
23
0
@@ -13,7 +13,11 @@ code is strictly bus-driven. Bus Scheme is primarily a toy; using it
0
 for anything serious is (right now) ill-advised.
0
 
0
 Bus Scheme aims for general Scheme usefulness optimized for learning
0
-and fun. It's loosely targeting R5RS, but varies in huge ways.
0
+and fun. It's loosely targeting R5RS, but varies in huge ways. (For
0
+the purposes of this project we pretend that R6RS never happened.) See
0
+the file R5RS.diff for ways in which Bus Scheme differs from the
0
+standard, both things that are yet unimplemented and things that are
0
+intentionally different.
0
 
0
 == Usage
0
 
...
48
49
50
51
 
52
53
54
...
48
49
50
 
51
52
53
54
0
@@ -48,7 +48,7 @@ task :rbx_test do
0
   if ENV['test']
0
     system "#{BIN} test/test_#{ENV['test']}.rb"
0
   else
0
- system "#{BIN} -w -Ilib:ext:bin:test -e '#{Dir.glob('test/test_*.rb').map{ |f| "require \"" + f + "\" "}.join('; ')}'"
0
+ system "#{BIN} -w -Ilib:test -e '#{Dir.glob('test/test_*.rb').map{ |f| "require \"" + f + "\" "}.join('; ')}'"
0
   end
0
 end
0
 
...
75
76
77
78
 
 
79
...
75
76
77
 
78
79
80
0
@@ -75,5 +75,6 @@ module BusScheme
0
     (@loaded_files ||= ["(eval)"])
0
   end
0
 
0
- ['core.scm', 'test.scm', 'list.scm'].each { |file| load(file) }
0
+ ['core.scm', 'test.scm', 'list.scm', 'predicates.scm'
0
+ ].each { |file| load(file) }
0
 end
...
1
2
3
4
 
 
5
6
7
...
1
2
3
 
4
5
6
7
8
0
@@ -1,7 +1,8 @@
0
 module BusScheme
0
   class Cons
0
     attr_accessor :car, :cdr
0
-
0
+
0
+ # TODO: figure out default values
0
     def initialize(car, cdr = nil)
0
       @car, @cdr = [car, cdr]
0
     end
...
48
49
50
51
 
52
53
54
...
48
49
50
 
51
52
53
54
0
@@ -48,7 +48,7 @@ module BusScheme
0
   end
0
 
0
   def stacktrace
0
- # (stacktrace)'s own frame shouldn't be included...
0
+ # TODO: notrace is super-duper-hacky!
0
     @@stack.reverse.map{ |frame| frame.trace if frame.respond_to? :trace and frame.called_from != 'begin-notrace'}.compact
0
   end
0
 
...
6
7
8
 
9
10
11
...
6
7
8
9
10
11
12
0
@@ -6,6 +6,7 @@ module BusScheme
0
     
0
     # create new Lambda object
0
     def initialize(formals, body)
0
+ @special_form = false
0
       @formals, @body, @enclosing_scope = [formals, body, BusScheme.current_scope]
0
       @car = :lambda.sym
0
       @cdr = Cons.new(@formals.sexp, @body.sexp)
...
1
2
3
4
 
 
 
 
 
 
5
6
7
 
 
 
 
 
 
 
 
 
 
 
8
9
10
 
11
12
13
...
25
26
27
 
 
 
 
 
 
 
 
 
 
28
29
30
...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
...
 
 
 
 
1
2
3
4
5
6
7
 
 
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
...
60
61
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
64
65
0
@@ -1,13 +1,25 @@
0
-module Callable
0
- # allows for (mylist 4) => mylist[4]
0
- def call_as(sym, *args)
0
- self.call(*args)
0
+class Sym < String
0
+ attr_accessor :file, :line
0
+
0
+ # TODO: refactor?
0
+ def special_form
0
+ BusScheme[self].special_form
0
   end
0
- def call(*args)
0
- self.[](*args)
0
+
0
+ def inspect
0
+ self
0
+ end
0
+
0
+ def to_s
0
+ self
0
+ end
0
+
0
+ def sym
0
+ self
0
   end
0
 end
0
 
0
+
0
 class Object
0
   # Return self after evaling block
0
   # see http://www.ruby-forum.com/topic/131340
0
@@ -25,6 +37,16 @@ class Object
0
   end
0
 end
0
 
0
+module Callable
0
+ # allows for (mylist 4) => mylist[4]
0
+ def call_as(sym, *args)
0
+ self.call(*args)
0
+ end
0
+ def call(*args)
0
+ self.[](*args)
0
+ end
0
+end
0
+
0
 class String
0
   include Callable
0
   def sym
0
@@ -38,27 +60,6 @@ class Symbol
0
   end
0
 end
0
 
0
-class Sym < String
0
- attr_accessor :file, :line
0
-
0
- # TODO: refactor?
0
- def special_form?
0
- BusScheme[self].special_form?
0
- end
0
-
0
- def inspect
0
- self
0
- end
0
-
0
- def to_s
0
- self
0
- end
0
-
0
- def sym
0
- self
0
- end
0
-end
0
-
0
 class Hash
0
   include Callable
0
 end
...
21
22
23
24
 
25
26
27
...
36
37
38
39
 
40
41
42
...
21
22
23
 
24
25
26
27
...
36
37
38
 
39
40
41
42
0
@@ -21,7 +21,7 @@ module BusScheme
0
   define '/', lambda { |x, y| x / y }
0
 
0
   define 'concat', lambda { |*args| args.join('') }
0
- define 'cons', lambda { |car, cdr| Cons.new(car, cdr) }
0
+ define 'cons', lambda { |*args| Cons.new(*args) }
0
   define 'list', lambda { |*members| members.to_list }
0
   define 'vector', lambda { |*members| members.to_a }
0
   define 'map', lambda { |fn, list| list.map(lambda { |n| fn.call(n) }).sexp }
0
@@ -36,7 +36,7 @@ module BusScheme
0
   define 'fail', lambda { |message| raise AssertionFailed, "#{message}\n #{BusScheme.stacktrace.join("\n ")}" }
0
   
0
   define 'ruby', lambda { |*code| Kernel.eval code.join('') }
0
- define 'send', lambda { |obj, *message| obj.send(*message) }
0
+ define 'send', lambda { |obj, message, *args| obj.send(message.to_sym, *args) }
0
 
0
   define 'load', lambda { |filename| BusScheme.load filename }
0
   define 'exit', lambda { exit }
...
1
2
3
 
4
5
6
...
1
2
 
3
4
5
6
0
@@ -1,6 +1,6 @@
0
 ;; Test list functions defined in list.scm
0
 
0
-(assert-equal (quote (1 2 3)) (reverse (quote (3 2 1))))
0
+(assert-equal (list 1 2 3) (reverse (list 3 2 1)))
0
 
0
 (assert-equal (quote (1 2 3 4)) (append (quote ()) (quote (1 2 3 4))))
0
 (assert-equal (quote (1 2 3 4)) (append (quote (1 )) (quote (2 3 4))))
...
8
9
10
11
 
 
 
12
13
14
...
8
9
10
 
11
12
13
14
15
16
0
@@ -8,7 +8,9 @@ class PrimitivesTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_run_scheme_tests
0
- BusScheme.load(File.dirname(__FILE__) + '/test_primitives.scm')
0
+ Dir.glob(File.dirname(__FILE__) + '/test_*.scm').each do |f|
0
+ BusScheme.load f
0
+ end
0
   end
0
 
0
   def test_load_file
...
17
18
19
 
 
20
21
22
...
17
18
19
20
21
22
23
24
0
@@ -17,6 +17,8 @@
0
 (assert-equal 9 (begin (define foo 779) 9))
0
 (assert-equal 779 foo)
0
 
0
+(assert (null? (cdr (cons 3))))
0
+
0
 ;; define
0
 (define foo 5)
0
 (define bar (quote (5 5 5)))

Comments

    No one has commented yet.