develooper Front page | perl.perl6.language | Postings from March 2009

Signature notes and questions

Jon Lang
March 16, 2009 16:07
Signature notes and questions
Message ID:
OK: as I see it, this is how signatures work:

There are three broad use-cases for signatures: function parameters
(S06), role parameters (S14), and variable declarators (S03).
Question: Do binding operators (S03) count as a fourth use?

There are two broad styles of signatures: those that want an invocant,
and those that don't.  The former includes methods, submethods, and
roles; the latter includes subroutines, regexes, tokens, rules,
macros, and variable declarators.  Signatures that want an invocant
will implicitly add one if none is explicitly specified; signatures
that don't want one will complain if you specify one.

Signature literal syntax: usually, this involves enclosing the
signature between ':(' and ')'.  In variable and function declarators,
you may omit the leading colon; in a pointy-block signature, you must
omit both the colon and the parentheses.  In a role declarator, you
must use square braces instead.  (Questions: why is the pointy-block
exclusion of the enclosing delimiters mandatory?  Why do role
declarators use different enclosing delimiters?)

Variable declarators have no use for longname parameters.  Function
and role declarators do.  (Question: are optional and/or slurpy
parameters excluded from the longname?)

Can attributive parameters be used in methods, or are they exclusive
to submethods?


Questions and issues pertaining to absent signatures:

All functions have a default signature of :(*%_, *@_).  Note that
methods and submethods will implicitly prepend :($?CLASS $self:) to
this.  All roles are parameterized, and have a default signature of
:(Any $?CLASS:).  Variable declarators have no default signatures.
(Question: is it still appropriate to use the '$?' twigil?)

Placeholder variables can be used within bare blocks (but not pointy
blocks) and methods that lack signatures.  Can they be used in any
other function declarators?  If not, why not?  If so, are they
considered to be part of the longname of a named function?
(Doubtful.)  They can't be used in variable declarators for several
reasons, not the least of which is that a variable declarator will
always have an explicit signature.  But can they be used in roles?

Can you have a placeholder variable for a type parameter?

Jonathan "Dataweaver" Lang Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About