Difference between revisions of "Hash"

From ZCubes Wiki
Jump to navigation Jump to search
Line 55: Line 55:
 
 
  
==# to an index arrays, etc==  
+
==# To Access Object Members==  
  
 
  # can be used to access members of arrays as below.
 
  # can be used to access members of arrays as below.

Revision as of 10:44, 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 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 an index arrays, etc

# 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

# 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"]]]	;

Other

	
	2..10|.%|1..5
	
	(1..10)@"SIN"!
	
	(1..100n)!