Beyond This Documentation
Sometimes you need more power
“Real” RuleScript specifications use lots of epressions not explained in this documentation.
These expressions are from the Clojure programming language, which RuleScript sits on top of. Almost any Clojure expression can be used from within RuleScript (see below for a list of disallowed symbols). This allows RuleScript writers to be incredibly expressive, although there are a lot of new expressions to learn. Some especially usefuly ones are below.
The official Clojure cheatsheet is a great tool for learning new expressions and refreshing your memory about old ones.
Starting expressions
+,-,*(multiplication), and/(division) work like you’d expect.minandmaxtake the minimum and maximum, respectively, of the provided arguments.andtakes any number of values or expressions, and returns either the firstfalse/nilvalue (called, amusingly, “falsy”), or else the final value. Answers the question, “Are all of these things true?”oris similar; given values, return the first non-falsy (called “truthy”) value, or else the final value. Anwsers the question, “Are ANY of these things true?”iftakes the form(if test then else), wheretestis a boolean expression/value,thenis the thing that will be returned iftestis true, andelseis the thing that will be returned iftestis false.maptakes an expression and a sequence, and applies that expression to each element of the sequence. It returns a sequence of those results. For example, consider(map complete? some-elements).filter, likemap, takes an expression and a sequence, and applies the expression to each element of the sequence. However: the expression must return a boolean value, andfilterreturns the original values for which the expression istrue.
Other expressions?
There are hundreds! In addition to the Clojure cheatsheet, you may wish to check out Clojure’s full API documentation. Pro tip: function names that end with ? are boolean expressions.