From fba9698b8b2c239789069ca788a519e8af815bcc Mon Sep 17 00:00:00 2001 From: Francesco Cozzuto Date: Wed, 1 Dec 2021 00:11:57 +0100 Subject: [PATCH] removed outdated doc paragraph about functions --- docs/language.md | 42 ---------------------------------------- samples/deepfailure.noja | 27 +------------------------- 2 files changed, 1 insertion(+), 68 deletions(-) diff --git a/docs/language.md b/docs/language.md index d857006..ecc39a7 100644 --- a/docs/language.md +++ b/docs/language.md @@ -275,46 +275,4 @@ As an example, the `print` function always returns `none` ```py 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'); ``` \ No newline at end of file diff --git a/samples/deepfailure.noja b/samples/deepfailure.noja index 05e5701..6584a67 100644 --- a/samples/deepfailure.noja +++ b/samples/deepfailure.noja @@ -9,29 +9,4 @@ fun fail(p) assert(false); } -#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(); \ No newline at end of file +fail(0); \ No newline at end of file