Bob Rogers <[EMAIL PROTECTED]> wrote: > From: Leopold Toetsch <[EMAIL PROTECTED]>
> 1) is there a MultiSub object with one short name that holds all > possible long names (and function references)? > If yes, who is creating it: the Perl6 compiler emits code to do so or > it's up to Parrot to do the right thing? > FWIW, Common Lisp specifies a "generic function" [1] that collects all > methods defined for a given operation name. (In Perl/Parrot, the > generic function name for your examples would be the string "foo"; in > Lisp, it would be the symbol "FOO" in some package, but the practical > difference should be slight.) The important thing is that the GF has > all the information required to make method dispatch decisions. That sounds exactly like the MultiSub object that gathers a candidate list of all subroutines with the same short name. > ... But on the other hand, the CL community has > more than 15 years of experience with MMD, so I wanted to be sure > everyone was aware of it. Yeah, that's really helpful. > 2) namespaces of (multi) subs. > A non-multi method is in the classes' namespace. In Parrot terms that's > currently: > %globals{"\0class_name"}{"method_name"} > I'm not quite sure, if the method hash shouldn't live inside the class. > Is naming at this level really important here? Well, the short name of the multi sub has to be stored somewhere. > ... The operation itself > needs a name (so that people can call it), and classes need class names > (maybe), but all methods are implicitly named by the combination of > operation plus argument signature. Yes. That's the "long name" in Perl6 design documents. > ... Which would seem to mean that, > unlike perl5, the package in which a multimethod is defined doesn't > matter; all that is captured by the argument signature. Yep. You can define a multi sub anywhere. > ... Or is it > possible to have more than one method with the identical signature? And > if so, what does that mean? There can be identical signatures in different scopes. Within one scope, I don't know. > The "long name" is therefore a list of class names, which suggests > that the single-dispatch naming above is backwards. Of course, I'm > probably out of my depth here . . . The "long name" contains the signature. The "short name" is the bare "foo". > A multi method is similar, except that their can be more then one > with the same short name (which probably means that there has to be a > MultiSub object holding the long names) > I'm not sure it is meaningful to give a sub a "short name," You call it by the short name. > %globals{"foo"} --> MultiSub{"foo_A_B" => Sub, ...} > This sounds right to me. Or perhaps > %globals{"foo"} --> MultiSub{["foo", 'A', 'B'] => Sub, ...} Yep, something like that. > just to belabor the point a bit. > What about a not so global multi: > multi sub foo(A $a, B $b) {...} > Thanks for clarifying, > leo > Is this really different? After all, the operation "foo" should be just > a string in either case. Sure. But the string "foo" has to live in some namespace. But, it it's not marked as global it's probably in either a package or a module, so again it has it's namespace. > -- Bob Rogers leo