aboutsummaryrefslogtreecommitdiff
path: root/ruby/printer.rb
blob: 424ca2354bbbe1d9de4ebe440495fc2a682f1618 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require "types"

def _pr_str(obj, print_readably=true)
    _r = print_readably
    return case obj
        when List
            "(" + obj.map{|x| _pr_str(x, _r)}.join(" ") + ")"
        when Vector
            "[" + obj.map{|x| _pr_str(x, _r)}.join(" ") + "]"
        when String
            if _r
                obj.inspect  # escape special characters
            else
                obj
            end
        when nil
            "nil"
        else
            obj.to_s
    end
end