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

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Sep 16 12:23:26 EDT 2011

I don't like it either because it makes the function a contract violator:

(define (listy l)
 (cond
  [(empty? l)
   ...]
  [else
   ... (first l) ...]))

(define (f x)
 ... (listy 5) ...)

f breaks listy's contract, but it goes undetected in most of Racket
and all of HtDP and listy gets blamed for breaking first's contract. A
student sees an error message about first, not listy. If you had
[(cons? ...) ...], then you'd get "all questions were false" inside
listy, which is nicer.

I understand that signatures are meant to solve this, but they aren't
part of HtDP yet.

On the other hand, if the contracts are there, I like else because
each cond eliminates one variant and there is finally just one variant
left. (Note: I only like this if it is unlikely I will add more
variants. I dislike that type-case from PLAI has else, for example.)

Jay



On Fri, Sep 16, 2011 at 10:13 AM, Robby Findler
<robby at eecs.northwestern.edu> wrote:
> Why is else evil? I can see how it might be pragmatic to avoid it in a
> language without contracts, but I'm having trouble seeing evil.
>
> Robby
>
> On Fri, Sep 16, 2011 at 10:52 AM, Shriram Krishnamurthi <sk at cs.brown.edu> 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".)
>>
>> Shriram
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://lists.racket-lang.org/listinfo/dev
>>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93



Posted on the dev mailing list.