Difference between revisions of "Hash"
(→Other) |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=== Hash # Operator === | === Hash # Operator === | ||
− | + | Hash Operator (#) can have multiple meanings, when used as a binary operator or as suffix. It can be used to: (1) Arrafy Functions, (2) Index, Search and Filter Arrays, and (3) Index and Search Objects. | |
− | |||
− | |||
====# To Arrayfy Functions==== | ====# To Arrayfy Functions==== | ||
− | Any | + | Any function can be enabled with Array handling for all (or some) parameters, by using # operator. For example: v:=u+a*t; creates a function v which computes the expression u+a*t, with u, a, and t as parameters. However, this function only takes simple parameters as inputs. To make the function v to be able to compute combinations of arrays as parameters, using [[ZCubes/Z_Programming_and_Combinatorial_Arguments | Combinatorial Arguments]], simply use the notation v# to enable array handling capabilities to each of the parameters. If we wish to exclude any parameter, provide an array of such parameters index as the suffix to #. For example, v#[1] will exclude "a" (the 1st index parameter) from handling input arrays. |
Once arrayfied, the function can take arrays as arguments, and for each of the cartesian product of the parameters, a result will be computed. For example, once arrayfied, v(1..2,3..4,1..10) will compute the value for v for each combination of the three parameter arrays. | Once arrayfied, the function can take arrays as arguments, and for each of the cartesian product of the parameters, a result will be computed. For example, once arrayfied, v(1..2,3..4,1..10) will compute the value for v for each combination of the three parameter arrays. | ||
Line 24: | Line 22: | ||
====# To Index and Extract From Arrays==== | ====# To Index and Extract From Arrays==== | ||
− | + | Hash Operator (#) can be used to index arrays, as below. If the right argument is an array, it will extract all elements represented by the indices on the right. If a multi-dimensional index is required, provide a subarray, such as [[2,3]] instead of [2,3]. To get the length of elements along a particular dimension, use the notation nd (For example, 1d to extract the size along the 1st dimension). | |
<pre> | <pre> | ||
Line 56: | Line 54: | ||
====# To Access Object Members==== | ====# To Access Object Members==== | ||
− | # can be used to access members of arrays as below. | + | Hash Operator (#) can be used to access members of arrays as below. |
<pre> | <pre> | ||
Line 78: | Line 76: | ||
</pre> | </pre> | ||
− | =See Also | + | =See Also= |
− | + | [[Fabulous_!_Operator | Fabulous ! Operator]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 21:15, 12 June 2024
Hash # Operator
Hash Operator (#) can have multiple meanings, when used as a binary operator or as suffix. It can be used to: (1) Arrafy Functions, (2) Index, Search and Filter Arrays, and (3) Index and Search Objects.
# To Arrayfy Functions
Any function can be enabled with Array handling for all (or some) parameters, by using # operator. For example: v:=u+a*t; creates a function v which computes the expression u+a*t, with u, a, and t as parameters. However, this function only takes simple parameters as inputs. To make the function v to be able to compute combinations of arrays as parameters, using Combinatorial Arguments, simply use the notation v# to enable array handling capabilities to each of the parameters. If we wish to exclude any parameter, provide an array of such parameters index as the suffix to #. For example, v#[1] will exclude "a" (the 1st index parameter) from handling input arrays.
Once arrayfied, the function can take arrays as arguments, and for each of the cartesian product of the parameters, a result will be computed. For example, once arrayfied, v(1..2,3..4,1..10) will compute the value for v for each combination of the three parameter arrays.
# To Split Strings
# splits strings into arrays.
If numbers are provided on the right of #, then splits can be done in a pattern. If regular expressions are provided on the right, the splits will be based on the regular expression.
"this"# // Splits this to four separate elements, t, h, i and s. "this"#[3,3] // Splits this to separate elements, of size 3, 3, etc.
# To Index and Extract From Arrays
Hash Operator (#) can be used to index arrays, as below. If the right argument is an array, it will extract all elements represented by the indices on the right. If a multi-dimensional index is required, provide a subarray, such as 2,3 instead of [2,3]. To get the length of elements along a particular dimension, use the notation nd (For example, 1d to extract the size along the 1st dimension).
(1..10)#0..2 (1..10)#2 (1..10)#22 (1..10)#1d // dimension 1st, made to 1-1=0 of size |4|#2d |4|#1d |4|#[2,3] MS(4)#[2,3,6] MS(4)#[2,1] MS(4)#[[2,1]] MS(4)#[2d] // size of 2d MS(4)#[2d,1d] "this"#[3,3] [..4,..5]#[1,0] [..4,..5]#[[1,3]]
(1..12)#2 (1..12)#2..6 (1..12)#/4/ (1..12)#/4/#TRUE
# To Access Object Members
Hash Operator (#) can be used to access members of arrays as below.
a={speed:3,weight:34}; a#"speed" a={speed:3,weight:34}; a#["speed","weight"] a#; // will arrayfy the object. // header based with a notation? a={speed:3,weight:34}; a#[["speed","weight"]] a= {speed:3, weight:34, details:{color:"red",size:"large"} }; a#[["speed","weight"],[["details","size"]]] ; a#[[["details","size"]]] ;