[racket] Visitor Pattern and Racket
On Sun, Jan 20, 2013 at 6:25 PM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
>
> Normal OOPLs suffer from a lack of expressiveness.
> OO programmers make up for this lack with programming
> patterns. If you don't have first-class functions,
> simulate them with the command pattern. If you don't
> have functions but you want to emphasize functional
> style, use the visitor pattern.
>
> The extensible visitor pattern is the only contribution
> in the book that is of some interest to Racket programmers.
> But we have units and mixins, and we can do this thing
> even better.
>
> Once we have types for these, the question becomes whether
> the type system will be strong enough to get away without
> the one ugly cast.
>
Many thanks Matthias.
1)
What I found useful in the book is the way it shows recursion with
OOP, I had never seen this before.
About the recursion in the book. The examples so far all depend on
the last object in the recursion being a particular class to end the
recursion. For example to use the shish-kabob example, I can
construct the following two shish-kabob but only the first gives the
correct answer because the recursion ends in skewer%,
Example 1: gives correct answer
(define shish-c (new onion% [sh (new onion% [sh (new lamb% [sh (new
skewer%)])])]))
(send shish-c only-onions? )
Example 2: gives incorrect answer
(define shish-c (new onion% [sh (new onion% [sh (new skewer% [sh (new
lamb%)])])]))
(send shish-c only-onions? )
Is it possible to make a contract that will flag example 2 as a
contract violation?
2) Regarding types, I see that "The Little MLer" is about types.
Would it be useful for a Racket programmer who only knows C types, to
go through "the little MLer" but using typed Racket instead of ML.
Thanks,
Harry Spier