[racket] About genericity...

From: Alexander D. Knauth (alexander at knauth.org)
Date: Fri Apr 4 17:48:23 EDT 2014

Oh never mind I realized it’s expecting a list of predicates, not a predicate that takes a list.

But it would probably be a good thing to make it to accept a predicate too, so that you can do (listof number?).  

On Apr 4, 2014, at 5:44 PM, Alexander D. Knauth <alexander at knauth.org> wrote:

> I wanted to try it out, but it’s giving me an error about car expecting a pair:
> 
> . . car: contract violation
>  expected: pair?
>  given: #<flat-contract: (listof vector?)>
> 
> #lang racket
> 
> (require (submod def-multi/def-multi multim))
> (require plot/utils)
> (require (only-in racket [+ rkt:+]))
> (require rackunit)
> 
> (def-multi +)
> 
> (add-multi + '() (lambda () 0))
> (add-multi + (listof number?) (lambda args (apply + args)))
> (add-multi + (listof vector?) (lambda args (apply v+ args)))
> 
> (check-equal? (+ 1 2 3) 6)
> (check-equal? (+ (vector 1 2 3)
>                 (vector 2 3 4)
>                 (vector 3 4 5))
>              (vector 6 9 12))
> 
> 
> 
> On Apr 4, 2014, at 11:23 AM, Patrick Useldinger <uselpa.list at gmail.com> wrote:
> 
>> On 02/04/2014 20:48, Patrick Useldinger wrote:
>> 
>>> I can share it if you're interested, it's roughly 40 lines of code.
>> 
>> Here's the link: https://github.com/uselpa/def-multi
>> 
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
> 



Posted on the users mailing list.