Skip to content

Commit

Permalink
4.4: improve display of strings in unparse used in programs; fixes so…
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-henz committed Dec 13, 2021
1 parent ec99172 commit 1f82b74
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion xml/chapter4/section4/subsection4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3183,9 +3183,23 @@ function unparse(exp) {
}
</JAVASCRIPT>
<JAVASCRIPT_RUN>
function has_char(x, c) {
let found = false;
let i = 0;
while (char_at(x, i) !== undefined) {
found = found || char_at(x, i) === c;
i = i + 1;
}
return found;
}
function better_stringify(x) {
return is_string(x) &amp;&amp; ! has_char(x, "'")
? "'" + x + "'"
: stringify(x);
}
function unparse(exp) {
return is_literal(exp)
? stringify(literal_value(exp))
? better_stringify(literal_value(exp))
: is_name(exp)
? symbol_of_name(exp)
: is_list_construction(exp)
Expand Down

0 comments on commit 1f82b74

Please sign in to comment.