[plt-scheme] Catch an unknown method error

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed Feb 20 16:32:21 EST 2008

Oops -- the header should be

  #lang scheme

not

  #lang scheme/base
  (require scheme/class)

Robby

On Wed, Feb 20, 2008 at 3:31 PM, Robby Findler <robby at cs.uchicago.edu> wrote:
> On Wed, Feb 20, 2008 at 3:25 PM, Filipe Cabecinhas <filcab at gmail.com> wrote:
>  >
>  >  On 20 Feb, 2008, at 19:19, Robby Findler wrote:
>  >
>  >  > On Feb 20, 2008 1:15 PM, Filipe Cabecinhas <filcab at gmail.com> wrote:
>  >  >> is it possible, in scheme/class to catch the error for an unknown
>  >  >> method, from inside the object?
>  >  >> Kind of Objective-C's forwardInvocation:, Ruby's method_missing (or
>  >  >> something), and many others ;-)
>  >  >
>  >  > There's not any such thing, but maybe if we knew some larger context
>  >  > for what you're doing, we might able to suggest an alternative.
>  >  >
>  >
>  >  I'm trying to make some proxies for MysterX (COM classes) in a quick
>  >  way, for rapid prototyping. If I had that functionality I could just
>  >  implement the forwardInvocation: method and just change that method
>  >  call to a COM method call. And then incrementally making the objects
>  >  more Scheme-like and rearranging the interface.
>  >
>  >  I hope that paragraph isn't very confusing ;-)
>
>  It's clear! I guess the easiest thing would be to write a macro that
>  consumes the names of the methods and generates classes that respond
>  to those methods. Something like this:
>
>  #lang scheme/base
>
>  (require scheme/class)
>
>  (define-syntax (stub stx)
>   (syntax-case stx ()
>     [(_ name . names)
>      (identifier? #'name)
>      #'(begin
>          (define/public (name . args)
>            (do-com-call-here 'name args))
>          (stub . names))]
>     [(_)
>      #'(void)]))
>
>  (define (do-com-call-here name args)
>   (printf "calling com method ~s with args ~s\n" name args))
>
>  (define my-class%
>   (class object%
>     (stub a b c)
>     (stub d e f)
>     (define/public (m x) (printf "not a com method\n"))
>     (super-new)))
>
>  (define o (new my-class%))
>  (send o a 1 2 3)
>  (send o b 'p 'q)
>  (send o m 12)
>
>
>
>  >
>  >  >> P.S: Where can I find the documentation for the missing sections in
>  >  >> the PLT Guide (v3.99)
>  >  >
>  >  > What you see is what's written, I'm sorry to say. You might try v372
>  >  > docs for some things, but not for missing parts of the Guide.
>  >
>  >
>  >  Hmm. Any docs on reader extensibility or must I read the code? Also,
>  >  where is that stuff defined, I couldn't find it :s
>
>  Oh! everything is documented! Of course. You asked about the Guide
>  specifically, which isn't complete. But the basic information is all
>  there (in the reference or in v372's docs (our latest non pre-release)
>  if the docs aren't ported yet).
>
>  Try search in Help Desk for "reader" or "reader macro".
>
>  Robby
>


Posted on the users mailing list.