function signatures?

1 view
Skip to first unread message

Yuval Kogman

unread,
May 28, 2005, 8:44:24 PM5/28/05
to perl6-l...@perl.org
We have a pretty complex declarative language for argument
processing in the parameter declaration:

types, subtypes, constraint blocks
context propagation
default values
slurpiness

arity as a number does not give enough reflection into these
properties.

Are signatures going to be an exposed first class object in Perl 6?

--
() Yuval Kogman <nothi...@woobling.org> 0xEBD27418 perl hacker &
/\ kung foo master: /me sneaks up from another MIME part: neeyah!!!!!

Ingo Blechschmidt

unread,
May 29, 2005, 10:01:02 AM5/29/05
to perl6-l...@perl.org
Hi,

Yuval Kogman wrote:
> We have a pretty complex declarative language for argument
> processing in the parameter declaration:

[...]


> arity as a number does not give enough reflection into these
> properties.

Indeed.

> Are signatures going to be an exposed first class object in Perl 6?

I hope so, too.

~&foo.signature;
# Signature objects should stringify to a canonized form, e.g.:
# ~sub (Str $bar, CoolClass $z where {...}) {...}.signature ==>
# 'Str $bar, ANONCLASS(0xDEADBEEF)'
# (BTW, I don't think it's possible to display anonymous subtypes more
# friendly, as the where-clause may contain arbitrary code, and Code
# objects are not (yet?) fully introspectable -- i.e.
# &foo.statements[3].line doesn't work.)

+&foo.signature.required_args;
# Number of required args
&foo.signature.required_args;
# Hash name -> class

&foo.signature.positional_args;
&foo.signature.named_args;
# etc.


Thoughts?

--
Linux, the choice of a GNU | There are no answers, only
generation on a dual AMD | cross-references.
Athlon! |

Sam Vilain

unread,
May 30, 2005, 12:41:29 AM5/30/05
to Ingo Blechschmidt, perl6-l...@perl.org
Ingo Blechschmidt wrote:
>>Are signatures going to be an exposed first class object in Perl 6?
> I hope so, too.
> ~&foo.signature;
> # Signature objects should stringify to a canonized form, e.g.:
> # ~sub (Str $bar, CoolClass $z where {...}) {...}.signature ==>
> # 'Str $bar, ANONCLASS(0xDEADBEEF)'
> # (BTW, I don't think it's possible to display anonymous subtypes more
> # friendly, as the where-clause may contain arbitrary code, and Code
> # objects are not (yet?) fully introspectable -- i.e.
> # &foo.statements[3].line doesn't work.)
>
> +&foo.signature.required_args;
> # Number of required args
> &foo.signature.required_args;
> # Hash name -> class
>
> &foo.signature.positional_args;
> &foo.signature.named_args;
> # etc.
> Thoughts?

Translations of the corresponding Pugs types into Perl 6 code is at:

ext/Perl-MetaModel/lib/Pugs/VCode.pm

However they are mostly still sketches. If you have specific ideas about
the Code::Signature signature in Pure Perl terms, place it in;

ext/Perl-MetaModel/lib/Code/Signature.pm

These objects will eventually be what you get from &foo.meta, etc. Or at
least I assume that the way to get to the object's signature will be .meta.
Maybe the "Code" class will define a ".signature" method as an alternative
to .meta.signature.

Sam.

Reply all
Reply to author
Forward
0 new messages