[plt-scheme] The Scheme way of: Using 'global' variables ?
Matthias Felleisen <matthias at ccs.neu.edu> writes:
> use classes instead:
>
> #lang scheme
>
> (define the-function%
> (class object%
> (init-field var)
> (define/public (var++) (set! var (+ var 1)))
> (define/public (display) (printf "~s\n" var))
> (super-new)))
>
> (define the-function (new the-function% [var 0]))
> (send the-function display) ;; => 0
> (send the-function var++)
> (send the-function display) ;; => 11
>
>
> It really scales.
But the class methods can only be defined statically inside
the class (or its parents), right? How does that scale more
than a traditional dispatch handler?
--
Alex