At Fri, 25 Mar 2016 22:13:16 -0400, Matthias Felleisen wrote:
> 
> Consider this program (a poem of a real problem I encountered): 
> 
> #lang racket
> 
> (module server racket
>   (provide c%)
> 
>   (define c%
>     (class object%
>       (super-new)
>       (define/public (m) 0))))
> 
> (module client racket
>   (require (submod ".." server))
> 
>   (define-local-member-name m)
>   
>   (define d%
>     (class object%
>       (super-new)
>       (define/public (m o)
>         (displayln (interface->method-names (object-interface o)))
>         (send o m))))
> 
>   (module+ test
>     (require (submod ".."))
>     (send (new d%) m (new c%))))
> 
> (require (submod 'client test))
> 
> If you run this, you will get 
> 
> Welcome to DrRacket, version 6.4.0.14--2016-03-19(-/f) [3m].
> Language: racket, with debugging.
> (o has methods: (m))
> . . send: no such method
>   method name: m
>   class name: c%
> 
> So right after confirming that ‘m' is a method of o, our dear friend Racket 
> tells us that m is not a a method of o. 
> 
> I get it. The define-local-member-name ‘kills' the ‘m’ from ‘server’ as well 
> as client outside of the scope, but that’s because Racket fails to 
> acknowledge 
> that some positions are referentially transparent and some are not when it 
> replaces ‘m’ with the gensym-ed identifier that replaces it in scope. 
> 
> I really would like this program to run and if not, I’d like to record it 
> here 
> why our implementation (as opposed to a specification) fails. 

The error message should be improved to say something about `m` being a
local name, but the failure to call a method is certainly as intended.
That is, the use of `m` as a method name in a given scope is intended
to be statically the same in all forms that involve a method name,
including both `define/public` and `send`.

I don't get the "referentially transparent" suggestion. The `(send o
m)` call belongs to the `server` module, not whatever object is the
value of `o` dynamically. The method name `m` within `server` refers a
local name, unrelated to any method name that might be spelled the same
elsewhere. It's a question of the syntactic location of `m`, and the
syntactic location of `(send o m)` is definitely in the `server`
module.


I could imagine making the example work by redefining local names for
`send` as implying a dynamic search: first for the local `m`, then
whatever member name the local definition shadows, and so on. In the
example below, the final call would then produce 'b instead of 'a.

A search doesn't seem like a good idea to me. setting aside the
run-time cost, in places where I use a local member name, if the local
name is not present in the target object, then something has gone
wrong. My intent is never to call either the local name or a similarly
spelled non-local name, whichever is present.

But you didn't say anything about a search, and I'm not sure what you
had in mind. It's just my attempt to make sense out of what local names
could mean to make your example produce 0 instead of an error.

----------------------------------------

#lang racket

(module a racket
  (provide a-mixin
           a-m)
  
  (define-local-member-name m)

  (define (a-mixin %)
    (class %
      (super-new)
      (define/public (m) 'a)))

  (define (a-m o)
    (send o m)))

;; just like `a`, but without `define-local-member-name`
(module b racket
  (provide b-mixin
           b-m)

  (define (b-mixin %)
    (class %
      (super-new)
      (define/public (m) 'b)))

  (define (b-m o)
    (send o m)))

(require (submod "." a)
         (submod "." b))

(a-m (new (a-mixin object%))) ; 'a
(b-m (new (b-mixin object%))) ; 'b
(a-m (new (b-mixin (a-mixin object%)))) ; 'a
(a-m (new (a-mixin (b-mixin object%)))) ; 'a
(b-m (new (b-mixin (a-mixin object%)))) ; 'b
(b-m (new (a-mixin (b-mixin object%)))) ; 'b
(a-m (new (b-mixin object%))) ; error, but search would mean 'b

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-dev/56f68adc.10b5420a.642f9.ffff80b9SMTPIN_ADDED_MISSING%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to