<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1643364309931537120</id><updated>2024-08-29T18:02:55.665-07:00</updated><category term="scheme"/><category term="how to design programs 2nd ed"/><category term="htdp2e"/><category term="racket"/><category term="htdp"/><category term="space invaders"/><category term="tetris"/><category term="arrangements"/><category term="htpd 150 scheme"/><category term="quote"/><category term="worm"/><category term="157"/><category term="158"/><category term="159"/><category term="160"/><category term="161"/><category term="162"/><category term="163"/><category term="164"/><category term="165"/><category term="166"/><category term="167"/><category term="168"/><category term="169"/><category term="170"/><category term="172"/><category term="173"/><category term="174"/><category term="175"/><category term="176"/><category term="177"/><category term="182"/><category term="184"/><category term="185"/><category term="186"/><category term="187"/><category term="188"/><category term="189"/><category term="190"/><category term="191"/><category term="192"/><category term="193"/><category term="194"/><category term="195"/><category term="196"/><category term="arrange-main"/><category term="cons"/><category term="how"/><category term="html"/><category term="htpd 144"/><category term="htpd 149 scheme"/><category term="htpd 157 scheme"/><category term="list"/><category term="quasiquote"/><category term="rack"/><category term="scheme htdp 148"/><title type='text'>How To Design Programs - 2nd Ed - Code Solutions</title><subtitle type='html'>My solutions to the scheme text &quot;How to Design Programs 2nd ed&quot;. (Or htdp2e)&#xa;&#xa;I aim to complete as many as these as I can - please feel free to comment on my solutions/answers!</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>53</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-2625651378672339868</id><published>2013-02-12T16:35:00.000-08:00</published><updated>2013-02-12T16:35:00.652-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="196"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 196: Develop a-function=. </title><content type='html'>&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em; text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&amp;nbsp;196: Develop&amp;nbsp;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;a-function=&lt;/span&gt;. The function determines whether two functions from numbers to numbers produce the same results for&amp;nbsp;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1.2&lt;/span&gt;,&amp;nbsp;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;3&lt;/span&gt;, and&amp;nbsp;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&lt;span class=&quot;nobreak&quot; style=&quot;white-space: nowrap;&quot;&gt;-5&lt;/span&gt;.775&lt;/span&gt;.&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em; text-align: left;&quot;&gt;
Can we hope to define&amp;nbsp;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;function=?&lt;/span&gt;, which determines whether two functions from numbers to numbers are equal?&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em; text-align: left;&quot;&gt;
&lt;b&gt;Answer&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; returns true if the functions supplied return the same value for 3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; different numbers&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Function, Function -&amp;gt; Booleas&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (a-function= x y)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (and (a-helper x y 1.2) (a-helper x y 3) (a-helper x y -5.775)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; tests if the two functions supplied return the same number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Function, Function, Number -&amp;gt; Boolean&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (a-helper x y number)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (= (x number) (y number)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; some test functions - both 1 and 3 should return the same value, 2 should not.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (test1 x) (* 2 x))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (test2 x) (* 3 x))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (test3 x) (+ x x))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; and some tests&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (a-function= test1 test2) false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (a-function= test1 test3) true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;b&gt;Can we hope to define function=?, which determines whether two functions from numbers to numbers are equal?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;We cannot (depending on how you define &#39;equal functions&#39;). We can check to see the return value of the functions are equal for a specified set of arguments, but without the code introspection offered by languages such as Ruby, you can&#39;t see what is inside these black box functions. &amp;nbsp;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/2625651378672339868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2013/02/exercise-196-develop-function.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/2625651378672339868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/2625651378672339868'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2013/02/exercise-196-develop-function.html' title='Exercise 196: Develop a-function=. '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-5918273666946466173</id><published>2013-02-05T16:20:00.000-08:00</published><updated>2013-02-05T16:20:00.284-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="195"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 195: Argue why the following sentences are now legal definitions</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&amp;nbsp;195: Argue why the following sentences are now legal definitions:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;ol&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
Explain your reasoning.&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
&lt;span style=&quot;font-family: serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;1) &amp;nbsp;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
&lt;span style=&quot;color: #843c24; font-family: inherit;&quot;&gt;We are now&lt;/span&gt;&lt;span style=&quot;color: #843c24; font-family: monospace;&quot;&gt;&amp;nbsp;allowed to:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;font-family: serif;&quot;&gt;include the names of functions and primitive operations in the definition.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: serif;&quot;&gt;use variables and function parameters in the first position in a definition&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
In this case the parameter x is a function that will have the value 10 applied to it. &amp;nbsp;As we can include functions in a function definition this is legal.&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
&lt;span style=&quot;font-family: serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;2) (&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In this case, both x and f are functions. This function will call the function x passing in the value of itself (ie f). As we can include functions in function definitions, this is now legal.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
&lt;span style=&quot;color: #843c24; font-family: monospace;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;3) (&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace; font-weight: bold;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; font-weight: bold; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In this case f and x are functions, and y is a value (that could potentially be a function!). The function x will be called, with the values &#39;a, y and &#39;b being passed into it. At this point y could either be a value, or a function and provided that the function x is expected the actual item in, this code is legal.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
&lt;span style=&quot;color: #843c24; font-family: monospace;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/5918273666946466173/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2013/02/exercise-195-argue-why-following.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/5918273666946466173'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/5918273666946466173'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2013/02/exercise-195-argue-why-following.html' title='Exercise 195: Argue why the following sentences are now legal definitions'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-1905900564147503080</id><published>2013-01-29T17:00:00.000-08:00</published><updated>2013-01-29T17:00:03.309-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="194"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 194:  Identify the values among the following expressions:</title><content type='html'>&lt;span style=&quot;background-color: white; font-family: serif; font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: serif;&quot;&gt;&amp;nbsp;194: Assume the definitions area in DrRacket contains&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: serif;&quot;&gt;. Identify the values among the following expressions:&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;SubFlow&quot; style=&quot;background-color: white; font-family: serif; margin: 0em;&quot;&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
&lt;ol&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;empty&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;empty&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
Explain why they are values and why the remaining expressions are not values.&lt;/div&gt;
&lt;/blockquote&gt;
&lt;b&gt;Answer&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I&#39;m not completely confident on this answer - my understanding is that a value is being used in an expression, and a function will be using one (or more or less) values as input.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1. &amp;nbsp;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;empty&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In this case f and empty are values. They are being operated on by the cons.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2.&amp;nbsp;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In this case the first f is a function, and the second f is a value - it is being operated on f&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;3.&amp;nbsp;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;empty&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In this case all the cons&#39;s are functions. &amp;nbsp;The first f is a value (being operated on by the first cons). The second f is a function (operating on the 10). The remaining 10 and empty are simple values.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/1905900564147503080/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise-194-identify-values-among.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1905900564147503080'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1905900564147503080'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise-194-identify-values-among.html' title='Exercise 194:  Identify the values among the following expressions:'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-1314406962882170465</id><published>2013-01-22T16:14:00.000-08:00</published><updated>2013-01-22T16:14:00.410-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="193"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 193: Take a look at this data definition</title><content type='html'>&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: serif; font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: serif;&quot;&gt;&amp;nbsp;193: Take a look at this data definition:&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;A [&lt;/span&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=1643364309931537120&quot; name=&quot;(tech._sim-dd._bucket)&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Bucket&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;ITEM] is&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-bucket&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_two.html#(tech._n)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;N&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._list._of)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;List-of&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;ITEM&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;interp. the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;in&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-bucket&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;is the length of&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;i.e.,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._~3d))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;=&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._length))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;is always true&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
When you instantiate&amp;nbsp;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._bucket)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Bucket&lt;/span&gt;&lt;/a&gt;&amp;nbsp;with&amp;nbsp;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._string)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;,&amp;nbsp;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._ir)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;IR&lt;/span&gt;&lt;/a&gt;, and&amp;nbsp;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._posn)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Posn&lt;/span&gt;&lt;/a&gt;, you get three different data collections. Describe each of them with a sentence and with two distinct examples.&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
Now consider this instantiations:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._bucket)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Bucket&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;[&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._list._of)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;List-of&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;[&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._list._of)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;List-of&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;String]]]&lt;/span&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
Construct three distinct pieces of data that belong to this collection.&lt;/div&gt;
&lt;br /&gt;
&lt;h3&gt;
Answer&lt;/h3&gt;
&lt;b&gt;String&lt;/b&gt;&lt;br /&gt;
This is a data structure containing a number and a list of strings, where the number is the same as (length List-of-Strings)&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;eg (make-bucket 2 (list &quot;The&quot; &quot;cat&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;eg (make-bucket 4 (list &quot;The&quot; &quot;cat&quot; &quot;in&quot; &quot;the&quot; &quot;hat&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;IR&lt;/b&gt;&lt;br /&gt;
Assuming that &#39;IR&#39; in this case refers back to the Inventory Records discussed previously, then this is a data structure containing a number and a list of Inventory Records,&amp;nbsp;where the number is the same as (length List-of-IR)&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;eg (make-bucket 2 (list (make-ir &quot;widget&quot; 3) (make-ir &quot;gadget&quot; 4)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;eg (make-bucket 3 (list (make-ir &quot;widget&quot; 3)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-ir &quot;gadget&quot; 4)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-ir &quot;midget&quot; 9)))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Posn&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
This is a data structure containing a number and a list of Posns,&amp;nbsp;where the number is the same as (length List-of-Posn)&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;eg (make-bucket 2 (list (make-posn 1 2) (make-posn 4 2)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;eg (make-bucket 3 (list (make-posn 1 2) (make-posn 4 2) (make-posn 9 1)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;[Bucket [List-of [List-of String]]]&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Construct three distinct pieces of data that belong to this collection.&lt;br /&gt;
;&lt;br /&gt;
We construct 3 lists here. Note that the number (1 2 and 3) refers to the number of Lists-of-strings we have, *not* the number of strings in the Lists-of-strings.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(make-bucket 1 (list (list &quot;this&quot; &quot;is&quot; &quot;a&quot; &quot;string&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(make-bucket 2 (list (list &quot;this&quot; &quot;is&quot; &quot;a&quot; &quot;string&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list &quot;this&quot; &quot;is&quot; &quot;another&quot; &quot;string&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(make-bucket 3 (list (list &quot;this&quot; &quot;is&quot; &quot;a&quot; &quot;string&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list &quot;this&quot; &quot;is&quot; &quot;another&quot; &quot;string&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list &quot;this&quot; &quot;is&quot; &quot;a&quot; &quot;third&quot; &quot;string&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/1314406962882170465/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise-193-take-look-at-this-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1314406962882170465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1314406962882170465'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise-193-take-look-at-this-data.html' title='Exercise 193: Take a look at this data definition'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-7239247403759364553</id><published>2013-01-15T17:53:00.000-08:00</published><updated>2013-01-15T17:53:00.329-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="192"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 192: Here are two strange but similar data definitions:</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&amp;nbsp;192: Here are two strange but similar data definitions:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;table cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px;&quot; valign=&quot;top&quot; width=&quot;500&quot;&gt;&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;A&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=1643364309931537120&amp;amp;pli=1&quot; name=&quot;(tech._sim-dd._nested._string)&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Nested-string&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;is one of:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;–&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._string)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;–&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-layer&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._nested._string)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Nested-string&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/td&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px;&quot; valign=&quot;top&quot; width=&quot;500&quot;&gt;&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;A&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=1643364309931537120&amp;amp;pli=1&quot; name=&quot;(tech._sim-dd._nested._number)&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Nested-number&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;is one of:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;–&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._number)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Number&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;–&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-layer&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._nested._number)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Nested-number&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
Both data definitions exploit this structure type definition:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define-struct))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;define-struct&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;layer&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;stuff&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
Both define nested forms of data’ one is about numbers and the other about strings. Make examples for both. Abstract over the two. Then instantiate the abstract definition to get back the originals.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Answer&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A Nested String and Neste Number are data constructs that contain further datastructures of the same time.&lt;br /&gt;
This seems very similar to a list, but it&#39;s not quite the same...&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Nested-string examples - a simple example and then a nested example&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(make-layer &quot;cat&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(make-layer (make-layer &quot;bob&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Nested-number examples - a simple example and then a nested example&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(make-layer 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(make-layer (make-layer 2))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Abstraction of the two&lt;/b&gt; - this question seems a little strangely worded. I think it means to define an astract function definition.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; A [Nested ITEM] is one of:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; – empty&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; – (make-layer [Nested ITEM])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;b&gt;Instantiate to get back to the originals. &lt;/b&gt;This part seems to simple - probably I am overlooking something here. This is just reversing our abstraction for each type&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; String&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; A Nested-string is one of:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; – empty&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; – (make-layer [Nested-string])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; A Nested-number is one of:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; – empty&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; – (make-layer [Nested-number])&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/7239247403759364553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise192-here-are-two-strange-but.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/7239247403759364553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/7239247403759364553'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise192-here-are-two-strange-but.html' title='Exercise 192: Here are two strange but similar data definitions:'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-1486682568128964630</id><published>2013-01-08T16:40:00.000-08:00</published><updated>2013-01-08T16:40:00.601-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="191"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 191: Abstract the following two functions into a single function:</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&amp;nbsp;191: Abstract the following two functions into a single function:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;table cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px;&quot; valign=&quot;top&quot; width=&quot;500&quot;&gt;&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._nelon)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Nelon&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;-&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._number)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Number&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;to determine the smallest&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;number on&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;inf&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cond))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;cond&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty~3f))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;empty?&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._rest))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;rest&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._first))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;first&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._else))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;else&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cond))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;cond&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._~3c))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;&amp;lt;&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._first))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;first&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;inf&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._rest))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;rest&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._first))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;first&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._else))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;else&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;inf&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._rest))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;rest&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/td&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px;&quot; valign=&quot;top&quot; width=&quot;500&quot;&gt;&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._nelon)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Nelon&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;-&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._number)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Number&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;to determine the largest&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;number on&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;sup&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cond))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;cond&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty~3f))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;empty?&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._rest))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;rest&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._first))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;first&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._else))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;else&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cond))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;cond&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._~3e))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;&amp;gt;&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._first))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;first&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;sup&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._rest))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;rest&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._first))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;first&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._else))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;else&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;sup&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._rest))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;rest&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
Both consume non-empty lists of numbers (&lt;a href=&quot;&quot; name=&quot;(tech._nelon)&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Nelon&lt;/span&gt;) and produce a single number. The left one produces the smallest number in the list, the right one the largest.&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
Define&amp;nbsp;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;inf-1&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;sup-1&lt;/span&gt;&amp;nbsp;in terms of the abstract function. Test each of them with these two lists:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._list))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;22&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;21&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;17&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._list))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;17&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;21&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;22&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
Why are these functions slow on some of the long lists?&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Answer&lt;/h3&gt;
&lt;br /&gt;
This is the same type of function as on the last question - to abstract it we can just pass in the conditional operator that&amp;nbsp;we need.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Condition, Nelon -&amp;gt; Number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine the smallest/largest&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; number on l&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (function c l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(empty? (rest l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(first l)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[(c (first l) (function c (rest l)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (first l)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (function c (rest l))])]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Nelon -&amp;gt; Number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine the largest&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; number on l&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (sup-1 l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (function &amp;gt; l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Nelon -&amp;gt; Number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine the smallest&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; number on l&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (inf-1 l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (function &amp;lt; l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; some happy tests&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (inf-1 (list 1 2 3)) 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (sup-1 (list 1 2 3)) 3)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Why do these take so long to process some of the lists? &lt;br /&gt;
This is dependent on the operator and the order of the list passed in. The function as given above will&amp;nbsp;recurse&amp;nbsp;to the end&amp;nbsp;of the list or until the condition passed in is met. At each point that it recurses (with a slightly smaller list), that list will also require to be fully recursed all the way down. This leads to an exponential increase in the number of function calls as the list size increases.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Part Two - rewrite using min/max&lt;/h3&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Condition, comparator, Nelon -&amp;gt; Number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine the smallest/largest&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; number on l&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; c is &amp;lt; / &amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; m is min / max&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (function-2 c m l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(empty? (rest l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(first l)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[(c (first l) (m (first (rest l))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (first l)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (function-2 c m (rest l))])]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Nelon -&amp;gt; Number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine the largest&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; number on l&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (sup-2 l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (function-2 &amp;gt; max l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Nelon -&amp;gt; Number&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine the smallest&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; number on l&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (inf-2 l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (function-2 &amp;nbsp;&amp;lt; min l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; some happy tests&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (inf-2 (list 1 2 3)) 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (sup-2 (list 1 2 3)) 3)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I&#39;m not 100% happy with these definitions - it feels like I shouldn&#39;t need to be passing in both the min/max function name and the comparator (less-than and greater-than)&amp;nbsp;but I cant see a better way of structuring these.&lt;br /&gt;
&lt;br /&gt;
Why is this so much faster? If you turn on tracing within racket you can get a visual representation of what&#39;s going on - you can see that the number of function calls is not increasing exponentially with the size of the list.&amp;nbsp;As min/max &amp;nbsp;take in only two numbers, and don&#39;t require recursion through the entire list to get the next result the function is only called a maximum of 25 times.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/1486682568128964630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise-191-abstract-following-two.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1486682568128964630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1486682568128964630'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise-191-abstract-following-two.html' title='Exercise 191: Abstract the following two functions into a single function:'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-2917819037546187440</id><published>2013-01-01T16:51:00.000-08:00</published><updated>2013-01-01T16:51:00.783-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="190"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 190: Evaluate (squared&gt;? 3 10), (squared&gt;? 4 10), and (squared&gt;? 5 10) by hand</title><content type='html'>&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: serif; font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: serif;&quot;&gt;&amp;nbsp;190: Evaluate&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;squared&amp;gt;?&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;background-color: white; color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;background-color: white; color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: serif;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;squared&amp;gt;?&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;background-color: white; color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;background-color: white; color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: serif;&quot;&gt;, and&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;background-color: white; color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;squared&amp;gt;?&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;background-color: white; color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;background-color: white; font-family: monospace;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;background-color: white; color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;background-color: white; color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: serif;&quot;&gt;&amp;nbsp;by hand. Then show that&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;extract&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;squared&amp;gt;?&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._list))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
evaluates to&amp;nbsp;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._list))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;.&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._number)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Number&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._number)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Number&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;-&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._boolean)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Boolean&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;is the area of a square with side&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;larger than&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;c&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;squared&amp;gt;?&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._~3e))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;&amp;gt;&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._*))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;*&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;h3&gt;
(squared&amp;gt;? 3 10)&lt;/h3&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(squared&amp;gt;? 3 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;(&amp;gt; (* 3 3) 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;(&amp;gt; 9 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;= false&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
(squared&amp;gt;? 4 10)&lt;/h3&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(squared&amp;gt;? 4 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;(&amp;gt; (* 4 4) 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;(&amp;gt; 16 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;= true&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
(squared&amp;gt;? 5 10)&lt;/h3&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(squared&amp;gt;? 5 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;(&amp;gt; (* 5 5) 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;(&amp;gt; 15 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;= true&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Part Two&lt;/h3&gt;
&lt;br /&gt;
Show that&amp;nbsp;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(extract squared&amp;gt;? (list 3 4 5) 10)&lt;/span&gt;&amp;nbsp;evaluates to &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(list 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This exercise I found very long winded but it was very useful to step through and see how the recursion built up the final result.&amp;nbsp;Even though I am comfortable using recursion, it&#39;s not often you step through it like this.&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(extract squared&amp;gt;? (list 3 4 5) 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [(empty? (list 3 4 5)) empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(squared&amp;gt;? (first (list 3 4 5) 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 3 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list 3 4 5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest (list 3 4 5)) 10)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [false empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(squared&amp;gt;? (first (list 3 4 5) 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 3 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list 3 4 5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest (list 3 4 5)) 10)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(squared&amp;gt;? (first (list 3 4 5) 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 3 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list 3 4 5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest (list 3 4 5)) 10)])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(squared&amp;gt;? 3 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 3 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list 3 4 5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest (list 3 4 5)) 10)])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [false&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 3 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list 3 4 5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest (list 3 4 5)) 10)])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (extract squared&amp;gt;? (rest (list 3 4 5)) 10)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ; time to recurse&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (extract squared&amp;gt;? (list 4 5) 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [(empty? (list &amp;nbsp;4 5)) empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(squared&amp;gt;? (first (list 4 5) 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (extract squared&amp;gt;? (rest (list 4 5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest (list 4 5)) 10)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [false empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(squared&amp;gt;? (first (list 4 5) 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (extract squared&amp;gt;? (rest (list 4 5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest (list 4 5)) 10)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [(squared&amp;gt;? 4 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (extract squared&amp;gt;? (rest (list 4 5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest (list 4 5)) 10)])]) &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [true&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (extract squared&amp;gt;? (rest (list 4 5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest (list 4 5)) 10)])]) &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (extract squared&amp;gt;? (rest (list 4 5)) 10)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4 &amp;nbsp;(extract squared&amp;gt;? (rest (list 4 5)) 10)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; recurse again. &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4 &amp;nbsp;(extract squared&amp;gt;? (list &amp;nbsp;5)) 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[empty? (list 5) empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[(squared&amp;gt;? (first (list &amp;nbsp;5) 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (first (list &amp;nbsp;5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else (extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)])]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4 &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[false empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[(squared&amp;gt;? (first (list &amp;nbsp;5) 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (first (list &amp;nbsp;5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else (extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)])]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[(squared&amp;gt;? (first (list &amp;nbsp;5) 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (first (list &amp;nbsp;5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else (extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[(squared&amp;gt;? ( &amp;nbsp;5 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (first (list &amp;nbsp;5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else (extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[true&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (first (list &amp;nbsp;5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else (extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (list &amp;nbsp;5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons &amp;nbsp;5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (extract squared&amp;gt;? (rest (list &amp;nbsp;5)) 10)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons &amp;nbsp;5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (extract squared&amp;gt;? empty 10)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; recurse again&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons &amp;nbsp;5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [empty? empty] empty)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(squared&amp;gt;? (first empty 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first empty&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (extract squared&amp;gt;? (rest empty) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract squared&amp;gt;? (rest empty) 10)])])))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons &amp;nbsp;5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[true empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[(squared&amp;gt;? (first empty 10))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (first empty&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract squared&amp;gt;? (rest empty) 10)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[else (extract squared&amp;gt;? (rest empty) 10)])])))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons &amp;nbsp;4&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons &amp;nbsp;5&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= (list 4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/2917819037546187440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise-190-evaluate-squared-3-10.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/2917819037546187440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/2917819037546187440'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2013/01/exercise-190-evaluate-squared-3-10.html' title='Exercise 190: Evaluate (squared&gt;? 3 10), (squared&gt;? 4 10), and (squared&gt;? 5 10) by hand'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-244104641647381430</id><published>2012-12-25T16:48:00.000-08:00</published><updated>2012-12-25T16:48:00.197-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="189"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 189: Evaluate the expression</title><content type='html'>&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&amp;nbsp;189: Evaluate the expression&lt;br /&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;extract&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._~3c))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;&amp;lt;&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;empty&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/blockquote&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;div style=&quot;font-family: serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;;extract function from question&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (extract R l t)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(empty? l) empty]&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(R (first l) t)&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first l) (extract R (rest l) t))]&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else&lt;/span&gt;&lt;span style=&quot;background-color: transparent; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract R (rest l) t)])]))&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;background-color: white; font-family: serif; text-align: left;&quot;&gt;&amp;nbsp;Answer&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(extract &amp;lt; (cons 8 (cons 6 (cons 4 empty))) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [(empty? (cons 8 (cons 6 (cons 4 empty))) empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; (first (cons 8 (cons 6 (cons 4 empty))) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (cons 8 (cons 6 (cons 4 empty))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 8 (cons 6 (cons 4 empty)))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest (cons 8 (cons 6 (cons 4 empty)))) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [false empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; (first (cons 8 (cons 6 (cons 4 empty))) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (cons 8 (cons 6 (cons 4 empty))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 8 (cons 6 (cons 4 empty)))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest (cons 8 (cons 6 (cons 4 empty)))) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; 8 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (cons 8 (cons 6 (cons 4 empty))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 8 (cons 6 (cons 4 empty)))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest (cons 8 (cons 6 (cons 4 empty)))) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [false&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (cons 8 (cons 6 (cons 4 empty))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 8 (cons 6 (cons 4 empty)))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest (cons 8 (cons 6 (cons 4 empty)))) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(extract &amp;lt; (rest (cons 8 (cons 6 (cons 4 empty)))) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(extract &amp;lt; &amp;nbsp;(cons 6 (cons 4 empty)) 5)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This takes us right back to the problem from the last exercise and we can use the rest of the solution from there.</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/244104641647381430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/12/exercise189-evaluate-expression.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/244104641647381430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/244104641647381430'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/12/exercise189-evaluate-expression.html' title='Exercise 189: Evaluate the expression'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-6753226165700956112</id><published>2012-12-18T16:44:00.000-08:00</published><updated>2012-12-18T16:44:00.350-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="188"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 188: Check step 1 of the last calculation</title><content type='html'>&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&amp;nbsp;188: Check step 1 of the last calculation&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;Show every step.&lt;/span&gt;&lt;/blockquote&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;extract&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://pre.racket-lang.org/docs/html/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._~3c))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;&amp;lt;&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://pre.racket-lang.org/docs/html/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://pre.racket-lang.org/docs/html/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://pre.racket-lang.org/docs/html/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;empty&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/blockquote&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;blockquote&gt;
&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://pre.racket-lang.org/docs/html/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._~3d))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;=&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;extract&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://pre.racket-lang.org/docs/html/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._~3c))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;&amp;lt;&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://pre.racket-lang.org/docs/html/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://pre.racket-lang.org/docs/html/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;empty&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/blockquote&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;h3&gt;
Answer&lt;/h3&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; extract function in question.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (extract R l t)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(empty? l) empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(R (first l) t)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first l) (extract R (rest l) t))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract R (rest l) t)])]))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
I have answered this as a series of steps. This anwer is a bit verbose, but I have shown each change an a seperate step.&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [(empty? (cons 6 (cons 4 empty))) empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; (first (cons 6 (cons 4 empty))) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (cons 6 (cons 4 empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [false empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; (first (cons 6 (cons 4 empty))) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (cons 6 (cons 4 empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; (first (cons 6 (cons 4 empty))) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (cons 6 (cons 4 empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; 6 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (cons 6 (cons 4 empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [true&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first (cons 6 (cons 4 empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(cons (first (cons 6 (cons 4 empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(cons &amp;nbsp;6 (extract &amp;lt; (rest (cons 6 (cons 4 empty))) 5))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp; ; step seven - and we get the result we are looking for&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(cons &amp;nbsp;6 (extract &amp;lt; (cons 4 empty)) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;*******&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;= &amp;nbsp;; recursing now...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(empty? (cons 4 empty)) empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; (first &amp;nbsp;(cons 4 empty)) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first &amp;nbsp;(cons 4 empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [false empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; (first &amp;nbsp;(cons 4 empty)) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first &amp;nbsp;(cons 4 empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; (first &amp;nbsp;(cons 4 empty)) 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first &amp;nbsp;(cons 4 empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; &amp;nbsp;4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first &amp;nbsp;(cons 4 empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5)])])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;=&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; &amp;nbsp;4 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first &amp;nbsp;(cons 4 empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (extract &amp;lt; (rest &amp;nbsp;(cons 4 empty)) 5)])])&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/6753226165700956112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/12/exercise188-check-step-1-of-last.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/6753226165700956112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/6753226165700956112'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/12/exercise188-check-step-1-of-last.html' title='Exercise 188: Check step 1 of the last calculation'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-5673028072659754249</id><published>2012-12-11T16:40:00.000-08:00</published><updated>2012-12-11T16:40:00.385-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="187"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="rack"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 187: Create test suites for the following two functions:</title><content type='html'>&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: serif; font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: serif;&quot;&gt;&amp;nbsp;187: Create test suites for the following two functions:&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;table cellpadding=&quot;1&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px;&quot; valign=&quot;top&quot; width=&quot;500&quot;&gt;&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._lon)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Lon&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;-&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._lon)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Lon&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;add&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;to each number on&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;add1*&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cond))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;cond&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty~3f))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;empty?&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._false))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;false&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._else))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;else&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._add1))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;add1&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._first))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;first&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;add1*&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._rest))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;rest&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/td&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px;&quot; valign=&quot;top&quot; width=&quot;500&quot;&gt;&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._lon)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Lon&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;-&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._lon)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Lon&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;add&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;to each number on&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;plus5&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cond))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;cond&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty~3f))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;empty?&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._false))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;false&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._else))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;else&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._%2B))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;+&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._first))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;first&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;plus5&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._rest))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;rest&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Then abstract over them. Define above two functions in terms of the abstraction as one-liners and use the existing test suites to confirm that the revised definitions work properly. Finally, design a function that subtracts 2 from each number on a given list.&lt;/blockquote&gt;
&lt;div style=&quot;background-color: white; font-family: serif; margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
I had to fix the above functions to do this exercise - the empty case is returning &lt;b&gt;false&lt;/b&gt; in the book which will make the &lt;b&gt;cons&lt;/b&gt; fail as you can&#39;t cons a list to false.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Test Cases&lt;/h3&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; simple happy test - all numbers should be increased by one&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (add1* &#39;(1 2 3))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;(2 3 4))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; test empty list returns empty&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (add1* empty)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; empty)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; simple happy test - all numbers should be increased by five&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (plus5 &#39;(1 2 3))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;(6 7 8))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; test empty list returns empty&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (plus5 empty)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; empty)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; My abstraction - allow them to pass in the size of the increment&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Number, Lon -&amp;gt; Lon&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (inc* amount l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(empty? l) empty]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (+ (first l) amount)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(inc* amount (rest l) ))]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Lon -&amp;gt; Lon&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; add 1 to each number on l&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (add1* l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(inc* 1 l))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Lon -&amp;gt; Lon&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; add 5 to each number on l&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (plus5 l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (inc* 5 l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: inherit; font-size: small;&quot;&gt;Part Two&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;Define a function that subtracts 2 from each member of a list.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; a function that subtracts 2 from each member of a list&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;;&amp;nbsp;Lon -&amp;gt; Lon&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (minus2 l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (inc* -2 l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; happy test&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (minus2 &#39;(5 7 9))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;(3 5 7))&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/5673028072659754249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/12/exercise187-create-test-suites-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/5673028072659754249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/5673028072659754249'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/12/exercise187-create-test-suites-for.html' title='Exercise 187: Create test suites for the following two functions:'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-1865168840884441179</id><published>2012-12-04T15:38:00.000-08:00</published><updated>2012-12-04T15:38:00.767-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="186"/><category scheme="http://www.blogger.com/atom/ns#" term="how"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 186: Use contains? to define functions that search for &quot;atom&quot;, &quot;basic&quot;, and &quot;zoo&quot;, respectively</title><content type='html'>&lt;h2&gt;
Exercise 186: Use contains? to define functions that search for &quot;atom&quot;, &quot;basic&quot;, and &quot;zoo&quot;, respectively.&lt;/h2&gt;
&lt;br /&gt;
The contains function is supplied by the text&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._string)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_three.html#(tech._sim-dd._lo)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Los&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;-&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/part_one.html#(tech._boolean)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Boolean&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;to determine whether&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;contains the string&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;s&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;contains?&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._cond))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;cond&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._empty~3f))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;empty?&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._false))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;false&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._else))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;else&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(form._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._or))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: initial;&quot;&gt;or&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._string~3d~3f))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;string=?&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._first))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;first&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;highlighted&quot; style=&quot;background-color: #ddddff;&quot;&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;s&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;contains?&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/intermediate-lam.html#(def._htdp-intermediate-lambda._((lib._lang%2Fhtdp-intermediate-lambda..rkt)._rest))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: initial;&quot;&gt;rest&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
Answer&amp;nbsp;&lt;/h3&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; String Los -&amp;gt; Boolean&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine whether l contains the string s&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (contains? s l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(empty? l) false]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else (or (string=? (first l) s)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (contains? s (rest l)))]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Los -&amp;gt; Boolean&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine whether l contains the string &quot;atom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (contains-atom l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (contains? &quot;atom&quot; l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Los -&amp;gt; Boolean&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine whether l contains the string &quot;basic&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (contains-basic l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (contains? &quot;basic&quot; l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Los -&amp;gt; Boolean&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; to determine whether l contains the string &quot;zoo&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (contains-zoo l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (contains? &quot;zoo&quot; l))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/1865168840884441179/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/12/exercise-186-use-contains-to-define.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1865168840884441179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1865168840884441179'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/12/exercise-186-use-contains-to-define.html' title='Exercise 186: Use contains? to define functions that search for &quot;atom&quot;, &quot;basic&quot;, and &quot;zoo&quot;, respectively'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-1158468668049687364</id><published>2012-11-21T15:51:00.000-08:00</published><updated>2012-11-21T15:51:00.601-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="185"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="html"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 185: Create the function make-ranking, which consumes a list of ranked song titles and produces an HTML table representation. </title><content type='html'>&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;Exercise&lt;/span&gt;&amp;nbsp;185: Create the function&amp;nbsp;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-ranking&lt;/span&gt;, which consumes a list of ranked song titles and produces an HTML table representation.&amp;nbsp;&lt;/h2&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
Consider this example:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner-abbr.html#(form._((lib._lang%2Fhtdp-beginner-abbr..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;one-list&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;Asia: Heat of the Moment&quot;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;U2: One&quot;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;The White Stripes: Seven Nation Army&quot;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;br /&gt;
The type of output expected here isn&#39;t really clarified. You could argue we should provide an html string (eg &quot;&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;...&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&quot;) or the HTML table representation we were given as an example in the previous question. I&#39;m opting for the latter as it matches better the previous question in the book.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (ranking los)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (reverse (add-ranks (reverse los))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (add-ranks los)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(empty? los) &#39;()]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else (cons (list (length los) (first los))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (add-ranks (rest los)))]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define one-list&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &#39;(&quot;Asia: Heat of the Moment&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &quot;U2: One&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &quot;The White Stripes: Seven Nation Army&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; draws a single cell of data wrapped in a td&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Song -&amp;gt; Nested List&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-cell data)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; `(td ,data))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; makes a row for the song table based on a list of values (eg ranking + title)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-row l)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? l) &#39;())&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (cons (make-cell (first l))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-row (rest l))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; simple test on a single row. These tests are the same, I am just practising the new list notation.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (make-row &#39;(1 &quot;A&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (list &#39;td 1) (list &#39;td &quot;A&quot;) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (make-row &#39;(1 &quot;A&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;((td 1) (td &quot;A&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; creates a list row for each song in the list&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-rows los)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? los) empty)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else &amp;nbsp;`( (tr ,@(make-row (first los)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ,@(make-rows (rest los))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; a short happy test. should split our short list into two rows&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; I really struggled to get this function working before I wrote this test.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; Once I had the test, the function was simple.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect(make-rows (ranking short-list))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;((tr (td 1) (td &quot;A&quot;)) (tr (td 2) (td &quot;B&quot;))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; creates a list based table structure&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-table-list los)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; `(table ((border 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;,@los))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; happy test - this should produce a complete table list&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (make-table-list (make-rows (ranking short-list)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;(table ((border 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tr (td 1) (td &quot;A&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tr (td 2) (td &quot;B&quot;))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;; helper function that wraps the ranking and name into a table list from a list&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-table-helper list)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-table-list (make-rows (ranking list))))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When run, we get:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(make-table-helper&amp;nbsp;one-list)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(list &#39;table (list (list &#39;border 1)) (list &#39;tr (list &#39;td 1) (list &#39;td &quot;Asia: Heat of the Moment&quot;)) (list &#39;tr (list &#39;td 2) (list &#39;td &quot;U2: One&quot;)) (list &#39;tr (list &#39;td 3) (list &#39;td &quot;The White Stripes: Seven Nation Army&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/1158468668049687364/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/11/exercise185-create-functionmake-ranking.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1158468668049687364'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1158468668049687364'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/11/exercise185-create-functionmake-ranking.html' title='Exercise 185: Create the function make-ranking, which consumes a list of ranked song titles and produces an HTML table representation. '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-1650920370749667523</id><published>2012-11-14T15:37:00.003-08:00</published><updated>2012-11-14T15:37:37.437-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="184"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="quote"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><title type='text'>Exercise 184: Eliminate quasiquote, unquote, and unquote-splicing from the following expressions so that they are written with list instead</title><content type='html'>&lt;br /&gt;
&lt;h2&gt;
Eliminate quasiquote, unquote, and unquote-splicing from the following expressions so that they are written with list instead:&lt;/h2&gt;
&lt;h3&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; font-size: medium; font-weight: normal; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktRdr&quot; style=&quot;font-family: monospace; white-space: inherit;&quot;&gt;,@&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
this table-like shape:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;alan&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktRdr&quot; style=&quot;font-family: monospace; white-space: inherit;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner-abbr.html#(def._htdp-beginner-abbr._((lib._lang%2Fhtdp-beginner-abbr..rkt)._*))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;*&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;barb&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2000&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktRdr&quot; style=&quot;font-family: monospace; white-space: inherit;&quot;&gt;,@&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;carl&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot; , the great&quot;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1500&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;dawn&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2300&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
and this third web page:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;html&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;body&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;table&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;border&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;tr&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;200&quot;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktRdr&quot; style=&quot;font-family: monospace; white-space: inherit;&quot;&gt;,@&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-row&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;tr&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;200&quot;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktRdr&quot; style=&quot;font-family: monospace; white-space: inherit;&quot;&gt;,@&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-row&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;99&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;65&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
where&amp;nbsp;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-row&lt;/span&gt;&amp;nbsp;is the function from above.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; font-size: medium; font-weight: normal; margin: 1em 0px; text-align: left;&quot;&gt;
Also write down the nested lists that the expressions produce.&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; font-size: medium; font-weight: normal; margin: 1em 0px; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/h3&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: inherit; font-size: small;&quot;&gt;Question One&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;`(0 ,@&#39;(1 2 3) 4)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;becomes&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(list 0 1 2 3 4)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
This is very straight forward. The ` operator will start creating a list, the ,@&#39;(1 2 3) will execute the &#39; creating (list 1 2 3) which will&amp;nbsp;&amp;nbsp;will be spliced back into our main list.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;Question Two&lt;/span&gt;&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;`((&quot;alan&quot; ,(* 2 500))&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (&quot;barb&quot; 2000)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (,@&#39;(list &quot;carl&quot; &quot; , the great&quot;) &amp;nbsp; 1500)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (&quot;dawn&quot; 2300))&lt;/span&gt;&lt;/blockquote&gt;
This is what I thought the list would produce - I was wrong.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(list (list &quot;alan&quot; 1000)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;barb&quot; 2000)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;carl the great&quot; 1500)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (&quot;dawn&quot; 2300))&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
What it actually produced was:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(list (list &quot;alan&quot; 1000)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;barb&quot; 2000)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &#39;list &quot;carl&quot; &quot; , the great&quot; 1500)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;dawn&quot; 2300))&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
I&#39;m not sure if this was meant to be a trick question, but it got me =)&lt;br /&gt;
With the answer in front of me, I now interpret the line &lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(,@&#39;(list &quot;carl&quot; &quot; , the great&quot;) &amp;nbsp; 1500)&lt;/span&gt; as&amp;nbsp;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(list &quot;carl&quot; &quot;, the great)&lt;/span&gt; as create a list containing the symbol &#39;list, the word &quot;carl&quot; and &quot;, the great&quot;)&amp;nbsp;and splice this list back into the result.&lt;br /&gt;
&lt;br /&gt;
Nest listed Representation - I&#39;m not 100% sure about this - I think the representation for carl the great is wrong:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&#39;((alan 1000)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (barb 2000)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (&#39;(carl (the great)) 1500)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (dawn 2300))&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
&lt;h3&gt;
Question Three&lt;/h3&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;`(html&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(body&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(table ((border &quot;1&quot;))&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(tr ((width &quot;200&quot;)) ,@(make-row &#39;( 1 &amp;nbsp;2)))&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(tr ((width &quot;200&quot;)) ,@(make-row &#39;(99 65))))))&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
My first cut - this was pretty much 100% wrong.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(list &quot;html&quot;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;body&quot;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;table&quot;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;border 1&quot;)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;tr&quot;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;width&quot; &quot;200&quot;)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (list &quot;td&quot; 1) (list &quot;td&quot; 2))))&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;tr&quot;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;width&quot; &quot;200&quot;)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (list &quot;td&quot; 99) (list &quot;td&quot; 65))))) &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
This is the actual answer as given by racket. I&#39;ve forgotten to use symbols completely, and messed up the double list wrapping for the border styles.&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(list &#39;html&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &#39;body&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &#39;table&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (list &#39;border &quot;1&quot;))&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &#39;tr (list (list &#39;width &quot;200&quot;))&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &#39;td &quot;1&quot;) (list &#39;td &quot;2&quot;))&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &#39;tr (list (list &#39;width &quot;200&quot;))&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &#39;td &quot;99&quot;) (list &#39;td &quot;65&quot;)))))&lt;/span&gt;&lt;/blockquote&gt;
&lt;br /&gt;
Nested List Representation:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&#39;(html&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (body&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(table (border &quot;1&quot;)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tr (width &quot;200&quot;)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (td 1) (td 2))&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tr (width &quot;200&quot;)&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (td 99) (td 65)))))&lt;/span&gt;&lt;/blockquote&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; </content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/1650920370749667523/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/11/exercise-184-eliminate-quasiquote.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1650920370749667523'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1650920370749667523'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/11/exercise-184-eliminate-quasiquote.html' title='Exercise 184: Eliminate quasiquote, unquote, and unquote-splicing from the following expressions so that they are written with list instead'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-4901124555657506345</id><published>2012-10-02T16:59:00.001-07:00</published><updated>2012-10-02T17:02:16.415-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="quasiquote"/><category scheme="http://www.blogger.com/atom/ns#" term="quote"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 183: Eliminate quasiquote and unquote from the following expressions</title><content type='html'>&lt;br /&gt;
&lt;h2&gt;
Eliminate quasiquote and unquote from the following expressions:&lt;/h2&gt;
&lt;br /&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;#f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;c&quot;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
this table-like shape:&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: justify; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;alan&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktRdr&quot; style=&quot;font-family: monospace; white-space: inherit;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner-abbr.html#(def._htdp-beginner-abbr._((lib._lang%2Fhtdp-beginner-abbr..rkt)._*))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;*&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;barb&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2000&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktRdr&quot; style=&quot;font-family: monospace; white-space: inherit;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner-abbr.html#(def._htdp-beginner-abbr._((lib._lang%2Fhtdp-beginner-abbr..rkt)._string-append))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;string-append&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;carl&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot; , the great&quot;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1500&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;dawn&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2300&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
and this second web page:&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: justify; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;html&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;head&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktRdr&quot; style=&quot;font-family: monospace; white-space: inherit;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;body&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktRdr&quot; style=&quot;font-family: monospace; white-space: inherit;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;A second web page&quot;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
where&amp;nbsp;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner-abbr.html#(form._((lib._lang%2Fhtdp-beginner-abbr..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;ratings&quot;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;.&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: serif;&quot;&gt;Also write down the nested lists that the expressions produce.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Answers&lt;/h3&gt;
There are two answers for each question - the normal list, and the nested list representation.&lt;br /&gt;
&lt;br /&gt;
1)&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(list 1 &quot;a&quot; 2 false 3 &quot;c&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&#39;(1 &quot;a&quot; 2 false 3 &quot;c&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
2)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;(list (list &quot;alan&quot; (* 2 5000))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;barb&quot; 2000)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (string-append &quot;carl&quot; &quot; , the great&quot;) 1500)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;dawn&quot; 2300))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;(list &quot;html&quot; (list &quot;head&quot; (list title))&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list &quot;body&quot; (list &quot;h1&quot; title)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;p&quot; &quot;A second web page&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;&#39;((&quot;allan&quot; 1000)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; (&quot;barb&quot; &amp;nbsp;2000)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; (&quot;carl&quot; &amp;nbsp;1500)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; (&quot;dawn&quot; &amp;nbsp;3000))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;
3)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;
(cons&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;&quot;html&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;(cons (cons &quot;head&quot; (cons (cons &quot;ratings&quot; empty) empty)) (cons (cons &quot;body&quot; (cons (cons &quot;h1&quot; (cons &quot;ratings&quot; empty)) (cons (cons &quot;p&quot; (cons &quot;A second web page&quot; empty)) empty))) empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp;&#39;(&quot;html&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; (&quot;head&quot; (&quot;title&quot; &quot;ratings&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; (&quot;body&quot; (&quot;h1&quot; &quot;ratings&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (&quot;p&quot; &amp;nbsp;&quot;A second web page&quot;)))&lt;/span&gt;&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/4901124555657506345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/10/exercise-183-eliminate-quasiquote-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/4901124555657506345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/4901124555657506345'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/10/exercise-183-eliminate-quasiquote-and.html' title='Exercise 183: Eliminate quasiquote and unquote from the following expressions'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-5527351761251090002</id><published>2012-09-11T15:12:00.000-07:00</published><updated>2012-09-11T15:12:12.584-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="182"/><category scheme="http://www.blogger.com/atom/ns#" term="cons"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="list"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><title type='text'>Exercise 182: Eliminate quote from the following expressions</title><content type='html'>&lt;br /&gt;
&lt;h2&gt;
&lt;span style=&quot;font-family: serif;&quot;&gt;Exercise 182: Eliminate quote from the following expressions&lt;/span&gt;&lt;/h2&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
Eliminate&amp;nbsp;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner-abbr.html#(form._((lib._lang%2Fhtdp-beginner-abbr..rkt)._quote))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;quote&lt;/a&gt;&lt;/span&gt;&amp;nbsp;from the following expressions so that they use&amp;nbsp;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner-abbr.html#(def._htdp-beginner-abbr._((lib._lang%2Fhtdp-beginner-abbr..rkt)._list))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;list&lt;/a&gt;&amp;nbsp;&lt;/span&gt;instead:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;ol&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;#f&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;c&quot;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div style=&quot;margin-bottom: 1em; margin-top: 1em;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
and this table-like shape:&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;margin: 1em 0px;&quot;&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;alan&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;barb&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2000&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;carl&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;1500&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;&quot;dawn&quot;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;2300&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;color: forestgreen; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;SCodeFlow&quot; style=&quot;margin: 0em 1em; white-space: nowrap;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;Now eliminate list in favor of&amp;nbsp;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner-abbr.html#(def._htdp-beginner-abbr._((lib._lang%2Fhtdp-beginner-abbr..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&amp;nbsp;where needed.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; font-family: serif; margin: 1em 0px;&quot;&gt;
&lt;br /&gt;
&lt;h3&gt;
Eliminate in favour of list&lt;/h3&gt;
&lt;br /&gt;
This is very straight forward.&lt;/div&gt;
&lt;div class=&quot;SIntrapara&quot; style=&quot;background-color: white; margin: 1em 0px;&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(list 1 &quot;a&quot; 2 false 3 &quot;c&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(list)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(list (list &quot;alan&quot; 1000)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;barb&quot; 2000)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;carl&quot; 1500)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (list &quot;dawn&quot; 3000))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3&gt;
Eliminate in favour of cons&lt;/h3&gt;
&lt;div style=&quot;font-family: serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: serif;&quot;&gt;
This is not hard, but painful. Constructing lists like this is frustrating - which is the point of the exercise.&lt;/div&gt;
&lt;div style=&quot;font-family: serif;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cons 1 (cons &quot;a&quot; (cons 2 (cons false (cons 3 (cons &quot;c&quot; empty))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;empty&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;(cons (cons &quot;allan&quot; (cons 1000 empty))&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (cons &quot;barb&quot; (cons 2000 empty)) &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (cons &quot;carl&quot; (cons 1500 empty))&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (cons &quot;dawn&quot; (cons 3000 empty))&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;empty &amp;nbsp;))))&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/5527351761251090002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/09/exercise-182-eliminate-quote-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/5527351761251090002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/5527351761251090002'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/09/exercise-182-eliminate-quote-from.html' title='Exercise 182: Eliminate quote from the following expressions'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-2766356823261481584</id><published>2012-08-29T18:13:00.000-07:00</published><updated>2012-08-29T18:13:00.343-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><category scheme="http://www.blogger.com/atom/ns#" term="space invaders"/><title type='text'>Special Exercise - Space Invaders Part 4</title><content type='html'>&lt;h2&gt;
&amp;nbsp;Space Invaders Part 4&lt;/h2&gt;
&lt;br /&gt;
My goals for the 4th iteration were to:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp; allow the tank to shoot at the invaders&lt;/li&gt;
&lt;li&gt;&amp;nbsp; have invaders &amp;nbsp;&#39;die&#39; when hit&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
To implement these goals we need a number of new elements and behaviours:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp;the world now has a collection of bullets.&lt;/li&gt;
&lt;li&gt;&amp;nbsp;bullets &amp;nbsp;have a location and consist of a single block.&lt;/li&gt;
&lt;li&gt;&amp;nbsp;bullets move upwards until they collide with a space invader (cause the &amp;nbsp;invader to disappear)&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
In addition play testing showed that we need to restrict the number of bullets on the screen (or introduce a delay between shots). Without this you can just fire a lethal stream of bullets taking out all the UFO&#39;s very quickly.&lt;br /&gt;
&lt;br /&gt;
Bullets, tanks and ufos turned out to be structured very similarly. I should have implemented these using plain &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;posn&#39;s&lt;/span&gt; as this would have allowed more function sharing.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Code&lt;/h3&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(require racket/base)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct ufo (x y direction) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct bullet (x y) #:transparent )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct tank (x y) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct world (ufos tank bullets))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 300) &amp;nbsp; &amp;nbsp; ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define HEIGHT 300) &amp;nbsp; &amp;nbsp;; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define BULLET_DIST 5) ; the distance travelled by a bullet&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SIZE 10) &amp;nbsp; &amp;nbsp; &amp;nbsp; ; the size of the block making up the ufo&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define UFO-WIDTH 50)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define MAX-BULLETS 2) ; max number of bullets on screen at a time&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(define BLOCK ;rendered as red squares with black rims &amp;nbsp;- stolen from tetris&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (overlay (rectangle (- SIZE 1) (- SIZE 1) &quot;solid&quot; &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rectangle SIZE SIZE &quot;outline&quot; &quot;black&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(define TEST-UFO (make-ufo 30 30 1)) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;; for testing&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TEST-UFOS (list (make-ufo 30 30 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-ufo 80 30 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-ufo 130 30 1))); for testing&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; initial tank position should be middle of the screen, one block up&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; from the bottom&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TANK (make-tank (/ WIDTH 2) (- HEIGHT (* SIZE 2))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; creates a row of ufos on the y-cordinate&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Integer Ufos -&amp;gt; Ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-ufos-for-y y-cordinate ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? ufos) (make-ufos-for-y y-cordinate &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (make-ufo 20 y-cordinate 1) ufos)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((&amp;gt; (+ (ufo-x (first ufos)) UFO-WIDTH) WIDTH) ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (printf &amp;nbsp;&quot;first ~a&quot; (+ (ufo-x (first ufos))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-ufos-for-y y-cordinate&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons &amp;nbsp;(make-ufo (+ (ufo-x (first ufos))&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;UFO-WIDTH) y-cordinate 1) ufos )))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; create a collection of rows of ufos&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Integer Ufos -&amp;gt; Ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-ufos rows ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((= 0 rows) ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (make-ufos (- rows 1)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(append ufos&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(make-ufos-for-y&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(- ( * rows 60) 30)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;empty))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; draw a triangular shaped alien&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-ufo ufo background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (ufo-x ufo) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image/align BLOCK (- (ufo-x ufo) SIZE) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (place-image/align BLOCK (+ (ufo-x ufo) SIZE) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (ufo-x ufo) (+ (ufo-y ufo) SIZE) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;background)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a tank shaped tank&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-tank tank background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (tank-x tank) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image/align BLOCK (- (tank-x tank) SIZE) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (place-image/align BLOCK (+ (tank-x tank) SIZE) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (tank-x tank) (+ (tank-y tank) SIZE)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (tank-x tank) SIZE) (+ (tank-y tank) SIZE )&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (tank-x tank) SIZE) (+ (tank-y tank) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (tank-x tank) (- (tank-y tank) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background))))))))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draw a bullet on the background&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; bullet, scene -&amp;gt; scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-bullet bullet background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image/align BLOCK (bullet-x bullet)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (bullet-y bullet) &quot;left&quot; &quot;bottom&quot; background))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draw a collection of bullets&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-bullets bullets background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? bullets) background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (draw-bullet (first bullets)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-bullets (rest bullets) background)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; Move the bullets;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; If the bullet moves past the top of the screen, remove it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-bullets bullets)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? bullets) bullets)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else &amp;nbsp;(cond ((&amp;gt; 0 (bullet-y (first bullets)))&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(move-bullets (rest bullets)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (move-bullet (first bullets))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(move-bullets (rest bullets))))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; simple test case for moving a list of bullets&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-bullets (list (make-bullet 100 100) (make-bullet 90 100)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-bullet 100 (- 100 BULLET_DIST))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-bullet 90 (- 100 BULLET_DIST))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; Move a bullet&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-bullet bullet)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-bullet (bullet-x bullet) (- (bullet-y bullet) BULLET_DIST)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; basic bullet moving test&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-bullet (make-bullet 50 50)) (make-bullet 50 (- 50 BULLET_DIST)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw the collection of ufos on to the background.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a simple recursive function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Ufos Scene -&amp;gt; Scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-ufos ufos background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? ufos) &amp;nbsp;background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (draw-ufo (first ufos) (draw-ufos (rest ufos) background)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; draws the world as a scene&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; World -&amp;gt; Scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (render-scene world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-ufos (world-ufos world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-tank (world-tank world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (draw-bullets (world-bullets world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene WIDTH HEIGHT)))))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; move the ufo left or right according to it&#39;s current direction&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; when it reaches the edge of the screen, flip the direction the ufo&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; is travelling&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-ufo ufo)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(future-ufo-x &amp;nbsp;ufo) (ufo-direction ufo) WIDTH)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((&amp;gt; 10 (future-ufo-x ufo)) &amp;nbsp;(change-ufo-direction ufo))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((&amp;lt; (- WIDTH 10) (future-ufo-x &amp;nbsp;ufo)) (change-ufo-direction ufo))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else &amp;nbsp; &amp;nbsp;(make-ufo (future-ufo-x &amp;nbsp;ufo)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(ufo-y ufo) (ufo-direction ufo)))))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; returns an identical ufo but with the direction changed&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (change-ufo-direction ufo)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-ufo (ufo-x ufo) (+ (ufo-y ufo) 30) (* -1 (ufo-direction ufo))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; simplest test for changing direction.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (change-ufo-direction (make-ufo 10 10 1)) (make-ufo 10 40 -1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; moves each ufo one at a time&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-ufos ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? ufos) ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (cons (move-ufo (first ufos)) (move-ufos (rest ufos))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; moves the tank left or right&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the direction is positive/negative mulitplier that will&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; determine in which direction the tank moves&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; we use the future-tank-x function to determine if the tank would be moved&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; into a position&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;outside of the game word.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; tank direction -&amp;gt; tank&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-tank tank direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((&amp;gt; 10 (future-tank-x direction tank)) &amp;nbsp;tank)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((&amp;lt; (- WIDTH 20) (future-tank-x direction tank)) &amp;nbsp;tank)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else &amp;nbsp;(make-tank (future-tank-x direction tank) (tank-y tank) ))))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; returns the position the tank will be in if it moves in *direction*&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; used for collision detection with walls and actual moving of tank&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Integer Tank -&amp;gt; Integer&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (future-tank-x direction tank)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (+ (* SIZE direction) (tank-x tank) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; just like future-tank-x but for ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the diference is that the ufo holds the direction internally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (future-ufo-x &amp;nbsp;ufo)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (+ (* 1 (ufo-direction ufo)) (ufo-x ufo) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; Fire a bullet and returns new collection of bullets&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Allows only MAX-BULLETS on screen&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; World -&amp;gt; Bullets&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (fire-tank world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((eq? MAX-BULLETS (length (world-bullets world))) (world-bullets world))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (make-bullet (tank-x (world-tank world) )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(tank-y (world-tank world) )) (world-bullets world) ))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; respond to keyboard input.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Left - Move tank left&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Right - Move tank right&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Space - Fire (not yet)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (handle-key-events world ke)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-world (world-ufos world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(string=? &quot;left&quot; ke) &amp;nbsp;(move-tank (world-tank world) -1)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(string=? &quot;right&quot; ke) (move-tank (world-tank world) 1) ]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (world-tank world)])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(key=? &quot; &quot; ke) &amp;nbsp;(fire-tank world)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (world-bullets world)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; bullets/ufo collision detector&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; returns true in the event of a collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; ufo, bullets -&amp;gt; boolean&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (collide? ufo bullets)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? bullets) false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((collide-helper? &amp;nbsp;(first bullets) ufo) true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ( else (collide? ufo (rest bullets)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; bullet/ufo collision helper. detects collision between a single bullet and&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a ufo&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; ufo, bullet -&amp;gt; boolean&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (collide-helper? &amp;nbsp;bullet ufo)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((and (between? (bullet-x bullet) (- (ufo-x ufo) SIZE 5)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (+ (ufo-x ufo) &amp;nbsp;SIZE 5))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (between? (bullet-y bullet) (- (ufo-y ufo) SIZE 5)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (+ (ufo-y ufo) SIZE 5)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else false)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; helper function to determine if a number is within a range.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; i&#39;m sure there must be a similar one defined in the libs, but I&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; couldn&#39;t find it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Integer, Integr, Integer -&amp;gt; Boolean&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (between? x low high)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((and (&amp;gt; x low) (&amp;lt; x high) true))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else false)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(check-expect (between? 50 10 100) true)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (between? 10 50 100) false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; remove any ufos from the collection that have been hit by a bullet&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; ufos, bullets -&amp;gt; ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (bullet-collision-ufos ufos bullets)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? ufos) &amp;nbsp; &amp;nbsp; &amp;nbsp; ufos )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (cond ((collide? (first ufos) bullets)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(bullet-collision-ufos (rest ufos) bullets))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (cons (first ufos)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (bullet-collision-ufos (rest ufos) bullets)))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; On each clock tick, move the world further in time.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; this calls the bullet-collision-ufos function twice - this calculates which&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; bullets and ufos&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;are left. I wish I didn&#39;t have to call this twice but not&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; sure how else to save the value...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (progress-world world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-world &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(bullet-collision-ufos (move-ufos (world-ufos world))&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(world-bullets &amp;nbsp;world))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (world-tank world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (move-bullets (world-bullets world))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; This is the big bang function that drives the game.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (space-invaders-main rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (big-bang (make-world (make-ufos 3 empty ) TANK empty)&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-key &amp;nbsp; &amp;nbsp; handle-key-events)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-tick &amp;nbsp; &amp;nbsp;progress-world rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (to-draw &amp;nbsp; &amp;nbsp;render-scene)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(space-invaders-main 0.01)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;; TESTS&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; check moving ufo left and right works as expected&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-ufo (make-ufo 10 10 1)) (make-ufo 20 10 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-ufo (make-ufo 20 10 -1)) (make-ufo 10 10 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; check hitting the edge of the screen changes the ufos direction&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-ufo (make-ufo WIDTH 10 1)) (make-ufo WIDTH 10 -1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; check the ufo change direction changes left and right&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (change-ufo-direction (make-ufo 10 10 1)) (make-ufo 10 10 -1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (change-ufo-direction (make-ufo 10 10 -1)) (make-ufo 10 10 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; simple example - a single block in an empty landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-ufo TEST-UFO (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (ufo-x TEST-UFO) (ufo-y TEST-UFO) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (ufo-x TEST-UFO) SIZE) (ufo-y TEST-UFO)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (ufo-x TEST-UFO) SIZE) (ufo-y TEST-UFO)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (ufo-x TEST-UFO) (+ (ufo-y TEST-UFO) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene WIDTH HEIGHT))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; test drawing three ufo&#39;s via the draw-ufos function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-ufos TEST-UFOS (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (draw-ufo (first TEST-UFOS)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (draw-ufo (second TEST-UFOS)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-ufo (third TEST-UFOS) (empty-scene WIDTH HEIGHT)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; test the tank drawing works&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-tank TANK (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (tank-x TANK) (tank-y TANK) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image/align BLOCK (- (tank-x TANK) SIZE) (tank-y TANK) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (place-image/align BLOCK (+ (tank-x TANK) SIZE) (tank-y TANK) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (tank-x TANK) (+ (tank-y TANK) SIZE) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (tank-x TANK) SIZE) (+ (tank-y TANK) SIZE )&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (tank-x TANK) SIZE) (+ (tank-y TANK) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (tank-x TANK) (- (tank-y TANK) SIZE)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene WIDTH HEIGHT)))))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/2766356823261481584/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/08/special-exercise-space-invaders-part-4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/2766356823261481584'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/2766356823261481584'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/08/special-exercise-space-invaders-part-4.html' title='Special Exercise - Space Invaders Part 4'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-6177291532464551495</id><published>2012-08-21T18:22:00.000-07:00</published><updated>2012-08-21T18:22:00.892-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><category scheme="http://www.blogger.com/atom/ns#" term="space invaders"/><title type='text'>Special Exercise - Space Invaders Part 3</title><content type='html'>&lt;h2&gt;
Special Exercise - Space Invaders Part 3&lt;/h2&gt;
For this third iteration my goals were to&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Make the tank move left and right.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Make the ufos move left and right and (always) down.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
While I found it is nice and simple to make the&amp;nbsp;pieces&amp;nbsp;move as needed, I always struggle with the bounds checking. It this case we needed to stop the tank and the ufo&#39;s from moving off the side of the screen.&lt;br /&gt;
&lt;br /&gt;
It&#39;s not that bounds checking is hard to do, just it always ends up looking messy and detracting from the simplicity of the code. Instead of &quot;move left&quot;, it&#39;s &quot;move left . . . unless this, or that or something else&quot;. &amp;nbsp;The way I have written it below works, but there is bound to be a better way to do it.&lt;br /&gt;
&lt;br /&gt;
In addition to the changes needed to support the goals above, &amp;nbsp;ufos&#39; now hold a direction integer to say which direction (left or right) they are currently travelling in.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Code&lt;/h3&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(require racket/base)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct ufo (x y direction) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct tank (x y) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct world (ufos tank))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; physical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 300) ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define HEIGHT 300) ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; graphical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SIZE 10) ; the size of the block making up the ufo&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define UFO-WIDTH 50)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define BLOCK ; they are rendered as red squares with black rims &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (overlay (rectangle (- SIZE 1) (- SIZE 1) &quot;solid&quot; &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rectangle SIZE SIZE &quot;outline&quot; &quot;black&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TEST-UFO (make-ufo 30 30 1)) &amp;nbsp; ; for testing&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TEST-UFOS (list (make-ufo 30 30 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-ufo 80 30 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-ufo 130 30 1))); for testing&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; initial tank position should be middle of the screen, one block up from the bottom&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TANK (make-tank (/ WIDTH 2) (- HEIGHT (* SIZE 2))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; creates a row of ufos on the y-cordinate&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Integer Ufos -&amp;gt; Ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-ufos-for-y y-cordinate ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? ufos) (make-ufos-for-y y-cordinate&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (make-ufo 20 y-cordinate 1) ufos)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((&amp;gt; (+ (ufo-x (first ufos)) UFO-WIDTH) WIDTH) ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(make-ufos-for-y y-cordinate&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(make-ufo (+ (ufo-x (first ufos)) UFO-WIDTH)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; y-cordinate 1) ufos )))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; create a collection of rows of ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Integer Ufos -&amp;gt; Ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-ufos rows ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((= 0 rows) ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (make-ufos (- rows 1)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(append ufos (make-ufos-for-y (- ( * rows 60) 30) empty))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a triangular shaped alien&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-ufo ufo background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (ufo-x ufo) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (ufo-x ufo) SIZE) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (ufo-x ufo) SIZE) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (ufo-x ufo) (+ (ufo-y ufo) SIZE) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a tank shaped tank&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-tank tank background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (tank-x tank) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image/align BLOCK (- (tank-x tank) SIZE) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (place-image/align BLOCK (+ (tank-x tank) SIZE) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (tank-x tank) (+ (tank-y tank) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (tank-x tank) SIZE) (+ (tank-y tank) SIZE )&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(place-image/align BLOCK (+ (tank-x tank) SIZE) (+ (tank-y tank) SIZE) &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (tank-x tank) (- (tank-y tank) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background))))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw the collection of ufos on to the background.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a simple recursive function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Ufos Scene -&amp;gt; Scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-ufos ufos background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? ufos) &amp;nbsp;background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (draw-ufo (first ufos) (draw-ufos (rest ufos) background)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draws the world as a scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; World -&amp;gt; Scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (render-scene world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-ufos (world-ufos world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-tank (world-tank world) (empty-scene WIDTH HEIGHT))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; move the ufo left or right according to it&#39;s current direction&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; when it reaches the edge of the screen, flip the direction the ufo&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; is travelling&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-ufo ufo)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(future-ufo-x &amp;nbsp;ufo) (ufo-direction ufo) WIDTH)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((&amp;gt; 10 (future-ufo-x ufo)) &amp;nbsp;(change-ufo-direction ufo))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((&amp;lt; (- WIDTH 10) (future-ufo-x &amp;nbsp;ufo)) (change-ufo-direction ufo))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else &amp;nbsp; &amp;nbsp;(make-ufo (future-ufo-x &amp;nbsp;ufo)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(ufo-y ufo) (ufo-direction ufo)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; returns an identical ufo but with the direction changed&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (change-ufo-direction ufo)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-ufo (ufo-x ufo) (+ (ufo-y ufo) 30) (* -1 (ufo-direction ufo))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; moves each ufo one at a time&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-ufos ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? ufos) ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (cons (move-ufo (first ufos)) (move-ufos (rest ufos))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; moves the tank left or right&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the direction is positive/negative mulitplier that will&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; determine in which direction the tank moves&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; we use the future-tank-x function to determine if the tank would be moved&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; into a position&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;outside of the game word.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; tank direction -&amp;gt; tank&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-tank tank direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((&amp;gt; 10 (future-tank-x direction tank)) &amp;nbsp;tank)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((&amp;lt; (- WIDTH 20) (future-tank-x direction tank)) &amp;nbsp;tank)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else &amp;nbsp;(make-tank (future-tank-x direction tank) (tank-y tank) ))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; returns the position the tank will be in if it moves in *direction*&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; used for collision detection with walls and actual moving of tank&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Integer Tank -&amp;gt; Integer&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (future-tank-x direction tank)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (+ (* SIZE direction) (tank-x tank) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; just like future-tank-x but for ufos&#39;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the diference is that the ufo holds the direction internally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (future-ufo-x &amp;nbsp;ufo)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (+ (* 1 (ufo-direction ufo)) (ufo-x ufo) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; respond to keyboard input.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Left - Move tank left&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Right - Move tank right&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Space - Fire (not yet)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (handle-key-events world ke)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-world (world-ufos world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(string=? &quot;left&quot; ke) &amp;nbsp;(move-tank (world-tank world) -1)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(string=? &quot;right&quot; ke) (move-tank (world-tank world) 1) ])))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; On each clock tick, move the world further in time.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (progress-world world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-world (move-ufos (world-ufos world)) (world-tank world)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is the big bang function that drives the game.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (space-invaders-main rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (big-bang (make-world (make-ufos 2 empty) TANK)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;(big-bang (make-world (list (make-ufo 10 10 1)) TANK)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-key &amp;nbsp; &amp;nbsp; handle-key-events)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-tick &amp;nbsp; &amp;nbsp; progress-world rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (to-draw &amp;nbsp; &amp;nbsp;render-scene)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(space-invaders-main 0.01)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: inherit; font-size: small;&quot;&gt;Tests&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; check moving ufo left and right works as expected&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-ufo (make-ufo 10 10 1)) (make-ufo 20 10 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-ufo (make-ufo 20 10 -1)) (make-ufo 10 10 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; check hitting the edge of the screen changes the ufos direction&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-ufo (make-ufo WIDTH 10 1)) (make-ufo WIDTH 10 -1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; check the ufo change direction changes left and right&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (change-ufo-direction (make-ufo 10 10 1)) (make-ufo 10 10 -1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (change-ufo-direction (make-ufo 10 10 -1)) (make-ufo 10 10 1))&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;(other tests are unchanged)&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/6177291532464551495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/08/special-exercise-space-invaders-part-3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/6177291532464551495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/6177291532464551495'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/08/special-exercise-space-invaders-part-3.html' title='Special Exercise - Space Invaders Part 3'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-4716579137254140624</id><published>2012-08-14T18:20:00.000-07:00</published><updated>2012-08-14T18:20:00.384-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><category scheme="http://www.blogger.com/atom/ns#" term="space invaders"/><title type='text'>Special Exercise - Space Invaders Part 2</title><content type='html'>&lt;br /&gt;
&lt;h2&gt;
Design a complete Space Invaders Game &amp;nbsp;- Part 2&lt;/h2&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;For the second iteration I am going to add a big-bang function to the game and draw the game as a game world. The game world current consists of a collection of ufos and our tank.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;As adding the game code here for drawing the world is pretty simple I have also added a function that will programatically generate a collection of ufos. This is to save specifying the initial position of each ufo by hand. &amp;nbsp;To start with I am drawing 3 rows of how ever many ufos will currently fit.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Code&lt;/h2&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(require racket/base)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct ufo (x y) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct tank (x y) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct world (ufos tank))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; physical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 300) ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define HEIGHT 300) ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; graphical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SIZE 10) ; the size of the block making up the ufo&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define UFO-WIDTH 50)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define BLOCK ; they are rendered as red squares with black rims &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (overlay (rectangle (- SIZE 1) (- SIZE 1) &quot;solid&quot; &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rectangle SIZE SIZE &quot;outline&quot; &quot;black&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TEST-UFO (make-ufo 30 30)) &amp;nbsp; ; for testing&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TEST-UFOS (list (make-ufo 30 30)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-ufo 80 30)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-ufo 130 30))); for testing&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; initial tank position should be middle of the screen, one block up from&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the bottom&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TANK (make-tank (/ WIDTH 2) (- HEIGHT (* SIZE 2))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Creates a row of ufos on the supplied y-cordinate&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Integer Ufos -&amp;gt; Ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-ufos-for-y y-cordinate ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? ufos) (make-ufos-for-y y-cordinate&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (make-ufo 20 y-cordinate) ufos)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((&amp;gt; (+ (ufo-x (first ufos)) UFO-WIDTH) WIDTH) ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(make-ufos-for-y y-cordinate&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(make-ufo (+ (ufo-x (first ufos)) UFO-WIDTH)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;y-cordinate) ufos )))))&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; create a complete collection of rows of ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Integer Ufos -&amp;gt; Ufos&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (make-ufos rows ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((= 0 rows) ufos)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else (make-ufos (- rows 1)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (append ufos (make-ufos-for-y ( * rows 30) empty))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a triangular shaped alien&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-ufo ufo background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (ufo-x ufo) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (ufo-x ufo) SIZE) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (ufo-x ufo) SIZE) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (ufo-x ufo) (+ (ufo-y ufo) SIZE) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a tank shaped tank&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-tank tank background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (tank-x tank) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image/align BLOCK (- (tank-x tank) SIZE) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (place-image/align BLOCK (+ (tank-x tank) SIZE) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (tank-x tank) (+ (tank-y tank) SIZE)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (tank-x tank) SIZE) (+ (tank-y tank) SIZE )&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (tank-x tank) SIZE) (+ (tank-y tank) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (tank-x tank) (- (tank-y tank) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background))))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw the collection of ufos on to the background.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a simple recursive function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Ufos Scene -&amp;gt; Scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-ufos ufos background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cond ((empty? ufos) &amp;nbsp;background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else (draw-ufo (first ufos) (draw-ufos (rest ufos)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draws the world as a scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; World -&amp;gt; Scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (render-scene world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-ufos (world-ufos world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-tank (world-tank world) (empty-scene WIDTH HEIGHT))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is the big bang function that drives the game.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (space-invaders-main rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (big-bang (make-world (make-ufos 3 empty) TANK)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (to-draw &amp;nbsp; &amp;nbsp;render-scene)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(space-invaders-main 0.2)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; tests&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; simple example - a single block in an empty landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-ufo TEST-UFO (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (ufo-x TEST-UFO) (ufo-y TEST-UFO) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (ufo-x TEST-UFO) SIZE) (ufo-y TEST-UFO)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (ufo-x TEST-UFO) SIZE) (ufo-y TEST-UFO)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (ufo-x TEST-UFO) (+ (ufo-y TEST-UFO) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene WIDTH HEIGHT))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; test drawing three ufo&#39;s via the draw-ufos function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-ufos TEST-UFOS (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (draw-ufo (first TEST-UFOS)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (draw-ufo (second TEST-UFOS)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-ufo (third TEST-UFOS) (empty-scene WIDTH HEIGHT)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; test the tank drawing works&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-tank TANK (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (tank-x TANK) (tank-y TANK) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image/align BLOCK (- (tank-x TANK) SIZE) (tank-y TANK) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (place-image/align BLOCK (+ (tank-x TANK) SIZE) (tank-y TANK) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (tank-x TANK) (+ (tank-y TANK) SIZE) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (tank-x TANK) SIZE) (+ (tank-y TANK) SIZE )&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (tank-x TANK) SIZE) (+ (tank-y TANK) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (tank-x TANK) (- (tank-y TANK) SIZE)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene WIDTH HEIGHT)))))))))&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/4716579137254140624/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/08/special-exercise-space-invaders-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/4716579137254140624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/4716579137254140624'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/08/special-exercise-space-invaders-part-2.html' title='Special Exercise - Space Invaders Part 2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-7621239335764232404</id><published>2012-08-07T00:14:00.000-07:00</published><updated>2012-08-07T00:14:00.205-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><category scheme="http://www.blogger.com/atom/ns#" term="space invaders"/><title type='text'>Special Exercise - Space Invaders Part 1</title><content type='html'>&lt;h2&gt;


&lt;span style=&quot;font-family: inherit;&quot;&gt;Design a complete Space Invaders Game&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;The description of the space invader game we are given is very sparse. This is probably because the details don&#39;t matter so much as the act of actually designing the game. &amp;nbsp;For lack of further specification I&#39;m going to try for&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;something similar to the original space invader game.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;We will have a &amp;nbsp;few rows of aliens that will be moving slowly closer (and left and right). At the moment I am not planning on letting them shoot, but that may change. On the ground there will be a tank that can move left and right and shoot at and destroy the aliens. (With possibly some blocks to hide behind if the aliens end up being able to shoot. &amp;nbsp;If any of the aliens reach earth, the player loses. If he manages to destroy all the ufo&#39;s the player wins.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;For this&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&amp;nbsp;first iteration I&#39;m going to create the functions to:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&amp;nbsp;draw the ufo,&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&amp;nbsp;draw a collection of ufos&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&amp;nbsp;draw our tank&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;h3&gt;


&lt;span style=&quot;font-family: inherit;&quot;&gt;Code&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(require racket/base)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct ufo (x y) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct tank (x y) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TEST-UFO (make-ufo 30 30)) &amp;nbsp; ; for testing&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TEST-UFOS (list (make-ufo 30 30)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-ufo 80 30)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-ufo 130 30))); for testing&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TANK (make-tank 100 100))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; physical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 300) ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define HEIGHT 300) ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; graphical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SIZE 10) ; the size of the block making up the ufo&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define BLOCK ; they are rendered as red squares with black rims &amp;nbsp;- stolen from tetris&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (overlay (rectangle (- SIZE 1) (- SIZE 1) &quot;solid&quot; &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rectangle SIZE SIZE &quot;outline&quot; &quot;black&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a triangular shaped alien&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-ufo ufo background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (ufo-x ufo) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (ufo-x ufo) SIZE) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (ufo-x ufo) SIZE) (ufo-y ufo) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (ufo-x ufo) (+ (ufo-y ufo) SIZE) &quot;left&quot; &quot;bottom&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a tank shaped tank&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-tank tank background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (tank-x tank) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image/align BLOCK (- (tank-x tank) SIZE) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (place-image/align BLOCK (+ (tank-x tank) SIZE) (tank-y tank) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (tank-x tank) (+ (tank-y tank) SIZE) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (tank-x tank) SIZE) (+ (tank-y tank) SIZE )&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (tank-x tank) SIZE) (+ (tank-y tank) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (tank-x tank) (- (tank-y tank) SIZE)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background))))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-ufos ufos background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cond ((empty? ufos) &amp;nbsp;background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else (draw-ufo (first ufos)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-ufos (rest ufos) background)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; tests&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; simple example - a single block in an empty landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-ufo TEST-UFO (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (ufo-x TEST-UFO) (ufo-y TEST-UFO) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (ufo-x TEST-UFO) SIZE) (ufo-y TEST-UFO)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (ufo-x TEST-UFO) SIZE) (ufo-y TEST-UFO)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (ufo-x TEST-UFO) (+ (ufo-y TEST-UFO) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene WIDTH HEIGHT))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; test drawing three ufo&#39;s via the draw-ufos function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-ufos TEST-UFOS (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (draw-ufo (first TEST-UFOS)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (draw-ufo (second TEST-UFOS)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-ufo (third TEST-UFOS) (empty-scene WIDTH HEIGHT)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; test the tank drawing works&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-tank TANK (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image/align BLOCK (tank-x TANK) (tank-y TANK) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image/align BLOCK (- (tank-x TANK) SIZE) (tank-y TANK) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (place-image/align BLOCK (+ (tank-x TANK) SIZE) (tank-y TANK) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (tank-x TANK) (+ (tank-y TANK) SIZE) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (- (tank-x TANK) SIZE) (+ (tank-y TANK) SIZE )&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK (+ (tank-x TANK) SIZE) (+ (tank-y TANK) SIZE)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK (tank-x TANK) (- (tank-y TANK) SIZE)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;left&quot; &quot;bottom&quot;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene WIDTH HEIGHT)))))))))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/7621239335764232404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/08/special-exercise-space-invaders-part-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/7621239335764232404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/7621239335764232404'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/08/special-exercise-space-invaders-part-1.html' title='Special Exercise - Space Invaders Part 1'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-6791402886701084042</id><published>2012-07-31T18:29:00.000-07:00</published><updated>2012-07-31T18:29:00.445-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><category scheme="http://www.blogger.com/atom/ns#" term="tetris"/><title type='text'>Exercise 178: Equip the program from exercise 177 with a stop-when clause.</title><content type='html'>&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2&gt;



&lt;span style=&quot;font-family: inherit; font-size: small;&quot;&gt;&lt;span style=&quot;text-align: left;&quot;&gt;Exercise&lt;/span&gt;&lt;span style=&quot;text-align: left;&quot;&gt;&amp;nbsp;178: Equip the program from&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part2.html#(counter._(exercise._ex~3atetris2))&quot; pltdoc=&quot;x&quot; style=&quot;text-align: left;&quot;&gt;exercise&amp;nbsp;177&lt;/a&gt;&lt;span style=&quot;text-align: left;&quot;&gt;&amp;nbsp;with a&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; text-align: left;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/teachpack/2htdpuniverse.html#(form._((lib._2htdp%2Funiverse..rkt)._stop-when))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;stop-when&lt;/a&gt;&lt;/span&gt;&lt;span style=&quot;text-align: left;&quot;&gt;&amp;nbsp;clause. The game ends when one of the columns contains&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; text-align: left;&quot;&gt;HEIGHT&lt;/span&gt;&lt;span style=&quot;text-align: left;&quot;&gt;&amp;nbsp;blocks.&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;i&gt;Download code for this exercise &lt;a href=&quot;https://gist.github.com/3109697&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/i&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;I implemented the stop-when handler slightly differently than suggested in the book. The way it was described did not make sense to me. The suggestion was to 1) create a function that will create a column of blocks/landscape to determine the end of the game. 2) Create a function to function to get the height &amp;nbsp;of a particular column, and 3) stop when the height of a column exceeds HEIGHT.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;It seems that if you do steps 2 and 3, then you don&#39;t need step 1) at all. All you need to do is to check each column for the height. This is how I have chosen to implement it.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The score function was reasonably straight forward to create - we just needed to count all the blocks in the landscape and then convert that number to a string.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;In the end we have a reasonably functional game. I did contemplate trying to extend this to do shapes, but the next exercise (creating a space invaders game) looked too interesting to be put off!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;h3&gt;






&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;Code&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(require racket/base)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct block (x y) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct tetris (block landscape))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; physical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 10) ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; graphical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SIZE 10) ; blocks are square&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define BLOCK ; they are rendered as red squares with black rims&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (overlay (rectangle (- SIZE 1) (- SIZE 1) &quot;solid&quot; &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rectangle SIZE SIZE &quot;outline&quot; &quot;black&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; this is just an example/test Tetris scene.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TETRIS &amp;nbsp;(make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list (make-block 20 40) )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SCENE-SIZE &amp;nbsp;(* WIDTH SIZE) )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; new function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (game-over-scene tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image (text (string-append &quot;Score: &quot; (score tetris)) 15 &quot;black&quot;) 50 70&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image (text &quot;game over&quot; 20 &quot;black&quot;) 50 50&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-render tetris))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Returns the score - the number of blocks in the landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (score tetris);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(number-&amp;gt;string (length (tetris-landscape tetris))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; takes in a landscape and an x co-ordinate.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; produces a list (landscape) of blocks with that co-ordinate.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; standard recursion - if the landscape is empty, we&#39;re at the end so return it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; if the block at the top has the right x co-ordinate, create a list out of it&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; + the recursion&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; if the block at the top doesn&#39;t match, just recurse further&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; landscape, number -&amp;gt; landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (get-column landscape x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((empty? landscape) landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((= x (block-x (first landscape)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cons (first landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(get-column (rest landscape) x)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (get-column (rest landscape) x))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; test the happy case - should get all the blocks in the 10 x-cordinate&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (get-column (list (make-block 10 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-block 10 20)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-block 20 20)) 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-block 10 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-block 10 20)))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; returns true any of the columns in the landscape exceed the maximum height&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; landscape: the game landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; height: the max height&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; column: the current column as we recurse down. Start at the far right column&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (height-exceeded landscape height column)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ; if we reach last column without finding an exceeded column then return false&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ; if the current column exceeds the height, return true&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ; else recurse....&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((empty? landscape) false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((= 0 column) false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ; get the column for the current co-ordinates&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ((= height (length (get-column landscape (* column SIZE)))) true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (height-exceeded landscape height (- column 1)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; test the happy case - should get all the blocks in the 10 x-cordinate&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (height-exceeded empty 10 1) false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (height-exceeded &amp;nbsp;(list (make-block 10 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-block 10 20)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-block 10 20)) 3 1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (end-game? tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (height-exceeded (tetris-landscape tetris) 2 WIDTH))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; start the block in the middle&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define INITIAL-BLOCK (make-block (/ SCENE-SIZE 2) 0))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Block -&amp;gt; Block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Creates a new block at random, anywhere but the current column&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (block-create b)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (block-check-create b (make-block (* (random WIDTH) SIZE) 0)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Block Bloc -&amp;gt; Block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; generative recursion&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; checks that the candidate and b are in different colums on the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; if they are at the same point, create a new candiate by recursing into&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; block-create, otherwise return the new candidate (which will then be returned&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; via block-create)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (block-check-create b candidate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (if (equal? (block-x b) (block-x candidate))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (block-create b) candidate))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This tetris-render function is a wrapper around the main function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This just splits the tetris into the initial block/landscape tuple and&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; calls the main tetris-render-helper function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-render tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (tetris-render-helper (tetris-block tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a tetris scene. This is the function that does the guts of the work.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; If our landscape is empty, just draw the block onto an empty scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; otherwise recurse, and draw draw the current block on the result of drawing the rest of the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; blocks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-render-helper block landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-block block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond ((empty? landscape ) &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(empty-scene SCENE-SIZE SCENE-SIZE))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (tetris-render-helper &amp;nbsp;(first landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rest landscape))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draw a block on our background. I&#39;m using place-image/align instead of&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; place-image as we need to define where our block is appearing. By default&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; place-image will center the image at the x/y co-ordinates. This would leave&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a block drawn at 0,0 to be drawn half off the left of the screen and half&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; off the top of the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-block block background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(place-image/align BLOCK&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (block-x block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (block-y block) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Handle keyboard events.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; The move-block function is called by both handle-key-events and progress world. ; To keep &amp;nbsp;it simple it only takes in a block . This means we&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; need &amp;nbsp;to construct the new tetris around the cond clauses - if the user hasn&#39;t&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; pressed left or right, we just pass the unaltered block straight back in&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Also we are checking to see if the moved block (left/right) would collide with&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; an existing block. Without this check, you can move inside a column of blocks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This probably shouldn&#39;t be handled here - it would be better extracted out and&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; handled in a dedicated function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (handle-key-events tetris ke)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-tetris&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;left&quot; ke) &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(cond ((landscape-collision? tetris &quot;left&quot;) (tetris-block tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else &amp;nbsp;(move-block (tetris-block tetris) &quot;left&quot;)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;right&quot; ke)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(cond ((landscape-collision? tetris &quot;right&quot;) (tetris-block tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else &amp;nbsp;(move-block (tetris-block tetris) &quot;right&quot;))) ] )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (tetris-landscape tetris)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; On each clock tick, move the world further in time.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (progress-world tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (check-collisions&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(make-tetris (move-block (tetris-block tetris) &quot;down&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; moves the block and returns a new block.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; we do bounds checking for each direction - make sure we can&#39;t go off the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; right or the left of &amp;nbsp;the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-block block direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(cond ((string=? direction &quot;left&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cond ((&amp;gt; SIZE (block-x block)) block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else (make-block &amp;nbsp;(- (block-x block) SIZE) (block-y block)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;((string=? direction &quot;right&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond ((= (- SCENE-SIZE SIZE) (block-x block)) block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (make-block (+ (block-x block) SIZE ) (block-y block)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;((string=? direction &quot;down&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-block (block-x block) (+ SIZE ( block-y block))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; checks for collisions between the block and the landscape. if this is the case,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the block becomes part of the landscape and we generate a new block.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; In order for the blocks to stack, we need to forecast a collision - ie,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; look at where the block will be if it moved down one more square)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; I&#39;m not overly happy with this - I need a special case to handle if the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; landscape is empty (which it will be at the start of the game). I&#39;m not sure&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; if this means I&#39;m structuring this wrong, or if this is a genuine need...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (check-collisions tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ; collision - either with another block, or with the floor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ; make block part of landscape and create new block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ((or (landscape-collision? tetris &quot;down&quot;) (floor-collision? tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(make-tetris (block-create (tetris-block tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(append (tetris-landscape tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (tetris-block tetris) empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ; no collision - just return&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (else tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; detects block collision with the landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (landscape-collision? tetris direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (and (not (empty? (tetris-landscape tetris)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(member? (move-block (tetris-block tetris) direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; checks for a collision with the floor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; we don&#39;t check if we&#39;ve exceeded the height, we check we haven&#39;t exceeded&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the height less the width of the block. otherwise our block won&#39;t trigger&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the collision until they are below the floor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (floor-collision? tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(&amp;gt; (block-y (tetris-block tetris)) (- SCENE-SIZE SIZE)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is the big bang function that drives the game.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-main rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (big-bang (make-tetris INITIAL-BLOCK empty)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (to-draw &amp;nbsp; &amp;nbsp;tetris-render)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-key &amp;nbsp; &amp;nbsp; handle-key-events)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-tick &amp;nbsp; &amp;nbsp;progress-world rate) &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (stop-when &amp;nbsp;end-game? game-over-scene)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(tetris-main 0.2)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; ## TESTS ##&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; simple example - a single block in an empty landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (tetris-render (make-tetris (make-block 20 40) empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK 20 40 &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(empty-scene SCENE-SIZE SCENE-SIZE)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a slightly more complex test - drawing two blocks&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (tetris-render (make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-block 20 40) )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK 10 60 &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK 20 40 &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(empty-scene SCENE-SIZE SCENE-SIZE))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; landscape collision - no collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (landscape-collision? &amp;nbsp;(make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list (make-block 20 40))) &quot;down&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; floor collision - no collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (floor-collision? &amp;nbsp;(make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; floor collision - &amp;nbsp;collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (floor-collision? &amp;nbsp;(make-tetris (make-block 10 &amp;nbsp;SCENE-SIZE )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; true)&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/6791402886701084042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/07/exercise-178-equip-program-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/6791402886701084042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/6791402886701084042'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/07/exercise-178-equip-program-from.html' title='Exercise 178: Equip the program from exercise 177 with a stop-when clause.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-8031310366527788834</id><published>2012-07-24T23:20:00.000-07:00</published><updated>2012-07-24T23:20:00.185-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="177"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><category scheme="http://www.blogger.com/atom/ns#" term="tetris"/><title type='text'>Exercise 177: Modify the program from exercise 176 so that a player can control the left or right movement of the dropping block.</title><content type='html'>&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2&gt;


&lt;span style=&quot;font-family: serif; text-align: left;&quot;&gt;Modify the program from&amp;nbsp;&lt;/span&gt;exercise&amp;nbsp;176&lt;span style=&quot;font-family: serif; text-align: left;&quot;&gt;&amp;nbsp;so that a player can control the left or right movement of the dropping block.&amp;nbsp;&lt;/span&gt;&lt;/h2&gt;
&lt;i&gt;&lt;span style=&quot;font-family: serif; text-align: left;&quot;&gt;Each time the player presses the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;font-family: monospace; text-align: left;&quot;&gt;&quot;left&quot;&lt;/span&gt;&lt;span style=&quot;font-family: serif; text-align: left;&quot;&gt;&amp;nbsp;arrow key, the dropping block should shift one column to the left unless it is in column&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;font-family: monospace; text-align: left;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: serif; text-align: left;&quot;&gt;&amp;nbsp;or there is already a stack of resting blocks to its left. Similarly, each time the player presses the&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktVal&quot; style=&quot;font-family: monospace; text-align: left;&quot;&gt;&quot;right&quot;&lt;/span&gt;&lt;span style=&quot;font-family: serif; text-align: left;&quot;&gt;&amp;nbsp;arrow key, the dropping block should move one column to the right if possible.&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
Download code for this exercise &lt;a href=&quot;https://gist.github.com/3109697&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3&gt;

&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;Code&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(require racket/base)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct block (x y) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct tetris (block landscape))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; physical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 10) ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; graphical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SIZE 10) ; blocks are square&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define BLOCK ; they are rendered as red squares with black rims&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (overlay (rectangle (- SIZE 1) (- SIZE 1) &quot;solid&quot; &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rectangle SIZE SIZE &quot;outline&quot; &quot;black&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; this is just an example/test Tetris scene.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TETRIS &amp;nbsp;(make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list (make-block 20 40) )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SCENE-SIZE &amp;nbsp;(* WIDTH SIZE) )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; start the block in the middle&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define INITIAL-BLOCK (make-block (/ SCENE-SIZE 2) 0))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Block -&amp;gt; Block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Creates a new block at random, anywhere but the current column&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (block-create b)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (block-check-create b (make-block (* (random WIDTH) SIZE) 0)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Block Bloc -&amp;gt; Block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; generative recursion&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; checks that the candidate and b are in different colums on the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; if they are at the same point, create a new candiate by recursing into&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; block-create, otherwise return the new candidate (which will then be returned&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; via block-create)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (block-check-create b candidate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (if (equal? (block-x b) (block-x candidate))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (block-create b) candidate))&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This tetris-render function is a wrapper around the main function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This just splits the tetris into the initial block/landscape tuple and&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; calls the main tetris-render-helper function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-render tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (tetris-render-helper (tetris-block tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a tetris scene. This is the function that does the guts of the work.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; If our landscape is empty, just draw the block onto an empty scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; otherwise recurse, and draw draw the current block on the result of drawing the rest of the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; blocks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-render-helper block landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-block block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond ((empty? landscape ) &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(empty-scene SCENE-SIZE SCENE-SIZE))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (tetris-render-helper &amp;nbsp;(first landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rest landscape))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draw a block on our background. I&#39;m using place-image/align instead of&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; place-image&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;as we need to define where our block is appearing. By default&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; place-image will center&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;the image at the x/y co-ordinates. This would leave&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a block drawn at 0,0 to be drawn&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;half off the left of the screen and half&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; off the top of the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-block block background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(place-image/align BLOCK&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (block-x block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (block-y block) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Handle keyboard events.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; The move-block function is called by both handle-key-events and progress world. ; ; To keep &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;it simple it&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;only takes in a block (rather than a tetris). This means we&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; need&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;to construct the new tetris&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;around the cond clauses - if the user hasn&#39;t&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; pressed left or right, we just pass the unaltered&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;block straight back in&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Also&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;we are checking to see if&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;the moved block (left/right)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;would collide with&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; an existing block. Without &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;this check, you can move &#39;inside&#39; a column of blocks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This probably shouldn&#39;t be handled here - it would be better extracted out and&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; handled in a dedicated function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (handle-key-events tetris ke)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-tetris&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;left&quot; ke) &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(cond ((landscape-collision? tetris &quot;left&quot;) (tetris-block tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else &amp;nbsp;(move-block (tetris-block tetris) &quot;left&quot;)))]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;right&quot; ke)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(cond ((landscape-collision? tetris &quot;right&quot;) (tetris-block tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else &amp;nbsp;(move-block (tetris-block tetris) &quot;right&quot;))) ] )&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (tetris-landscape tetris)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; On each clock tick, move the world further in time.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (progress-world tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (check-collisions&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(make-tetris (move-block (tetris-block tetris) &quot;down&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; moves the block and returns a new block.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; we do bounds checking for each direction - make sure we can&#39;t go off the&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; right or the left of &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-block block direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(cond ((string=? direction &quot;left&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(cond ((&amp;gt; SIZE (block-x block)) block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else (make-block &amp;nbsp;(- (block-x block) SIZE) (block-y block)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;((string=? direction &quot;right&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond ((= (- SCENE-SIZE SIZE) (block-x block)) block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (make-block (+ (block-x block) SIZE ) (block-y block)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;((string=? direction &quot;down&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-block (block-x block) (+ SIZE ( block-y block))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; checks for collisions between the block and the landscape. if this is the case,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the block&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;becomes part of the landscape and we generate a new block.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; In order for the blocks to stack, we need to forecast a collision - ie,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; look at where the block&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;will be if it moved down one more square)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; I&#39;m not overly happy with this - I need a special case to handle if the&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; landscape is empty (which&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;it will be at the start of the game). I&#39;m not sure&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; if this means I&#39;m structuring this wrong, or if&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;this is a genuine need...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (check-collisions tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ; collision - either with another block, or with the floor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ; make block part of landscape and create new block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ((or (landscape-collision? tetris &quot;down&quot;) (floor-collision? tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(make-tetris (block-create (tetris-block tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(append (tetris-landscape tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (tetris-block tetris) empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ; no collision - just return&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (else tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; detects block collision with the landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (landscape-collision? tetris direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (and (not (empty? (tetris-landscape tetris)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(member? (move-block (tetris-block tetris) direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; checks for a collision with the floor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; we don&#39;t check if we&#39;ve exceeded the height, we check we haven&#39;t exceeded&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the height&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;less the width of the block. otherwise our block won&#39;t trigger&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the collision until they&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;are below the floor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (floor-collision? tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(&amp;gt; (block-y (tetris-block tetris)) (- SCENE-SIZE SIZE)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is the big bang function that drives the game.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-main rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (big-bang (make-tetris INITIAL-BLOCK empty)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (to-draw &amp;nbsp; &amp;nbsp;tetris-render)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-key &amp;nbsp; &amp;nbsp; handle-key-events)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-tick &amp;nbsp; &amp;nbsp;progress-world rate) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(tetris-main 0.2)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; ## TESTS ##&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; simple example - a single block in an empty landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (tetris-render (make-tetris (make-block 20 40) empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK 20 40 &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(empty-scene SCENE-SIZE SCENE-SIZE)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a slightly more complex test - drawing two blocks&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (tetris-render (make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-block 20 40) )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK 10 60 &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK 20 40 &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene SCENE-SIZE SCENE-SIZE))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; landscape collision - no collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (landscape-collision? &amp;nbsp;(make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-block 20 40))) &quot;down&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; floor collision - no collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (floor-collision? &amp;nbsp;(make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; floor collision - &amp;nbsp;collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (floor-collision? &amp;nbsp;(make-tetris (make-block 10 &amp;nbsp;SCENE-SIZE )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; true)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/8031310366527788834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/07/exercise-177-modify-program-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/8031310366527788834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/8031310366527788834'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/07/exercise-177-modify-program-from.html' title='Exercise 177: Modify the program from exercise 176 so that a player can control the left or right movement of the dropping block.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-7416114616904814060</id><published>2012-07-17T18:26:00.000-07:00</published><updated>2012-07-17T18:26:00.379-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="176"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><category scheme="http://www.blogger.com/atom/ns#" term="tetris"/><title type='text'>Exercise 176: Design the interactive program tetris-main...</title><content type='html'>&lt;br /&gt;
&lt;h2&gt;

Design the interactive program tetris-main, which displays blocks dropping in a straight&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;line from the top of the canvas and landing on the floor or on blocks that are already resting.&amp;nbsp;&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;i&gt;Download the code for this exercise &lt;a href=&quot;https://gist.github.com/3044599&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/i&gt;&lt;/div&gt;
&lt;br /&gt;
This was a fairly straight forward extension to the previous exercise. The main &#39;gotcha&#39; I came across involved the &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;member?&lt;/span&gt;&amp;nbsp;function which was used to determine if a block had collided with a landscape. The problem was that my tests were returning false (that there was no collision), when I knew that there should be a collision. &amp;nbsp;This led to two discoveries - firstly, in order for &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;member?&lt;/span&gt;&amp;nbsp;to be able to look into an arbitrary struct, the struct needs to be declared as #:transparent. Secondly, in order for a struct to be able to be declared as transparent, we need to specifically require &amp;nbsp;&#39;racket/base&#39;. &lt;br /&gt;
&lt;br /&gt;
One aspect changed since my solution for exercise 175 is the use of&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt; place-image/align&lt;/span&gt; instead of &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;place-image&lt;/span&gt;. This is to ensure that the blocks are correctly placed within the boundaries of the screen&lt;br /&gt;
using the native co-ordinate points stored for them. Without the use of this method I would have need to manually shift each block by 5 pixels in order to make them appear correctly.&lt;br /&gt;
&lt;h3&gt;

Code&lt;/h3&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(require racket/base)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; The struct block contains the blocks that make up landscape and the&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; current falling block. W&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;e need to define this struct as transparent or&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the member? function won&#39;t be able to look inside it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct block (x y) #:transparent)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; A tetris consists of a block, and a landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct tetris (block landscape))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; physical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 10) ; the maximal number of blocks horizontally/vertically&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SIZE 10) &amp;nbsp;; blocks are square&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define BLOCK &amp;nbsp; &amp;nbsp; ; blocks are rendered as red squares with black rims&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (overlay (rectangle (- SIZE 1) (- SIZE 1) &quot;solid&quot; &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rectangle SIZE SIZE &quot;outline&quot; &quot;black&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SCENE-SIZE &amp;nbsp;(* WIDTH SIZE) )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; an initial block, starting the block in the middle of the screen&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define INITIAL-BLOCK (make-block (/ SCENE-SIZE 2) 0))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Block -&amp;gt; Block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Creates a new block at random, anywhere but the current column&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; These are essentially the same as the generative recursion functions used in&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the worm game exercises&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (block-create b)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (block-check-create b (make-block (* (random WIDTH) SIZE) 0)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Block Bloc -&amp;gt; Block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Checks that the candidate and b are in different colums on the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; If they are at the same point, create a new candiate by recursing into&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; block-create, otherwise return the new candidate (which will then be returned&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; via block-create)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (block-check-create b candidate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (if (equal? (block-x b) (block-x candidate))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (block-create b) candidate))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This tetris-render function is a wrapper around the main function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This just splits the tetris into the initial block/landscape tuple and&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; calls the main tetris-render-helper function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-render tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (tetris-render-helper (tetris-block tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draw a tetris scene. This is the function that does the guts of the work.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; If our landscape is empty, just draw the block onto an empty scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; otherwise recurse, and draw draw the current block on the result of drawing the rest of the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; blocks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-render-helper block landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-block block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond ((empty? landscape ) &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(empty-scene SCENE-SIZE SCENE-SIZE))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (tetris-render-helper &amp;nbsp;(first landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rest landscape))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draw a block on our background. I&#39;m using place-image/align instead of&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; place-image&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;as we need to define where our block is appearing. By default&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; place-image will center&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;the image at the x/y co-ordinates. This would leave&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a block drawn at 0,0 to be drawn&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;half off the left of the screen and half off the top of the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-block block background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(place-image/align BLOCK&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (block-x block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (block-y block) &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; On each clock tick, move the world further in time. This currently just&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; moves our block&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;down one square&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is pretty clunky, but I&#39;m okay with it for now as it is only moving&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the block&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;down one square - as soon as the tetris needs to move in 3&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; directions this will be&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;separated out into a separate function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (progress-world tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (check-collisions&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(make-tetris (move-block (tetris-block tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; moves the block and returns a new block. Currently this only moves in one direction - down&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-block block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-block (block-x block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (+ SIZE ( block-y block))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; checks for collisions between the block and the landscape. if this is the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; case, the block&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;becomes part of the landscape and we generate a new block.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; In order for the blocks to stack, we need to forecast a collision - ie,&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; look at where the block&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;will be if it moved down one more square)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (check-collisions tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ; collision - either with another block, or with the floor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ; make block part of landscape and create new block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ((or (landscape-collision? tetris) (floor-collision? tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(make-tetris (block-create (tetris-block tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(append (tetris-landscape tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cons (tetris-block tetris) empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; ; no collision - just return&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (else tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; detects block collision with the landscape&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; I&#39;m not overly happy with this - I need a special check to handle if&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the landscape is empty (which&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;it will be at the start of the game). &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; I&#39;m not sure if this means I&#39;m structuring this wrong, or if&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;this is a&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; genuine need...&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (landscape-collision? tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (and (not (empty? (tetris-landscape tetris)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(member? (move-block (tetris-block tetris))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; checks for a collision with the floor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; we don&#39;t check if we&#39;ve exceeded the height, we check we haven&#39;t&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; exceeded the height&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;less the width of the block. otherwise our block&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; won&#39;t trigger the collision until they&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;are below the floor&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (floor-collision? tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(&amp;gt; (block-y (tetris-block tetris)) (- SCENE-SIZE SIZE))&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is the big bang function that drives the game.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-main rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (big-bang (make-tetris INITIAL-BLOCK empty)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (to-draw &amp;nbsp; &amp;nbsp; tetris-render)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-tick &amp;nbsp; &amp;nbsp; progress-world rate))&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(tetris-main 0.04)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; ## TESTS ##&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; simple example - a single block in an empty landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (tetris-render (make-tetris (make-block 20 40) empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK 20 40 &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(empty-scene SCENE-SIZE SCENE-SIZE)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a slightly more complex test - drawing two blocks&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (tetris-render (make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-block 20 40) )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image/align BLOCK 10 60 &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image/align BLOCK 20 40 &quot;left&quot; &quot;bottom&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(empty-scene SCENE-SIZE SCENE-SIZE))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; landscape collision - no collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (landscape-collision? &amp;nbsp;(make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-block 20 40))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; landscape collision - a collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (landscape-collision? &amp;nbsp;(make-tetris&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-block 20 30)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-block 20 40)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-block 30 40))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; floor collision - no collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (floor-collision? &amp;nbsp;(make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; floor collision - &amp;nbsp;collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (floor-collision? &amp;nbsp;(make-tetris (make-block 10 &amp;nbsp;SCENE-SIZE )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list empty)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; true)&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/7416114616904814060/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/07/exercise-176-design-interactive-program.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/7416114616904814060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/7416114616904814060'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/07/exercise-176-design-interactive-program.html' title='Exercise 176: Design the interactive program tetris-main...'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-5063366905362642095</id><published>2012-07-10T18:24:00.000-07:00</published><updated>2012-07-10T18:24:00.276-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="175"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><category scheme="http://www.blogger.com/atom/ns#" term="tetris"/><title type='text'>Exercise 175: Design the program tetris-render...</title><content type='html'>&lt;br /&gt;
&lt;h2&gt;

Design the program tetris-render, which turns a given instance of Tetris into an Image.&lt;/h2&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
You can download the code for this question from &lt;a href=&quot;https://gist.github.com/3036890&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
This is a straight forward question. We have a data structure containing a collection of tetris blocks, which we need to turn into a world (game) scene.&lt;br /&gt;
&lt;br /&gt;
We can do this by &amp;nbsp;recursing through our data structure until we have a complete scene.&lt;br /&gt;
&lt;br /&gt;
I chose to split the &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;tetris-render&lt;/span&gt; function into two functions - a main function and a helper function. This because the main &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;render-tetris &lt;/span&gt;function only takes a single&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;argument (a Tetris) and if I wanted to recurse into this I would need to continually be created a a new Tetris from the component parts I had (the head and the tail)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;font-family: serif; text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;A&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=1643364309931537120&quot; name=&quot;(tech._tetri)&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Tetris&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;is&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-tetris&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part2.html#(tech._block)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Block&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part2.html#(tech._landscape)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Landscape&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;A&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=1643364309931537120&quot; name=&quot;(tech._landscape)&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Landscape&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;is one of:&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;–&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(def._((lib._lang%2Fhtdp-beginner..rkt)._empty))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;empty&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;–&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(def._(lib._htdp-beginner..rkt._lang)._((lib._lang%2Fhtdp-beginner..rkt)._cons))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;cons&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part2.html#(tech._block)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Block&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part2.html#(tech._landscape)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;Landscape&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.blogger.com/blogger.g?blogID=1643364309931537120&quot; name=&quot;(tech._block)&quot;&gt;&lt;/a&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Block&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;is&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-block&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part2.html#(tech._n)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;N&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a class=&quot;techoutside&quot; href=&quot;http://www.ccs.neu.edu/home/matthias/HtDP2e/htdp2e-part2.html#(tech._n)&quot; pltdoc=&quot;x&quot; style=&quot;color: #b0b0b0;&quot;&gt;&lt;span class=&quot;techinside&quot; style=&quot;color: black;&quot;&gt;N&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;interpretation: given&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-tetris&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;make-block&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(def._(lib._htdp-beginner..rkt._lang)._((lib._lang%2Fhtdp-beginner..rkt)._list))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;b1&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;b2&lt;/span&gt;&lt;span class=&quot;stt&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(form._((lib._lang%2Fhtdp-beginner..rkt)._......))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;...&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;/span&gt;(&lt;span style=&quot;font-style: italic;&quot;&gt;x,y&lt;/span&gt;)&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;is the logical position of the dropping block, while&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;b1&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;b2&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;, etc are the positions of the resting blocks&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;a logical position&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;/span&gt;(&lt;span style=&quot;font-style: italic;&quot;&gt;x,y&lt;/span&gt;)&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;determines how many&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;SIZE&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;s the block is&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;from the left&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;—&lt;wbr&gt;&lt;/wbr&gt;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;—&lt;wbr&gt;&lt;/wbr&gt;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;and from the top&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;—&lt;wbr&gt;&lt;/wbr&gt;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&lt;h3&gt;

Code&lt;/h3&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct block (x y))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct tetris (block landscape))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; physical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 10) ; the maximal number of blocks horizontally&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; graphical constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SIZE 10) ; blocks are square&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define BLOCK ; they are rendered as red squares with black rims&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (overlay (rectangle (- SIZE 1) (- SIZE 1) &quot;solid&quot; &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rectangle SIZE SIZE &quot;outline&quot; &quot;black&quot;)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; this is just an example/test Tetris scene.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define TETRIS &amp;nbsp;(make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(list (make-block 20 40) )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SCENE-SIZE (* WIDTH SIZE))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This tetris-render function is a wrapper around the main function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This just splits the tetris into the initial block/landscape tuple and&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; calls the main tetris-render-helper function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-render tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (tetris-render-helper (tetris-block tetris)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (tetris-landscape tetris)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw a tetris scene. This is the function that does the guts of the work.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; If our landscape is empty, just draw the block onto an empty scene&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; otherwise recurse, and draw draw the current block on the result of drawing&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the rest of the&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;blocks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (tetris-render-helper block landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-block block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond ((empty? landscape ) &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(empty-scene SCENE-SIZE SCENE-SIZE))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else (tetris-render-helper &amp;nbsp;(first landscape)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(rest landscape))))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw our block on supplied background.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-block block background)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(place-image BLOCK&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (block-x block) (block-y block)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; background))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(tetris-render &amp;nbsp;TETRIS)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; ## TESTS ##&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; simple example - a single block in an empty landscape&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (tetris-render (make-tetris (make-block 20 40) empty))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image BLOCK 20 40 (empty-scene SCENE-SIZE SCENE-SIZE)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a slightly more complex test - drawing two blocks&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (tetris-render (make-tetris (make-block 10 60)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-block 20 40) )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image BLOCK 10 60 (place-image BLOCK 20 40&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene SCENE-SIZE SCENE-SIZE))))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/5063366905362642095/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/07/exercise-175-design-program-tetris.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/5063366905362642095'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/5063366905362642095'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/07/exercise-175-design-program-tetris.html' title='Exercise 175: Design the program tetris-render...'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-7784864186810447360</id><published>2012-07-03T18:22:00.000-07:00</published><updated>2012-07-03T18:22:00.202-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="174"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="htpd 150 scheme"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="worm"/><title type='text'>Exercise 174: Equip your program from exercise 173 with food.</title><content type='html'>&lt;br /&gt;
&lt;h2&gt;



Exercise 174: Equip your program from exercise 173 with food&amp;nbsp;&lt;/h2&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
At any point in time, the box should contain one piece of food. To keep things simple, a piece of food is of the same size as worm segment. When the worm’s head is located at the same position as the food, the worm eats the food, meaning the worm’s tail is extended by one segment. As the piece of food is eaten, another one shows up at a different location.&lt;br /&gt;
Your program should place the food randomly within the box. To do so properly, you need a design technique that you haven’t seen before—so-called generative recursion—so we provide function definitions:&lt;br /&gt;
&lt;br /&gt;
&lt;table cellspacing=&quot;0&quot; class=&quot;RktBlk&quot; style=&quot;font-family: serif; text-align: left; white-space: inherit;&quot;&gt;&lt;tbody&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;Posn -&amp;gt; Posn&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;???&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(form._((lib._lang%2Fhtdp-beginner..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;food-create&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;food-check-create&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(def._(lib._htdp-beginner..rkt._lang)._((lib._lang%2Fhtdp-beginner..rkt)._make-posn))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;make-posn&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(def._(lib._htdp-beginner..rkt._lang)._((lib._lang%2Fhtdp-beginner..rkt)._random))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;random&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;MAX&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(def._(lib._htdp-beginner..rkt._lang)._((lib._lang%2Fhtdp-beginner..rkt)._random))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;random&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;MAX&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;Posn Posn -&amp;gt; Posn&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;generative recursion&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktCmt&quot; style=&quot;color: #c2741f; font-family: monospace; white-space: inherit;&quot;&gt;???&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(form._((lib._lang%2Fhtdp-beginner..rkt)._define))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;define&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;food-check-create&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;candidate&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;white-space: inherit;&quot;&gt;&lt;td style=&quot;padding-left: 0px; padding-right: 0px; vertical-align: baseline; white-space: inherit;&quot;&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktStxLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(form._((lib._lang%2Fhtdp-beginner..rkt)._if))&quot; pltdoc=&quot;x&quot; style=&quot;color: black; text-decoration: none;&quot;&gt;if&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;&lt;a class=&quot;RktValLink&quot; href=&quot;http://docs.racket-lang.org/htdp-langs/beginner.html#(def._(lib._htdp-beginner..rkt._lang)._((lib._lang%2Fhtdp-beginner..rkt)._equal~3f))&quot; pltdoc=&quot;x&quot; style=&quot;color: blue; text-decoration: none;&quot;&gt;equal?&lt;/a&gt;&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;candidate&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;food-create&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;hspace&quot; style=&quot;font-family: monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;RktSym&quot; style=&quot;color: #262680; font-family: monospace; white-space: inherit;&quot;&gt;candidate&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;RktPn&quot; style=&quot;color: #843c24; font-family: monospace; white-space: inherit;&quot;&gt;)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
The code for the exercise can be downloaded &lt;a href=&quot;https://gist.github.com/3008089&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/blockquote&gt;
&lt;br /&gt;
Generative recursion is defined by &lt;a href=&quot;http://en.wikipedia.org/wiki/Recursion_(computer_science)#Structural_versus_generative_recursion&quot; target=&quot;_blank&quot;&gt;wikipedia&lt;/a&gt; as&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;recursion that creates an entirely new object.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;The function &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;food-check-create&lt;/span&gt; creates a random object (via &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;food-create&lt;/span&gt;) and then checks to make sure it&#39;s not in the same position as the&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;posn passed in. &amp;nbsp;This is &amp;nbsp;to ensure that the food does not appear directly under the snakes head thus prematurely ending the game.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
The function as supplied does not ensure that the food does not appear under the snake body - however that shouldn&#39;t matter too much as this will not&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;end the game due to the collision detection only checking the worms head - it would just seem a bit funny to watch.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In my answer below, I have modified this function somewhat. This is due to the nature of the error collision I have used in checking for food&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;collisions. I am checking the co-ordinates of the food and of the snake and determining a collision has&amp;nbsp;occurred&amp;nbsp;if the x and y co-ordinates are&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;the same. This is an issue because if the co-ordinates are out by 1-20 pixels, the snake would appear to touch (or overlap) the food and pass right over it.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Therefore I have locked the food generation to appear on only x and y co-ordinates that the snake can appear on. I could have also fixed this in&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;the food-collision method, but this would have mean the snake could still only partially intersect the food. It would work, but still look funny (and this is not how snake games are meant&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;to work!)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Whilst I was writing this final stage of this question, I finally recall the the posn structure and realise I probably should have been using them all a&lt;span style=&quot;background-color: white;&quot;&gt;long (instead of the structure I called segments). This would be a minor thing to change, but I will leave them called segments as this makes the&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;code easier to read and makes it consistant with the answers I have already created.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WORM-SIZE 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WORM-MOVE (* WORM-SIZE 2))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 800) &amp;nbsp;; width of the game&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define HEIGHT 500) ; height of the game&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SEGMENT (circle WORM-SIZE &quot;solid&quot; &quot;red&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define FOOD (circle WORM-SIZE &quot;solid&quot; &quot;black&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; these structs will hold the current list of worm segments, the direction&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the worm is travelling in, and our world object&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct segment(x-pos y-pos))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct direction(x y))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; worm is a list of worm segments&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; direction is the direction the worm is travelling&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; segment is our current food segment&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct world(worm direction segment))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WORM (list (make-segment 100 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 80)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 60)) ) &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; To save repeating these directions in tests and code, we&#39;ll define them here&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define DOWN &amp;nbsp;(make-direction 0 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define UP &amp;nbsp; &amp;nbsp;(make-direction 0 -1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define RIGHT (make-direction &amp;nbsp;1 0))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define LEFT &amp;nbsp;(make-direction -1 0))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Functions&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;This first function &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;food-create&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt; is one of the supplied functions. I have changed the dimensions for the allowed positions for the food segment.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;This is because we need to make sure the food is in a position that our worm can travel over completely. (Currently this is&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;&amp;nbsp;multiples of 20). If we don&#39;t do this, the food could be off by for example 5 pixels, so we could travel&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt;over it and not trigger a collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Posn -&amp;gt; Posn&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Creates a new item of food at anywhere on the screen *except* for the&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; point defined by posn p.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(eg the current snake position)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (food-create p)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (food-check-create&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;p&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(make-segment (* (random (/ WIDTH WORM-MOVE)) WORM-MOVE)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(* (random (/ HEIGHT WORM-MOVE)) WORM-MOVE))))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Posn Posn -&amp;gt; Posn&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; checks that the candidate and p are at different points on the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; If they are at the same point, create a new candiate by recursing into&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; food-create, otherwise return the new candidate (which will then be returned&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; via food-create)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (food-check-create p candidate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (if (equal? p candidate) (food-create p) candidate))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw worm in its current location on the screen. Instead of simply drawing&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a single dot&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;on the screen, we need to recurse down our list of worm&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; segments drawing each one at a&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;time&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-worm background worm)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond [(empty? worm) background]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (place-image&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SEGMENT&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(segment-x-pos (first worm)) (segment-y-pos (first worm))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-worm background (rest worm))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is a new method for question 174.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This draws the food on to the background of our world&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Returns a new image.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-food background food)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (place-image FOOD (segment-x-pos food) (segment-y-pos food) background) )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; function to determine if we have collided with a food block&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; returns true if the worm&#39;s segment is on top of the food&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (worm-hit-food? segment food)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((and (= (segment-x-pos segment) (segment-x-pos food))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (= (segment-y-pos segment) (segment-y-pos food))) true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else false)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is a new function for question 174. It grows the worm one segment.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; To do this we just append a segment in the existing foods position&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; on to the worm. Another way to do this would be to append at the end of&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the list.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This method was simpler though (but doesn&#39;t look quite as good)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (grow-worm worm food)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(cons (make-segment (segment-x-pos food) (segment-y-pos food)) worm &amp;nbsp;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is a new function for question 174. This method will check if we are&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; in the same location as a food item, and if so, eat it. (and make the worm&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; grow longer)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; returns a world state with either nothing changed, or a longer worm and&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a new food;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (eat-food world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond ((worm-hit-food? (first (world-worm world)) (world-segment world))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-world &amp;nbsp;(grow-worm (world-worm world) (world-segment world))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(world-direction world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(food-create (first (world-worm world)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else world)))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Checks if the snake has collided with either itself, or with the walls&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Returns true in the event of a collision&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (collision-detected world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (or&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(collision-detected-wall (first (move-worm-helper world )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(collision-detected-worm (first (move-worm-helper world)) &amp;nbsp;(world-worm world ))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Returns true if the worm has collided with itself.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (collision-detected-worm segment worm)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (member? segment worm))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; helper function for collision detection. Operates directly&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; on a worm, rather than world object.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (collision-detected-wall segment)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(cond [(&amp;gt; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(segment-x-pos segment)) true] &amp;nbsp;; exceeding left edge&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;gt; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; (segment-y-pos segment)) true] &amp;nbsp;; exceeding top edge&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; WIDTH &amp;nbsp; (segment-x-pos segment)) true] &amp;nbsp;; exceeding right edge&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; HEIGHT &amp;nbsp;(segment-y-pos segment)) true] &amp;nbsp;; exceeding bottom edge&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else false]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draw our final scene with the worm departing the board&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Displays a &quot;Game Over&quot; type message. We should probably be calculating the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; width and height of the image to calculate the offsets, but it&#39;s simpler just&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; to arbitrarily put it somewhere in the bottom right of the screen&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (final-scene world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-worm&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (text&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(cond &amp;nbsp;((collision-detected-wall (first (move-worm-helper world )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&quot;worm hit border&quot; )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (else &quot;worm hit worm&quot;)) &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;20 &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (- WIDTH 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (- HEIGHT 50)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(world-worm world)))&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draws the current world.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (show world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-food&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(draw-worm (empty-scene WIDTH HEIGHT) (world-worm world))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(world-segment world)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Move the worm in the current direction. Instead of changing the position of&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a single segment, now we add a segment to start of the worm (in the&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; current direction)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;and get rid of the end of the worm&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-worm worm direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(cons (new-segment (first worm) direction) (remove-last worm))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; helper method to DRY up code when calling this from a world object&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-worm-helper world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (move-worm (world-worm world) (world-direction world)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; return a new segment moved in &#39;direction&#39; from the segment passed in&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (new-segment segment direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (make-segment &amp;nbsp;(+ (segment-x-pos segment)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (* WORM-MOVE (direction-x direction)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(+ (segment-y-pos segment)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (* WORM-MOVE (direction-y direction)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; remove the last worm segment. this is a pretty unoptimised function. just&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; reverse the list, grab the rest of it, and reverse it again to get it the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; correct order.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (remove-last worm)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(reverse (rest (reverse worm))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This has changed for question 174 - we now need to check for food&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; collisions on each&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;clock tick.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; On each clock tick, move the world further in time. This is a new function&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; that takes part of the responsibily of the old move-worm function. It just&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; moves the worm and creates a new world based on it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (progress-world world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (eat-food&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(make-world&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (move-worm &amp;nbsp;(world-worm world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (world-direction world))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (world-direction world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (world-segment world))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; handle keyboard events.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (handle-key-events ws ke)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;left&quot; ke) &amp;nbsp;(change-direction ws LEFT)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;right&quot; ke) (change-direction ws RIGHT)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;up&quot; ke) &amp;nbsp; &amp;nbsp;(change-direction ws UP )]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;down&quot; ke) &amp;nbsp;(change-direction ws DOWN)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else ws]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; create a new world with the direction the worm is travelling in changed.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (change-direction world &amp;nbsp;direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-world (world-worm world) direction &amp;nbsp;(world-segment world)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is the big bang function that drives the game.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (worm-main rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (big-bang (make-world WORM&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-direction 1 0)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-segment 300 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (to-draw &amp;nbsp; &amp;nbsp;show)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (stop-when &amp;nbsp;collision-detected final-scene)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-key &amp;nbsp; &amp;nbsp; handle-key-events)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-tick &amp;nbsp; &amp;nbsp;progress-world rate) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; start the game off!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(worm-main 0.1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;# TESTS&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Test when we move the worm up, a new segment is added to the start and removed&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; from the end.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm WORM LEFT)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment (- 100 WORM-MOVE) 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 80)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Check the remove-last function removes the last segment correctly&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (remove-last WORM)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 100 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 80)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Test that new segment returns a new segment in the correct position&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; (as per the current direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (new-segment &amp;nbsp;(make-segment 100 100) UP)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-segment 100 (- 100 WORM-MOVE)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; exceeding the bottom of the screen&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;; Test our worm draws as we expect it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-worm (empty-scene 200 200) WORM)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image SEGMENT 100 100&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image SEGMENT 100 80&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image SEGMENT 100 60 (empty-scene 200 200)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Test our worm moves in the direction we expect&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm (list (make-segment 50 50)) DOWN)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 50 70)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm (list (make-segment 50 50)) UP)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 50 30)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm (list (make-segment 50 50)) LEFT)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 30 50)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm &amp;nbsp;(list (make-segment 50 50)) RIGHT)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 70 50)))&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/7784864186810447360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/06/exercise-174-equip-your-program-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/7784864186810447360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/7784864186810447360'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/06/exercise-174-equip-your-program-from.html' title='Exercise 174: Equip your program from exercise 173 with food.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1643364309931537120.post-1535045656683361532</id><published>2012-06-27T18:56:00.000-07:00</published><updated>2012-06-26T21:09:45.187-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="173"/><category scheme="http://www.blogger.com/atom/ns#" term="how to design programs 2nd ed"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp"/><category scheme="http://www.blogger.com/atom/ns#" term="htdp2e"/><category scheme="http://www.blogger.com/atom/ns#" term="racket"/><category scheme="http://www.blogger.com/atom/ns#" term="scheme"/><title type='text'>Exercise 173: Re-design your program so that it stops if the worm has run into the walls of the world or into itself.</title><content type='html'>&lt;br /&gt;
&lt;b&gt;Re-design your program from exercise 172 so that it stops if the worm has run into the walls of the world or into itself. Display a message like the one in exercise 171 to explain whether the program stopped because the worm hit the wall or because it ran into itself.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;i&gt;Code for this exercise is&amp;nbsp;available&amp;nbsp;&lt;a href=&quot;https://gist.github.com/2822118&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/i&gt;&lt;/div&gt;
&lt;br /&gt;
Only fairly straight forward changes were required to accomodate this new iteration. Changes needed to be &amp;nbsp;made to the &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;collision-detection&lt;/span&gt; function and the&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt; final-scene &lt;/span&gt;function.&lt;br /&gt;
&lt;br /&gt;
The &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;collision-detection&lt;/span&gt;&amp;nbsp;function now needs to check for both collisions with the wall &lt;i&gt;and&lt;/i&gt; collisions with the tail of the worm. By breaking this method into two independent functions; one checking for wall collisions and one checking for tail collisions, I was able to re-use the code for the wall collisions in&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt; final-scene&lt;/span&gt; function for determining which message to display - either &quot;You have hit the wall&quot;, or &quot;You have hit yourself&quot;.&lt;br /&gt;
&lt;br /&gt;
Although we have a multi-segmented worm now, the collision detection functions didn&#39;t need to be drastically modified as it only needs to check the head of the worm. We can just pop off the first segment and use this to check for collisions.&amp;nbsp;For worm tail collisions we use the &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;member?&lt;/span&gt; function as specified in the hint.&lt;br /&gt;
&lt;br /&gt;
For the&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt; final-scene&lt;/span&gt; function the only change was to determine which message to display. As the &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;collision-detection&lt;/span&gt; function only returns true or false we can&#39;t use this directly. By calling the indivdiual functions within this method (ie &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;collision-detection-wall&lt;/span&gt;) we can determine the method. There is no need to check for collisions with the worm, as if the worm has collided with something and it was not the wall, then it must have collided with itself.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;




Code&lt;/h3&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Constants&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WORM-SIZE 10)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WORM-MOVE (* WORM-SIZE 2))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WIDTH 800) &amp;nbsp;; width of the game&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define HEIGHT 500) ; height of the game&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define SEGMENT (circle WORM-SIZE &quot;solid&quot; &quot;red&quot;)) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; these structs hold the current list of worm segments, the direction&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the worm is travelling in, and our world object&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct segment(x-pos y-pos))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct direction(x y))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define-struct world(worm direction))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define WORM (list (make-segment 100 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 80)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 60)) ) &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; To save repeating these directions in tests and code, we&#39;ll define them here&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define DOWN &amp;nbsp;(make-direction 0 1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define UP &amp;nbsp; &amp;nbsp;(make-direction 0 -1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define RIGHT (make-direction &amp;nbsp;1 0))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define LEFT &amp;nbsp;(make-direction -1 0))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Functions&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; draw worm in its current location on the screen. This function recurses&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; down our list of worm segments drawing each one at a&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;time on to the background&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; passed in&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (draw-worm background worm)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond [(empty? worm) background]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else (place-image&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SEGMENT&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(segment-x-pos (first worm)) (segment-y-pos (first worm))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(draw-worm background (rest worm))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;This function has changed for this exercise so that instead of just checking for a collision with the wall, we check for a collision with the&amp;nbsp;worm as well. This is accomplished by calling two separate collision functions - one for the wall, and one for the worm. The reason this has been split up is so that we can use the same function to determine which end of game message should be displayed. This function could be trivially extended to check for collisions with objects in the room.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Check for collisions with either the walls or the rest of the worm.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; return true if collision detected, false otherwise&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (collision-detected world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (or&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(collision-detected-wall (first (move-worm-helper world )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(collision-detected-worm (first (move-worm-helper world))&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (world-worm world ))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a helper function for checking for collision with the worm.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This works by checking if area the worm would move into is already in the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; list of worm segments&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; return true if collision detected, false otherwise&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (collision-detected-worm segment worm)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (member? segment worm))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; a helper function for collision detection with the wall&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; returns true if a collision is detected, false otherwise&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (collision-detected-wall segment)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;(cond [(&amp;gt; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(segment-x-pos segment)) true] &amp;nbsp;; exceeding left edge&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;gt; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; (segment-y-pos segment)) true] &amp;nbsp;; exceeding top edge&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; WIDTH &amp;nbsp; (segment-x-pos segment)) true] &amp;nbsp;; exceeding right edge&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [(&amp;lt; HEIGHT &amp;nbsp;(segment-y-pos segment)) true] &amp;nbsp;; exceeding bottom edge&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [else false]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;final-scene&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt; method also changed for this exercise. To display the correct end of game message we need to determine if we&#39;ve collided with the worm or the wall.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;We can use the&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;collision-detected-wall&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt; method to determine if the game finished because we hit the wall. If it didn&#39;t finish because of that, it must have finished because we hit the rest of the worm.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draw our final scene with the worm departing the board&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Displays a &quot;Game Over&quot; type message. We should probably be calculating the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; width and height of the image to calculate the offsets, but it&#39;s simpler just&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; to arbitrarily put it somewhere in the bottom right of the screen&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (final-scene world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-worm&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(place-image (text&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (cond &amp;nbsp;((collision-detected-wall&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (first&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(move-worm-helper world )))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;worm hit border&quot; )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(else &quot;worm hit worm&quot;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20 &quot;red&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (- WIDTH 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (- HEIGHT 50)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene WIDTH HEIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(world-worm world)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Draws the current world. This consists of the snake and the food objects&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (show world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (draw-worm (empty-scene WIDTH HEIGHT) (world-worm world)) )&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Move the worm in the current direction. To move the worm&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;we add a segment&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; to start of the worm (in the current direction)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;and get rid of the end of&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the worm&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-worm worm direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(cons (new-segment (first worm) direction) (remove-last worm))&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; helper method to DRY up code.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (move-worm-helper world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (move-worm (world-worm world) (world-direction world)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; returns a new segment moved in &#39;direction&#39; from the segment&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; passed in&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (new-segment segment direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (make-segment &amp;nbsp;(+ (segment-x-pos segment)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (* WORM-MOVE (direction-x direction)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(+ (segment-y-pos segment)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (* WORM-MOVE (direction-y direction)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; remove the last worm segment. this is a pretty unoptimised function. just&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; reverse the list, grab the rest of it, and reverse it again to get it the&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; correct order.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (remove-last worm)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(reverse (rest (reverse worm))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; On each clock tick, move the world further in time.&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;It&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;moves the worm&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; and creates a new world based on this.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (progress-world world)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;(make-world&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (move-worm &amp;nbsp;(world-worm world) &amp;nbsp;(world-direction world))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; (world-direction world))&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;; handle keyboard events.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (handle-key-events ws ke)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (cond&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;left&quot; ke) &amp;nbsp;(change-direction ws LEFT)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;right&quot; ke) (change-direction ws RIGHT)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;up&quot; ke) &amp;nbsp; &amp;nbsp;(change-direction ws UP )]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [(string=? &quot;down&quot; ke) &amp;nbsp;(change-direction ws DOWN)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; [else ws]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; create a new world with the direction the worm is travelling in changed.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (change-direction world &amp;nbsp;direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (make-world (world-worm world) direction))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; This is the big bang function that drives the game.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(define (worm-main rate)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; (big-bang (make-world WORM&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-direction 1 0))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (to-draw &amp;nbsp; &amp;nbsp;show)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (stop-when &amp;nbsp;collision-detected final-scene)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-key &amp;nbsp; &amp;nbsp; handle-key-events)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (on-tick &amp;nbsp; &amp;nbsp;progress-world rate) ))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; start the game off!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(worm-main 0.1)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; TESTS&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Test when we move the worm up, a new segment is added to the start and removed&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; from the end.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm WORM LEFT)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment (- 100 WORM-MOVE) 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 80)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Check the remove-last function removes the last segment correctly&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (remove-last WORM)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 100 100)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-segment 100 80)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Test that new segment returns a new segment in the correct position&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; (as per the current direction)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (new-segment &amp;nbsp;(make-segment 100 100) UP)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-segment 100 (- 100 WORM-MOVE)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;; exceeding the bottom of the screen&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;(check-expect (collision-detected (make-world&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-worm (- WIDTH 10) (+ HEIGHT 10)) RIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;; exceeding the right side of the scren&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;(check-expect (collision-detected (make-world&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-worm (+ WIDTH 10) (- HEIGHT 10)) RIGHT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;; exceeding the top of the screen&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;(check-expect (collision-detected (make-world&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-worm -10 (- HEIGHT 10)) LEFT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;; exceeding the left side of the screen&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;(check-expect (collision-detected (make-world&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-worm (- WIDTH 10) -10) LEFT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;true)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;;in the middle of the screen - should not collide&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;(check-expect (collision-detected (make-world&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(make-worm (- WIDTH 10) (- HEIGHT 10)) LEFT))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;false)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;;; Test our worm draws as we expect it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (draw-worm (empty-scene 200 200) WORM)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image SEGMENT 100 100&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(place-image SEGMENT 100 80&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (place-image SEGMENT 100 60&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (empty-scene 200 200)))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Test our worm moves in the direction we expect&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm (list (make-segment 50 50)) DOWN)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 50 70)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm (list (make-segment 50 50)) UP)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 50 30)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm (list (make-segment 50 50)) LEFT)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 30 50)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (move-worm &amp;nbsp;(list (make-segment 50 50)) RIGHT)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (list (make-segment 70 50)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; Test our change-direction function changes the direction, but doesn&#39;t impact&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;; the postion&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (change-direction (make-world (make-segment 50 50) DOWN) UP)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-world (make-segment 50 50) UP))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;(check-expect (change-direction (make-world (make-segment 50 50) DOWN) RIGHT)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (make-world (make-segment 50 50) RIGHT)) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://htdp2e.blogspot.com/feeds/1535045656683361532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://htdp2e.blogspot.com/2012/05/exercise-173-re-design-your-program-so.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1535045656683361532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1643364309931537120/posts/default/1535045656683361532'/><link rel='alternate' type='text/html' href='http://htdp2e.blogspot.com/2012/05/exercise-173-re-design-your-program-so.html' title='Exercise 173: Re-design your program so that it stops if the worm has run into the walls of the world or into itself.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>