Operators and Expressions

Pikt provides the usual operators, and a few not so usual.  Most of them are borrowed from Perl, but several are unique to Pikt.

LOGICAL       DESCRIPTION

&&            logical AND
||            logical OR
!             logical NOT
( )           logical grouping
(Note that for config file #if-#endif preprocessing, you use the & and | set operators, not && or ||.)

The && and || operators use short-circuiting evaluation.

ARITHMETIC    DESCRIPTION

+             add
-             subtract
*             multiply
/             divide
%             modulus
**            exponentiate
&             bit AND
|             bit OR
^             bit EXOR
~             bit COMP
<<            bit left shift
>>            bit right shift

==            equals
>             greater than
<             less than
>=            greater than or equal to
<=            less than or equal to
!=            not equal to
<>            not equal to
!>            not greater than
!<            not less than
!>=           not greater than or equal to
!<=           not less than or equal to
Note the absence of the auto-increment and auto-decrement operators.  Instead, you would use += and -= (see below).

The last four operators above are a bit unusual, and note that != and <> are interchangeable.

STRING        DESCRIPTION

.             concatenate

eq            is identical to
ne            is not identical to
lt            precedes in dictionary order
gt            follows in dictionary order
le            precedes in dictionary order,
              or is identical to
ge            follows in dictionary order,
              or is identical to
Aside from concatenation, there are many more things one can do with strings using the built-in string functions.
ASSIGNMENT    DESCRIPTION

=             assign to variable, used with all data
              types (string, number, filehandle)
+=            add and assign
-=            subtract and assign
*=            multiply and assign
/=            divide and assign
%=            modulus and assign
**=           exponentiate and assign
&=            bit AND and assign
|=            bit OR and assign
^=            bit EXOR and assign
<<=           bit left shift and assign
>>=           bit right shift and assign
.=            concatenate and assign

FILE          DESCRIPTION

-e            exists
-z            is zero length
-f            is a regular file
-d            is a directory
-c            is a character special file
-b            is a block special file
-p            is a pipe
-l            is a symlink
-S            is a socket
(proc tests, similar in format to file tests, are planned for a future PIKT version.)

These operators follow the usual associativity and precedence rules.

So, too, with how objects and operators combine to form expressions.  The usual rules apply (no real surprises here).

prev page 1st page next page
Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software | DevNotes | Licensing | Authors | Pikt-Users | Pikt-Workers | Links | SiteIndex | ContactUs
Page best viewed at 1024x768.   Page last updated 2006-09-10.   This site is PIKT® powered.
PIKT® is a registered trademark of the University of Chicago.   Copyright © 1998-2006 Robert Osterlund.  All rights reserved.
Home FAQ News Intro Samples Tutorial Reference Software
PIKT Logo
PIKT Page Title