Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
fun [2019/12/09 21:25] – [Functions with no parameters] neilsfun [2020/08/07 09:02] (current) – correct FUNC to FUN thraka
Line 12: Line 12:
 The ''FUN ... ENDFUN'' directives are used for defining a user function. Functions are similar to procedures with the exception that: The ''FUN ... ENDFUN'' directives are used for defining a user function. Functions are similar to procedures with the exception that:
  
-  * They **must** return a value +  * They **must** return a value. 
-  * They can be called from within an expression+  * They can be called from within an expression
 + 
 +The name of the function and the name of a parameter **can't** start with a command or directive name. For example, you can't define a function named ''repeatnumber'' as ''REPEAT'' is a command. Likewise, you can't name a parameter ''funparameter1'' as ''FUN'' is a directive.
  
 ===== Defining functions ===== ===== Defining functions =====
Line 47: Line 49:
 If you want a routine that does not return a value, use [[procedures|]] instead. If you want a routine that does not return a value, use [[procedures|]] instead.
  
-==== Functions with no parameters ====+==== Parameterless functions ====
  
 You can omit the parameter list, but bear in mind that you still have to write the empty parentheses: You can omit the parameter list, but bear in mind that you still have to write the empty parentheses:
Line 58: Line 60:
 You can call a function from within an expression by using the function name, sigil and the argument list in parentheses, for example: You can call a function from within an expression by using the function name, sigil and the argument list in parentheses, for example:
  
-  let x! = my_function!(a, b!)+  let x! = my_function!(a, b!) * 2
      
 Note that in the example above ''my_function!'' is a function that returns a byte and accepts an integer and a byte as arguments. Note that in the example above ''my_function!'' is a function that returns a byte and accepts an integer and a byte as arguments.
  
 Important note: you must pass exactly the same amount of parameters and the parameter types must match those in the function definition. Important note: you must pass exactly the same amount of parameters and the parameter types must match those in the function definition.
 +
 +===== Recursion =====
 +
 +While procedures do support direct recursion, functions don't.