C++ Multimethods / What are Multimethods good For? 
Author Message
 C++ Multimethods / What are Multimethods good For?

'Modern C++ Design' by Andrei Alexandrescu has a chapter on implementing multimethods in C++. It mentions Dylan twice in the overview :-) . The 'Loki' library that accompanies the book has a C++ multimethod implementation.

Alexandrescu has a fairly concise answer to the question 'what are generic functions good for?':

"Detecting the need for multimethods is simple. You have an operation that manipulates multiple polymorphic objects through pointers or references to their base classes. You would like the behavior of that operation to vary with the dynamic type of more than one of those objects."

He then gives the collision-in-computer-games example that Scott Meyers gives in his discussion of C++ multimethods in 'More Effective C++'. This seems to be becoming the classic multimethod example. :-)

- Rob.



Fri, 12 Aug 2005 21:13:50 GMT  
 C++ Multimethods / What are Multimethods good For?

Quote:

> 'Modern C++ Design' by Andrei Alexandrescu has a chapter on
> implementing multimethods in C++. It mentions Dylan twice in the
> overview :-) . The 'Loki' library that accompanies the book has a
> C++ multimethod implementation.

What are the limitations of the C++ implementation? Is it very
intrusive?

Here's another approach to multimethods in C++ - but it uses a
'compiler wrapper':

http://frost.flewid.de/

At the moment I'm programming in 'C' and I can honestly say that I
miss using Dylan! I think what I miss most has got to be macros,
closures, higher order functions and multimethod dispatch in that
order.

Chris.
--
http://www.double.co.nz/dylan



Fri, 12 Aug 2005 21:35:52 GMT  
 C++ Multimethods / What are Multimethods good For?

Quote:

>What are the limitations of the C++ implementation? Is it very
>intrusive?

I haven't had time to go into the specifics yet. The project is here:

http://sourceforge.net/projects/loki-lib/

Quote:
>At the moment I'm programming in 'C' and I can honestly say that I
>miss using Dylan! I think what I miss most has got to be macros,
>closures, higher order functions and multimethod dispatch in that
>order.

Here's a handy C++ macro:

#define should_use_dylan        friend

I wish Dylan's string support was as good as C++'s, though.

- Rob.



Fri, 12 Aug 2005 23:54:48 GMT  
 C++ Multimethods / What are Multimethods good For?

Quote:


> >What are the limitations of the C++ implementation? Is it very
> >intrusive?

> I haven't had time to go into the specifics yet. The project is here:

> http://sourceforge.net/projects/loki-lib/

> >At the moment I'm programming in 'C' and I can honestly say that I
> >miss using Dylan! I think what I miss most has got to be macros,
> >closures, higher order functions and multimethod dispatch in that
> >order.

> Here's a handy C++ macro:

> #define should_use_dylan        friend

> I wish Dylan's string support was as good as C++'s, though.

> - Rob.

There is copy-subsequence().

        Gabor



Sat, 13 Aug 2005 00:57:14 GMT  
 C++ Multimethods / What are Multimethods good For?

Quote:


>> I wish Dylan's string support was as good as C++'s, though.
> There is copy-subsequence().

And there's string-extensions, and I wrote a tokenizer. So it's not
that bad, I suppose, but it's still not particularly amazing. :-)

- Rob.



Sat, 13 Aug 2005 05:47:38 GMT  
 C++ Multimethods / What are Multimethods good For?

Quote:

>>> I wish Dylan's string support was as good as C++'s, though.
>> There is copy-subsequence().
> And there's string-extensions, and I wrote a tokenizer. So it's not
> that bad, I suppose, but it's still not particularly amazing. :-)

Well, it's all there, it just needs somebody to clean it up and make
it shiny.  I miss the ease of use regular expressions have in perl,
for instance...

Andreas

--
"In my eyes it is never a crime to steal knowledge. It is a good
theft. The pirate of knowledge is a good pirate."
                                                       (Michel Serres)



Tue, 16 Aug 2005 17:16:47 GMT  
 C++ Multimethods / What are Multimethods good For?

Quote:


>>>> I wish Dylan's string support was as good as C++'s, though.
>>> There is copy-subsequence().
>> And there's string-extensions, and I wrote a tokenizer. So it's not
>> that bad, I suppose, but it's still not particularly amazing. :-)

> Well, it's all there, it just needs somebody to clean it up and make
> it shiny.

We could pop it in string-ext.

Quote:
>  I miss the ease of use regular expressions have in perl,
> for instance...

There's an old pcre interface in gd/contributions. PCRE doesn't look
that difficult to add to Dylan...

- Rob.



Tue, 16 Aug 2005 17:35:55 GMT  
 C++ Multimethods / What are Multimethods good For?


Quote:
>He then gives the collision-in-computer-games example that Scott Meyers gives in his discussion of C++
>multimethods in 'More Effective C++'. This seems to be becoming the classic multimethod example. :-)

There is a 'Boost' library for multimethods - but I can't use it on my
platform (and certainly not in my job).

I've ended up using closure techniques in C++ to reduce the code-size
overhead of template-based generics - it's a nightmare getting
started, but isn't too bad for maintenance, but I seriously wish there
was support for this stuff built in.

In my case, the no. 1 use that I'd have for multimethods would be in
the implementation of dynamic typing for a scripting language.

Of course the compile-time equivalent of polymorphism (ie overloading)
already supports the equivalent of multimethods. Multimethods may be
more difficult for the compiler, but IMO establishing the need for
multimethods is a no-brainer.

I've never used (or even read a tutorial) for Dylan, but my reason for
being here mainly involves multimethods. I'm also concerned with the
rules for encapsulation and data hiding. In my experience, the classes
and objects tend to be structured into tightly coupled systems. The
natural boundary for data hiding, therefore, should be a system (ie a
module, package or whatever) - not a class. I was therefore wondering
whether methods still 'belong to' classes in Dylan, or whether there
is a different approach.

--
steve at ninereeds dot fsnet dot co dot uk



Wed, 24 Aug 2005 19:46:33 GMT  
 C++ Multimethods / What are Multimethods good For?
On Sat, 08 Mar 2003 11:46:33 +0000, Stephen Horne

Quote:

>There is a 'Boost' library for multimethods - but I can't use it on my
>platform (and certainly not in my job).

Whoops - I think I confused my library names - Frost is already
mentioned here.

--
steve at ninereeds dot fsnet dot co dot uk



Wed, 24 Aug 2005 21:11:21 GMT  
 C++ Multimethods / What are Multimethods good For?


Quote:
> I've never used (or even read a tutorial) for Dylan, but my reason for
> being here mainly involves multimethods. I'm also concerned with the
> rules for encapsulation and data hiding. In my experience, the classes
> and objects tend to be structured into tightly coupled systems. The
> natural boundary for data hiding, therefore, should be a system (ie a
> module, package or whatever) - not a class. I was therefore wondering
> whether methods still 'belong to' classes in Dylan, or whether there
> is a different approach.

Which class would a multimethod belong to?

In Dylan a "Generic Function" is a 1st class object in its own right,
and individual methods belong to the GF.

Dylan's boundary for data hiding is the module, which consists of one or
more of the source files [1] within a library (the unit of compilation).  
Each file starts with a line such as "Module: EmployeeData".

Data hiding is accomplished by either exporting a name or not exporting
it.  Names refer to classes, types, global variables, constants, generic
functions.

Note that exporting a class does *not* automatically export GFs that use
that class.

Note also that read access to slot (field) "foo" in an object is done by
the GF "foo" and write access to the same slot is done by the GF
"foo-setter".  You can export either, both, or neither.

-- Bruce

[1] that's not quite right.  Some Dylan implementations don't store
source code in files.



Thu, 25 Aug 2005 04:32:59 GMT  
 C++ Multimethods / What are Multimethods good For?
Quote:



> >He then gives the collision-in-computer-games example that Scott Meyers gives in his discussion of C++
> >multimethods in 'More Effective C++'. This seems to be becoming the classic multimethod example. :-)

> There is a 'Boost' library for multimethods - but I can't use it on my
> platform (and certainly not in my job).

Loki library... dont think its in boost yet.  It wont work in msvc,
though clever people are porting it... but it only works with exact
matches anyway.
Where's the fun in that?  I have a version that does polymorphic
multiple dispatch on
http://homepage.ntlworld.com/w.weston/multiple_dispatch.html

from which you can get an msvc friendly example... the example is just
double dispatch, email me for a more useful version if you are
interested.

Check out Julian Smiths cmm too.  It puts in an extra preprocessing
stage to enable multiple dispatch (and potentially much more) without
explicitly registering the implementations.

http://www.op59.net/cmm/readme.html

Quote:
> I've ended up using closure techniques in C++ to reduce the code-size
> overhead of template-based generics - it's a nightmare getting
> started, but isn't too bad for maintenance, but I seriously wish there
> was support for this stuff built in.

> In my case, the no. 1 use that I'd have for multimethods would be in
> the implementation of dynamic typing for a scripting language.

> Of course the compile-time equivalent of polymorphism (ie overloading)
> already supports the equivalent of multimethods. Multimethods may be
> more difficult for the compiler, but IMO establishing the need for
> multimethods is a no-brainer.

interesting!  what are the killer apps then?  event handling, sure...
parsing... what about mediator pattern type setups with complex dialog
boxes?

...

Quote:
> being here mainly involves multimethods. I'm also concerned with the
> rules for encapsulation and data hiding. In my experience, the classes
> and objects tend to be structured into tightly coupled systems. The
> natural boundary for data hiding, therefore, should be a system (ie a
> module, package or whatever) - not a class. I was therefore wondering
> whether methods still 'belong to' classes in Dylan, or whether there
> is a different approach.

i would advocate making everything public in the classes in C++, and
using namespaces to organise the functions, which would generally be
external to the classes.   Is that like Dylan?  I don't know Dylan
either.

HTH
Bill Weston



Thu, 01 Sep 2005 20:10:20 GMT  
 C++ Multimethods / What are Multimethods good For?

Quote:

> i would advocate making everything public in the classes in C++, and
> using namespaces to organise the functions, which would generally be
> external to the classes.   Is that like Dylan?  I don't know Dylan
> either.

That's exactly like things are in Dylan, just that the namespaces are
called modules.

Andreas

--
"In my eyes it is never a crime to steal knowledge. It is a good
theft. The pirate of knowledge is a good pirate."
                                                       (Michel Serres)



Thu, 01 Sep 2005 22:52:51 GMT  
 C++ Multimethods / What are Multimethods good For?


Quote:

> > i would advocate making everything public in the classes in C++, and
> > using namespaces to organise the functions, which would generally be
> > external to the classes.   Is that like Dylan?  I don't know Dylan
> > either.

> That's exactly like things are in Dylan, just that the namespaces are
> called modules.

With the addition that in Dylan you can control which field names are
exported across the module/namespace boundary -- and you can export only
the ablility to read a field, or only the ability to change it, or both
or neither.

Dylan also uses the same foo.bar syntax to read and write a field
("slot"), no matter whether the access is direct or via user written
getter- and setter- functions.  Or, to put it another way, the compiler
automatically generates trivial getter and setter functions if you don't
tell it not to.  These are of course inlined most of the time.

-- Bruce



Fri, 02 Sep 2005 03:28:50 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Multimethod.py -- multimethods in Python

2. Multimethod.py -- multimethods for Python

3. Multimethod.py -- multimethods in Python

4. multimethods

5. multimethods, papers on implementing?

6. Multiple dispatch / multimethods??

7. Multiple Polymorphism In Java/MultiMethods - New Implementation

8. What is multimethod dispatch useful for.

9. Multimethods in UML?

10. multimethods, papers on implementing?

11. dynamic class hierarchies, dynamic changes to multimethods ?

12. message passing not-vs. multimethods

 

 
Powered by phpBB® Forum Software