[racket] Visitor Pattern and Racket
On Jan 20, 2013, at 7:55 PM, Harry Spier <vasishtha.spier at gmail.com> wrote:
> 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?
Doesn't the constructor for lamb% expect an argument? In this data structure, the only base case is skewer%, so the only legal way to build a shish-kebab is with a skewer at the end.
Stephen Bloch
sbloch at adelphi.edu