to be more precise:
gambit's reader allows you to specify a symbolic macro for curly braces {} we use @method, so when the reader sees {print o "hello"} it gets read to (@method print o hello). @method is a (user-programmable) core macro, with default expansion to (call-method 'print o "hello")
call-method in gambit is implemented like this: (define (call-method obj id . args) (cond ((method-ref obj id) => (lambda (method) (apply method obj args))) (else (error "Cannot find method" obj id))))
(define (method-ref obj id) (and (object? obj) (find-method (object-type obj) id)))
hope that helps, -- vyzo
On Sun, Dec 13, 2015 at 12:39 PM, Dimitris Vyzovitis vyzo@hackzen.org wrote:
Or you can do what we use in gerbil: {print o "hello"}
reader translates to (call-method 'print o "hello")
-- vyzo
On Mon, Dec 7, 2015 at 5:13 PM, Marc Feeley feeley@iro.umontreal.ca wrote:
At the Scheme level, you can express the OO style in various ways. Here are 2 that come to mind:
- Your “new” operator could return a closure which receives as a first parameter the name of the method to be called. So you could:
(define o (new Lib)) (o print: "hello")
or
(define .print '.print) (o .print "hello")
- You could make .print a function that receives as a first parameter the object on which the method applies. For example:
(define .print (lambda (self text) …)) (define o (new Lib)) (.print o "hello")
You can of course use macros to automate these styles.
Marc
On Dec 7, 2015, at 8:31 AM, ben yakawp ben.lists@yakawp.com wrote:
hi Sorry if this too obvious, but I don't understand how gambit handles objects from the hosts backend.
For example: if one would like to construct a 'Node' library for the JS backend, how would you do that? The whole node api seems to be object oriented. But also the Python standard libaries (batteries) are layed out class based. You had to do something like
(define o (new Lib)) (o.print "hello")
This looks wrong. What am I missing?
Regards ben _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list