Operatory

Operatory

W systemie jPALIO zdefiniowano wiele różnego rodzaju operatorów

Operatory arytmetyczne

Operatory logiczne

Operatory bitowe

Inne

Sposób użycia operatorów
$operator(argumenty)

Operator konkatenacji ciągów znaków poza wersją dwuargumentową posiada także wersję jednoargumentową, gdzie argumentem jest tablica ciągów znaków a wynikiem działania konkatenacja wszystkich ciągów znaków z tej tablicy

$+([ciąg1, ciąg2, ciąg3, ... ])

 

Operatory logiczne iloczynu i sumy logicznej poza wersją dwuargumentową posiadają również wersję jednoargumentową, gdzie argumentem jest tablica wyrażeń logicznych a wynikiem zastosowania operatora odpowiednio iloczyn i suma logiczna wszystkich wyrażeń z takiej tablicy.

Operator dzielenia poza wersją dwuargumentową posiada też wersję trójargumentową, w której trzeci argument określa pożądaną dokładność wyniku dzielenia (ilość miejsc po przecinku).

Operatory stanowią skrócony zapis wywołań określonych funkcji i w trakcie kompilacji są zamieniane na wywołania odpowiednich funkcji

+   funkcja add
–   funkcja subtract
*   funkcja multiply
/   funkcja divide
%   funkcja remainder
++  funkcja increment
––  funkcja decrement
&&  funkcja and
||  funkcja or
!   funkcja not
==  funkcja equals
!=  funkcja notEquals
<>  funkcja notEquals
<   funkcja lesser
<=  funkcja lesserOrEquals
>   funkcja bigger
>=  funkcja biggerOrEquals
&   funkcja bitwiseAnd
|   funkcja bitwiseOr
^   funkcja bitwiseXor
~   funkcja bitwiseNot
=   funkcja setParam
?   funkcja condition

Zatem przykładowo wywołanie

$+(2, 7)

 

jest równoważne z

$add(2, 7)

 

Przykłady

$// assign 5 to variable "z"
$=(z, 5)
$// incrementation
$++(z)
$// get variable value and place it in your HTML code
$z
$// calculation and put in the HTML the expression ((24 + 76) * 8.99)
$*($+(24, 76), 8.99)
$// assign 7 to variable "x"
$=(x, 7)
$// assign value of "x" devided by 14 to the nearest 1 decimal place to variable "y"
$=(y, $/((Long)$x, 14, 1))
$// assign string "def" to variable "t"
$=(t, "def")
$// concatenation of strings "abc" and "def" and put the result in HTML
$+("abc", "def")
$// assign to variable "t" result of concatenation "abc" string and variable "t" 
$=(t, $+("abc", (String)$t))
$// assigment to variable "s" result of concatenation "abc", "def" and "ghi" strings 
$// ciągów znaków "abc" , "def" i "ghi"
$=(s, $+(["abc", "def", "ghi"]))
$// assigment true value to "b" variable
$=(b, true)
$// calculate and place in your HTML code expression (~ b)
$!((Boolean)$b)
$// calculate and place in your HTML code expression (b? (True? ~ B))
$||((Boolean)$b, $&&(true, $!((Boolean)$b))) 
$// assigment 3 vaue to "i" varable
$=(i, 3)
$// putting in the HTML code letter "P" if the variable has a value even or N is not
$?($==($%((Long)$i, 2), 0), "P", "N")
$// assign current date to "today" variable
$=(today, sysdate)
$// assign number of seconds elapsed since the beginning of 2005 to the present to variable "s"
$=(s, $-((Date)$today, 01-01-2005 00:00:00))
$// put in HTML code number of days elapsed since the begining of 2005 to the present
$toLong($/((Long)$s, 86400))
$// assign array of arrays to tab2D
$=(tab2D, [[1, 2, 3], ["A", "B"]])
$// assign a second array of tables tab2D to table tab1D
$=(tab1D, (Object[])$tab2D[1])
$// put first element of the array tab1D to HTML code
$tab1D[0]