Content deleted Content added
Citation bot (talk | contribs) Misc citation tidying. | You can use this bot yourself. Report bugs here. | Suggested by Abductive | Category:Cross-platform free software | via #UCB_Category 50/379 |
m →Lists and list processing: syntaxhighlight |
||
Line 191:
Furthermore, Cuneiform provides lists as compound data types. The example below shows the definition of a variable <code>xs</code> being a file list with three elements.
<syntaxhighlight lang="erlang">
let xs : [File] =
['a.txt', 'b.txt', 'c.txt' : File];
</syntaxhighlight>
Lists can be processed with the for and fold operators. Herein, the for operator can be given multiple lists to consume list element-wise (similar to <code>for/list</code> in [[Racket (programming language)|Racket]], <code>mapcar</code> in [[Common Lisp]] or <code>zipwith</code> in [[Erlang (programming language)|Erlang]]).
Line 200:
The example below shows how to map over a single list, the result being a file list.
<syntaxhighlight lang="ruby">
for x <- xs do
process-one( arg1 = x )
: File
end;
</syntaxhighlight>
The example below shows how to zip two lists the result also being a file list.
<syntaxhighlight lang="ruby">
for x <- xs, y <- ys do
process-two( arg1 = x, arg2 = y )
: File
end;
</syntaxhighlight>
Finally, lists can be aggregated by using the fold operator. The following example sums up the elements of a list.
<syntaxhighlight lang="text">
fold acc = 0, x <- xs do
add( a = acc, b = x )
end;
</syntaxhighlight>
==Parallel execution==
|