Advanced List Operations


Advanced List Operations

There are several operators that take a list as argument and return another list derived from it. This section deals with such operators. These operators form very powerful tools for performing a high-level computation. For examples of how to use and apply these operators in a realistic context, we strongly recommend to read the example section for CindyScript.

Pairs and Triples

Building pairs: pairs(<list>)

Description: This operator produces a list that contains all two-element sublists of a list. These are all pairs of elements of <list>. This operator is particularly useful for creating all segments determined a set of points.

pairs([1, 2, 3, 4])[[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]

Creating a chain: consecutive(<list>)

Description: This operator produces a list that contains all pairs of elements of consecutive elements of the argument <list>.

consecutive([1, 2, 3, 4, 5])[[1, 2], [2, 3], [3, 4], [4, 5]]

Creating a cycle: cycle(<list>)

Description: This operator produces a list that contains all pairs of consecutive elements of the argument <list>. Furthermore, the pair consisting of the last and the first elements is added.

cycle([1, 2, 3, 4, 5])[[1, 2], [2, 3], [3, 4], [4, 5], [5, 1]]

Building triples: triples(<list>)

Description: This operator produces a list that contains all three-element sublists of a list. These are all the triples of elements of <list>.

triples([1, 2, 3, 4])[[1,2,3], [1,2,4], [1,3,4], [2,3,4]]

Creating the direct product of two lists: directproduct(<list1>,<list2>)

Description: This operator produces a list that resembles the direct product of two given lists. The direct products consists of all pairs whose first element is taken from <list1> and whose second element is taken from <list2>.

directproduct([1,2,3], ["A", "B"])[[1,"A"], [1,"B"], [2,"A"], [2,"B"], [3,"A"], [3,"B"]]

Flattening a nested list lists: flatten(<list>)

Description: This operator takes a list that may itself again consist of lists. It returns a single list of elements that results from appending all the second order lists. Using a modifier flattening can be applied recursively. Also the levels of flattening can be controlled.

This operator produces a list that resembles the direct product of two given lists. The direct products consists of all pairs whose first element is taken from <list1> and whose second element is taken from <list2>.

Modifiers: The modifier levels can be set either to "all", which results in a complete recursive flattening, or it can be set to an integer, that specifies the maximal recursion level of flattening. The statement flatten(...,levels->1) is equivalent to flatten(...).

Example: Let us assume that we set


then we get the following responses to various calls of flattening:


Order of Elements

The following operators change the order of the elements within a list.

Reversing a list: reverse(<list>)

Description: This operator reverses the order of the elements in <list>.

reverse([1, 2, 3, 4])[4, 3, 2, 1]

Sorting a list: sort(<list>)

Description: Within CindyScript, all elements are in a natural complete order that makes it possible to compare any two elements. Two elements are equal, or one of them is greater than the other. Within the real numbers, the order is the usual numeric order. Within strings, the order is the lexicographic order. Complex numbers are ordered by their real parts first. If two complex numbers have the same real part, then they are compared with respect to their imaginary parts. Two lists are compared by the first entry in which they differ. Furthermore, by convention Cinderella uses the order

booleans < numbers < strings < lists

sort([4.5, 1.3, 6.7, 0.2])[0.2, 1.3, 4.5, 6.7]
sort(["one", "two", "three", "four", "five"])["five","four","one","three","two"]

Sorting a list: sort(<list>, <expr>)

Description: This operator takes each element of the list and evaluates a function expressed by <expr> applied to it. All elements of the list are sorted with respect to the result of these evaluations.

sort([-4.5, 1.3, -6.7, 0.2], abs(#))[0.2, 1.3, -4.5, -6.7]
sort(["one", "two", "three", "four", "five"],length(#))["one","two","four","five","three"]

Sorting a list: sort(<list>, <var>, <expr>)

Description: Similar to sort(<list>, <expr>) but with <var> as the run variable.

Sets from lists: set(<list>)

Description: This operator sorts all elements of a list and removes occurrences of identical elements. Thus a unique representation of the list is computed if the list is considered as a set of objects. Together with the operators concat, remove, and common, this can be used as an implementation of set functionality.

set([3, 5, 2, 4, 3, 5, 7])[2, 3, 4, 5, 7]
set([3, 5, 2]++[4, 5, 2])[2, 3, 4, 5]
set([3, 5, 2]~~[4, 5, 2])[2, 5]

Contributors to this page: Kortenkamp , Richter , Kohler and Lembach .
Page last modified on Friday 02 of September, 2011 [17:22:07 UTC] by Kortenkamp.

The content on this page is licensed under the terms of the License.

free viagra samplehentai girlsmature pussymilfseeker cialis samplescam clip movie nude webcammother incest order viagra online cialis ukanime rapeparis hilton phone numbers viagra alternatives cialis forum cialis free samplehot girls in pantiesmonster of cocks discount cialis cilias free viagra samplesfree chat rooms cilia structurefree cartoon sex comics buy cialis order viagrafree adult videosplump girl gallerypantyhose gallerycum on her face cheapest cialisbisexual moviestampa bukakehuge black cock thumbnails buy cialis onlineporn star cialis drugwomen having sex cheap generic viagra alternative to viagra natural viagra cheap viagraoral sexteen webcam strip videosnude spanish girlserotic sex cams movies viagra side effectscartoon adultdisney sex animenude blonde hairygang bang swinger cialis viagrabisexual free moviesgay twinkswebcam chat live xxxyoung teens order cialislatina girls thongscum loversjapanese girl viagra cheapyoung japanese girlsmr chews asian beavergangbang squadshoshone indiansmature wiveslive webcam chat girlsfree ebony viagra on lineasian ladyboysteen boys viagra pillsself bondage techniques cailisincest familyfree ebony cheap cialisgay amateur cialis genericbusty asian viagra onlinemature breasts viagra for women free viagrabig boobies cialis generic viagragloryhole gaylatinas in thongs female viagraindian tits viagra 6 free samplesamateur upskirt viagra alternativefree xxx video cialis online discountgalleries of teen girls cialis dosage cheap generic cialisparis hilton pornopussy cat dollsbrutal sexgay peopleblack milfsno tits discount viagrablonde hairy pussyshemale animefree hardcore moviesmom strips for sonfat titscelebrity legsdouble anal levitra vs cialis cialis tadalafil cialis cheapgay bdsmcelebrities exposed viagra generic alternatives to viagra viagra canadabestialitypink porn stars viagra jokesclips of teen sexchicks suck horse cock online viagrasex with horsespainful analglory holes floridafree american bukkake cialis online buy viagrabig cock cum free cialisteen gay porn cialis side effects herbal viagra best price viagra purchase cialis cialis soft tabs cialis vs viagrafree fat girl webcamfree porn movie clipsoral penis suckingebony hardcore viagra pricepantyhose crossed legs cialis and levitralesbiennesblonde boobs buy viagra online