hello everybody,<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; well, it's me again. i know what are you thinking, this newbie is really totally<br>brain-less. but i have spent my 6 months of financial-sums to order HtDP from USA and i want to solve 100% of exercises given in the book at any cost even if i need to spend 8 hrs. in front my AMD64. Also Mr. Matthias is very helpful regarding problems faced by newbies.
<br><br>anyway here is the original exercise from the book:<br><br><b><span style="font-weight: bold;">--- </span>Exercise 11.4.6.</b>&nbsp;&nbsp; 
In exercises&nbsp;<a href="http://htdp.org/2003-09-26/Book/curriculum-Z-H-15.html#node_thm_11.2.2">11.2.2</a>, <a href="http://htdp.org/2003-09-26/Book/curriculum-Z-H-15.html#node_thm_11.4.4">11.4.4</a>,
and&nbsp;<a href="http://htdp.org/2003-09-26/Book/curriculum-Z-H-15.html#node_thm_11.4.5">11.4.5</a>, we developed
functions that tabulate the mathematical function <code class="scheme"><span class="variable">f</span></code> in various
ranges. In both cases, the final function produced a list of <code class="scheme"><span class="variable">posn</span></code>s
that was ordered in <em>descending</em> order. That is, an expression like
<code class="scheme">(<span class="variable">tabulate-f</span> <span class="selfeval">3</span>)</code> yields the list

<div align="left"><pre class="scheme">(<span class="builtin">cons</span> (<span class="builtin">make-posn</span> <span class="selfeval">3</span> <span class="selfeval">2.4</span>)<br>  (<span class="builtin">cons</span> (
<span class="builtin">make-posn</span> <span class="selfeval">2</span> <span class="selfeval">3.4</span>)<br>    (<span class="builtin">cons</span> (<span class="builtin">make-posn</span> <span class="selfeval">1</span> <span class="selfeval">
3.6</span>)<br>      (<span class="builtin">cons</span> (<span class="builtin">make-posn</span> <span class="selfeval">0</span> <span class="selfeval">3.0</span>)<br>        <span class="builtin">empty</span>))))<br></pre>
</div>
<p>
If we prefer a list of <code class="scheme"><span class="variable">posn</span></code>s in <em>ascending</em> order, we
must look at a  different data collection, natural numbers up to a
certain point in the chain: </p>
<p>
A <i>natural number <code class="scheme">[<span class="builtin">&lt;=</span> <span class="selfeval">20</span>]</code></i> (<code class="scheme"><strong>N</strong>[<span class="variable">&lt;=20</span>]</code>)
is either 
</p>
<ol><li><p><code class="scheme"><span class="selfeval">20</span></code> or 
</p>
</li><li><p><code class="scheme">(<span class="builtin">sub1</span> <span class="variable">n</span>)</code> if <code class="scheme"><span class="variable">n</span></code> is a natural number <code class="scheme">[<span class="builtin">
&lt;=</span> <span class="selfeval">20</span>]</code>.  
</p>
</li></ol>
<p>
Of course, in high school, we refer to <code class="scheme"><strong>N</strong>[<span class="variable">&lt;=-1</span>]</code> 
as <em>the</em> negative integers.</p>
<p>
Develop the function 
<a name="node_idx_974"></a></p>
<div align="left"><pre class="scheme"><span class="comment">;; <code class="scheme"><span class="variable">tabulate-f-up-to-20</span> <span class="selfeval">:</span> <strong>N</strong> [<span class="builtin">&lt;=</span>
 <span class="selfeval">20</span>] &nbsp;<tt>-&gt;</tt>&nbsp; <strong>N</strong></code></span><br>(<span class="keyword">define</span> (<span class="variable">tabulate-f-up-to-20</span> <span class="variable">n-below-20</span>) ...)
<br></pre></div>
which tabulates the values of <code class="scheme"><span class="variable">f</span></code> for natural numbers less than
<code class="scheme"><span class="selfeval">20</span></code>. Specifically, it consumes a natural number <code class="scheme"><span class="variable">n</span></code> less
than or equal to <code class="scheme"><span class="selfeval">20</span></code> and produces a list of <code class="scheme"><span class="variable">posn</span></code>s, each of
which has the shape <code class="scheme">(<span class="builtin">make-posn</span> <span class="variable">n</span> (<span class="variable">f</span> <span class="variable">n</span>))</code> for some <code class="scheme"><span class="variable">
n</span></code>
between <code class="scheme"><span class="selfeval">0</span></code> and <code class="scheme"><span class="variable">n</span></code>
(inclusively). ----<br><br>i have developed the solution but according to the data-definition it is wrong (i know it) but i am not able to solve it, even i have solved all the previous problems of sec-11.<br><br>may you help me out?
<br><br>------------------------ start ----------------------------------------------------------<br>;; A natural number [&lt;=20] is either:<br>;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1. 20, or<br>;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2. (sub1 n) where nis a natural number[&lt;=20]
<br><br>;; in this case natural numbers end upto 0, because beyond zero starts the series of -ve integers..<br>;; which we do not refer to as natural numbers in this case.<br><br>;; tabulate-f-upto-20 : N[&lt;=20] -&gt; list
<br>;; to pruduce a list of posns in ascending order which has shape (make-posn n (f n)) for N[&lt;=20] and upto n only.<br>;; (define (tabulate-f-upto-20 n)..)<br><br><br>#| TEMPLATE<br>(define (tabulate-f-upto-20 n)<br>
&nbsp; (cond<br>&nbsp;&nbsp;&nbsp; [(= n 20)...]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; [else....(tabulate-f-upto-20 (add1 n))...]))<br><br>;; (= n 20) it is because we want the list in ascending order<br>;; 2nd it exactly matches the data-definition<br><br>
(tabulate-f-upto-20 20) <br>;; expected answer<br>empty<br><br>(tabulate-f20 5)<br>;; expected answer<br>(cons (make-posn 0 (f 0))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons (make-posn 1 (f 1))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons (make-posn 2 (f 2))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons (make-posn 3 (f 3))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons (make-posn 4 (f 4)) (cons (make-posn 5 (f 5)) empty)))))) |#<br><br><br>(define (tabulate-f-upto-20 n)<br>&nbsp; (cond<br>&nbsp;&nbsp;&nbsp; [(= n 20) empty]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; [else (cons (make-posn n (f n)) (tabulate-f-upto-20 (add1 n)))]))
<br><br><br>(define (f x)<br>&nbsp; (+ (* 3 (* x x))<br>&nbsp;&nbsp;&nbsp;&nbsp; (+ (* -6 x)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -1)))<br><br>;; tests<br>(tabulate-f-upto-20 20) <br>;; expected answer<br>'empty<br><br>(tabulate-f-upto-20 5)<br>;; expected answer<br>(cons (make-posn 0 (f 0))
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons (make-posn 1 (f 1))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons (make-posn 2 (f 2))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons (make-posn 3 (f 3))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (cons (make-posn 4 (f 4)) (cons (make-posn 5 (f 5)) empty))))))<br><br>
--------------------------- end -------------------------------------------------------<br>OUPUT it produces:<br><br>'empty<br>-- in 2nd test-case it produces all posn from 5-20 not from 0-5 as problem wants.--<br><br><br>
-- <br>&quot;the great intellectuals&quot;