Multivalues

From Swym Wiki
Jump to: navigation, search

A multivalue represents a series of several values. Most operators and function calls that are passed a multivalue will (conceptually) be executed multiple times, once for each actual value. The result is a new multivalue composed of all the results.

(1,3,5)*2
RunSandbox

Given two or more multivalues, the expression is executed once for all possible pairings of values.

(2,3,4)*(11,111,1111)
RunSandbox

The same applies to function calls.

[ pair(1..3)(4..6) ] // pair(a,b) returns the array [a,b].
RunSandbox

[edit] Operators that interact with multivalues

The Comma operator takes two values or multivalues, and concatenates them to form a new multivalue.

The Repeat operator and the Range operators generate multivalues.

The Box operator, [] takes a multivalue, and returns an array containing those values.

[edit] Important multivalue-related functions

The each function is the inverse of the box operator. It takes an array, and returns a multivalue containing each value from it.

The for function is designed to be passed a multivalue as its first argument. Like any function, it then runs once for each of those values.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox