Update page 'P# 1.0 Draft Specification'
@@ -138,9 +138,11 @@ Callbacks can be denoted in P# language by callback type hint. This pseudo-type
|
|||||||
callback $callme = int() {
|
callback $callme = int() {
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
int $var = $callme();
|
int $var = $callme(); // value is 7
|
||||||
%>
|
%>
|
||||||
|
|
||||||
|
What is more, P# allows a language constructs in the context of a function call:
|
||||||
|
|
||||||
<%
|
<%
|
||||||
callback $echo = 'print';
|
callback $echo = 'print';
|
||||||
$echo('Hello world'); // Calls the print function on the fly
|
$echo('Hello world'); // Calls the print function on the fly
|
||||||
@@ -251,6 +253,15 @@ TODO
|
|||||||
TODO
|
TODO
|
||||||
|
|
||||||
## 8. Object-Oriented Programming
|
## 8. Object-Oriented Programming
|
||||||
TODO
|
### 8.X. Anonymous Functions
|
||||||
|
Anonymous functions, also known as closures, allow the creation of functions which have no specified name. In P#, anonymous function arguments can take a default value exactly like standard function arguments. The default value associated with the function argument can be any complex expression including function calls.
|
||||||
|
|
||||||
|
<%
|
||||||
|
callback $anon = void(string $msg = 'Hello' + ' ' + 'World!' /* Complex expression */){
|
||||||
|
print($msg + PS_EOL);
|
||||||
|
}; // semicolon is required here
|
||||||
|
$anon(); // You should see 'Hello World!'
|
||||||
|
$anon('Welcome guest!'); //You should see 'Welcome guest!'
|
||||||
|
%>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user