Compare a list of strings: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
(3 intermediate revisions by 3 users not shown)
Line 677:
test1 lstC succeeds
test2 lstC fails</pre>
 
=={{header|Bruijn}}==
{{trans|Haskell}}
 
<syntaxhighlight lang="bruijn">
:import std/String .
 
all-eq? [land? (zip-with eq? 0 (tail 0))]
 
all-gt? [land? (zip-with lt? 0 (tail 0))]
 
# --- tests ---
 
list-a "abc" : ("abc" : {}("abc"))
 
list-b "abc" : ("def" : {}("ghi"))
 
:test (all-eq? list-a) ([[1]])
:test (all-eq? list-b) ([[0]])
:test (all-gt? list-a) ([[0]])
:test (all-gt? list-b) ([[1]])
</syntaxhighlight>
 
=={{header|C}}==
Line 999 ⟶ 1,021:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import system'collections;
import system'routines;
Line 1,007 ⟶ 1,029:
{
isEqual()
= nil == self.seekEach(self.FirstMember, (n,m => m.equal:n.Inverted != n));
isAscending()
Line 1,016 ⟶ 1,038:
later.next();
^ nil == former.zipBy(later, (prev,next => next <= prev )).seekEach::(b => b)
}
}
Line 1,030 ⟶ 1,052:
public program()
{
testCases.forEach::(list)
{
console.printLine(list.asEnumerable()," all equal - ",list.isEqual());
Line 1,043 ⟶ 1,065:
AA,BB,CC ascending - true
AA,AA,AA all equal - true
AA,AA,AA ascending - falsetrue
AA,CC,BB all equal - false
AA,CC,BB ascending - false
Line 2,708 ⟶ 2,730:
(formerly Perl 6)
 
In Raku, putting square brackets around an [[wp:Infix_notation|infix]] operator turns it into a listop that effectively works as if the operator had been butput in between all of the elements of the argument list ''(or in technical terms, it [[wp:Fold_(higher-order_function)|folds/reduces]] the list using that operator, while taking into account the operator's inherent [https://design.raku.org/S03.html#Operator_precedence associativity] and identity value)'':
 
<syntaxhighlight lang="raku" line>[eq] @strings # All equal
55

edits