[plt-scheme] Re: polymorphism of primitive types

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Oct 19 15:28:46 EDT 2005

On Oct 19, 2005, at 3:04 PM, David Van Horn wrote:

> Matthias Felleisen wrote:
>> Now you can use it as advertised and it is contracted.
>
> I don't believe so.
>
>> But it would blow up on this:
>>
>>           (let/ec jump
>>             (mymap (lambda (x y) (if (= x y) (jump #f) (+ x y))) '(1 
>> 2 .
>> 3) '(1 . 2)))
>>
>> Should it? -- Matthias
>
> The jump is a red herring here.  The function breaks even without
> escaping continuations:
>
> (mymap (lambda (x y) (+ x y)) '(1 2 . 3) '(1 . 2)))

There is no proper list so it should throw up.

> I believe the problem is in has-at-least-as-many-cons-as.  In
> particular, you don't use the min argument except to decrement it at
> each recursion, so the function returns true just when list? would.
>
> Since there is rarely a chance to get so say this sort of thing, I'll
> take my opportunity now:  Matthias, use the recipe.

Still this is particularly embarrassing because I taught a class on 
exactly this design recipe with David in it:

   ;; (Listof X) Nat -> Boolean
   (define (has-at-least-as-many-cons-as l min)
     (let loop ([l l][min min])
       (cond [(= min 0) #t]
             [(null? l) #f]
             [else (and (pair? l) (loop (cdr l) (- min 1)))])))

Test suite suitably adjusted :-)

-- Matthias

>
> David
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.