Hi,
The statement 'return' in a closure is now returning from the scope that
evaluate the closure (evaluation scope).
It could have been in an other way.
It could mean return from the scope were the closure is create (define
scope).
May be it could be interesting to have a syntax for returning from the
define scope.
For example.
$findedElment = $myList->selectIfAbsent($fooo, function(){
return 'No item founded'; //Retrun from the define scope
})
//Do somthing with $findedElment
So I am asking if there has been some discussion on it or if it could
be added?
Thanks
--Mathieu Suen
Are you serious?
Op 3-5-2010 15:01, mathieu.suen schreef:
Hi,
The statement 'return' in a closure is now returning from the scope that
evaluate the closure (evaluation scope).
It could have been in an other way.
It could mean return from the scope were the closure is create (define
scope).May be it could be interesting to have a syntax for returning from the
define scope.
For example.$findedElment = $myList->selectIfAbsent($fooo, function(){
return 'No item founded'; //Retrun from the define scope
})
//Do somthing with $findedElmentSo I am asking if there has been some discussion on it or if it could be
added?Thanks
--Mathieu Suen
Hello,
Hi,
The statement 'return' in a closure is now returning from the scope that
evaluate the closure (evaluation scope).
It could have been in an other way.
It could mean return from the scope were the closure is create (define
scope).May be it could be interesting to have a syntax for returning from the
define scope.
For example.$findedElment = $myList->selectIfAbsent($fooo, function(){
return 'No item founded'; //Retrun from the define scope
})
//Do somthing with $findedElment
uh? Could you please provide a clear example of what you mean, in
contrast of how it works now.
"return" returns to just after the call, returning somewhere else
doesn't make much sense IMHO.
So I am asking if there has been some discussion on it or if it could be
added?Thanks
--Mathieu Suen
--
Etienne Kneuss
http://www.colder.ch
mathieu.suen wrote:
May be it could be interesting to have a syntax for returning from the
define scope.
For example.$findedElment = $myList->selectIfAbsent($fooo, function(){
return 'No item founded'; //Retrun from the define scope
})
//Do somthing with $findedElment
I think you actually misunderstand the difference in
http://en.wikipedia.org/wiki/Closure_%28computer_science%29#Differences_in_semantics
The way I read if the difference is wether it returns from the closure
function or the surrounding function calling it. Not the defining scope.
And no, it doesn't make sense in the PHP context IMHO.
- Chris
I think you actually misunderstand the difference in
http://en.wikipedia.org/wiki/Closure_%28computer_science%29#Differences_in_semanticsThe way I read if the difference is wether it returns from the closure
function or the surrounding function calling it. Not the defining scope.And no, it doesn't make sense in the PHP context IMHO.
- Chris
"returns from the closure function"
To go were?
I had maintain a smalltalk compiler.
I did not misunderstand the difference.
The Common Lisp implementation is the more explicit one.
For exemple:
(defun eval-l1 (fct) (funcall fct))
(defun bar (x) (eval-l1 #'(lambda () (return-from bar 45)))
x)
(bar 23) -> 45
When funcall is apply you do not return from eval-l1. You return from bar.
Which is the defining scope of the lanbda.
-- Mathieu Suen
I think you actually misunderstand the difference in
http://en.wikipedia.org/wiki/Closure_%28computer_science%29#Differences_in_semantics
The way I read if the difference is wether it returns from the closure
function or the surrounding function calling it. Not the defining
scope.And no, it doesn't make sense in the PHP context IMHO.
- Chris
"returns from the closure function"
To go were?I had maintain a smalltalk compiler.
I did not misunderstand the difference.The Common Lisp implementation is the more explicit one.
For exemple:(defun eval-l1 (fct) (funcall fct))
(defun bar (x) (eval-l1 #'(lambda () (return-from bar 45)))
x)(bar 23) -> 45
When funcall is apply you do not return from eval-l1. You return from bar.
Which is the defining scope of the lanbda.
So
<?php
$a = function() { return; }
$a();
echo "end";
?>
would it be an infinite loop? would it print end?
what about:
<?php
function foo($c) {
bar($c);
echo "f";
}
function bar($c) {
$c();
echo "b";
}
$c = function() { return; }
foo($c);
what would it print? "f"? "fb" ? nothing?
Please, if you want to propose design changes, make a decent proposal
first, add some examples, not simply "what if PHP did <vague>".
Best,
-- Mathieu Suen
--
Etienne Kneuss
http://www.colder.ch
I think you actually misunderstand the difference in
http://en.wikipedia.org/wiki/Closure_%28computer_science%29#Differences_in_semantics
The way I read if the difference is wether it returns from the closure
function or the surrounding function calling it. Not the defining
scope.And no, it doesn't make sense in the PHP context IMHO.
- Chris
"returns from the closure function"
To go were?I had maintain a smalltalk compiler.
I did not misunderstand the difference.The Common Lisp implementation is the more explicit one.
For exemple:(defun eval-l1 (fct) (funcall fct))
(defun bar (x) (eval-l1 #'(lambda () (return-from bar 45)))
x)(bar 23) -> 45
When funcall is apply you do not return from eval-l1. You return from bar.
Which is the defining scope of the lanbda.So
<?php
$a = function() { return; }$a();
echo "end";
?>would it be an infinite loop? would it print end?
what about:
<?php
function foo($c) {
bar($c);
echo "f";
}function bar($c) {
$c();
echo "b";
}
$c = function() { return; }foo($c);
what would it print? "f"? "fb" ? nothing?
This is an interesting question.
It depend on whether you consider your lanbda as a continuation.
The other safe possibility is to generate an error when you evaluate a
lambda
were the context has escape which is the case in your example.
But a would not change the semantic of "return" just chose an other keyword.
$c = function() { return-from-def-scope; }
Please, if you want to propose design changes, make a decent proposal
first, add some examples, not simply "what if PHP did<vague>".
No big deal, I don't want to make any proposition, I am just asking.
I am not using PHP as a language for fun.
Best,
-- Mathieu Suen
-- Mathieu Suen
On Mon, May 3, 2010 at 11:42 PM, Christian Schneider
cschneid@cschneid.com wrote:
mathieu.suen wrote:
May be it could be interesting to have a syntax for returning from the
define scope.
For example.$findedElment = $myList->selectIfAbsent($fooo, function(){
return 'No item founded'; //Retrun from the define scope
})
//Do somthing with $findedElmentI think you actually misunderstand the difference in
http://en.wikipedia.org/wiki/Closure_%28computer_science%29#Differences_in_semanticsThe way I read if the difference is wether it returns from the closure
function or the surrounding function calling it. Not the defining scope.
Mathieu is right in that it would return from the defining scope, but
it's important to note that when the closure is called the function
that defined the closure is still on the stack.
Consider the following example:
function f() { return function() { return; } }
$c = f();
$c();
If the semantics of Smalltalk were to apply, this would give an error,
because it's impossible to return from f() when the closure is being
called.
And no, it doesn't make sense in the PHP context IMHO.
I second that ;-) In terms of clarity I find that the ECMAScript
implementation is much clearer.
- Chris
--
--
Tjerk
On Mon, May 3, 2010 at 11:42 PM, Christian Schneider
cschneid@cschneid.com wrote:mathieu.suen wrote:
May be it could be interesting to have a syntax for returning from the
define scope.
For example.$findedElment = $myList->selectIfAbsent($fooo, function(){
return 'No item founded'; //Retrun from the define scope
})
//Do somthing with $findedElmentI think you actually misunderstand the difference in
http://en.wikipedia.org/wiki/Closure_%28computer_science%29#Differences_in_semanticsThe way I read if the difference is wether it returns from the closure
function or the surrounding function calling it. Not the defining scope.Mathieu is right in that it would return from the defining scope, but
it's important to note that when the closure is called the function
that defined the closure is still on the stack.Consider the following example:
function f() { return function() { return; } }
$c = f();
$c();If the semantics of Smalltalk were to apply, this would give an error,
because it's impossible to return from f() when the closure is being
called.And no, it doesn't make sense in the PHP context IMHO.
I second that ;-) In terms of clarity I find that the ECMAScript
implementation is much clearer.
Of course ECMAScript has the same semantic than PHP. :)
(for this particular point, I don't mean for the rest)
May be one could fink of a different syntax:
function() { return-from-def-scope; }
And that would also remove the ambiguity in your example:
function f() { return function() { return-from-def-scope; } }
- Chris
--
-- Mathieu Suen
mathieu.suen wrote:
May be it could be interesting to have a syntax for returning from the
define scope.
For example.$findedElment = $myList->selectIfAbsent($fooo, function(){
return 'No item founded'; //Retrun from the define scope
})
//Do somthing with $findedElmentI think you actually misunderstand the difference in
http://en.wikipedia.org/wiki/Closure_%28computer_science%29#Differences_in_semanticsThe way I read if the difference is wether it returns from the closure
function or the surrounding function calling it. Not the defining scope.And no, it doesn't make sense in the PHP context IMHO.
You need to give me more argument on that point.
- Chris
-- Mathieu Suen