<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Feb 21, 2012, at 7:18 AM, Rodolfo Carvalho wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote"><div>BTW I just found the nested-cond pattern appearing on HtDP, throughout section 9:<br>

<a href="http://htdp.org/2003-09-26/Book/curriculum-Z-H-13.html">http://htdp.org/2003-09-26/Book/curriculum-Z-H-13.html</a><br></div></div></blockquote></div><br><div>That happens when you follow the HtDP design recipe directly and there are conditionals for two unrelated reasons, e.g.&nbsp;</div><div><br></div><div>(cond [(empty? L) ...]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[(cons? L)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (cond [(snark? (first L)) ...]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[(boojum? (first L)) ...]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[(beeblebrox? (first L)) ...]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )])</div><div><br></div><div>Yes, this COULD be collapsed into</div><div>(cond [(empty? L) ...]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[(snark? (first L)) ...]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[(boojum? (first L)) ...]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[(beeblebrox? (first L)) ...]</div><div>)</div><div>but that doesn't match the data structure as transparently.</div><div><br></div><div>Incidentally, if you want to bulletproof the above code against non-lists, the first version is easy: just add</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [else (error ...)]</div><div>as a new third branch of the outer "cond". &nbsp;The second version doesn't bulletproof as neatly: you can either add&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [(not (cons? L)) (error ...)]</div><div>as a new second branch of the "cond", or you can revert to the nested-cond structure.</div><div><br></div><div>It's a judgment call, which can go different ways in different circumstances.</div><br><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Stephen Bloch</div><div><a href="mailto:sbloch@adelphi.edu">sbloch@adelphi.edu</a></div></div></span></span>
</div>
<br></body></html>