[racket] About genericity...

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Thu Apr 3 05:43:51 EDT 2014

 Or even simpler 

(define (dup a)
  (cond
    [(string? a) (string-append a a)]
    [(integer? a) (list a a)])

:-)

I think, Alejandro wanted to add clauses in different places (generic in one module, added method in another, for example).


Thu, 3 Apr 2014 20:11:36 +1100 от Daniel Prager <daniel.a.prager at gmail.com>:
>Here's an out-of-the-box option, using Racket's  pattern matching  with the (? predicate) form:
>
>(define/match (dup a)
>  [((? string?)) (string-append a a)]
>  [((? integer?)) (list a a)])
>
>Dan
>____________________
>  Racket Users list:
>   http://lists.racket-lang.org/users
>


-- 
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140403/bfb82881/attachment.html>

Posted on the users mailing list.