[racket-dev] Racket docs and data-driven design

From: Bloch Stephen (bloch at adelphi.edu)
Date: Fri Sep 16 11:58:50 EDT 2011

On Sep 16, 2011, at 11:52 AM, Shriram Krishnamurthi wrote:

> I introduced templates today.  Almost as if on cue, one student asked
> whether he could use else instead of (cons?  l).  I told them I was
> going to make a MORAL judgment about why it was EVIL, and spent ten
> minutes talking about all that.
> As class ended, one of my students came up and said,
> "So why doesn't the Racket language Web site agree with you?"
> http://docs.racket-lang.org/guide/Lists__Iteration__and_Recursion.html
> (Look for "[else".)


I'm with you: I tell my students to use "else" to capture true "none  
of the above" cases that can't easily be described directly, e.g.

(define (size thing)
	(cond [(string? thing) (string-length thing)]
		   [(real? thing) (abs thing)]
		   [(image? thing) (* (image-width thing) (image-height thing))]
		   [else (error 'size "I don't know how to handle that type.")]))

Stephen Bloch
sbloch at adelphi.edu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20110916/f7f83481/attachment.html>

Posted on the dev mailing list.