Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-26 Thread Lars Strojny
Hi everyone, On 24 Sep 2014, at 23:17, Rowan Collins rowan.coll...@gmail.com wrote: switch ( $number ) use ( === ) { [...] switch ( $age ) use ( ) { [...] switch ( calculate_age($birth_date, $departure_date) as $age_at_departure ) use ( ) { [...] switch ( $product ) use ( instanceOf ) {

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-26 Thread Rowan Collins
Lars Strojny wrote (on 26/09/2014): Hi everyone, On 24 Sep 2014, at 23:17, Rowan Collins rowan.coll...@gmail.com wrote: switch ( $number ) use ( === ) { [...] switch ( $age ) use ( ) { [...] switch ( calculate_age($birth_date, $departure_date) as $age_at_departure ) use ( ) { [...]

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-26 Thread Lars Strojny
Hi Rowan, On 26 Sep 2014, at 18:11, Rowan Collins rowan.coll...@gmail.com wrote: [...] Without the additional guarantees provided by a purely functional environment, that's really just inverting the function header and if statement. Adding an extra case to that still means repeating the

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-26 Thread Rowan Collins
On 26 September 2014 18:41:02 GMT+01:00, Lars Strojny l...@strojny.net wrote: That is exactly my point: instead of optimising the switch/case construct which is good enough as if/elseif/else replacement I feel our time would be better spent on thinking of polymorphism, guards and pattern matching.

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-25 Thread Rowan Collins
Rowan Collins wrote (on 24/09/2014): On 24/09/2014 22:33, Andrea Faulds wrote: On 24 Sep 2014, at 22:17, Rowan Collins rowan.coll...@gmail.com wrote: Perhaps rather than a magic function or constant, though, the switch statement could be extended with an as argument, which would store the

RE: [PHP-DEV] Little switch improvement: get the used variable

2014-09-25 Thread Christian Stoller
Mit freundlichen Grüßen aus Paderborn Christian Stoller Softwareentwicklung LEONEX Internet GmbH Technologiepark 20 33100 Paderborn Tel: 05251-14807-27 Fax: 05251-14807-30 HRB 8694 AG Paderborn Geschäftsführer: Stephan Winter

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-25 Thread Rowan Collins
Christian Stoller wrote (on 25/09/2014): Am I missing something equally obvious there? Or just, it doesn't interest people much as an idea? Why should one add a new operator in that context if it is already possible with assigments as expressions? This makes the language more complex without

RE: [PHP-DEV] Little switch improvement: get the used variable

2014-09-25 Thread Christian Stoller
From: Rowan Collins [mailto:rowan.coll...@gmail.com], Sent: Thursday, September 25, 2014 12:31 PM Sorry, I was talking about this bit: Currently, switch always uses a loose comparison (==), so cannot distinguish between case 3 and case 3.0. Occasionally, it would be nice to switch on a

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-25 Thread Rowan Collins
Christian Stoller wrote (on 25/09/2014): From: Rowan Collins [mailto:rowan.coll...@gmail.com], Sent: Thursday, September 25, 2014 12:31 PM Sorry, I was talking about this bit: Currently, switch always uses a loose comparison (==), so cannot distinguish between case 3 and case 3.0.

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-24 Thread Rowan Collins
On 23/09/2014 08:29, Sanford Whiteman wrote: The `get_the_used_switch_variable()` is just a placeholder, name can be changed to something natural...maybe a constant. I feel this has diminished utility once you consider that the switch variable is actually an expression and could well include

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-24 Thread Sanford Whiteman
You can already do: $a = 1; $b = 2; switch( $switch_value = $a + $b ) { default: print $switch_value; } No magic or new operator required -- S. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-24 Thread Andrea Faulds
On 24 Sep 2014, at 22:17, Rowan Collins rowan.coll...@gmail.com wrote: Perhaps rather than a magic function or constant, though, the switch statement could be extended with an as argument, which would store the evaluated expression into a normal variable, allowing nesting, and easier

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-24 Thread Rowan Collins
On 24/09/2014 22:33, Andrea Faulds wrote: On 24 Sep 2014, at 22:17, Rowan Collins rowan.coll...@gmail.com wrote: Perhaps rather than a magic function or constant, though, the switch statement could be extended with an as argument, which would store the evaluated expression into a normal

Re: [PHP-DEV] Little switch improvement: get the used variable

2014-09-23 Thread Sanford Whiteman
Hi Martin, The `get_the_used_switch_variable()` is just a placeholder, name can be changed to something natural...maybe a constant. I feel this has diminished utility once you consider that the switch variable is actually an expression and could well include multiple $variables. Plus there's