ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-dev
php-dev
Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP
by Larry Garfield other posts by this author
Jun 20 2008 12:19PM messages near this date
Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP | Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP
On Fri, 20 Jun 2008 12:00:07 -0400, Robert Cummings <robert@[...].com>  wrote:

> > function foo($a, $b, &$c) global ($d, &$e) {
> >   // ...
> > }
> >
> > $myfunc = lambda($a, $b, &$c) lexical ($d, &$e) {
> >   // ...
> > }
> >
> > That puts all the information in the declaration line with parallel
>  syntax and semantics, and would even allow both by-val and by-ref usage
>  for both lexical and global values.  The following would then be exactly
>  equivalent functionality-wise:
> >
> > function foo() global (&$a) {
> >   // ...
> > }
> >
> > function foo() {
> >   global $a;
> >   // ...
> > }
> >
> > Is that too crazy an idea?
>  
>  I like that, and also like the parenthesis on both parameter listings
>  for greater readability. In a related question, would the following be a
>  natural extension?

Agreed to it being better with parens than without.

>  $myfun = lambda($a, $b, &$c) lexical ($d, &$e) global ($f, &$g){
>      // ...
>  }

I realized that right after I sent my last email.  Yes, that would be the logical implicatio
n, and it somewhat parallels class Foo extends Bar implements Baz.  It seems if lexical valu
es are going to have both by-val and by-ref uses at all, following the function parameter sy
ntax for it has the lowest wtf factor.  I don't see global and $GLOBALS going away any time 
soon, though.

Mind you, I have no idea what the above would do to the engine-level implementation.  I woul
d, however, much prefer explicit lexical declaration than implicit.  Implicit declaration in
 a "create variables on demand" language can have some very odd behaviors.  For instance, if
 you have a lambda that is declared in a function and has an internal variable it uses named
 $foo, and then 6 months later you add a $foo 20 lines up in the calling function, you now h
ave a very strange and difficult bug to track down that won't show up until the lambda is in
voked, which could be a long time later.

--Larry Garfield


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Thread:
Christian Seiler
Wez Furlong
Dmitry Stogov
Stanislav Malyshev
Alexander Wagner
Dmitry Stogov
Andi Gutmans
Christian Seiler
Lukas Kahwe Smith
Sebastian Bergmann
Marcus Boerger
Markus Fischer
Troels Knak-Nielsen
Christian Seiler
Dmitry Stogov
Larry Garfield
Christian Seiler
Dmitry Stogov
Christian Seiler
Lars Strojny
Stanislav Malyshev
Marcus Boerger
Lars Strojny
Troels Knak-Nielsen
Larry Garfield
Marcus Boerger
Dmitry Stogov
Andi Gutmans
Alexander Wagner
Andi Gutmans
Alexander Wagner
Alexander Wagner
Christian Seiler
Alexander Wagner
Lars Strojny
Dmitry Stogov
Marcus Boerger
Lars Strojny
Dmitry Stogov
Alexey Zakhlestin
Federico Lebron
Dmitry Stogov
Rodrigo Saboya
lenar
Larry Garfield
Stanislav Malyshev
Marcus Boerger
Alexander Wagner
Lars Strojny
Larry Garfield
Robert Cummings
Rodrigo Saboya
Alexander Wagner
Christian Seiler
Chris Stockton
Alexander Wagner
Troels Knak-Nielsen
Andi Gutmans
Marcus Boerger
Christian Seiler
Lukas Kahwe Smith
Gwynne Raskind
Andi Gutmans
Christian Seiler
Stanislav Malyshev
Kalle Sommer Nielsen
Troels Knak-Nielsen
Lars Strojny
Alexander Wagner
Stanislav Malyshev
Alexander Wagner
Andi Gutmans
Marcus Boerger
Kalle Sommer Nielsen
Troels Knak-Nielsen
Stanislav Malyshev
Alexey Zakhlestin
Chris Stockton
Alexey Zakhlestin
Gwynne Raskind
Stanislav Malyshev
Christian Seiler
Gwynne Raskind
Stanislav Malyshev
Richard Quadling
Christopher Jones
Marcus Boerger
Steph Fox
Christian Seiler
Marcus Boerger
Stanislav Malyshev
Lars Strojny
Christian Seiler
Stanislav Malyshev
Marcus Boerger
Marcus Boerger
Andrei Zmievski
Stanislav Malyshev
Stanislav Malyshev
Alexey Zakhlestin
Chris Stockton
Christian Seiler
Christian Seiler
Larry Garfield
Edward Z. Yang
Christian Seiler
Larry Garfield
Christian Seiler
Nathan Nobbe
Christian Seiler
Alexey Zakhlestin
Larry Garfield
Philip Olson

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved