User Tools

Site Tools


at:tutorial:basic

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
at:tutorial:basic [2007/04/17 17:04] tvcutsemat:tutorial:basic [2007/04/17 17:08] tvcutsem
Line 148: Line 148:
 This example also illustrates how a function can be made "private" by means of lexical scoping rules. Variables and functions defined locally to functions are only visible in the scope of the function where there were defined. Note that the local ''inner'' function is only visible inside the ''fac'' function and its nested scopes. This example also illustrates how a function can be made "private" by means of lexical scoping rules. Variables and functions defined locally to functions are only visible in the scope of the function where there were defined. Note that the local ''inner'' function is only visible inside the ''fac'' function and its nested scopes.
    
 +
 ==== Variable-Length Argument Functions ==== ==== Variable-Length Argument Functions ====
  
Line 177: Line 178:
 In that case, the //sum// function still accepts an arbitrary number of arguments as long as two arguments are supplied. //a// and //b// are considered as mandatory arguments of the argument list.  In that case, the //sum// function still accepts an arbitrary number of arguments as long as two arguments are supplied. //a// and //b// are considered as mandatory arguments of the argument list. 
  
-A function can also declare optional arguments as shown below. Optional arguments can be omitted in a function call. Internally, the default value provided in their definition is passed as the argument to the function. +A function can also declare optional arguments as shown below. Optional arguments can be omitted in a function call. If this is the case, the default expression provided in their definition is evaluated and passed as argument to the function instead.
 <code> <code>
 >def incr( number, step := 1){ number + step} >def incr( number, step := 1){ number + step}
Line 186: Line 187:
 >>6 >>6
 </code> </code>
 +
 +As is customary in languages with the above parameter passing semantics, AmbientTalk requires mandatory parameters to be defined //before// optional parameters, which should in turn be defined //before// a variable-argument parameter, if any.
  
 ===== Closures ===== ===== Closures =====
at/tutorial/basic.txt · Last modified: 2020/02/09 22:05 by elisag