Hi,

1) please don't abuse another thread for something completely unrelated,
that makes tracking things really hard.
2) Most of you want should be doable with 5.3's anonymous
functions/closures.
3) More than that isn't really planned at the moment.

johannes

On Tue, 2009-08-18 at 12:46 +0300, Ville Jungman wrote:
> 1) it would be fun if code recycling was easier. nowadays extracting a
> function from code is sometimes complicated if you need to reuse it
> elsewhere.
> 
> For example you have this ...
> 
> while($numbers as $value){
>    while(...){
>       while(...){
>          ...
>          do_something_with($value);
>          ...
>       }
>    }
> }
> 
> ... but you would like to use the inner loop also elsewhere. Just
> define it as a function ...
> 
> while($numbers as $value){
>    while(...){
>       while(...){
>          do_something_with($value);
>          do_something_with($value + 1);
>       } as function inner_loop($value);
>    }
> }
> 
> ... and go ...
> 
> inner_loop(3);
> 
> 
> 
> Or you have a function below and would like to use only the if-part
> elsewhere. Again define that as a function:
> 
> function something($value){
>    something();
>    foreach(...){
>       if(...){
>          do_something_with($value);
>          do_something_with($value + 1);
>       } as function snippet($value);
>    }
>    something();
> }
> 
> ... and call it ...
> snippet(3);
> 
> 
> ---
> 
> 
> 2) i think it might be useful if all php internal commands returned
> some value(s)
> 
> something like this could do ...
> 
> while(
>    if($x){
>       return array(1,2);
>    }else{
>       return array(3,4,5);
>    } as $value
> ){
>    do_something_with($value);
> }
> 
> ... or even ...
> 
> $selection_array =
>    while(
>       if($x){
>          return array(1,2);
>       }else{
>          return array(3,4,5);
>       } as $value
>    ){
>       do_something_with($value);
>       return if($value == 2 ||  $value == 4){
>          return $value;
>       }
>    }
> ;
> 
> this would make code more straightforward and easier to understand
> (when you get used to it). and enables "a maximum degree of
> recursivability that can lead to impressive solutions some areas".
> also think about pipes in shell.
> 
> (the return idea is stolen from postgres pl/pgsql. loop commands
> (while, foreach etc) return always arrays.)
> 
> see also:
> http://www.rebol.net/r3blogs/0024.html
> http://www.mail-archive.com/beginn...@perl.org/msg47298.html
> http://www.postgresql.org/docs/8.0/interactive/plpgsql-control-structures.html
> 
> ---
> Ville
> 


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to