User Tools

Site Tools


Sidebar

Passage markup

basics

coding

extra

list

section

whitespace

Macros

basics

colour

data structure

date and time

game state

live

maths

number

revision

saving

showing and hiding

string

styling

url

deprecated

Types of data

Special keywords

Special passage tags

harlowe:all-pass

(all-pass: lambda, …Any) → boolean

This takes a “where” lambda and a series of values, and evaluates to true if the lambda, when run using each value, always evaluated to true.

Example usage:

  • (all-pass: _num where _num > 1 and _num < 14, 6, 8, 12, 10, 9) is true.
  • (all-pass: _room where "Egg" is not in _room's objs, ...$rooms) is true if each datamap in $rooms doesn't have the string "Egg" in its “objs”.

Rationale:

While the contains and is in operators can be used to quickly check if a sequence of values contains an exact value or values, you'll often find yourself wanting to check that the values in a sequence merely resemble a kind of value - for instance, that they're positive numbers, or strings beginning with “E”.

The (all-pass:) macro lets you perform these checks easily using a lambda, identical to that used with (find:) - simply write a “temp variable where a condition” expression, and every value will be put into the temp variable one by one, and the condition checked for each.

Details:

Of course, if any condition should cause an error, such as checking if a number contains a number, then the error will appear.

The temp variable, which you can name anything you want, is controlled entirely by the lambda - it doesn't exist outside of it, it won't alter identically-named temp variables outside of it, and you can't manually (set:) it within the lambda.

You can refer to other variables, including other temp variables, in the where condition. For instance, you can write (set: _name to "Eva")(all-pass: _item where _item is _name, "Evan", "Eve", "Eva"). However, for obvious reasons, if the outer temp variable is named the same as the lambda's temp variable, it can't be referred to in the condition.

See also:

harlowe/all-pass.txt · Last modified: 2017/06/18 22:11 by l