Lists and Linear AlgebraLists and Linear AlgebraUsing Lists in CindyScriptList are among the most fundamental and elementary concepts of CindyScript. In CindyScript lists serve several purposes. They serve as
This section covers the very general aspects of creating lists and accessing their elements as well as all elementary aspects of array functionality. For information on all other aspects of lists, consult the sections
Creating ListsLists can be created very easily by placing the elements in square brackets, separated by commas. For example, [45,12.5,123,2,5.5,5] is a list of numbers. ["this", "is", "a", "list", "of", "strings"] is a list of strings. Objects of different kinds can be mixed in a list: ["this", 3,"is",5 , "a",654, "mixed",234 , "list"] Lists can also have lists as elements, and these can be nested arbitrarily. [[4,6], ["a", "b"], 1, [4, "b", [23, "b"]], [ ]] The last element [ ] of this list does not contain any elements. It is the empty list.Alternatively lists consisting of at least two elements can also be enclosed by round brackets (...) . This is sometimes convenient to have a more mathematical appealing notation in the the code. A three-dimensional vector may then be written as follows:(7.3,9.3,-14.3) Accessing Elements of Lists:
|
Code | Result |
[2 ,5 ,7 ,3]_3 | 7
|
take([2 ,5 ,7 ,3],2) | 5
|
[2 ,5 ,7 ,3]_5 | ___
|
Code | Result |
[ [2, [4,5]],1]_1 | [2,[4,5]]
|
[ [2, [4,5]],1]_(7-5) | 1
|
[ [2, [4,5]],1]_1_2 | [4,5]
|
[ [2, [4,5]],1]_1_2_2 | 5
|
[ [2, [4,5]],1]_1_2_2_2 | ___
|
_
operator. So for example, after the code fragmenta=[[2,[4,5]],1]; a_2="A"; a_1_2_1="B";
a
is [[2,["B",5]],"A"]
.Code | Result |
[2 ,5 ,7 ,3]_(-1) | 3
|
take([2 ,5 ,7 ,3],(-3)) | 5
|
[ [2,6] ,5 ,7 ,3]_(-4)_(-1) | 6
|
Code | Result |
[2 ,5 ,7 ,3]_[2,3] | [5,7]
|
[2 ,5 ,7 ,3]_[-1,1,1] | [3,2,2]
|
Contributors to this page: von Gagern
,
Kortenkamp
,
Kohler
and
Richter
.
Page last modified on Friday 27 of March, 2015 [08:38:58 UTC] by von Gagern.
The content on this page is licensed under the terms of the License.