Re: Ternary operator enhancement for fluent code
| From: | Andi Gutmans | Date: | Sat, 01 Jul 2000 12:17:02 +0000 |
| Subject: | Re: Ternary operator enhancement for fluent code | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-23137@lists.php.net to get a copy of this message | ||
You are right. This construct is ambiguous. If we really want this feature we would need to find a different syntax for it.
Personally, I don't think I would like this added to the language. It's not such a big deal and I doubt you'll notice overall performance increase in your script.
Andi
At 01:44 PM 7/1/00 +0200, Jade Nicoletti wrote:
Hi, I basicly like that idea, so i've tried to implement it. I modified the bison input file and got an addional shift/reduce conflict. If I interpret this correcly, it meens that if the parser sees an ambiguous expression like--- Andi Gutmans <andi@zend.com> http://www.zend.com/$a ? $b ? $c : $dit doesn't exactly know what to do. The script writer could want it do behave like1. $a ? ($b ? $c : $d)_or_2. ($a ? $b) ? $c : $dBecause Bison's default resolution is to shift, it would go with the first one, (but I'm not absolutly shure). So the questions that arise are:i) Do we want more ambiguousity in our language, for the purpose of simplifying things?(A solution would be to use another operator, for example '??')ii) Do we want extentions in the language (syntax enhancements) at all? pro: simplifing things is a good thing in general if well done, it may lead to an easier understanding of php source code in this case: faster development in php faster execution cont: it may mess up core stuff-Jade. On Wed, Jun 28, 2000 at 04:11:57PM +0200, waldschrott wrote: @Core-devs: I´ve a little proposal, what about improving the ternary operator a bit. I like the ternary operator and I´ve used it very often, but there´s also a configuration I´ve used very often. This one: if (!$class=$val1) $class=$val2; what is ternary: $class = $val1 ? $val1 : $val2; what about if this would be possible: $class = $val1 ? $val2; using methods and so on the current syntax can become very long: $this->foo= $this->dfoo->foobie ? $this->dfoo->foobie : $this->dfoo->foobie2); what would be *a lot smaller* if so: $this->foo= $this->dfoo->foobie ? $this->dfoo->foobie2); this enhancement would be also *downwards compatible*, because the missing of : throws an error message, in my opinion it could also increase the *performance* if the middle term must not be evalulated twice fot the reason that it does not exist regards ps. in fact it´s no visible ternary operator anymore, it´s like a virtual ternary operator, consisting of two parts, you could name it twice operator if you like :) -- =========================================================================== ====Jade Nicoletti Nicoletti Net Services Tel. 01 240 4774 Geschäftsleitung Postfach 2519 Fax 01 240 4775 System-Administration 8021 Zürich ============================================[ Weitere Infos: http://nns.ch/ ]==