<font size="2" face="SFTT1000"><font size="2" face="SFTT1000">
<div align="left">Hi Rodolfo,</div>
<div align="left"> </div>
<div align="left">Thank you for the help. ( I assume add1 is</div>
<div align="left"> </div>
<div align="left">(</div></font></font><font color="#ff0000" size="2" face="SFTT1000"><font color="#ff0000" size="2" face="SFTT1000"><font color="#ff0000" size="2" face="SFTT1000">define </font></font></font><font size="2" face="SFTT1000"><font size="2" face="SFTT1000">(</font></font><font color="#228c22" size="2" face="SFTT1000"><font color="#228c22" size="2" face="SFTT1000"><font color="#228c22" size="2" face="SFTT1000">add1 </font></font></font><font size="2" face="SFTT1000"><font size="2" face="SFTT1000">x)
<p align="left">(+ x 1))</p>
<p align="left">)</p></font></font><br><br>
<div class="gmail_quote">On Tue, May 31, 2011 at 10:02 PM, Rodolfo Carvalho <span dir="ltr"><<a href="mailto:rhcarvalho@gmail.com">rhcarvalho@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>[Moving the thread to the users mailing list]</div>
<div><br></div>
<div>Yingjian,</div>
<div><br></div>
<div>Good to see you persevering and getting it done! Congratulations.</div>
<div><br></div>
<div>Before I reasoned about your code, just looking at its shape was enough to imagine it was not properly indented.</div>
<div>You can use and abuse of DrRacket for your on good.</div>
<div><br></div>
<div>Using the shortcut <font face="'courier new', monospace">CTRL+I</font> let's you reindent all of your code, which gives this:</div>
<div><br></div>
<div>
<div><font face="'courier new', monospace">#lang racket</font></div>
<div class="im">
<div><font face="'courier new', monospace">(define (count-matches s l) </font></div>
<div><font face="'courier new', monospace"> (define (addone s l x)</font></div>
<div><font face="'courier new', monospace"> (cond</font></div>
<div><font face="'courier new', monospace"> [(empty? l) x]</font></div>
<div><font face="'courier new', monospace"> [(equal? s (first l)) (addone s (rest l) (+ 1 x))]</font></div>
<div><font face="'courier new', monospace"> [else (addone s (rest l) x)]))</font></div>
<div><font face="'courier new', monospace"> (addone s l 0))</font></div></div></div>
<div><br></div>
<div><br></div>
<div>The change in indentation makes clear that you're defining an auxiliary function and the result of calling count-matches is that of calling (addone s l 0).</div>
<div><br></div>
<div>BTW "addone" doesn't really sound to me to describe what the function is doing -- it not always "adds one".</div>
<div><br></div>
<div><br></div>
<div>Look how a similar implementation is possible without an inner auxiliary function:</div>
<div><br></div>
<div>
<div><font face="'courier new', monospace">#lang racket</font></div>
<div class="im">
<div><font face="'courier new', monospace">(define (count-matches s l) </font></div></div>
<div><font face="'courier new', monospace"> (cond</font></div>
<div><font face="'courier new', monospace"> [(empty? l) 0]</font></div>
<div><font face="'courier new', monospace"> [(equal? s (first l)) (add1 (count-matches s (rest l)))]</font></div>
<div class="im">
<div><font face="'courier new', monospace"> [else (count-matches s (rest l))]))</font></div>
<div><font face="'courier new', monospace"><br></font></div></div>
<div class="im">
<div><font face="'courier new', monospace">(count-matches 'x '()) ; should be 0</font></div>
<div><font face="'courier new', monospace">(count-matches 'x '(a b x)) ; should be 1</font></div>
<div><font face="'courier new', monospace">(count-matches 'x '(x b x)) ; should be 2</font></div></div></div>
<div><br></div>
<div><br></div>
<div>[]'s</div><br clear="all"><font color="#888888">Rodolfo Carvalho</font>
<div>
<div></div>
<div class="h5"><br><br><br>
<div class="gmail_quote">On Wed, Jun 1, 2011 at 01:37, Yingjian Ma <span dir="ltr"><<a href="mailto:yingjian.ma1955@gmail.com" target="_blank">yingjian.ma1955@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>I finished it. The purpose of the function is to count the occurrance of a letter in a list. Ex:</div>
<div> </div>
<div>(count-matches 'x '()) should be 0</div>
<div>(count-matches 'x '(a b x)) should be 1 </div>
<div>(count-matches 'x '(x b x)) should be 2 </div>
<div> </div>
<div>The keywords I can use are limited. Thank you all for the help. Another I need to write is to remove duplicated items from the list.</div>
<div> </div>
<div>It seems that under cond, one condition can only take one expression. What can I do if I want to do two statements?</div>
<div> </div>
<div>Here is the code. </div>
<div> </div>
<div>
<div>(define (count-matches s l) <br></div> (define (addone s l x)<br> (cond<br> [(empty? l) x]<br> [(equal? s (first l)) (addone s (rest l) (+ 1 x))]<br> [else (addone s (rest l) x)]))<br> (addone s l 0))</div>
<div>
<div></div>
<div>
<div> </div>
<div> </div></div></div></blockquote></div></div></div></blockquote></div><br>