On 25/08/2024 22:09, Rowan Tommins [IMSoP] wrote:
On 25 August 2024 21:00:03 BST, Bilge<bi...@scriptfusion.com> wrote:
class Suspension {
/**
* @param int $delay Specifies the delay in milliseconds.
*/
public function suspend(int $delay = 1_000) {
var_dump($delay);
}
}
class MySuspension extends Suspension {
/**
* @param float|int|null $delay Specifies the delay in seconds.
*/
public function suspend(float|int|null $delay = null) {
parent::suspend((int)(($delay ?? 0) * 1000) ?: default);
}
}
new MySuspension()->suspend(2.2345); // int(2234)
Not only have I demonstrated the need to use multiplication or division to
change the scale, but also the need to cast.
Possibly something got lost as you redrafted the example, because as you've written it, neither the
multiplication nor the cast are applied to the value looked up by "default". The
parameter reduces to "(expression) ?: default", which I've already agreed is useful.
Great! I'm glad we're finally getting to this, because I think this is
what you, and everyone advocating for a restricted grammar, is actually
missing. You think you've caught me in some kind of "gotcha" moment, but
fair warning, I'm about to play my Uno Reverse card.
What you're saying is that, somehow, even though the default must be
constrained to a restricted subset of permissible grammars, it is still
acceptable to have unrestricted expressions in the other operands. So,
in this example, somehow `expr ?: default` is OK.This is simply
impossible and would cause catastrophic shift/reduce conflicts in the
grammar. If `default` is to live in a restricted subset of allowed
expression grammars, then it can only recurse with those same
restrictions, meaning /both/ operands of any operators are so
restricted. Ergo I do not need to demonstrate the usefulness of applying
other operators /directly/ to `default`, merely including them
/somewhere/ in the expression is sufficient to demonstrate they are
useful because at that point we're back to recursing the general
expression grammar (free of any restrictions), unless and until you're
willing to concede those particular operators I've just demonstrated the
useful application for should be entered into the arbitrarily-selected
restricted subset of grammars allowed to apply to `default`.
If you believe I am incorrect about this, I encourage you to submit a
(working) Bison patch to demonstrate how a restricted expression grammar
subset can still recurse with the unrestricted superset, then we can
start having this discussion more seriously.
Cheers, Bilge