Chapter 13 Device Logic (Pawn)
For example, if the "increment" function is defined as follows:
increment(&value, incr=1)
{
value += incr
}
The following function calls are all the same:
increment(a)
increment(a, _)
increment(a, 1)
Standard values for arguments that are transferred as a reference are helpful in making these parameters
optional. For example, if the "divmod" function was written to return the quotient and the rest as a parameter.
divmod(a, b, "ient=0, &remainder=0)
{
quotient = a / b
remainder = a % b
}
Based on the previous definition of the "divmod" function, the following function calls are all valid:
new p, q
divmod(10, 3, p, q)
divmod(10, 3, p, _)
divmod(10, 3, _, q)
divmod(10, 3, p)
divmod 10, 3, p, q
The next example adds the value of an array to another one. The values of the array are increased by one if
only one parameter is specified:
addvector(a[], const b[] = {1, 1, 1}, size = 3)
{
for (new i = 0; i < size; i++)
a[i] += b[i]
}
13.5 Differences to C
l
The pawn is missing the input mechanism of C and is an "integer-only" variant of C. There are no
structures or unions. Floating point support must be implemented with user-defined operators and the
help of native functions.
l
The syntax for floating point values is stricter than that in C. Values such as ".5" and "6." are acceptable
in C but must be written as "0.5" and "6.0" in the pawn. The decimal point is optional in C. If an
exponent is included, then you can write "2E8" in C, however the pawn will not accept the capital letter
"E". Use the lower case letter "e". It requires a comma: e.g. "2.0e8" (see "Numerical constants" on
page 214).
Rev. 05
231
Summary of Contents for myDatalogEASY V3
Page 2: ......
Page 13: ...Chapter 2 Declaration of conformity Chapter 2 Declaration of conformity Rev 05 13 ...
Page 14: ......
Page 42: ......
Page 76: ......
Page 88: ......
Page 102: ......
Page 110: ......
Page 116: ......
Page 234: ......
Page 244: ......
Page 252: ......
Page 254: ......
Page 266: ......
Page 276: ......