rubyx/lib/soml/parfait/integer.soml

38 lines
649 B
Plaintext
Raw Normal View History

2015-11-08 13:30:42 +01:00
class Integer < Value
2015-11-10 18:09:17 +01:00
int as_char()
if_plus( self - 9)
2015-11-08 16:11:03 +01:00
return 32
else
Word numbers = "0123456789"
2015-11-10 18:09:17 +01:00
int index = self + 1
return numbers.char_at(index)
2015-11-08 13:30:42 +01:00
end
end
2015-11-08 16:11:03 +01:00
Word as_string(Word str)
2015-11-08 22:58:54 +01:00
if_minus( self - 10 )
2015-11-10 18:09:17 +01:00
int num = as_char()
str = str.push_char( num )
2015-11-08 22:58:54 +01:00
else
int rest = self / 10
str = rest.as_string( str )
2015-11-10 18:09:17 +01:00
rest = rest * 10
rest = self - rest
str = rest.as_string(str)
2015-11-08 13:30:42 +01:00
end
return str
end
2015-11-08 16:11:03 +01:00
Word to_s()
2015-11-08 13:30:42 +01:00
Word start = " "
2015-11-08 16:11:03 +01:00
return as_string( start )
2015-11-08 13:30:42 +01:00
end
2015-11-10 18:09:17 +01:00
int puti()
Word str = self.to_s()
str.putstring()
return self
end
2015-11-08 13:30:42 +01:00
end