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.
/(division) work like you’d expect.
maxtake the minimum and maximum, respectively, of the provided arguments.
andtakes any number of values or expressions, and returns either the first
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), where
testis a boolean expression/value,
thenis the thing that will be returned if
testis true, and
elseis the thing that will be returned if
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).
map, takes an expression and a sequence, and applies the expression to each element of the sequence. However: the expression must return a boolean value, and
filterreturns the original values for which the expression is
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.