Skip to content

Commit

Permalink
fixes #862 (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-henz committed Jul 9, 2024
1 parent a9c6a21 commit 6f7425c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Binary file added static/img_javascript/ex-3-14-sol-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img_javascript/ex-3-14-sol-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions xml/chapter3/section3/subsection1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,33 @@ const w = mystery(v);
What would be printed as the values of <SCHEMEINLINE>v</SCHEMEINLINE>
and <SCHEMEINLINE>w</SCHEMEINLINE>?
<LABEL NAME="ex:mystery"/>
<SOLUTION>
(provided by GitHub user jonathantorres)
The application <JAVASCRIPTINLINE>mystery(x)</JAVASCRIPTINLINE> will
reverse the list <JAVASCRIPTINLINE>x</JAVASCRIPTINLINE> in-place.
Initially
<JAVASCRIPTINLINE>v</JAVASCRIPTINLINE> looks like this:

<FIGURE src="img_javascript/ex-3-14-sol-2.png">
<LABEL NAME= "ex:3-14-sol-1"/>
</FIGURE>

After evaluating
<JAVASCRIPTINLINE>const w = mystery(v);</JAVASCRIPTINLINE>
the values of
<JAVASCRIPTINLINE>v</JAVASCRIPTINLINE> and
<JAVASCRIPTINLINE>w</JAVASCRIPTINLINE> become:

<FIGURE src="img_javascript/ex-3-14-sol-2.png">
<LABEL NAME= "ex:3-14-sol-2"/>
</FIGURE>

The function <JAVASCRIPTINLINE>display</JAVASCRIPTINLINE>
prints <JAVASCRIPTINLINE>["a", null]</JAVASCRIPTINLINE> for
<JAVASCRIPTINLINE>v</JAVASCRIPTINLINE> and
<JAVASCRIPTINLINE>["d", ["c", ["b", ["a", null]]]]</JAVASCRIPTINLINE> for
<JAVASCRIPTINLINE>w</JAVASCRIPTINLINE>.
</SOLUTION>
</EXERCISE>

<INDEX>mutable data objects<SUBINDEX>list structure<CLOSE/></SUBINDEX></INDEX>
Expand Down

0 comments on commit 6f7425c

Please sign in to comment.