Rulz and Rulz Language is Copyright © G.A.Jennings, 2015-2022.
This is language specification 2-1/2; last updated 24 June 2022.
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()
.
Operators are categorized (grouped) by "character".
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".
# 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 += addition -= subtraction *= multiplication /= division %= modulo .= concatenation
The
+=
and-=
operators work like increment and decrement depending on the number of argments.
~= not &= and |= or ^= xor <= shift left >= shift right
!= unset (undef)
,= enumerations := set constant
? is true ! is false =? are equal =! are not equal <? less than <! not less than >? greater than >! not greater than
?? defined (variable) ?! not defined &? defined (subroutine) &! not defined
:? defined (constant) :! not defined
& 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 ; ]
<< 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 (goto) .. break, return, exit >. continue (next) <. redo ^. die
!! logical not || logical or && logical and ^^ logical exclusive or
// regular expression match/replace \\ character translation
`` shell execution
<( heredoc >) theredoc (( now heredoc )) now theredoc
f- is file d- is directory r- is readable w- is writeable x- is executable
s- file size p- file permissions t- file type g- file group a- file access time c- file change time m- file modification time
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
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.)
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
/[ 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.
v/ square root 2/ square 1/ reciprocal a/ absolute ^/ exponent
Not a complete list.
=% percentage of *% percentage against +% percentage add -% percentage from /% percentage between
=@ set parameters +@ append parameter <@ shift parameter >@ unshift parameter
These are based on Perl's shift with no argument, and partly on Bash's set.
@do un-conditional loop @each iterate a hash @for iterate an array @while while true @until while false @end end of loop
@if @switch @case @end end of block
_ = (f-value) c@ @case d@ @do e@ @each f@ @for i@ @if s@ @switch u@ @until w@ @while @ @end
~< readfile (to STDOUT) .< include (Rulz source)
/* C style comment */
<!-- HTML style comment -->