Re: (multi)subroutine names

2005-06-06 Thread TSa (Thomas Sandlaß)

Rod Adams wrote:

It used to be

   fooArray,Int
   fooHash,Int


And has become

  foo:(Array,Int)
  foo:(Hash,Int)

The return type arrow -- inside the :() type spec is not
yet approved by @Larry.


In my mind, the more interesting question is what does foo without the 
 specifiers return when foo is multi? I see the following three options:


1) undef/error, since there's no single sub called foo, and multi's need 
a postfix .


This applies only if you want to by-pass actual dispatch by
selecting a sub yourself. Otherwise foo is an instance of the
class/type MultiMethod which is a subtype of Sub and Method,
which in turn are subtypes of Code.


2) the name 'foo', and then performs in effect call by name when 
deferenced, using the dereferencing scope to determine which flavors of 
foo are available at this time, and dispatching accordingly.


I'm unsure how much the Perl6 semantics depend on name lookup
when no explicit symbolic expression ::('foo') is used. But that
aside I think the type is enough information to handle a value.
So foo is typed foo:(MultiMethod) or foo:(Ref of MultiMethod).
This latter thing is another open question on my end: the referential
semantics. E.g. are *all* plain sigil expressions :(Ref of ...) and
need an implicit or explicit dereferencer?


3) a dispatch table of all the foo's currently in scope at the time the 
reference is made.


Yes, that's it. But note that it's not a passive table that the caller
needs to handle correctly. MMD is about basing the decision which
implementation of a signature to call on the runtime types in the
argument list. Without multi this degenerates to a mere type compatibility
check for subs.

A direct extension of the above is that the type system might be able
to dynamically instanciate parametric types to fill 'gaps' dynamically.
Something like 'compilation on demand' if that is the only way to actually
instanciate a template---but I'm not sure if Perl6's parametric types are
actually called templates.


I hope that helps.
--
TSa (Thomas Sandlaß)



Re: (multi)subroutine names

2005-06-04 Thread dakkar
Rod Adams wrote:
 It used to be

fooArray,Int
fooHash,Int

 but I seem to recall that there was a mild change that occurred. Or
 maybe I'm thinking about the adding of the colon for operators. I'm not
 certain, but it's something very close to the above.
Well, it doesn't seem ambiguous to me. Operators would be in the form
infix:-Num,Num . But then, I don't design grammars... If enough
people think this syntax could work, I'll add unspecced tests to pugs
for it.

 In my mind, the more interesting question is what does foo without the
  specifiers return when foo is multi? I see the following three options:

 1) undef/error, since there's no single sub called foo, and multi's need
 a postfix .
At first I thought this was the right way, but then...

 2) the name 'foo', and then performs in effect call by name when
 deferenced, using the dereferencing scope to determine which flavors of
 foo are available at this time, and dispatching accordingly.

 3) a dispatch table of all the foo's currently in scope at the time the
 reference is made.
...one of these is actually necessary. Example:
- I write a module that exports a 'foo' (a sub)
- You use my module, and use that 'foo' to get a ref, which you
subsequently use as you please
- I then change my module so that 'foo' is a multi-sub (this is an
implementation detail, not an API change)
- Your code *must not* break

so we can't return undef. Your #3 seem useful (for introspection, at
least), but what about:

 multi sub foo(Array $a) {return 1}
 multi sub foo(Hash $a) {return 2}

 my $foo_A_H=foo;

 multi sub foo(Str $a) {return 3}

 print $foo_A_H.('a');

should that print 3? Or coerce 'a' into ['a'] and print 1?

What about (thinking aloud):

 my $foo_static=foo;
 my $foo_dynamic:=foo;

where the first one has snapshot semantic, as in your #3, and the
second one has 'name' semantic, as in your #2, in the same way that:

 my $a=1;
 my $b=$a;
 my $c:=$a;
 $a=2;
 print $b,$c;

prints 1 2 ?

--
Dakkar - Mobilis in mobile
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


signature.asc
Description: OpenPGP digital signature


(multi)subroutine names

2005-06-03 Thread dakkar
Say I have:

 multi sub foo(Array $a,Int $b) {...}
 multi sub foo(Hash %a, Int $b) {...}

and I want to (distinctly) wrap each multisub, say for testing, or AOP,
or whatever. How do I get the two different code references? As far as i
can gather from the Apocalipses and Synopses, there should be a way to
express the long name, and use that to get the ref. Is there any
proposed syntax for this? (I ask about syntax because the semantic seems
pretty clear...)

--
Dakkar - Mobilis in mobile
GPG public key fingerprint = A071 E618 DD2C 5901 9574
 6FE2 40EA 9883 7519 3F88
key id = 0x75193F88


signature.asc
Description: OpenPGP digital signature


Re: (multi)subroutine names

2005-06-03 Thread Yuval Kogman
With a meta model for code signatures you could generate a code
signature and then ask it to locate any matching multis.

For a more concrete handle on how this might look if I were king-
wait a while...  ;-)

When I have more time to finalize docs/mmd.kwid and then describe
the meta model for function signatures I promise to tell you =)

On Sat, Jun 04, 2005 at 01:20:13 +0200, dakkar wrote:
 Say I have:
 
  multi sub foo(Array $a,Int $b) {...}
  multi sub foo(Hash %a, Int $b) {...}
 
 and I want to (distinctly) wrap each multisub, say for testing, or AOP,
 or whatever. How do I get the two different code references? As far as i
 can gather from the Apocalipses and Synopses, there should be a way to
 express the long name, and use that to get the ref. Is there any
 proposed syntax for this? (I ask about syntax because the semantic seems
 pretty clear...)
 
 --
   Dakkar - Mobilis in mobile
   GPG public key fingerprint = A071 E618 DD2C 5901 9574
6FE2 40EA 9883 7519 3F88
   key id = 0x75193F88



-- 
 ()  Yuval Kogman [EMAIL PROTECTED] 0xEBD27418  perl hacker 
 /\  kung foo master: /me beats up some cheese: neeyah!



pgpeCSXevxk5a.pgp
Description: PGP signature