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
functions [2019/05/16 10:25] neilsfunctions [2019/12/12 19:35] (current) – [Functions] neils
Line 1: Line 1:
 ====== Functions ====== ====== Functions ======
  
-**XC=BASIC** offers several built-in functions. In addition, you can use the [[USR|USR() function]] to call your own machine language function.+Functions in **XC=BASIC** are procedures that return a value of a certain type.
  
-===== Return type =====+**XC=BASIC** supports:
  
-Some functions may return miscellaneous types and you have to explicitly tell the compiler which type you require. Just like with variables, the return type of a function is denoted with a [[https://en.wikipedia.org/wiki/Sigil_(computer_programming)|sigil]]. For example, the [[ABS|ABS function]] can return an integer or a float:+  * Several built-in functions 
 +  * The [[USR|USR() function]] to call a machine language function 
 +  * [[fun|User-defined functions]] (since version 2.2) 
 + 
 + 
 +===== Calling overloaded functions ===== 
 + 
 +Some of the built-in functions are overloaded and thus they may return values of miscellaneous types. When calling a function, you must explicitly specify which type you wish to call by appending the right [[https://en.wikipedia.org/wiki/Sigil_(computer_programming)|sigil]] to the function name. For example, the [[ABS|ABS function]] can return an integer or a float:
  
   myInt = abs(-5)   myInt = abs(-5)
   myFloat%= abs%(-3.14)   myFloat%= abs%(-3.14)
  
-Another example is [[RND|RND]] that can return three types:+Another example is [[RND|RND]] that can return three different types:
  
   myRandomByte!  = rnd!()   myRandomByte!  = rnd!()
   myRandomInt    = rnd()   myRandomInt    = rnd()
   myRandomFloat% = rnd%()   myRandomFloat% = rnd%()
 +  
 +Note: user defined functions may not be overloaded.
 +===== Defining user functions =====  
 +
 +Please refer to the [[fun|FUN ... ENDFUN]] directive for details.