in reply to RFC: Perl5 Language Extension: Definedness-Triggered Shortcut Operators

I very much like the spirit behind this proposal, though I'm not sure if : is a good choice as "defined"-modifier. It doesn't have any definedness connotation for me.

Maybe just stick with d? There's no rule that says operators need to be either word or non-word character only: A d|| B etc.

And while you're at it, you can also introduce a prefix meta operator for exists instead of defined: e|| and e&&

FWIW I don't see any problems with having multiple names for the same operator; it's a good way to deal with language change and graceful deprecation.

Update: I should add that Perl 6 has long taken the road of having meta operators, and even type prefixed operators. For example bitwise AND behaves different from strings and numbers, which is there are two operators for them: +& and ~& (the ~ generally stands for strings in Perl 6, concatenation is infix ~, and string context is prefix ~).

Meta operators are more general than that. For example the Z meta op can be applied to infix operators, making them "zip" two lists together:

my @sums = 1, 2, 3 Z+ 30, 20, 10; # 31, 22, 13;

It's a case where an operator consists of both word and non-word characters, and it's not particularly hard to read.

Replies are listed 'Best First'.
Re^2: Perl5 Language Extension: Definedness-Triggered Shortcut Operators
by tobyink (Canon) on Mar 17, 2012 at 13:27 UTC

    Using a letter such as "d" might allow a prototype to be written using Devel::Declare.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'