Re: Ternary operator enhancement for fluent code
| From: | Jade Nicoletti | Date: | Sat, 01 Jul 2000 11:44:11 +0000 |
| Subject: | Re: Ternary operator enhancement for fluent code | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-23135@lists.php.net to get a copy of this message | ||
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
$a ? $b ? $c : $d
it doesn't exactly know what to do.
The script writer could want it do behave like
1. $a ? ($b ? $c : $d)
_or_
2. ($a ? $b) ? $c : $d
Because 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/ ]==