diff options
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/manual/manual.of b/manual/manual.of index 3902f2f3..8b5e5d93 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -1538,9 +1538,6 @@ except that its value is @emph{closed} whenever the variable | |||
1538 | goes out of scope, including normal block termination, | 1538 | goes out of scope, including normal block termination, |
1539 | exiting its block by @Rw{break}/@Rw{goto}/@Rw{return}, | 1539 | exiting its block by @Rw{break}/@Rw{goto}/@Rw{return}, |
1540 | or exiting by an error. | 1540 | or exiting by an error. |
1541 | If a block ends in a tail call @see{functioncall}, | ||
1542 | all variables of the caller function go out of scope | ||
1543 | before the start of the callee function. | ||
1544 | 1541 | ||
1545 | To \emph{close} a value has the following meaning here: | 1542 | To \emph{close} a value has the following meaning here: |
1546 | If the value of the variable when it goes out of scope is a function, | 1543 | If the value of the variable when it goes out of scope is a function, |
@@ -2038,8 +2035,8 @@ A call of the form @T{f'@rep{string}'} | |||
2038 | is syntactic sugar for @T{f('@rep{string}')}; | 2035 | is syntactic sugar for @T{f('@rep{string}')}; |
2039 | that is, the argument list is a single literal string. | 2036 | that is, the argument list is a single literal string. |
2040 | 2037 | ||
2041 | A call of the form @T{return @rep{functioncall}} is called | 2038 | A call of the form @T{return @rep{functioncall}} not in the |
2042 | a @def{tail call}. | 2039 | scope of a to-be-closed variable is called a @def{tail call}. |
2043 | Lua implements @def{proper tail calls} | 2040 | Lua implements @def{proper tail calls} |
2044 | (or @emph{proper tail recursion}): | 2041 | (or @emph{proper tail recursion}): |
2045 | in a tail call, | 2042 | in a tail call, |
@@ -2049,13 +2046,15 @@ a program can execute. | |||
2049 | However, a tail call erases any debug information about the | 2046 | However, a tail call erases any debug information about the |
2050 | calling function. | 2047 | calling function. |
2051 | Note that a tail call only happens with a particular syntax, | 2048 | Note that a tail call only happens with a particular syntax, |
2052 | where the @Rw{return} has one single function call as argument; | 2049 | where the @Rw{return} has one single function call as argument, |
2053 | this syntax makes the calling function return exactly | 2050 | and it is outside the scope of any to-be-closed variable. |
2054 | the returns of the called function. | 2051 | This syntax makes the calling function return exactly |
2052 | the returns of the called function, | ||
2053 | without any intervening action. | ||
2055 | So, none of the following examples are tail calls: | 2054 | So, none of the following examples are tail calls: |
2056 | @verbatim{ | 2055 | @verbatim{ |
2057 | return (f(x)) -- results adjusted to 1 | 2056 | return (f(x)) -- results adjusted to 1 |
2058 | return 2 * f(x) | 2057 | return 2 * f(x) -- result multiplied by 2 |
2059 | return x, f(x) -- additional results | 2058 | return x, f(x) -- additional results |
2060 | f(x); return -- results discarded | 2059 | f(x); return -- results discarded |
2061 | return x or f(x) -- results adjusted to 1 | 2060 | return x or f(x) -- results adjusted to 1 |