File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -49,17 +49,18 @@ proc len*(v: Value): int =
49
49
if v.kind == vkInt: v.int_v
50
50
else : v.list_v.len
51
51
52
+ proc str(v: Value): string
53
+
52
54
proc `$` * (v: Value): string =
53
- # # Return the string of a vkStr Value
54
- # # or the only item of a vkList value.
55
- # # It is an error to use it on other kinds of Values.
56
- case v.kind
57
- of vkList:
58
- if v.list_v.is_nil or v.list_v.len != 1 :
59
- raise new_exception(ValueError,
60
- " Must have exactly 1 item to convert to string" )
55
+ # # Return the string of a vkStr Value,
56
+ # # or the item of a vkList Value, if there is exactly one,
57
+ # # or a string representation of any other kind of Value.
58
+ if v.kind == vkStr:
59
+ v.str_v
60
+ elif v.kind == vkList and
61
+ not v.list_v.is_nil and v.list_v.len == 1 :
61
62
v.list_v[0 ]
62
- else : v.str_v
63
+ else : v.str
63
64
64
65
proc `@` * (v: Value): seq [string ] =
65
66
# # Return the seq of a vkList Value.
You can’t perform that action at this time.
0 commit comments