1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-11 00:52:44 +03:00
mal/nim/printer.nim

17 lines
502 B
Nim
Raw Normal View History

2015-02-28 16:14:18 +03:00
import strutils, tables, types
proc pr_str*(m: MalType): string =
case m.kind
of Nil: result = "nil"
2015-02-28 17:20:37 +03:00
of Fun: result = "fun"
2015-02-28 16:14:18 +03:00
of Symbol: result = m.symbol
of Number: result = $m.number
of List: result = "(" & m.list.map(pr_str).join(" ") & ")"
of Vector: result = "[" & m.vector.map(pr_str).join(" ") & "]"
of HashMap:
result = "{"
for key, val in m.hash_map.pairs:
if result.len > 1: result.add " "
result.add key & " " & val.pr_str
result.add "}"