You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the current version of rakudo, if I were to run the code “my &foo ();”,
I would get the error “Signatures as constraints on variables not yet
implemented.”
To bring us a little closer to being able to implement this, I propose the
following:
First, provide a subtype (subrole?) of the Callable role, which has a
signature. These subrole would probably be created by writing
Callable[:(...)].
Second this paramaterized version of Callable would need to be somewhere in
the ancestry of every existing Block, Routine, Sub, Method, Submethod and
Macro objects, or at least, for those which have a signature.
Third, make "my &varname (blah) ;" become nearly the same as "my
Callable[:(blah)] $varname;" except of course for the sigil.
Fourth, ensure that paramaterization of Callable *doesn't* produce a
separate, distinct role for every signature passed in, but caches based on a
canonicalized version of the signature. For now, canonicalization of a
signature simply means removing the names of positional parameters, so :(Int $foo) is transformed into :(Int $)
These four changes together mean that a user can write:
constant two_ints_sub_t = Callable[:(Int $asdf, Int $qwerty -->Int)];
my two_ints_sub_t $foo = sub add (Int $lhs, Int $rhs --> Int) { $lhs+$rhs };
my (Int $x, Int $y --> Int) &bar;
say $foo.VAR.WHAT; # "(Callable[:(Int $, Int $-->Int)])"
say &bar.VAR.WHAT; # "(Callable[:(Int $, Int $-->Int)])"
say $foo.VAR.WHAT === &bar.VAR.WHAT; # "True"
A fifth step, adding a method named sub_signature to the paramaterized role,
which returns the captured signature, would make it NativeCall friendly.
The drawback of this proposal is that it only works with signatures which
don't differ other than parameter names. But at least it's a start.
Migrated from rt.perl.org#131511 (status was 'new')
Searchable as RT131511$
The text was updated successfully, but these errors were encountered: