1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00
mal/crystal/printer.cr

14 lines
440 B
Crystal
Raw Normal View History

2015-05-04 06:12:24 +03:00
require "./types"
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
when String then print_readably ? value.inspect : value
when Array 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
else raise "invalid MalType: #{value.to_s}"
end
end