Created
November 22, 2009 21:48
-
-
Save duckinator/240741 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
module R6rs | |
module Types | |
#Scheme booleans are in no way related to ruby booleans. | |
#For that reason we will make our own class for the scheme | |
#language for now. | |
# | |
#What needs to be done is check if the passed value is one | |
#of '#t' or '#T', if so it is true, else we are false. | |
class Boolean | |
attr_accessor :value | |
def initialize(value) | |
# Why is this next line not true when passing a string, | |
# but line 17 works flawlessly? | |
if value.class == String | |
# Assuming it's a string | |
self.value = (value.downcase == '#t') | |
elsif value.class == TrueClass || value.class == FalseClass | |
# Ruby boolean | |
self.value = value | |
else | |
# Unknown value, lets go with false | |
self.value = false | |
end | |
end | |
def to_s | |
self.value ? '#t' : '#f' | |
end | |
def ==(obj) | |
obj.value == self.value | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[/home/nick/dev/ruby/schemey]$ irb -r scheme/r6rs/load.rb [1] | |
irb(main):001:0> R6rs::Types::Boolean.new('#t') | |
=> #<R6rs::Types::Boolean:0x0000000232e788 @value=false> | |
irb(main):002:0> R6rs::Types::Boolean.new('#f') | |
=> #<R6rs::Types::Boolean:0x00000002323850 @value=false> | |
irb(main):003:0> R6rs::Types::Boolean.new(true) | |
=> #<R6rs::Types::Boolean:0x00000002318db0 @value=true> | |
irb(main):004:0> R6rs::Types::Boolean.new(false) | |
=> #<R6rs::Types::Boolean:0x0000000230e150 @value=false> | |
irb(main):005:0> R6rs::Types::Boolean.new(File) | |
=> #<R6rs::Types::Boolean:0x00000002305710 @value=false> | |
irb(main):006:0> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment