<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 </div><div><br></div><div>(provide </div><div> (contract-out</div><div> ;; given a natural number, produce the fizz/buzz list for it</div><div> (fizzbuzz (-> natural-number/c (listof (or/c number? symbol?))))))</div><div><br></div><div>(module+ test </div><div> (require rackunit))</div><div><br></div><div>(define (printer num)</div><div> (cond((and (= 0 (remainder num 3)) (= 0 (remainder num 5))) 'fizzbuzz)</div><div> ((= 0 (remainder num 3)) 'fizz)</div><div> ((= 0 (remainder num 5)) 'buzz)</div><div> (else num)))</div><div><br></div><div>(define (fizzbuzz limit)</div><div> (define (helper current limit)</div><div> (cond ((>= current limit) (list (printer limit)))</div><div> (else (cons (printer current) (helper (+ 1 current) limit)))))</div><div> (helper 1 limit))</div><div><br></div><div>(module+ test</div><div> (require (submod ".."))</div><div> (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. </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 fizzbuzz. 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? 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"> (cond((and (= 0 (remainder num 3)) (= 0 (remainder num 5))) 'fizzbuzz)</font></div><div><font class="Apple-style-span" face="Courier"> ((= 0 (remainder num 3)) 'fizz)</font></div><div><font class="Apple-style-span" face="Courier"> ((= 0 (remainder num 5)) 'buzz)</font></div><div><font class="Apple-style-span" face="Courier"> (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"> (define (helper current limit)</font></div><div><font class="Apple-style-span" face="Courier"> (cond ((>= current limit) (printer limit))</font></div><div><font class="Apple-style-span" face="Courier"> (else (cons (printer current)</font></div><div><font class="Apple-style-span" face="Courier"> (helper (+ 1 current) limit)))))</font></div><div><font class="Apple-style-span" face="Courier"> (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>> </div></div></div>
____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>