User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

harlowe:interlaced [2017/10/09 20:39] (current)
Line 1: Line 1:
 +**(interlaced:​ // [[harlowe:​Array|array]],​ ...Array//) -> //Array//**
 +Takes multiple [[harlowe:​array|array]],​ and pairs up each value in those arrays: it
 +creates an array containing each array'​s first value followed by each
 +array'​s second value, and so forth. If some values have no matching pair (i.e. one array
 +is longer than the other) then those values are ignored.
 +=== Example usage: ===
 +''​%%(interlaced:​ (a: '​A',​ '​B',​ '​C',​ '​D'​),​ (a: 1, 2, 3))%%''​ is the same as ''​%%(a:​ '​A',​1,'​B',​2,'​C',​3)%%''​
 +=== Rationale: ===
 +There are a couple of other macros which accept data in pairs - the most notable being
 +[[harlowe:​dm|(dm:​)]],​ which takes data names and data values paired. This macro can help
 +with using such macros. For instance, you can supply an array of [[harlowe:​datanames|(datanames:​)]] and
 +[[harlowe:​datavalues|(datavalues:​)]] to (interlaced:​),​ and supply that to [[harlowe:​dm|(dm:​)]],​ to produce the original
 +[[harlowe:​datamap|datamap]] again. Or, you can supply just the names, and use a macro like [[harlowe:​repeated|(repeated:​)]] to
 +fill the other values.
 +However, (interlaced:​) can also be of use alongside macros which accept a sequence: you
 +can use it to cleanly insert values between each item. For instance, one can pair
 +an array with another array of spaces, and then convert them to a [[harlowe:​string|string]] with [[harlowe:​text|(text:​)]].
 +''​%%(text:​ ...(interlaced:​ $arr, (repeated: $arr's length, ' '​))%%''​ will create a string containing
 +each element of $arr, followed by a space.
 +=== Details: ===
 +If one of the arrays provided is empty, the resulting array will be empty, as well.
 +=== See also: ===
 +[[harlowe:​a|(a:​)]],​ [[harlowe:​rotated|(rotated:​)]],​ [[harlowe:​repeated|(repeated:​)]]
harlowe/interlaced.txt ยท Last modified: 2017/10/09 20:39 (external edit)