<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div><br></div><div>Your base case must be a list (Contracts and tests are optional):</div><div><br></div><div><div>#lang racket</div><div><br></div><div>;; -----------------------------------------------------------------------------</div><div>;; a simple fizzbuzz function&nbsp;</div><div><br></div><div>(provide&nbsp;</div><div>&nbsp;(contract-out</div><div>&nbsp; ;; given a natural number, produce the fizz/buzz list for it</div><div>&nbsp; (fizzbuzz (-&gt; natural-number/c (listof (or/c number? symbol?))))))</div><div><br></div><div>(module+ test&nbsp;</div><div>&nbsp; (require rackunit))</div><div><br></div><div>(define (printer num)</div><div>&nbsp; (cond((and (= 0 (remainder num 3)) (= 0 (remainder num 5))) 'fizzbuzz)</div><div>&nbsp; &nbsp; &nbsp; &nbsp;((= 0 (remainder num 3)) 'fizz)</div><div>&nbsp; &nbsp; &nbsp; &nbsp;((= 0 (remainder num 5)) 'buzz)</div><div>&nbsp; &nbsp; &nbsp; &nbsp;(else num)))</div><div><br></div><div>(define (fizzbuzz limit)</div><div>&nbsp; (define (helper current limit)</div><div>&nbsp; &nbsp; (cond ((&gt;= current limit) (list (printer limit)))</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (else (cons (printer current) (helper (+ 1 current) limit)))))</div><div>&nbsp; (helper 1 limit))</div><div><br></div><div>(module+ test</div><div>&nbsp; (require (submod ".."))</div><div>&nbsp; (check-equal? (fizzbuzz 10) '(1 2 fizz 4 buzz fizz 7 8 fizz buzz)))</div></div><div><br></div><div>If you write down 'contracts' (even informally) they may help you formulate what to produce. If you're insecure, express contracts within the language.&nbsp;</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><br><div><div>On Apr 28, 2013, at 2:23 PM, Leonard Cuff wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; "><div style="font-family: Calibri, sans-serif; ">I'm trying to teach myself scheme (racket) and decided to try writing &nbsp;fizzbuzz. &nbsp;My program mostly works, but instead of getting a single list, I get a list with a dot before the last list item, which I assume means I've got a 'cons' at the end rather than just one list. What am I doing wrong? &nbsp;Any general comments on style or approach also welcome.</div><div style="font-family: Calibri, sans-serif; "><br></div><div style="font-family: Calibri, sans-serif; ">Thanks,</div><div style="font-family: Calibri, sans-serif; "><br></div><div style="font-family: Calibri, sans-serif; ">Leonard</div><div style="font-family: Calibri, sans-serif; "><br></div><div><div><font class="Apple-style-span" face="Courier">#lang racket</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">(define (printer num)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp; (cond((and (= 0 (remainder num 3)) (= 0 (remainder num 5))) 'fizzbuzz)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp; &nbsp; &nbsp; &nbsp;((= 0 (remainder num 3)) 'fizz)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp; &nbsp; &nbsp; &nbsp;((= 0 (remainder num 5)) 'buzz)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp; &nbsp; &nbsp; &nbsp;(else num)))</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">(define (fizzbuzz limit)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp; (define (helper current limit)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp; &nbsp; (cond ((&gt;= current limit) (printer limit))</font></div><div><font class="Apple-style-span" face="Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (else (cons (printer current)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (helper (+ 1 current) limit)))))</font></div><div><font class="Apple-style-span" face="Courier">&nbsp; (helper 1 limit))</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">(fizzbuzz 10)</font></div></div><div style="font-family: Calibri, sans-serif; "><br></div><div style="font-family: Calibri, sans-serif; "><div>'(1 2 fizz 4 buzz fizz 7 8 fizz . buzz)</div><div>&gt;&nbsp;</div></div></div>
____________________<br> &nbsp;Racket Users list:<br> &nbsp;<a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>