removed outdated doc paragraph about functions
This commit is contained in:
@@ -275,46 +275,4 @@ As an example, the `print` function always returns `none`
|
|||||||
|
|
||||||
```py
|
```py
|
||||||
print(print()); # none
|
print(print()); # none
|
||||||
```
|
|
||||||
|
|
||||||
Functions are always "pure", in the sense that the only values that the
|
|
||||||
function body can access are the ones provided as arguments. Usually in
|
|
||||||
other languages, functions can access the global scope and the parent
|
|
||||||
scope (closures). There's no such mechanism in this language (at the
|
|
||||||
moment).
|
|
||||||
|
|
||||||
The only exception is made for the "built in" variables, which are
|
|
||||||
provided by the runtime of the language and can't be modified by the
|
|
||||||
user. The print function is one of these variables. One may override
|
|
||||||
these variables but the effect only lasts for the lifetame of the
|
|
||||||
context local to the assignment.
|
|
||||||
|
|
||||||
```py
|
|
||||||
# Overwrite the print variable inside the global
|
|
||||||
# scope..
|
|
||||||
print = 5;
|
|
||||||
|
|
||||||
# The reference to the print function is lost
|
|
||||||
# withing this scope.
|
|
||||||
|
|
||||||
fun test()
|
|
||||||
{
|
|
||||||
# If the previous assignment were to overwrite the
|
|
||||||
# print function globally, the next statement would
|
|
||||||
# fail because the value 5 isn't a function. But
|
|
||||||
# it doesn't fail!
|
|
||||||
print('Not overwritten here!\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
test();
|
|
||||||
|
|
||||||
# We can take the reference to the print function
|
|
||||||
# by taking it from a function!
|
|
||||||
|
|
||||||
fun get_print_back()
|
|
||||||
return print;
|
|
||||||
|
|
||||||
print = get_print_back();
|
|
||||||
|
|
||||||
print('Hei! Print is back!\n');
|
|
||||||
```
|
```
|
||||||
@@ -9,29 +9,4 @@ fun fail(p)
|
|||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#fail(0);
|
fail(0);
|
||||||
|
|
||||||
defined_globally = 111;
|
|
||||||
|
|
||||||
fun A()
|
|
||||||
{
|
|
||||||
print('Hello from A!\n');
|
|
||||||
|
|
||||||
defined_in_A = 10;
|
|
||||||
|
|
||||||
fun B()
|
|
||||||
{
|
|
||||||
defined_in_B = 33;
|
|
||||||
|
|
||||||
print('Hello from B!\n');
|
|
||||||
print('defined_globally = ', defined_globally, '\n');
|
|
||||||
print('defined_in_A = ', defined_in_A, '\n');
|
|
||||||
print('defined_in_B = ', defined_in_B, '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
B();
|
|
||||||
|
|
||||||
print('defined_in_B = ', defined_in_B, '\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
A();
|
|
||||||
Reference in New Issue
Block a user