[racket] About genericity...
On 02/04/2014 20:53, Alejandro Zamora Fonseca wrote:
> (defmethod dup ((a string))
> (concatenate 'string a a))
>
> (defmethod dup ((a integer))
> (list a a))
1) From the standard Racket "swindle/tiny-clos" library, you can use the
CLOS-like functions that you may already know from Common Lisp.
2) I have written a short library myself for this, and your code would
look like this:
(def-multi dup)
(add-multi dup (list string?) (lambda (a) (string-append a a)))
(add-multi dup (list integer?) (lambda (a) (list a a)))
(dup "Hello") => "HelloHello"
(dup 10) => '(10 10)
I can share it if you're interested, it's roughly 40 lines of code.
-Patrick