2015-05-04 06:12:24 +03:00
|
|
|
require "./types"
|
|
|
|
|
2015-05-04 13:14:59 +03:00
|
|
|
def pr_str(value, print_readably = true)
|
2015-05-04 06:12:24 +03:00
|
|
|
case value
|
|
|
|
when Nil then "nil"
|
|
|
|
when Bool then value.to_s
|
|
|
|
when Int32 then value.to_s
|
2015-05-04 13:57:20 +03:00
|
|
|
when Mal::List then "(#{value.map{|v| pr_str(v, print_readably) as String}.join(" ")})"
|
|
|
|
when Mal::Vector then "[#{value.map{|v| pr_str(v, print_readably) as String}.join(" ")}]"
|
2015-05-04 06:12:24 +03:00
|
|
|
when Mal::Symbol then value.val.to_s
|
2015-05-04 22:23:12 +03:00
|
|
|
when Proc then "<function>"
|
2015-05-04 13:57:20 +03:00
|
|
|
when Mal::HashMap
|
|
|
|
"{#{value.map{|k, v| "#{pr_str(k, print_readably) as String} #{pr_str(v, print_readably) as String}"}.join(" ")}}"
|
|
|
|
when String
|
|
|
|
case
|
|
|
|
when value.empty?()
|
|
|
|
print_readably ? value.inspect : value
|
|
|
|
when value[0] == '\u029e'
|
|
|
|
":#{value[1..-1]}"
|
|
|
|
else
|
|
|
|
print_readably ? value.inspect : value
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise "invalid MalType: #{value.to_s}"
|
2015-05-04 06:12:24 +03:00
|
|
|
end
|
|
|
|
end
|