Difference between revisions of "Expression Syntax"

(added a few more hyperlinks)
(Rewrite of function syntax section)
Line 1: Line 1:
 
= Function Calls =
 
= Function Calls =
  
Analytica contains many [[Alphabetical_Function_List | built-in functions]], and you can extend these with [[User-Defined Functions]].  The syntax for calling an expression is:
+
Analytica contains many [[Alphabetical_Function_List | built-in functions]], and you can extend these with [[User-Defined Functions]].  The standard ''position-based'' syntax for the parameters of a function is:
  
  F(A,B,C)
+
  F(A, B, C)
  
where the parameter values A,B, and C may themselves be Analyica expressions.  For most (but not all) built-in functions and all [[User-Defined Functions]], parameter values can be listed either by position or by name, or a combination.  For example, the following four examples are all identical calls to the function [[Uniform]], specifying parameters by position, by name, and by a combination:
+
where the parameter values A, B, and C may themselves be expressions.   
  
[[Uniform]]( 1,100,true )
+
For most, but not all, built-in functions and all [[User-Defined Functions]], you can also used a ''name-based'' syntax for parameters. These examples show four ways to call function [[Uniform]] with the same parameter values, using position-based syntax, name-based syntax, and a combination:
[[Uniform]]( min:1, max:100, Integer:true )
 
  [[Uniform]]( Integer:true, min:1, max:100 )
 
[[Uniform]]( 1,100,Integer:true )
 
  
Each of these function calls defines a uniform distribution on the integers from 1 to 100. When specifying a parameter by name, the parameter name is followed by a colon, which is then followed by the parameter value.  
+
Uniform(1, 100, true)  --- position-based syntax
 +
  Uniform(min:1, max:100, integer: true)  --- name-based syntax
 +
Uniform(Integer: true, min:1, max: 100)  --- name-based syntax
 +
Uniform(1, 100, integer: true) --- mixed syntax
  
When parameters are specified by name, they can be specified in any order, as the third example demonstratesHowever, once one parameter is specified by name, all parameters that follow must be specified by name.
+
Name-based syntax means you specify the parameter by name, followed by colon, followed by the a number or expression giving its value. When you specify parameters by name, you can list them in any order, as in the third example.  Using mixed syntax, you can specify initial parameters by position, but after you specify a parameter by name, you must also specify all following parameters by name.
  
When a function expects an index or variable parameter, an object identifier must occupy that parameter positionThe [[Dot_operator::A.I#Dot_Operator:_A.I|dot-operator]] syntax, A.I,may also be usedHowever, arbitrary expressions, including function calls, cannot appear as a value to an index or variable parameter.   
+
If a function expects a parameter to be an index or variable, you must give it the identifier of a variable or indexYou can specify an index using the [[Dot_operator::A.I#Dot_Operator:_A.I|dot-operator]] syntax -- e.g. A.I.  But, in these cases, you may not use arbitrary expressions, including function calls, as the value.   
  
Parameter values are evaluated in various ways when a function call is evaluated, depending on the specific [[Function Parameter Qualifiers|parameter qualifiers]] in the declaration for the function, and on the [[Evaluation Modes|evaluation mode]] when the function is evaluated.
+
Functions evaluate ("call") their parameters in various ways, as specified by the[[Function Parameter Qualifiers|parameter qualifiers]], and on the [[Evaluation Modes|evaluation mode]] when the function is evaluated.
  
 
= Operator Precedence =
 
= Operator Precedence =

Revision as of 17:58, 17 April 2007

Function Calls

Analytica contains many built-in functions, and you can extend these with User-Defined Functions. The standard position-based syntax for the parameters of a function is:

F(A, B, C)

where the parameter values A, B, and C may themselves be expressions.

For most, but not all, built-in functions and all User-Defined Functions, you can also used a name-based syntax for parameters. These examples show four ways to call function Uniform with the same parameter values, using position-based syntax, name-based syntax, and a combination:

Uniform(1, 100, true)   --- position-based syntax
Uniform(min:1, max:100, integer: true)  --- name-based syntax
Uniform(Integer: true, min:1, max: 100)  --- name-based syntax
Uniform(1, 100, integer: true)  --- mixed syntax

Name-based syntax means you specify the parameter by name, followed by colon, followed by the a number or expression giving its value. When you specify parameters by name, you can list them in any order, as in the third example. Using mixed syntax, you can specify initial parameters by position, but after you specify a parameter by name, you must also specify all following parameters by name.

If a function expects a parameter to be an index or variable, you must give it the identifier of a variable or index. You can specify an index using the dot-operator syntax -- e.g. A.I. But, in these cases, you may not use arbitrary expressions, including function calls, as the value.

Functions evaluate ("call") their parameters in various ways, as specified by theparameter qualifiers, and on the evaluation mode when the function is evaluated.

Operator Precedence

Some operations in Analytica are parsed with a higher binding precedence than other operators. For example, exponentiation (^) binds more tightly than multiplication (*) and division (/), which binds more tightly than addition (+) and subtraction (-). Therefore, the following expression

1 / 2 * 3 - 4 / 5 ^ 6 + 7

would parse as

( ( 1 / 2 ) * 3 ) - ( 4 / ( 5 ^ 6 ) ) + 7

The following list shows the binding precedence of Analytica operators, with the highest precedence operators at the top. Those operators in the same bullet have the same level of precedence:

  • Parentheses: ( ... )
  • Function calls
  • Not
  • @I , \A, \[I]A, #R.
  • A.I
  • A[I=x]
  • Attrib of Obj
  • ^
  • - (unary)
  • *, /
  • +, - (binary minus)
  • m..n
  • =, <=, >=, <, >, <>
  • And, Or
  • &
  •  :=
  • If..Then..Else, Ifall..Then..Else, IfOnly..Then..Else
  • sequence of statements (;), comma separation of elements or parameters (,)
Comments


You are not allowed to post comments.