Update page 'P# 1.0 Draft Specification'

2018-07-17 10:06:14 +02:00
parent e6409d8b0e
commit 4b1d4b9329

@@ -138,9 +138,11 @@ Callbacks can be denoted in P# language by callback type hint. This pseudo-type
callback $callme = int() {
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';
$echo('Hello world'); // Calls the print function on the fly
@@ -251,6 +253,15 @@ TODO
TODO
## 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!'
%>