[racket] Visitor Pattern and Racket

From: Stephen Bloch (bloch at adelphi.edu)
Date: Sun Jan 20 20:39:43 EST 2013

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



Posted on the users mailing list.