Difference between revisions of "Hash"
(Created page with "=== Hash # Operator === # Operator can have multiple meanings, when used as a binary operator or as suffix. Hash # Operator . # can be used to (1) a...") |
|||
Line 4: | Line 4: | ||
# can be used to (1) arrafy functions, (2) index, search and filter arrays, and (3) index and search Objects. | # can be used to (1) arrafy functions, (2) index, search and filter arrays, and (3) index and search Objects. | ||
+ | |||
+ | ====# to arrayfy Functions==== | ||
+ | |||
+ | Any functions 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 [[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. | ||
+ | |||
+ | ==# to an index arrays, etc== | ||
+ | |||
+ | (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]] | ||
+ | |||
+ | 2..10|.%|1..5 | ||
+ | |||
+ | (1..10)@"SIN"! | ||
+ | |||
+ | (1..100n)! | ||
+ | (1..12)#2 | ||
+ | (1..12)#2..6 | ||
+ | (1..12)#/4/ | ||
+ | (1..12)#/4/#TRUE | ||
+ | |||
+ | 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"]]] ; |
Revision as of 10:32, 10 June 2024
Hash # Operator
# Operator can have multiple meanings, when used as a binary operator or as suffix. Hash # Operator .
# can be used to (1) arrafy functions, (2) index, search and filter arrays, and (3) index and search Objects.
# to arrayfy Functions
Any functions 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 an index arrays, etc
(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
2..10|.%|1..5
(1..10)@"SIN"!
(1..100n)! (1..12)#2 (1..12)#2..6 (1..12)#/4/ (1..12)#/4/#TRUE
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"]]] ;