|
From: | Jan Wedekind |
Subject: | Interesting project proposal for generics in Racket |
Date: | Wed, 5 Mar 2014 18:12:00 +0000 (GMT) |
User-agent: | Alpine 2.02 (DEB 1266 2009-07-14) |
Besides, I think that Scheme + OOP has its own flaws. In most OOP languages, you have this notation object.property or object->method(), which also allows for chain calls, i.e. object->getChild()->method(), or -- if you have nested objects -- to use object.property.propertys_property.
Somewhat related I have seen an interesting project proposal for generics in Racket [1]. The generics use predicate functions instead of classes. E.g.:
(defmethod add ((x number?) (y number?)) (+ (x y)) where 'number?' is a function returning '#t' for numbers. The type hierarchy (specialisation) is declared using 'defsubtype'. E.g.: (defsubtype zero? integer?) This facilitates defining factorial like this: (defgeneric fact (n)) (defmethod fact ((n integer?)) (* n (fact (- n 1)))) (defmethod fact ((n zero?)) 1) Regards Jan [1] https://fenix.tecnico.ulisboa.pt/downloadFile/3779579671692/project.pdf
[Prev in Thread] | Current Thread | [Next in Thread] |