Using Nasal functions: Difference between revisions

Jump to navigation Jump to search
m
→‎Anonymous function arguments: remove my old comments. P.S.: Hooray seems to be in a SCNR attitude today ;), and yet I say... SCNR :lol:
m (→‎Anonymous function arguments: remove my old comments. P.S.: Hooray seems to be in a SCNR attitude today ;), and yet I say... SCNR :lol:)
Line 88: Line 88:


Also, Nasal being a functional programming language, all passed arguments will be local to the corresponding scope. If you want to modify state in a function, you'll preferably return new state to the caller.
Also, Nasal being a functional programming language, all passed arguments will be local to the corresponding scope. If you want to modify state in a function, you'll preferably return new state to the caller.
As previously mentioned, parenthesis are generally optional, and func, func(), and func(arg...) are identical. However, what is not stated anywhere is there is always an invisible arg... after any argument list, thus func(a) and func(a, arg..) are actually the same! This means that while function's arguments may underflow (have too few), they will never overflow, instead they will just fill in the arg vector. The only way to prevent this is to manually die on the arg vector having any size, which IMO could be a bad thing depending on the way the error is printed (i.e. if they don't show the same thing, like "Nasal runtime error" and "Nasal parse error", but also the fact that the trace-back would not show the right line, as it would show the die() call not the place where it was called from).
As a side note, when arg... is not explicitly declared (e.g. func or func(a)), caller(0)[0] does not show "arg" and yet does not result in an undefined symbol error when I try and return arg. Why is this?


==Named function arguments==
==Named function arguments==
395

edits

Navigation menu