Rulz Operator Reference

Rulz and Rulz Language is Copyright © G.A.Jennings, 2015-2022.

This is language specification 2-1/2; last updated 24 June 2022.

Introduction

In Rulz, an "operator" differs from what are called operators in other languages. Here, they are, with a few exceptions, "first on the line tokens" that means "something that does something to something". In that sense, they are not to be confused with other language operators—which, with a few exceptions, "do something with expressions".

Here, operators perform traditional operations like arithmetic and bitwise, and perform what in other languages are named functions (or built-ins) such as print() and open().

Basic Operators

Operators are categorized (grouped) by "character".

Single Character Operators

There are several, basic, single character operators, such as.

=                       assignment
?                       conditional
^                       print

They can all be used alone or with another "prefix" character as a "modifier". Such as arithmetic:

+=                      addition
-=                      subtraction

Or other print functions:

>^                      print to stderr
%^                      print formated (printf)

Other operators always have two characters, one being the "main" character, defining the group, and a "prefix" to define the operator as a whole. Such as mathematic:

1/                      squareroot
^/                      exponent

Or the test operators:

f-                      file exists
d-                      directory exists

Or string operators:

u~                      toupper
i~                      index

There are several "pair" operators:

&&                      logical AND
//                      search replace

Some of those are a slight "deviation" from the above "rules" for operator characterizations—AND, &&, is not a modification of the open operator, &. These are only and always "of themselves".

Full Operator Reference

Comment Operators

#                       comment
##                      multi-line comment
^                       print
-^                      print with no newline
\^                      print just a newline	
/^                      print escaping control characters
>^                      print to STDERR
%^                      print formatted
?^                      print types

Assignment Operators

=                       assignment
+=                      addition
-=                      subtraction
*=                      multiplication
/=                      division
%=                      modulo
.=                      concatenation

The += and -= operators work like increment and decrement depending on the number of argments.

Bitwise Operators

~=                      not
&=                      and
|=                      or
^=                      xor
<=                      shift left
>=                      shift right

Unset Operator

!=                      unset (undef)

Constants Operators

,=                      enumerations
:=                      set constant

Conditional Operators

?                       is true
!                       is false
=?                      are equal
=!                      are not equal
<?                      less than
<!                      not less than
>?                      greater than
>!                      not greater than

Evaluation Operators

??                      defined (variable)
?!                      not defined
&?                      defined (subroutine)
&!                      not defined
:?                      defined (constant)
:!                      not defined

File Operators

&                       open file for reading
-&                      open file for writing
+&                      open file for appending
.&                      close
<&                      read line/bytes
[&                      read lines 
(&                      read line with chomp
{&                      read character
%&                      read formated string
/&                      read regular expression
>&                      write line/bytes
]&                      write lines (of list)
)&                      write line with chomp
}&                      write character
@&                      EOF test
=&                      seek
,&                      rewind
?&                      tell
:&                      truncate
^&                      touch
!&                      delete
|&                      rename/move
[&                      stat                                        ; ]

File Function Operators

<<                      get file contents
(<                      get file as list with EOL
[<                      get file as list without EOL (chomp)
>>                      put file contents
)>                      put list to file with EOL
]>                      put list to file without EOL (chomp)
+>                      append string to file
->                      prepend string to file

Jump Operators

.                       jump (goto)
..                      break, return, exit
>.                      continue (next)
<.                      redo
^.                      die

Logical Operators

!!                      logical not
||                      logical or
&&                      logical and
^^                      logical exclusive or

Regular Expression Operators

//                      regular expression match/replace
\\                      character translation

Exec Operator

``                      shell execution

Here Document Operators

<(                      heredoc
>)                      theredoc
((                      now heredoc
))                      now theredoc

File Test Operators

f-                      is file
d-                      is directory
r-                      is readable
w-                      is writeable
x-                      is executable

File Status Operators

s-                      file size
p-                      file permissions
t-                      file type
g-                      file group
a-                      file access time
c-                      file change time
m-                      file modification time

Type Test Operators

S-                      is string
I-                      is integer
D-                      is double
L-                      is list or hash
N-                      is numeric
B-                      is boolean
U-                      is null
T-                      is true
Z-                      is empty

String Test Operators

u?                      is uppercase
l?                      is lowercase
d?                      is decimal
s?                      is whitespace 
w?                      is word
n?                      is alpha numeric
a?                      is alpha
c?                      is control
g?                      is graph
p?                      is printable
t?                      is punctuation
x?                      is hexadecimal

All have a ! version to negate the test. (Though they look it, these are not considered modified conditional operators.)

String Function Operators

u~                      to upper case
l~                      to lower case
n~                      length
q~                      quote meta 
i~                      index (substr)
s~                      string occurrence
S~                      string occurrence (case insensitive)
p~                      string position
P~                      string position (case insensitive)
c~                      chop
C~                      chomp
t~                      trim
T~                      trim right
L~                      trim left
f~                      sprintf
F~                      sscanf
h~                      htmlentities
H~                      htmlspecialchars
x~                      explode
m~                      implode
w~                      wordwrap
r~                      string replace
R~                      string replace (case insensitive)
e~                      urlencode
E~                      urldecode
y~                      crypt
g~                      preg split
b~                      basename
d~                      dirname

List Operators

/[                      split
:[                      join
~[                      values
%[                      keys
@[                      sort
\[                      reverse
<[                      shift
>[                      unshift
-[                      pop
+[                      push
,[                      slice
~[                      implode
|[                      explode
([                      extract
^[                      difference
=[                      count
[[                      index/key exists (boolean)
'[                      value exists (boolean)
"[                      value exists (search) returns value
?[                      random value                                ; ]

Many of the arithmetic and bitwise operators can be applied to lists.

Mathematical Operators

v/                      square root
2/                      square
1/                      reciprocal
a/                      absolute
^/                      exponent

Not a complete list.

Percent Operators

=%                      percentage of
*%                      percentage against
+%                      percentage add
-%                      percentage from
/%                      percentage between

Parameter Operators

=@                      set parameters
+@                      append parameter
<@                      shift parameter
>@                      unshift parameter

These are based on Perl's shift with no argument, and partly on Bash's set.

Loop Operators

@do                     un-conditional loop
@each                   iterate a hash
@for                    iterate an array
@while                  while true
@until                  while false
@end                    end of loop

Block Operators

@if
@switch
@case
@end                    end of block

Aliases

_                       = (f-value)
c@                      @case
d@                      @do
e@                      @each
f@                      @for
i@                      @if
s@                      @switch
u@                      @until
w@                      @while
@                       @end

Other Operators

~<                      readfile (to STDOUT)
.<                      include (Rulz source)
/*
C style comment
*/
<!--
HTML style comment
-->