Skip to content

Commit 1f82b74

Browse files
committed
4.4: improve display of strings in unparse used in programs; fixes #571
1 parent ec99172 commit 1f82b74

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

xml/chapter4/section4/subsection4.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3183,9 +3183,23 @@ function unparse(exp) {
31833183
}
31843184
</JAVASCRIPT>
31853185
<JAVASCRIPT_RUN>
3186+
function has_char(x, c) {
3187+
let found = false;
3188+
let i = 0;
3189+
while (char_at(x, i) !== undefined) {
3190+
found = found || char_at(x, i) === c;
3191+
i = i + 1;
3192+
}
3193+
return found;
3194+
}
3195+
function better_stringify(x) {
3196+
return is_string(x) &amp;&amp; ! has_char(x, "'")
3197+
? "'" + x + "'"
3198+
: stringify(x);
3199+
}
31863200
function unparse(exp) {
31873201
return is_literal(exp)
3188-
? stringify(literal_value(exp))
3202+
? better_stringify(literal_value(exp))
31893203
: is_name(exp)
31903204
? symbol_of_name(exp)
31913205
: is_list_construction(exp)

0 commit comments

Comments
 (0)