develooper Front page | perl.perl5.porters | Postings from November 2019

Re: Miscellaneous suggestions

Paul "LeoNerd" Evans
November 30, 2019 16:46
Re: Miscellaneous suggestions
Message ID:
On Thu, 28 Nov 2019 17:06:21 +0000
Dave Mitchell <> wrote:

> =head2 Auto-declare $self
> Perhaps allow simple syntax to auto-declare $self as the first
> argument?
> In Perl 6, the invocant is implicit in method subs, and can be
> accessed using the 'self' keyword:
>     method foo ($x) {$x, 'foo') }
> but can be explicitly named (note the lack of comma):
>     method foo ($me: $x) {  $$x, 'foo') }
> Cperl supports a similar auto-declaration with an added 'method'
> keyword:
>     method foo ()           { $self->{foo} }
>     method bar ($this:, $x) { $this->{$x}  }
> Perl 5 of course doesn't have a 'method' keyword, and if we were to
> add it, we would need to decide what semantics it brought to the
> table.
> I don't have any strong urge to add such a feature.

As mentioned elsewhere - I've been experimenting in Object::Pad with
adding this, and in summary I don't feel a great need to allow it to be
customised. The invocant variable is called "$self", just like e.g. the
core builtin to print text is called "print".

> =head2 Allow a code block

I think allowing custom code block gives people an extension mechanism
to do more-or-less whatever they want that can't (yet) be provided; and
we can suitably annotate it with performance/etc.. warnings. In
addition it may be worth making it subject to an additional `use
feature` that people have to specifically request; so maybe one day we
decide it's too experimental and remove it without affecting anything

That would allow us the space to experiment with what other features
people need in the aim to adding them as core things later on, letting
people replace their code blocks with those features natively.

> =head2 Whitespace
> On the other hand, Perl 6 doesn't allow whitespace. Should we
> similarly ban it from Perl 5 signatures? My gut feeling is yes: fix
> this while still experimental.

+1  Please forbid that "$  foo" whitespace :)

> =head2 Other traits
> Should we in some fashion allow additional user/pragma defined traits?
> E.g. 'does', 'has' etc? I have absolutely no idea of how they could be
> hooked in (or even whether they could), or how useful they would be,
> or what they (in general terms) would do.

I think saying "we might add more or an extension facility in future"
is sufficient here. Until a concrete requirement for something turns up
there's no point guessing around it. People can use code-blocks for now
to experiment with whatever else they want, until officially-sanctioned
features exist.

> =head2 Signature introspection API.
> It has been suggested that  there should be a Signature Introspection
> API (possibly via a CPAN XS module) which say, given a code ref,
> allows perl code to return information about the sub's signature
> declaration.

I don't have much requirement for an XS API on signatures, but I can
imagine that Future::AsyncAwait is going to need to know, when
suspending one of these new CVs, that the @_ suppression is in effect.
Normally it has to take special measures around the PL_defav variable,
so it would need to act differently if such is not being used. Aside
from that, parameters get parsed into regular-looking lexical
variables, so it would act the same from that point onwards.

Will there be some CV flag or other mechanism by which I can ask "Is
this CV using signatures and hence snail suppression", and if so skip
that part?

> =head2 Caller parameter name auto-generation
>     foo(=$x, =$y);
>     %points = (=$x, =$y);
> (I'm not entirely convinced, though).

I dislike these. The entire attraction of Perl6's version is that the
callsite syntax looks the same as the callee's declaration. If we
couldn't provide that syntactic equivalence there's less in favour of
doing it. While DRY is good to an extent, I've never felt overly
burdened by having to type a little bit more just to pass

  draw(colour => $colour);

Paul "LeoNerd" Evans      |  | Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About