Using Nasal functions: Difference between revisions

Jump to navigation Jump to search
m
obviously, it's sorta "good" for the wiki that the forum is being maintained ;-)
m (→‎Function bodies: li'l hint/intro to function arguments as local variables)
m (obviously, it's sorta "good" for the wiki that the forum is being maintained ;-))
Line 2: Line 2:


'''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.
'''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.
So, to put things in layman's terms, imagine your function like a recipe in a cooking book - instead of always having to write down the recipe, you just open the cooking book, "jump" to the corresponding page, "execute" the recipee and then "return" to where you left off earlier.
Conceptually, a function works pretty much like that: it has a starting point where its instructions start, and prior to going there, it will note down where to continue afterwards - that way, it is possible to call functions in a nested fashion, i.e. in terms of our previous cooking analogy, just imagine a sophisticated meal with lots of different dishes, where each dish would be represented by a different function, and where certain steps  may use "helper function" (read: recipes).


== Simple examples ==
== Simple examples ==

Navigation menu