Why is `+' a method and not a generic function? 
Author Message
 Why is `+' a method and not a generic function?

Quote:
> Date: 4 Jul 93 19:44:27

> Page 149 of the Dylan book states

>    + and * are methods so you can't add other methods to them.
>    To extend the protocols, add methods to binary+ and binary*.

> Are + and * methods and not generic functions solely so other methods
> can't be added to them?

That does seem to be the main operational difference between methods
and generic functions.

Quote:
> Why not make + and * read-only generic functions?

I can't think of a reason why that would not work, but it seems like
extra complexity.  You would be replacing one object with two (a generic
function and a method for it).  What's the advantage?

Quote:
> As I work on a Dylan implementation with a C core and a Dylan runtime,
> I'm struck by the fact there is no good way of constructing such a
> method without it being anonymous (a pain from a debugging and error
> reporting point of view):

>   ? (define + (method (#rest numbers) (reduce binary+ 0 numbers)))
>   ? (+ 3 4 5)
>   12
>   ? +
>   {an anonymous method}          

I have a lot of trouble understanding why you think the compiler isn't allowed
to notice at compile time that the method is being bound to the variable + and
associate the name + with the method for printing purposes.  Why not make your
implementation do that?  In general, an implementation that wants to offer a
lot of debugging assistance should wherever possible identify where an object
came from rather than just giving up and saying its anonymous.

Quote:
> Why not define methods as instantiable with a debug-name: keyword?

> (define + (make <method> debug-name: '+
>                          method: (method (#rest numbers)
>                                    (reduce binary+ 0 numbers))))

Doesn't your example, with its method inside a method, answer your own
question?  If the way to make a method is the METHOD special form, to add a
debug-name feature to methods you would need to add that feature to the syntax
of the METHOD special form.  However, it's not clear that such a language
extension is necessary since the same information can usually be obtained
extralinguistically, as in your define + example.


Wed, 27 Dec 1995 20:23:02 GMT  
 Why is `+' a method and not a generic function?
# > Why not define methods as instantiable with a debug-name: keyword?
# >
# > (define + (make <method> debug-name: '+
# >                          method: (method (#rest numbers)
# >                                    (reduce binary+ 0 numbers))))
#
# Doesn't your example, with its method inside a method, answer your own
# question?  If the way to make a method is the METHOD special form, to add a
# debug-name feature to methods you would need to add that feature to the syntax
# of the METHOD special form.  However, it's not clear that such a language
# extension is necessary since the same information can usually be obtained
# extralinguistically, as in your define + example.

This seems inconsistent to me.  Both <class> and <generic-function>
classes support the debug-name: keyword.  Why not provide that for
methods as well?  

To be more like <class> and <generic-function> the above example
should probably be something more like this:

(define + (make <method> debug-name: '+
                         parameter-list: '(#rest numbers)
                         body: '(reduce binary+ 0 numbers)))

I don't have a problem with adding debug-name syntax to the METHOD
special form either.  For consistency sake, I don't think it should be
done extralinguistically, though.

--
Brent Benson                    
Harris Computer Systems



Sat, 30 Dec 1995 01:32:07 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Why is `+' a method and not a generic function?

2. Why is '+' a method and not a generic function?

3. @U$`')-`:023/7H

4. Distributed objects vs. generic functions and multi-methods

5. Distributed objects vs. generic functions and multi-methods

6. ENSURE-GENERIC-FUNCTION and method combinations?

7. Generic Functions vs. CLOS Methods

8. Inspecting the methods associated to a generic function

9. Why I am not enthusiatic about OO COBOL

10. Why I am not reaching callbacks ?

11. 'bind' functions into methods

12. 'capwords' is not a string method

 

 
Powered by phpBB® Forum Software