Skip to content

Control Flow

Victor Dumbrava edited this page Feb 3, 2018 · 7 revisions

1. Map

"Map" is the operator that helps you iterate over an object (either a list or a string), and apply a function to it.

Syntax: It is represented by the character M and it is bounded (ended) using the character }. It applies the code between M and } for each element of the object you iterate on.

Example: Let's say you have a list of integers given as input, and you want to increment each of them by 1. Then this code should do it:

..)..
.IEM.
@}...

Try it online!

Details: For each element in the given object, create a separate stack containing that element only and apply the given code. Once the execution finished, it appends the top of the created stack to a list. After each element is handled, the list is appended to the main stack.

2. Filter

"Filter" is the operator that lets you remove the elements in a list that don't meet certain conditions.

Syntax: It is represented by the character F and it bounded by {. So F...{ runs ... on a separate stack for each element of the iterable you filter, and removes those that yield a falsy result.

Example: Let's say that you are given a list of numbers as input, and you want to remove those that aren't higher than 6. Then this code should work just fine for you:

..)..
.IEF.
)6<{.

Details: For each element in the given object, create a separate stack containing that element only and apply the given code. Once the execution finished, it appends the element to a list if the top of the created stack is truthy. After each element is handled, the list is appended to the main stack.


Please note that control flow structures are not nestable.

Clone this wiki locally