20,741
edits
m (todo: should probably introduce anonymous/unnamed functions first (retained scope, closures)) |
|||
Line 1: | Line 1: | ||
{{Template:Nasal Navigation}} | {{Template:Nasal Navigation}} | ||
'''What is a function?''' A "function" is a piece of code that can be easily used repeatedly (without repeating the same code over and over again using your editor's copy&paste function), this is achieved by associating a symbolic name with the piece of code, such as "print", "show" or "get", setprop, getprop for example - here's a simple function that squares a number: | <syntaxhighlight lang="nasal"> | ||
(func() { | |||
print("Hello World"); | |||
}) | |||
(); | |||
</syntaxhighlight> | |||
'''What is a named function?''' A "function" is a piece of code that can be easily used repeatedly (without repeating the same code over and over again using your editor's copy&paste function), this is achieved by associating a symbolic name with the piece of code, such as "print", "show" or "get", setprop, getprop for example - here's a simple function that squares a number: | |||
<syntaxhighlight lang="nasal"> | <syntaxhighlight lang="nasal"> |