Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70285 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50789 invoked from network); 22 Nov 2013 17:08:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Nov 2013 17:08:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.52 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 74.125.82.52 mail-wg0-f52.google.com Received: from [74.125.82.52] ([74.125.82.52:62845] helo=mail-wg0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 93/A9-28674-38F8F825 for ; Fri, 22 Nov 2013 12:08:21 -0500 Received: by mail-wg0-f52.google.com with SMTP id x13so1429967wgg.19 for ; Fri, 22 Nov 2013 09:08:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=UJ0LgcFSi3C4guhRFfVMgd8ha1DwItSp4A6Y3/lPmfE=; b=HnQ9UE+8zJoTcy8RUMFZzoCzmTpq9GP96jFVRpEAvX6gpjlxyRDW3EeImGLeJxFcs3 VPjifa8vaNVjiEv9qWJ1ZyYxIGU/lUhh8fyQHJC8OT/c+tqmpg/yKxMhiAZ2ylYzqsMO 4daGlXviaccwSrHdVUwaUi7AFMqxApJuwfAfQ5dPes54Q7gQHTj7oat0xCNAu2U/bE+N WyUaDhEDhqd1cGuxIW2WUN9wHj/Hh2AG+16P2x1pvFArd+VOcO76Ou1teEgCPZy2mC2i Y/aMv0Py4EbSRCwWzfuuT5c3KYDU0vTU2RSkGrmp7Fdk2ZZztuCjCpQxCR32AEcs6i56 UveQ== MIME-Version: 1.0 X-Received: by 10.194.250.6 with SMTP id yy6mr11322819wjc.13.1385140096543; Fri, 22 Nov 2013 09:08:16 -0800 (PST) Received: by 10.227.134.196 with HTTP; Fri, 22 Nov 2013 09:08:16 -0800 (PST) In-Reply-To: References: Date: Fri, 22 Nov 2013 12:08:16 -0500 Message-ID: To: Tjerk Meesters Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c1ba4a6b32b104ebc70fed Subject: Re: [PHP-DEV] Power function as operator From: theanomaly.is@gmail.com (Sherif Ramadan) --001a11c1ba4a6b32b104ebc70fed Content-Type: text/plain; charset=ISO-8859-1 On Fri, Nov 22, 2013 at 11:58 AM, Tjerk Meesters 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 > I definitely like the idea of having pow as an operator. I've actually been wanting to copy that from Python for a while. I'm all for it. --001a11c1ba4a6b32b104ebc70fed--