Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

second airplane commit! got some more predicates

  • Loading branch information...
commit ab22cb87eb7253adc4dc50e5fac3210a6e5235f7 1 parent 51b7e3d
@technomancy authored
View
65 R5RS.diff
@@ -2,60 +2,29 @@
== Parsing
-"a sequence of letters, digits, and "extended alphabetic characters
-that begins with a character that cannot begin a number is an
-identifier"
+Unsupported:
+* Quasiquote, unquote, unquote-splice
+* Backslash in strings
+* Character literals
+* Alternate-base numbers
+* Alternate define lambda forms
-Extended chars:
-! $ % & * + - . / : < = > ? @ ^ _ ~
-
-Quasiquote, unquote, unquote-splice
-
-Backslash in strings
-
-[]{}| - reserved
-
-Character literals
-
-Alternate-base numbers
-
-Alternate lambda forms
+* []{}| should be reserved
== Functions
=== Basic
-read
-cond
-case
-let*
-letrec
-do
-delay
-
-=== Predicates
-boolean?
-symbol?
-char?
-vector?
-procedure?
-pair?
-number?
-string?
-port?
-
-== Errors
-
-Mutating constant values
-Using invalid identifiers
-
-== Macros
-
-...
-
-== Other
-
+Unsupported:
+* cond
+* case
+* let*
+* letrec
+* do
+* delay
+* read - uses Ruby's gets
+
+== General
Tail-recursion
Continuations
-Gone through the doc through section 4
View
6 README.txt
@@ -13,7 +13,11 @@ code is strictly bus-driven. Bus Scheme is primarily a toy; using it
for anything serious is (right now) ill-advised.
Bus Scheme aims for general Scheme usefulness optimized for learning
-and fun. It's loosely targeting R5RS, but varies in huge ways.
+and fun. It's loosely targeting R5RS, but varies in huge ways. (For
+the purposes of this project we pretend that R6RS never happened.) See
+the file R5RS.diff for ways in which Bus Scheme differs from the
+standard, both things that are yet unimplemented and things that are
+intentionally different.
== Usage
View
2  Rakefile
@@ -48,7 +48,7 @@ task :rbx_test do
if ENV['test']
system "#{BIN} test/test_#{ENV['test']}.rb"
else
- system "#{BIN} -w -Ilib:ext:bin:test -e '#{Dir.glob('test/test_*.rb').map{ |f| "require \"" + f + "\" "}.join('; ')}'"
+ system "#{BIN} -w -Ilib:test -e '#{Dir.glob('test/test_*.rb').map{ |f| "require \"" + f + "\" "}.join('; ')}'"
end
end
View
3  lib/bus_scheme.rb
@@ -75,5 +75,6 @@ def self.loaded_files
(@loaded_files ||= ["(eval)"])
end
- ['core.scm', 'test.scm', 'list.scm'].each { |file| load(file) }
+ ['core.scm', 'test.scm', 'list.scm', 'predicates.scm'
+ ].each { |file| load(file) }
end
View
3  lib/cons.rb
@@ -1,7 +1,8 @@
module BusScheme
class Cons
attr_accessor :car, :cdr
-
+
+ # TODO: figure out default values
def initialize(car, cdr = nil)
@car, @cdr = [car, cdr]
end
View
2  lib/eval.rb
@@ -48,7 +48,7 @@ def []=(sym, val)
end
def stacktrace
- # (stacktrace)'s own frame shouldn't be included...
+ # TODO: notrace is super-duper-hacky!
@@stack.reverse.map{ |frame| frame.trace if frame.respond_to? :trace and frame.called_from != 'begin-notrace'}.compact
end
View
1  lib/lambda.rb
@@ -6,6 +6,7 @@ class Lambda < Cons
# create new Lambda object
def initialize(formals, body)
+ @special_form = false
@formals, @body, @enclosing_scope = [formals, body, BusScheme.current_scope]
@car = :lambda.sym
@cdr = Cons.new(@formals.sexp, @body.sexp)
View
55 lib/object_extensions.rb
@@ -1,13 +1,25 @@
-module Callable
- # allows for (mylist 4) => mylist[4]
- def call_as(sym, *args)
- self.call(*args)
+class Sym < String
+ attr_accessor :file, :line
+
+ # TODO: refactor?
+ def special_form
+ BusScheme[self].special_form
end
- def call(*args)
- self.[](*args)
+
+ def inspect
+ self
+ end
+
+ def to_s
+ self
+ end
+
+ def sym
+ self
end
end
+
class Object
# Return self after evaling block
# see http://www.ruby-forum.com/topic/131340
@@ -25,6 +37,16 @@ def special_form
end
end
+module Callable
+ # allows for (mylist 4) => mylist[4]
+ def call_as(sym, *args)
+ self.call(*args)
+ end
+ def call(*args)
+ self.[](*args)
+ end
+end
+
class String
include Callable
def sym
@@ -38,27 +60,6 @@ def sym
end
end
-class Sym < String
- attr_accessor :file, :line
-
- # TODO: refactor?
- def special_form?
- BusScheme[self].special_form?
- end
-
- def inspect
- self
- end
-
- def to_s
- self
- end
-
- def sym
- self
- end
-end
-
class Hash
include Callable
end
View
4 lib/primitives.rb
@@ -21,7 +21,7 @@ def self.special_form(identifier, value)
define '/', lambda { |x, y| x / y }
define 'concat', lambda { |*args| args.join('') }
- define 'cons', lambda { |car, cdr| Cons.new(car, cdr) }
+ define 'cons', lambda { |*args| Cons.new(*args) }
define 'list', lambda { |*members| members.to_list }
define 'vector', lambda { |*members| members.to_a }
define 'map', lambda { |fn, list| list.map(lambda { |n| fn.call(n) }).sexp }
@@ -36,7 +36,7 @@ def self.special_form(identifier, value)
define 'fail', lambda { |message| raise AssertionFailed, "#{message}\n #{BusScheme.stacktrace.join("\n ")}" }
define 'ruby', lambda { |*code| Kernel.eval code.join('') }
- define 'send', lambda { |obj, *message| obj.send(*message) }
+ define 'send', lambda { |obj, message, *args| obj.send(message.to_sym, *args) }
define 'load', lambda { |filename| BusScheme.load filename }
define 'exit', lambda { exit }
View
2  test/test_list_functions.scm
@@ -1,6 +1,6 @@
;; Test list functions defined in list.scm
-(assert-equal (quote (1 2 3)) (reverse (quote (3 2 1))))
+(assert-equal (list 1 2 3) (reverse (list 3 2 1)))
(assert-equal (quote (1 2 3 4)) (append (quote ()) (quote (1 2 3 4))))
(assert-equal (quote (1 2 3 4)) (append (quote (1 )) (quote (2 3 4))))
View
4 test/test_primitives.rb
@@ -8,7 +8,9 @@ def test_test_framework
end
def test_run_scheme_tests
- BusScheme.load(File.dirname(__FILE__) + '/test_primitives.scm')
+ Dir.glob(File.dirname(__FILE__) + '/test_*.scm').each do |f|
+ BusScheme.load f
+ end
end
def test_load_file
View
2  test/test_primitives.scm
@@ -17,6 +17,8 @@
(assert-equal 9 (begin (define foo 779) 9))
(assert-equal 779 foo)
+(assert (null? (cdr (cons 3))))
+
;; define
(define foo 5)
(define bar (quote (5 5 5)))
Please sign in to comment.
Something went wrong with that request. Please try again.