harlowe:array

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

Both sides previous revision Previous revision Next revision | Previous revision | ||

harlowe:array [2017/10/09 20:39] 127.0.0.1 external edit |
harlowe:array [2019/04/16 03:52] (current) l |
||
---|---|---|---|

Line 17: | Line 17: | ||

to remove an item from, you can use an expression, in brackers, after it: ''%%$array's ($pos - 3)%%''. | to remove an item from, you can use an expression, in brackers, after it: ''%%$array's ($pos - 3)%%''. | ||

- | To see if arrays contain certain values, you can use the ''%%contains%%'' and ''%%is in%%'' operators like so: ''%%$array contains 1%%'' | + | To see if arrays contain certain values, you can use the ''%%contains%%'' and ''%%is in%%'' operators like so: ''%%$array contains 1%%'' is true if it contains the number 1 anywhere, and false if it does not. ''%%1 is in $array%%'' is another way to write that. |

- | is true if it contains the number 1 anywhere, and false if it does not. ''%%1 is in $array%%'' is another way to write that. | + | If you want to check if an array contains some, or all of the values, in another array (without needing to be in the same order), you can compare with a special ''%%any%%'' or ''%%all%%'' name on the other array: ''%%$array contains any of (a:2,4,6)%%'', and ''%%$array contains all of (a:2,4,6)%%'' will check if ''%%$array%%'' contains some, or all, of the numbers 2, 4 and 6. |

- | If you want to check if an array contains some, or all of the values, in another array, you can compare with a special | + | |

- | ''%%any%%'' or ''%%all%%'' name on the other array: ''%%$array contains any of (a:2,4,6)%%'', and ''%%$array contains all of (a:2,4,6)%%'' | + | |

- | will check if ''%%$array%%'' contains some, or all, of the numbers 2, 4 and 6. | + | |

(Incidentally, ''%%any%%'' and ''%%all%%'' can also be used with other operators, like ''%%is%%'', ''%%is not%%'', ''%%>%%'', ''%%<%%'', ''%%>=%%'', and ''%%<=%%'', | (Incidentally, ''%%any%%'' and ''%%all%%'' can also be used with other operators, like ''%%is%%'', ''%%is not%%'', ''%%>%%'', ''%%<%%'', ''%%>=%%'', and ''%%<=%%'', | ||

to compare every value in the array with a number or other value. For instance, ''%%all of (a:2,4) >= 2%%'' is true, as is | to compare every value in the array with a number or other value. For instance, ''%%all of (a:2,4) >= 2%%'' is true, as is | ||

''%%any of (a:2,4) >= 4%%''.) | ''%%any of (a:2,4) >= 4%%''.) | ||

+ | |||

+ | For a more thorough check of the contents of an array, you can use ''%%matches%%'' and a [[harlowe:datatype|datatype]] pattern. For instance, ''%%$array matches (a: num, num)%%'' lets you check that $array contains exactly two numbers, and ''%%$array matches (a: 2, num)%%'' lets you check that $array contains only 2 followed by another number. See the datatype article for more details. | ||

Arrays may be joined by adding them together: ''%%(a: 1, 2) + (a: 3, 4)%%'' is the same as ''%%(a: 1, 2, 3, 4)%%''. | Arrays may be joined by adding them together: ''%%(a: 1, 2) + (a: 3, 4)%%'' is the same as ''%%(a: 1, 2, 3, 4)%%''. | ||

Line 56: | Line 55: | ||

|''%%'s%%'' | Obtains the item at the right numeric position, or the''%%length%%'',''%%any%%'' or''%%all%%'' values. |''%%(a:"Y","Z")'s 1st%%'' (is "Y"),''%%(a:4,5)'s (2)%%'' (is 5),''%%(a:5,5,5)'s length%%'' (is 3)| | |''%%'s%%'' | Obtains the item at the right numeric position, or the''%%length%%'',''%%any%%'' or''%%all%%'' values. |''%%(a:"Y","Z")'s 1st%%'' (is "Y"),''%%(a:4,5)'s (2)%%'' (is 5),''%%(a:5,5,5)'s length%%'' (is 3)| | ||

|''%%of%%'' | Obtains the item at the left numeric position, or the''%%length%%'',''%%any%%'' or''%%all%%'' values. |''%%1st of (a:"Y","O")%%'' (is "Y"),''%%(2) of (a:"P","S")%%'' (is "S"),''%%length of (a:5,5,5)%%'' (is 3)| | |''%%of%%'' | Obtains the item at the left numeric position, or the''%%length%%'',''%%any%%'' or''%%all%%'' values. |''%%1st of (a:"Y","O")%%'' (is "Y"),''%%(2) of (a:"P","S")%%'' (is "S"),''%%length of (a:5,5,5)%%'' (is 3)| | ||

+ | | ''%%matches%%'' | Evaluates to boolean true if the array on one side matches the pattern on the other. | ''%%(a:2,3) matches (a: num, num)%%'', ''%%(a: array) matches (a:[[harlowe:a|(a:)]])%%''| | ||

+ | | ''%%is a%%'', ''%%is an%%'' | Evaluates to boolean true` if the right side is array and the left side is an array. | ''%%(a:2,3) is an array%%''| |

harlowe/array.1507595975.txt.gz · Last modified: 2017/10/09 20:39 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International