
Chapter 12 Device Logic (Pawn)
The following code example calls up the "addvector" function and adds five to each element of the "vect"
variables:
new vect[3] = [ 1, 2, 3 ]
addvector(vect, [5, 5, 5], 3)
/* vect[] now comprises the values 6, 7 and 8 */
12.5.7.2 Named parameters versus fixed parameters
In the previous examples, the order of the parameters in a function call were important as each parameter
was copied to the same position of the function parameter. For example, in the "weekday" function (defined
below), the expression "weekday(12 ,31, 1999)" would be used to get the weekday of the last day of the last
century.
weekday(month, day, year)
{
/* returns the day of the week: 0=Saturday, 1=Sunday, etc. */
if (month <= 2)
month += 12, --year
new j = year % 100
new e = year / 100
return (day + (month+1)*26/10 + j + j/4 + e/4 - 2*e) % 7
}
The date format changes depending on the culture and country, while the USA use the month/day/year
format, European countries frequently use the day/month/year format and technical publications use the
year/month/day (ISO/IEC 8824) format. In other words, the sequence of the parameters is not "standardised"
or "normal". For this reason, there is an alternative way of transferring parameters to a function, by using
"named parameters". These are illustrated in the next example (the function was declared in the same way as
the previous example).
new wkday1 = weekday( .month = 12, .day = 31, .year = 1999)
new wkday2 = weekday( .day = 31, .month = 12, .year = 1999)
new wkday3 = weekday( .year = 1999, .month = 12, .day = 31)
In "named parameters", a dot (".") precedes the name of the argument. The argument of the function can be
set to any expression that is valid for the argument. In the event of a named parameter, the equals sign ("=")
does not refer to an allocation but instead links the expression with a function argument.
Fixed and named parameters can be mixed together, although the fixed parameters must be specified before
the named parameters.
12.5.7.3 Standard values of function arguments
A function argument can have a standard value. The standard value of a function argument must be a
constant. To specify a standard value, add an equals sign ("=") and the value to the name of the parameter.
The standard value is adopted if a placeholder is specified instead of a valid function parameter during a
function call. The placeholder is the underscore character ("_"). The argument placeholder is only valid for
parameters with a standard value.
The right argument placeholders can be removed from the list of arguments.
Rev. 01
181
Содержание myDatalogEASY IoTmini
Страница 2: ......
Страница 11: ...Chapter 2 Declaration of conformity Chapter 2 Declaration of conformity Rev 01 11 ...
Страница 12: ......
Страница 34: ......
Страница 66: ......
Страница 78: ......
Страница 82: ......
Страница 186: ......
Страница 194: ......
Страница 196: ......
Страница 202: ......
Страница 205: ...Chapter 19 Document history Chapter 19 Document history Rev Date Changes 01 28 08 2020 First version Rev 01 205 ...
Страница 206: ......
Страница 208: ......