[plt-scheme] A matter of design

From: Daniel Yoo (dyoo at cs.wpi.edu)
Date: Tue Mar 20 23:53:48 EDT 2007

> On the core side we will have a huge issue... integer values defines 
> basic operations on integers +, -, etc with attached contracts and puts 
> this all in the functions hash-table. Then comes the matrix value and 
> defines +, -, * on matrices but with different contracts. Now the user 
> does (+ matrix matrix) or something... how is the core supposed to know 
> which + it is talking about (not to mention the best way to keep this.

Hi Paulo,

This feels very similiar to the "generic operations" stuff in:


'swindle' provides library support for these kinds of generic operations. 
Here's a quick and dirty example:

(module test-generics mzscheme
   (require (lib "clos.ss" "swindle"))

   (defgeneric plus)

   (defmethod plus ((x <number>) (y <number>))
     (+ x y))

   (defmethod plus ((x <string>) (y <string>))
     (string-append x y))

   (printf "~a~n" (plus 4 2))
   (printf "~a~n" (plus "4" "2")))

Posted on the users mailing list.