I see.  I cannot use it as I said in my first post.  But I got your idea.  I&#39;ll rename addone to count or something else.<br><br>
<div class="gmail_quote">On Tue, May 31, 2011 at 10:29 PM, Rodolfo Carvalho <span dir="ltr">&lt;<a href="mailto:rhcarvalho@gmail.com">rhcarvalho@gmail.com</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>add1 comes for free, it&#39;s built-in.</div>
<div><br></div>
<div>And it does exactly that!</div>
<div><br></div>
<div>[]&#39;s</div><br clear="all"><font color="#888888">Rodolfo Carvalho</font> 
<div><br></div>
<div><br></div>
<div>PS: please use this list [users at <a href="http://racket-lang.org/" target="_blank">racket-lang.org</a>] for user-related topics<br><br><br>
<div class="gmail_quote">
<div>
<div></div>
<div class="h5">On Wed, Jun 1, 2011 at 02:14, Yingjian Ma <span dir="ltr">&lt;<a href="mailto:yingjian.ma1955@gmail.com" target="_blank">yingjian.ma1955@gmail.com</a>&gt;</span> wrote:<br></div></div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>
<div></div>
<div class="h5"><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>
<div>
<div></div>
<div><br><br>
<div class="gmail_quote">On Tue, May 31, 2011 at 10:02 PM, Rodolfo Carvalho <span dir="ltr">&lt;<a href="mailto:rhcarvalho@gmail.com" target="_blank">rhcarvalho@gmail.com</a>&gt;</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="&#39;courier new&#39;, monospace">CTRL+I</font> let&#39;s you reindent all of your code, which gives this:</div>
<div><br></div>
<div>
<div><font face="&#39;courier new&#39;, monospace">#lang racket</font></div>
<div>
<div><font face="&#39;courier new&#39;, monospace">(define (count-matches s l)  </font></div>
<div><font face="&#39;courier new&#39;, monospace">  (define (addone s l x)</font></div>
<div><font face="&#39;courier new&#39;, monospace">    (cond</font></div>
<div><font face="&#39;courier new&#39;, monospace">      [(empty? l) x]</font></div>
<div><font face="&#39;courier new&#39;, monospace">      [(equal? s (first l)) (addone s (rest l) (+ 1 x))]</font></div>
<div><font face="&#39;courier new&#39;, monospace">      [else (addone s (rest l) x)]))</font></div>
<div><font face="&#39;courier new&#39;, monospace">  (addone s l 0))</font></div></div></div>
<div><br></div>
<div><br></div>
<div>The change in indentation makes clear that you&#39;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 &quot;addone&quot; doesn&#39;t really sound to me to describe what the function is doing -- it not always &quot;adds one&quot;.</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="&#39;courier new&#39;, monospace">#lang racket</font></div>
<div>
<div><font face="&#39;courier new&#39;, monospace">(define (count-matches s l)  </font></div></div>
<div><font face="&#39;courier new&#39;, monospace">  (cond</font></div>
<div><font face="&#39;courier new&#39;, monospace">    [(empty? l) 0]</font></div>
<div><font face="&#39;courier new&#39;, monospace">    [(equal? s (first l)) (add1 (count-matches s (rest l)))]</font></div>
<div>
<div><font face="&#39;courier new&#39;, monospace">    [else (count-matches s (rest l))]))</font></div>
<div><font face="&#39;courier new&#39;, monospace"><br></font></div></div>
<div>
<div><font face="&#39;courier new&#39;, monospace">(count-matches &#39;x &#39;())      ;   should be 0</font></div>
<div><font face="&#39;courier new&#39;, monospace">(count-matches &#39;x &#39;(a b x)) ;   should be 1</font></div>
<div><font face="&#39;courier new&#39;, monospace">(count-matches &#39;x &#39;(x b x)) ;   should be 2</font></div></div></div>
<div><br></div>
<div><br></div>
<div>[]&#39;s</div><br clear="all"><font color="#888888">Rodolfo Carvalho</font> 
<div>
<div></div>
<div><br><br><br>
<div class="gmail_quote">On Wed, Jun 1, 2011 at 01:37, Yingjian Ma <span dir="ltr">&lt;<a href="mailto:yingjian.ma1955@gmail.com" target="_blank">yingjian.ma1955@gmail.com</a>&gt;</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 &#39;x &#39;())   should be 0</div>
<div>(count-matches &#39;x &#39;(a b x))   should be 1  </div>
<div>(count-matches &#39;x &#39;(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></div></div><br></div></div>
<div class="im">_________________________________________________<br> For list-related administrative tasks:<br> <a href="http://lists.racket-lang.org/listinfo/dev" target="_blank">http://lists.racket-lang.org/listinfo/dev</a><br>
</div></blockquote></div><br></div></blockquote></div><br>