ZenScript main repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

arrays.zs 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //val a = new int[](3, 10);
  2. //
  3. //for i in a {
  4. // println(i);
  5. //}
  6. //
  7. //println(a[1]);
  8. ////
  9. ////
  10. val multiDim = new int[,,](1,2,3, 130);
  11. println(multiDim[0,1,2]);
  12. val t = multiDim;
  13. //
  14. //
  15. val b = new int[](3);
  16. for i in b {
  17. println(i);
  18. }
  19. val c = new int[,,](1,2,3);
  20. println(c[0,1,2]);
  21. //
  22. //
  23. //val d = new string[,,](5,5,5, "HelloWorld");
  24. //println(d[2,2,2]);
  25. //
  26. //
  27. ////val e = new int[](a, value => value);
  28. //
  29. //
  30. //var projection = (value => value) as function(value as string`borrow) as string;
  31. //val e = new string[](5, "HelloWorld");
  32. //val f = new string[]<string>(e, projection);
  33. //var projection = (value => value) as function(value as string`borrow) as string;
  34. //val a = new string[](5, "HelloWorld");
  35. //val b = new string[]<string>(a, projection);
  36. val d = new string[,,](3,4,5, "HelloWorld");
  37. val someString = "someString";
  38. var projection = (value => "" + value) as function(value as string`borrow) as string;
  39. val e = new string[,,]<string>(
  40. d,
  41. (value => "137" + value + someString) as function(value as string`borrow) as string
  42. );
  43. val aSomeArray = new string[](5, "HelloWorld");
  44. val bSomeArray = new string[]<string>(aSomeArray, projection);
  45. println("HelloWorldProjectedArray");
  46. println(bSomeArray[1]);
  47. println(e[2,3,4]);
  48. val constructorLambdaArray = new string[](5, i => "No" + i);
  49. println(constructorLambdaArray[1]);
  50. val constructorLambdaArrayMulti = new string[,](5, 5, (i1, i2) => "No" + i1 + i2);
  51. println(constructorLambdaArrayMulti[1, 2]);
  52. val testArray = new string[,](5, 5, "helloWorld");
  53. val indexedProjectionWithLambdaNonInlined = new string[,]<string>(testArray as string[,], (index1, index2, value) => {
  54. return value + "" + index1 + index2;
  55. } as function(index1 as usize, index2 as usize, value as string`borrow) as string);
  56. val indexedProjectionWithLambdaInlined = new string[,]<string>(testArray, ((i as usize, j as usize, s as string`borrow) => (s + "" + i + j) as string) as function(i as usize, j as usize, s as string`borrow) as string);
  57. println(indexedProjectionWithLambdaNonInlined[1, 2]);
  58. println(indexedProjectionWithLambdaInlined[1, 2]);