[% setvar title Allow Calling Any Function With A Syntax Like s/// %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/


Allow Calling Any Function With A Syntax Like s///


  Maintainer: John Porter <jdporter@min.net>
  Date: 17 Aug 2000
  Mailing List: perl6-language@perl.org
  Number: 139
  Version: 1
  Status: Developing


The calling syntaces of m()/s() should be consistent with other forms of function call; this should be achieved not by eliminating the traditional // form from m()/s(), but by allowing any function to be called with //.


The strings delimited by the slashes, or other allowed delimiters, would be passed as the arguments to the function. Note that this would include a possible trailing string of \w characters.

Furthermore, if the binding operator is used in conjunction with the function call, it is passed as the first argument by reference, appropriately arranged.

Some simple example should help to demonstrate the idea:

	greek( 'alpha', 'beta' );

could be written as any of the following:




And, taking advantage of the trailing \w string:




Now, the following in the new syntax

	$foo =~ greek/alpha/beta;

would be the same as the following in old syntax:

	greek( \$foo, 'alpha', 'beta' );


The mechanism that is currently invoked in the parsing of m()/s() expressions could be used generally.

Note that all the parameters are necessarily strings; numeric literals do not get pre-converted by the compiler. Or rather, whatever perl does for m()/s() arguments, that would also be done when this syntax is used to call other functions.

head2 Further Observations

The proposed semantics of the binding operator =~ looks to my eye very much like a method referencing operator for direct (non-blessed) variable objects.

That is, there is no reason to suppose that

	for ( %db =~ grok/SSN/$ssn/g ) ) { ...

is not an invocation of the grok "method" on the %db "object".


perlop for details on the calling syntax of m//, s///.