[racket] About genericity...

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Wed Apr 2 16:56:49 EDT 2014

On 2014-04-02 20:53:58 +0200, Alejandro Zamora Fonseca wrote:
> ¿How can I create generic-functions in Racket?
>
> Something like
> this samples in CL:
>
> (defmethod dup ((a string))
>      (concatenate 'string a a))
>
> (defmethod dup ((a integer))
>       (list a a))

See the docs for the `racket/generic` library:

  http://docs.racket-lang.org/reference/struct-generics.html

In particular, if you want functions with specialized behavior on
strings and integers, you'll need to use the #:defaults clause because
Racket does not allow a "monkeypatching"-like approach to overriding
behavior.

Cheers,
Asumu

Posted on the users mailing list.