[racket] Creating a useful snip
Does it make sense to have snip%'s copy method signal an error instead
of returning a (useless) snip%? or maybe it could check and see if
this is a subclass and signal an error in that case?
Robby
On Tuesday, April 5, 2011, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
>
> Please!
>
> On Apr 5, 2011, at 3:06 PM, Jay McCarthy wrote:
>
>> Should I update the docs to mention that as one that must be overridden?
>>
>> Jay
>>
>> 2011/4/5 Robby Findler <robby at eecs.northwestern.edu>:
>>> copy.
>>>
>>> Robby
>>>
>>> On Tue, Apr 5, 2011 at 1:34 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>>>> I'm trying to create a useful snip that displays a different sub-snip
>>>> every second. I think I've overridden every method required to get a
>>>> "useful" snip, but nothing gets display in DrRacket and the functions
>>>> aren't called ever. Are there other methods that need to be
>>>> overridden?
>>>>
>>>> The code is below...
>>>>
>>>> Jay
>>>>
>>>> #lang racket/base
>>>> (require (for-syntax racket/base)
>>>> racket/class
>>>> racket/function
>>>> racket/runtime-path
>>>> racket/snip)
>>>>
>>>> (define reactive-snip%
>>>> (class* snip% ()
>>>> (init-field sub-snips)
>>>>
>>>> (printf "Snips: ~a\n" sub-snips)
>>>>
>>>> (define (the-snip)
>>>> (list-ref sub-snips
>>>> (modulo (current-seconds) (length sub-snips))))
>>>>
>>>> (define-syntax-rule (delegate id)
>>>> (define/override (id . a)
>>>> (define some-snip (the-snip))
>>>> (printf "Delegating (~a ~a) to ~a\n"
>>>> 'id a
>>>> some-snip)
>>>> (send/apply some-snip id a)))
>>>>
>>>> (delegate get-extent)
>>>> (delegate draw)
>>>> (delegate get-text)
>>>> ; set-unmodified or modified
>>>>
>>>> (super-new)))
>>>>
>>>> (define-runtime-path img1 '(lib "PLT-206-larval.png" "icons"))
>>>> (define-runtime-path img2 '(lib "PLT-206-mars.jpg" "icons"))
>>>>
>>>> (define sub-snips
>>>> (map (curry make-object image-snip%)
>>>> (list img1 img2)))
>>>>
>>>> (define x
>>>> (make-object
>>>> reactive-snip%
>>>> sub-snips))
>>>>
>>>> sub-snips
>>>>
>>>> x
>>>>
>>>> --
>>>> Jay McCarthy <jay at cs.byu.edu>
>>>> Assistant Professor / Brigham Young University
>>>> http://faculty.cs.byu.edu/~jay
>>>>
>>>> "The glory of God is Intelligence" - D&C 93
>>>> _________________________________________________
>>>> For list-related administrative tasks:
>>>> http://lists.racket-lang.org/listinfo/users
>>>>
>>>
>>
>>
>>
>> --
>> Jay McCarthy <jay at cs.byu.edu>
>> Assistant Professor / Brigham Young University
>> http://faculty.cs.byu.edu/~jay
>>
>> "The glory of God is Intelligence" - D&C 93
>>
>> _________________________________________________
>> For list-related administrative tasks:
>> http://lists.racket-lang.org/listinfo/users
>
>