[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [plt-scheme] dynamic method-name for send, in v200



I used generics for that.  This method is part of a web view class:

      ;; start: -> string
      ;; starts the view and handles the first input
      ;; returns an error message or an empty string
      (define (start)
        (let* ([request (send/suspend
                         (build-start-page))]
               [bindings (request-bindings request)])
          (if (or (null? bindings)
                  (null? (car bindings)))
              "invalid button"
              (begin
                (send-generic controller
                              (make-generic controller<%>
                                            (car (car bindings))))
                ""))))

-----------------------------------
Daniel Silva
dsilva@ccs.neu.edu
 

-----Original Message-----
From: owner-plt-scheme@fast.cs.utah.edu
[mailto:owner-plt-scheme@fast.cs.utah.edu] On Behalf Of Peter Lane
Sent: Wednesday, May 22, 2002 10:42 AM
To: plt-scheme@fast.cs.utah.edu
Subject: [plt-scheme] dynamic method-name for send, in v200

Hi all,

In the send syntax with v200 (I'm using alpha 12), is it possible to 
have the method-name dynamically created?

e.g.

(require (lib "class.ss"))
(define tester%
   (class object%
     (define-values (x y) (values 0 0))
     (define (set-x! val) (set! x val))
     (define (set-y! val) (set! y val))
     (public set-x! set-y!)
     (super-instantiate ())))

(let ((o (make-object tester%))
       (do-x? #t))
   (send o (if do-x? set-x! set-y!) 10))

            ^^^^^^^^^^^^^^^^^^^^^^
            causes a compiler complaint (method name is not an
identifier)

The example should make it clear the functionality I wish to achieve. 
I get the same problem if I try send* or with-method.

The application for this is that I'm storing lists of methods for a 
number of classes within a hash table; I want to be able to retrieve 
the methods from the hash table and then apply them to the object 
using the send syntax.  At present, I'm creating separate methods for 
each option, as follows:

(define (set-x! obj val) (send obj set-x! val))

This works, but requires a lot of extra typing.

	thanks for any help,

		Peter.

-- 
--------------------------------------------------------------
Dr. Peter Lane
ESRC Centre for Research in Development,
Instruction and Training (CREDIT)
School of Psychology, University of Nottingham
NOTTINGHAM  NG7 2RD, England

Email: pcl@psychology.nottingham.ac.uk
Tel:   + 44 (0) 115 951 5310
Fax:   + 44 (0) 115 951 5324
URL:   http://www.psychology.nottingham.ac.uk/staff/Peter.Lane
--------------------------------------------------------------