lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Your program may also run in a console that will automatically print itself the last value computed when the code ends and may run it again in a loop if the program does not return a nil value, by calling the implied function again with that last value.
In that case, the program is a single _expression_ that does not have to be printed in the program itself; the program will terminate in just a few microseconds, and the user will actually wait for the screen to be refreshed (typically about 15 ms on average on a 60Hz monitor), before the user has even released the "enter" key or the click on the "run" button, and the user will still need about 30 ms to assimilate visually the value displayed (the console may only print the last non-nil value returned and not every value returned by the loop (which is equivalent to a trailing call).

But having to return a specific nil costs some bytes, it is simpler to just call the function recursively for a predefined number of steps, using  explicit function calls as "f(f(f(f(f(some _expression_)))))". The console will print that returned value itself, without having to insert the "out" or "=" statement which is implied by the console, just like the global name "f" of the function we can call inside the program will be implied (the console predefines that in the global environment with your "C" constant that must be defined somewhere (in the specific console program you use to run your input code, which can never run "alone").