This and other RFCs are available on the web at
http://dev.perl.org/rfc/
=head1 TITLE
Interpolation of subroutines
=head1 VERSION
Maintainer: Michael G Schwern <[EMAIL PROTECTED]>
Date: 17 Sep 2000
Mailing List: [EMAIL PROTECTED]
Number: 252
Version: 1
Status: Developing
=head1 ABSTRACT
Subroutines calls should interpolate in double-quoted strings and similar
contexts.
print "Sunset today is at &sunset($date)";
interpolates to:
print 'Sunset today is at '.sunset($date);
=head1 DESCRIPTION
Currently, subroutine calls cannot be placed directly into strings. This can
often complicate the generation of a string and place the code to generate
pieces of it distant from where they are put together causing maintenance
problems. Also, with scalars, arrays, hashes and methods interpolating (or
proposed to do so), users would expect subroutines to work.
Work arounds are as RFC 222.
Therefore, it is proposed that subroutine calls interpolate in double-quoted
strings and similar constructs.
print "Sunset today is at &sunset($date)";
should parse out as:
print 'Sunset today is at '.sunset($date);
implementing DWIMness. The & is mandatory. Parens are also mandatory if
arguments are to be passed.
Context and what to do with lists are as RFC 222.
Argument passing is as RFC 222.
=head2 Whitespace
Whitespace between the &, function name and opening paren should be disallowed
when interpolated. This will avoid many ambiguous cases.
=head1 MIGRATION
s/&/\\&/g in double quoted strings.
=head1 CAVEATS
&foo() does not honor prototypes. Should "&foo()"? The only thing keeping me
from saying yes is the apparent inconsistency.
Should the function not exist in the current scope, Perl will throw an
exception/die as usual.
This RFC is intended to generate discussion about the need and wisdom of
allowing subroutine interpolation in strings. Practical examples of code
where this is useful as well as where this would be a hinderance are
requested. It is presented seperately because I expect much more discussion
than RFC 222 and wish to keep the consideration of the two seperate.
=head1 IMPLEMENTATION
The tokenizer can watch for /&[A-Z_]\w*/i. If followed by a '(', then the
parsing becomes the same as for normal subroutine arguments.
=head1 REFERENCES
RFC 222 - Interpolation of object method calls
RFC 237 - Hashes should interpolate in double-quoted strings
RFC 251 - Interpolation of class method calls