Re: Power function as operator

From: Date: Sat, 23 Nov 2013 09:02:54 +0000
Subject: Re: Power function as operator
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-70322@lists.php.net to get a copy of this message
Hi again, On Sat, Nov 23, 2013 at 12:58 AM, Tjerk Meesters <tjerk.meesters@gmail.com>wrote: > Hi, > > To challenge myself I had tasked myself to introduce a new operator and > opcode to the language; now that I'm done with it, I wanted to measure the > response on the list to actually get it merged before writing an RFC. > > My work can be found here: > https://github.com/datibbaw/php-src/compare/pow-operator > > It introduces the pow() function as an operator ** (double asterisk), as > can be found in languages such as Python (with perhaps the notable > difference that it's right associative there). > > The logic gets exposed via the ZEND_POW opcode and all the logic that went > into pow() itself is copied into it. The exceptions are that an expression > such as [] ** 2 (squared empty array) will cause a fatal error because the > operands are incompatible, whereas pow([], 2) would give 0. > > Why this operator? Basically because: > 1) it's shorter (the keyboard rejoices). > 2) it's faster (no ZEND_CALL). > 3) it's found in other languages too. > > I've only implemented one of the test suites; there are quite a few for > just one function, but when needed I can add those others as well. > > Btw, changes to vld aren't pushed yet. > > Let me know! > > -- > -- > Tjerk > So far, there have been no violent objections against the proposal, so I shall go ahead and effect the following: 1) Investigate the GMP overloading option. 2) Write an RFC As for the associativity argument (assuming the precedence is now correct), if not resolved before the voting begins, I would suggest to move that into the vote itself, i.e.: a) don't implement; b) yes, with left associativity; c) yes, with right associativity. -- -- Tjerk

« previous php.internals (#70322) next »