Compare a list of strings: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
Line 26: Line 26:
=={{header|11l}}==
=={{header|11l}}==
{{trans|D}}
{{trans|D}}
<lang 11l>L(strings_s) [‘AA AA AA AA’, ‘AA ACB BB CC’]
<syntaxhighlight lang="11l">L(strings_s) [‘AA AA AA AA’, ‘AA ACB BB CC’]
V strings = strings_s.split(‘ ’)
V strings = strings_s.split(‘ ’)
print(strings)
print(strings)
print(all(zip(strings, strings[1..]).map(a -> a[0] == a[1])))
print(all(zip(strings, strings[1..]).map(a -> a[0] == a[1])))
print(all(zip(strings, strings[1..]).map(a -> a[0] < a[1])))
print(all(zip(strings, strings[1..]).map(a -> a[0] < a[1])))
print()</lang>
print()</syntaxhighlight>


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
The program uses one ASSIST macro (XPRNT) to keep the code as short as possible.
The program uses one ASSIST macro (XPRNT) to keep the code as short as possible.
<lang 360asm>* Compare a list of strings 31/01/2017
<syntaxhighlight lang="360asm">* Compare a list of strings 31/01/2017
COMPLIST CSECT
COMPLIST CSECT
USING COMPLIST,R13 base register
USING COMPLIST,R13 base register
Line 122: Line 122:
PG DS CL80
PG DS CL80
YREGS
YREGS
END COMPLIST</lang>
END COMPLIST</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 131: Line 131:


=={{header|Action!}}==
=={{header|Action!}}==
<lang Action!>DEFINE PTR="CARD"
<syntaxhighlight lang="action!">DEFINE PTR="CARD"


BYTE FUNC AreEqual(PTR ARRAY a BYTE len)
BYTE FUNC AreEqual(PTR ARRAY a BYTE len)
Line 196: Line 196:
a4(0)="aaa"
a4(0)="aaa"
Test(a4,1)
Test(a4,1)
RETURN</lang>
RETURN</syntaxhighlight>
{{out}}
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Compare_a_list_of_strings.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Compare_a_list_of_strings.png Screenshot from Atari 8-bit computer]
Line 220: Line 220:


We will store the "list" of strings in a vector. The vector will hold "indefinite" strings, i.e., the strings can have different lengths.
We will store the "list" of strings in a vector. The vector will hold "indefinite" strings, i.e., the strings can have different lengths.
<lang Ada> package String_Vec is new Ada.Containers.Indefinite_Vectors
<syntaxhighlight lang="ada"> package String_Vec is new Ada.Containers.Indefinite_Vectors
(Index_Type => Positive, Element_Type => String);
(Index_Type => Positive, Element_Type => String);
use type String_Vec.Vector;</lang>
use type String_Vec.Vector;</syntaxhighlight>


The equality test iterates from the first to the last-but one index. For index Idx,
The equality test iterates from the first to the last-but one index. For index Idx,
Line 229: Line 229:
yes for any Idx, the function immediately returns False. If the answer is no for all Idx,
yes for any Idx, the function immediately returns False. If the answer is no for all Idx,
the function finally returns True.
the function finally returns True.
<lang Ada> function All_Are_The_Same(Strings: String_Vec.Vector) return Boolean is
<syntaxhighlight lang="ada"> function All_Are_The_Same(Strings: String_Vec.Vector) return Boolean is
begin
begin
for Idx in Strings.First_Index .. Strings.Last_Index-1 loop
for Idx in Strings.First_Index .. Strings.Last_Index-1 loop
Line 237: Line 237:
end loop;
end loop;
return True;
return True;
end All_Are_The_Same;</lang>
end All_Are_The_Same;</syntaxhighlight>


Similarily, the strictly ascending test checks if Strings(Idx) is greater or equal Strings(Idx+1).
Similarily, the strictly ascending test checks if Strings(Idx) is greater or equal Strings(Idx+1).
<lang Ada> function Strictly_Ascending(Strings: String_Vec.Vector) return Boolean is
<syntaxhighlight lang="ada"> function Strictly_Ascending(Strings: String_Vec.Vector) return Boolean is
begin
begin
for Idx in Strings.First_Index+1 .. Strings.Last_Index loop
for Idx in Strings.First_Index+1 .. Strings.Last_Index loop
Line 248: Line 248:
end loop;
end loop;
return True;
return True;
end Strictly_Ascending;</lang>
end Strictly_Ascending;</syntaxhighlight>


If the variable Strings is of the type String_Vec.vector, one can call these two functions
If the variable Strings is of the type String_Vec.vector, one can call these two functions
as usual.
as usual.
<lang Ada>Put_Line(Boolean'Image(All_Are_The_Same(Strings)) & ", " &
<syntaxhighlight lang="ada">Put_Line(Boolean'Image(All_Are_The_Same(Strings)) & ", " &
Boolean'Image(Strictly_Ascending(Strings)));</lang>
Boolean'Image(Strictly_Ascending(Strings)));</syntaxhighlight>
If Strings holds two or more strings, the result will be either of TRUE, FALSE, or FALSE, TRUE, or FALSE, FALSE, indicating all strings are the same, or they are strictly ascending, or neither.
If Strings holds two or more strings, the result will be either of TRUE, FALSE, or FALSE, TRUE, or FALSE, FALSE, indicating all strings are the same, or they are strictly ascending, or neither.


Line 259: Line 259:


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<lang ALGOL68>[]STRING list1 = ("AA","BB","CC");
<syntaxhighlight lang="algol68">[]STRING list1 = ("AA","BB","CC");
[]STRING list2 = ("AA","AA","AA");
[]STRING list2 = ("AA","AA","AA");
[]STRING list3 = ("AA","CC","BB");
[]STRING list3 = ("AA","CC","BB");
Line 298: Line 298:
print (("...is not in strict ascending order", new line))
print (("...is not in strict ascending order", new line))
FI
FI
OD</lang>
OD</syntaxhighlight>
{{out}}
{{out}}
<pre>list: AA BB CC
<pre>list: AA BB CC
Line 318: Line 318:


=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
<lang algolw> % returns true if all elements of the string array a are equal, false otherwise %
<syntaxhighlight lang="algolw"> % returns true if all elements of the string array a are equal, false otherwise %
% As Algol W procedures cannot determine the bounds of an array, the bounds %
% As Algol W procedures cannot determine the bounds of an array, the bounds %
% must be specified in lo and hi %
% must be specified in lo and hi %
Line 353: Line 353:
end;
end;
ordered
ordered
end ascendingOrder ;</lang>
end ascendingOrder ;</syntaxhighlight>


=={{header|AppleScript}}==
=={{header|AppleScript}}==
Line 361: Line 361:




<lang AppleScript>-- allEqual :: [String] -> Bool
<syntaxhighlight lang="applescript">-- allEqual :: [String] -> Bool
on allEqual(xs)
on allEqual(xs)
_and(zipWith(my _equal, xs, rest of xs))
_and(zipWith(my _equal, xs, rest of xs))
Line 469: Line 469:
end script
end script
end if
end if
end mReturn</lang>
end mReturn</syntaxhighlight>


{{Out}}
{{Out}}
Line 476: Line 476:
=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>allEqual?: function [lst] -> 1 = size unique lst
<syntaxhighlight lang="rebol">allEqual?: function [lst] -> 1 = size unique lst
ascending?: function [lst] -> lst = sort lst
ascending?: function [lst] -> lst = sort lst


Line 490: Line 490:
print ["allEqual?" allEqual? l]
print ["allEqual?" allEqual? l]
print ["ascending?" ascending? l "\n"]
print ["ascending?" ascending? l "\n"]
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 511: Line 511:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f COMPARE_A_LIST_OF_STRINGS.AWK
# syntax: GAWK -f COMPARE_A_LIST_OF_STRINGS.AWK
BEGIN {
BEGIN {
Line 539: Line 539:
printf("\n%d\n%d\n",test1,test2)
printf("\n%d\n%d\n",test1,test2)
}
}
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 567: Line 567:


If all are not equal and the list is invariant under sorting, then it is in ascending order.
If all are not equal and the list is invariant under sorting, then it is in ascending order.
<lang bqn>AllEq ← ⍋≡⍒
<syntaxhighlight lang="bqn">AllEq ← ⍋≡⍒
Asc ← ¬∘AllEq∧∧≡⊢
Asc ← ¬∘AllEq∧∧≡⊢


Line 574: Line 574:


•Show AllEq ⟨"AA", "ACB", "BB", "CC"⟩
•Show AllEq ⟨"AA", "ACB", "BB", "CC"⟩
•Show Asc ⟨"AA", "ACB", "BB", "CC"⟩</lang>
•Show Asc ⟨"AA", "ACB", "BB", "CC"⟩</syntaxhighlight>
<lang bqn>1
<syntaxhighlight lang="bqn">1
0
0
0
0
1</lang>
1</syntaxhighlight>


[https://mlochbaum.github.io/BQN/try.html#code=QWxsRXEg4oaQIOKNi+KJoeKNkgpBc2Mg4oaQIMKs4oiYQWxsRXHiiKfiiKfiiaHiiqIKCuKAolNob3cgQWxsRXEg4p+oIkFBIiwgIkFBIiwgIkFBIiwgIkFBIuKfqQrigKJTaG93IEFzYyDin6giQUEiLCAiQUEiLCAiQUEiLCAiQUEi4p+pCgrigKJTaG93IEFsbEVxIOKfqCJBQSIsICJBQ0IiLCAiQkIiLCAiQ0Mi4p+pCuKAolNob3cgQXNjIOKfqCJBQSIsICJBQ0IiLCAiQkIiLCAiQ0Mi4p+pCg== Try It!]
[https://mlochbaum.github.io/BQN/try.html#code=QWxsRXEg4oaQIOKNi+KJoeKNkgpBc2Mg4oaQIMKs4oiYQWxsRXHiiKfiiKfiiaHiiqIKCuKAolNob3cgQWxsRXEg4p+oIkFBIiwgIkFBIiwgIkFBIiwgIkFBIuKfqQrigKJTaG93IEFzYyDin6giQUEiLCAiQUEiLCAiQUEiLCAiQUEi4p+pCgrigKJTaG93IEFsbEVxIOKfqCJBQSIsICJBQ0IiLCAiQkIiLCAiQ0Mi4p+pCuKAolNob3cgQXNjIOKfqCJBQSIsICJBQ0IiLCAiQkIiLCAiQ0Mi4p+pCg== Try It!]
Line 610: Line 610:




<lang Bracmat> (test1=first.~(!arg:%@?first ? (%@:~!first) ?))
<syntaxhighlight lang="bracmat"> (test1=first.~(!arg:%@?first ? (%@:~!first) ?))
& (test2=x.~(!arg:? %@?x (%@:~>!x) ?))</lang>
& (test2=x.~(!arg:? %@?x (%@:~>!x) ?))</syntaxhighlight>


Demonstration
Demonstration
<lang Bracmat>( ( lstA
<syntaxhighlight lang="bracmat">( ( lstA
. isiZulu
. isiZulu
isiXhosa
isiXhosa
Line 669: Line 669:
)
)
)
)
</syntaxhighlight>
</lang>
'''Output'''
'''Output'''
<pre>test1 lstA fails
<pre>test1 lstA fails
Line 679: Line 679:


=={{header|C}}==
=={{header|C}}==
<lang c>#include <stdbool.h>
<syntaxhighlight lang="c">#include <stdbool.h>
#include <string.h>
#include <string.h>


Line 698: Line 698:
return false;
return false;
return true;
return true;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
{{works with|C sharp|7}}
{{works with|C sharp|7}}
<lang csharp>public static (bool lexicallyEqual, bool strictlyAscending) CompareAListOfStrings(List<string> strings) =>
<syntaxhighlight lang="csharp">public static (bool lexicallyEqual, bool strictlyAscending) CompareAListOfStrings(List<string> strings) =>
strings.Count < 2 ? (true, true) :
strings.Count < 2 ? (true, true) :
(
(
strings.Distinct().Count() < 2,
strings.Distinct().Count() < 2,
Enumerable.Range(1, strings.Count - 1).All(i => string.Compare(strings[i-1], strings[i]) < 0)
Enumerable.Range(1, strings.Count - 1).All(i => string.Compare(strings[i-1], strings[i]) < 0)
);</lang>
);</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==
Line 714: Line 714:


{{works with|C++|11}}
{{works with|C++|11}}
<lang cpp>#include <algorithm>
<syntaxhighlight lang="cpp">#include <algorithm>
#include <string>
#include <string>


Line 722: Line 722:


std::is_sorted( strings.begin(), strings.end(),
std::is_sorted( strings.begin(), strings.end(),
[](std::string a, std::string b){ return !(b < a); }) ) // Strictly ascending</lang>
[](std::string a, std::string b){ return !(b < a); }) ) // Strictly ascending</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
Used similar approach as the Python solution
Used similar approach as the Python solution


<lang clojure>
<syntaxhighlight lang="clojure">


;; Checks if all items in strings list are equal (returns true if list is empty)
;; Checks if all items in strings list are equal (returns true if list is empty)
Line 735: Line 735:
(every? (fn [[a nexta]] (<= (compare a nexta) 0)) (map vector strings (rest strings))))
(every? (fn [[a nexta]] (<= (compare a nexta) 0)) (map vector strings (rest strings))))


</syntaxhighlight>
</lang>


=={{header|COBOL}}==
=={{header|COBOL}}==
{{works with|GnuCOBOL}}
{{works with|GnuCOBOL}}
<lang cobol> identification division.
<syntaxhighlight lang="cobol"> identification division.
program-id. CompareLists.
program-id. CompareLists.


Line 798: Line 798:
end-if
end-if
display " "
display " "
.</lang>
.</syntaxhighlight>
{{out}}
{{out}}
<pre>list:
<pre>list:
Line 827: Line 827:


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<syntaxhighlight lang="lisp">
<lang Lisp>
(defun strings-equal-p (strings)
(defun strings-equal-p (strings)
(null (remove (first strings) (rest strings) :test #'string=)))
(null (remove (first strings) (rest strings) :test #'string=)))
Line 835: Line 835:
for string2 in (rest strings)
for string2 in (rest strings)
always (string-lessp string1 string2)))
always (string-lessp string1 string2)))
</syntaxhighlight>
</lang>


=={{header|D}}==
=={{header|D}}==
<lang d>void main() {
<syntaxhighlight lang="d">void main() {
import std.stdio, std.algorithm, std.range, std.string;
import std.stdio, std.algorithm, std.range, std.string;


Line 847: Line 847:
writeln;
writeln;
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>["AA", "AA", "AA", "AA"]
<pre>["AA", "AA", "AA", "AA"]
Line 860: Line 860:
{{libheader| System.SysUtils}}
{{libheader| System.SysUtils}}
{{Trans|Go}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Compare_a_list_of_strings;
program Compare_a_list_of_strings;


Line 928: Line 928:


readln;
readln;
end.</lang>
end.</syntaxhighlight>
{{out}}
{{out}}
<pre>[a]
<pre>[a]
Line 944: Line 944:
=={{header|Dyalect}}==
=={{header|Dyalect}}==


<lang Dyalect>func isSorted(xs) {
<syntaxhighlight lang="dyalect">func isSorted(xs) {
var prev
var prev
for x in xs {
for x in xs {
Line 964: Line 964:
}
}
true
true
}</lang>
}</syntaxhighlight>


=={{header|Elena}}==
=={{header|Elena}}==
ELENA 5.0 :
ELENA 5.0 :
<lang elena>import system'collections;
<syntaxhighlight lang="elena">import system'collections;
import system'routines;
import system'routines;
import extensions;
import extensions;
Line 1,005: Line 1,005:
console.readChar()
console.readChar()
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,021: Line 1,021:


=={{header|Elixir}}==
=={{header|Elixir}}==
<lang elixir>defmodule RC do
<syntaxhighlight lang="elixir">defmodule RC do
def compare_strings(strings) do
def compare_strings(strings) do
{length(Enum.uniq(strings))<=1, strict_ascending(strings)}
{length(Enum.uniq(strings))<=1, strict_ascending(strings)}
Line 1,034: Line 1,034:
Enum.each(lists, fn list ->
Enum.each(lists, fn list ->
IO.puts "#{inspect RC.compare_strings(list)}\t<= #{inspect list} "
IO.puts "#{inspect RC.compare_strings(list)}\t<= #{inspect list} "
end)</lang>
end)</syntaxhighlight>


{{out}}
{{out}}
Line 1,048: Line 1,048:
{{trans|Haskell}}
{{trans|Haskell}}


<lang erlang>
<syntaxhighlight lang="erlang">
-module(compare_strings).
-module(compare_strings).


Line 1,061: Line 1,061:
all_fulfill(Fun,Strings) ->
all_fulfill(Fun,Strings) ->
lists:all(fun(X) -> X end,lists:zipwith(Fun, lists:droplast(Strings), tl(Strings)) ).
lists:all(fun(X) -> X end,lists:zipwith(Fun, lists:droplast(Strings), tl(Strings)) ).
</syntaxhighlight>
</lang>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>let allEqual strings = Seq.isEmpty strings || Seq.forall (fun x -> x = Seq.head strings) (Seq.tail strings)
<syntaxhighlight lang="fsharp">let allEqual strings = Seq.isEmpty strings || Seq.forall (fun x -> x = Seq.head strings) (Seq.tail strings)
let ascending strings = Seq.isEmpty strings || Seq.forall2 (fun x y -> x < y) strings (Seq.tail strings)</lang>
let ascending strings = Seq.isEmpty strings || Seq.forall2 (fun x y -> x < y) strings (Seq.tail strings)</syntaxhighlight>
<p>Actually <code>allEqual</code> is a shortcut and <code>ascending</code> is a general pattern. We can make a function
<p>Actually <code>allEqual</code> is a shortcut and <code>ascending</code> is a general pattern. We can make a function
out of it which constructs a new function from a comparision function</p>
out of it which constructs a new function from a comparision function</p>
<lang fsharp>let (!) f s = Seq.isEmpty s || Seq.forall2 f s (Seq.tail s)</lang>
<syntaxhighlight lang="fsharp">let (!) f s = Seq.isEmpty s || Seq.forall2 f s (Seq.tail s)</syntaxhighlight>
<p>and define the 2 task functions that way</p>
<p>and define the 2 task functions that way</p>
<lang fsharp>let allEqual = !(=)
<syntaxhighlight lang="fsharp">let allEqual = !(=)
let ascending = !(<)</lang>
let ascending = !(<)</syntaxhighlight>
<p>getting something similar as the builtin in Raku</p>
<p>getting something similar as the builtin in Raku</p>


=={{header|Factor}}==
=={{header|Factor}}==
Assuming the list is on top of the data stack, testing for lexical equality:
Assuming the list is on top of the data stack, testing for lexical equality:
<lang factor>USE: grouping
<syntaxhighlight lang="factor">USE: grouping
all-equal?</lang>
all-equal?</syntaxhighlight>
Testing for ascending order:
Testing for ascending order:
<lang factor>USING: grouping math.order ;
<syntaxhighlight lang="factor">USING: grouping math.order ;
[ before? ] monotonic?</lang>
[ before? ] monotonic?</syntaxhighlight>


=={{header|Forth}}==
=={{header|Forth}}==
Line 1,088: Line 1,088:
Raw Forth is a very low level language and has no Native lists so we have to build from scratch.
Raw Forth is a very low level language and has no Native lists so we have to build from scratch.
Remarkably by concatenating these low level operations and using the simple Forth parser we can build the linked lists of strings and the list operators quite simply. The operators and lists that we create become extensions to the language.
Remarkably by concatenating these low level operations and using the simple Forth parser we can build the linked lists of strings and the list operators quite simply. The operators and lists that we create become extensions to the language.
<lang forth>\ linked list of strings creators
<syntaxhighlight lang="forth">\ linked list of strings creators
: ," ( -- ) [CHAR] " WORD c@ 1+ ALLOT ; \ Parse input stream until " and write into next available memory
: ," ( -- ) [CHAR] " WORD c@ 1+ ALLOT ; \ Parse input stream until " and write into next available memory
: [[ ( -- ) 0 C, ; \ begin a list. write a 0 into next memory byte (null string)
: [[ ( -- ) 0 C, ; \ begin a list. write a 0 into next memory byte (null string)
Line 1,131: Line 1,131:
create strings [[ ," ENTRY 4" ," ENTRY 3" ," ENTRY 2" ," ENTRY 1" ]]
create strings [[ ," ENTRY 4" ," ENTRY 3" ," ENTRY 2" ," ENTRY 1" ]]
create strings2 [[ ," the same" ," the same" ," the same" ]]
create strings2 [[ ," the same" ," the same" ," the same" ]]
create strings3 [[ ," AAA" ," BBB" ," CCC" ," DDD" ]] </lang>
create strings3 [[ ," AAA" ," BBB" ," CCC" ," DDD" ]] </syntaxhighlight>


Test at the Forth console
Test at the Forth console
Line 1,150: Line 1,150:
It is better to hide low-level code in general-purpose code-libraries so that the application code can be simple.
It is better to hide low-level code in general-purpose code-libraries so that the application code can be simple.
Here is my solution using LIST.4TH from my novice-package: http://www.forth.org/novice.html
Here is my solution using LIST.4TH from my novice-package: http://www.forth.org/novice.html
<lang forth>
<syntaxhighlight lang="forth">
: test-equality ( string node -- new-string bad? )
: test-equality ( string node -- new-string bad? )
over count \ -- string node adr cnt
over count \ -- string node adr cnt
Line 1,164: Line 1,164:
seq .line @ seq 2nd 'test find-node
seq .line @ seq 2nd 'test find-node
nip 0= ;
nip 0= ;
</syntaxhighlight>
</lang>
Here is a test of the above code:
Here is a test of the above code:
{{out}}
{{out}}
Line 1,188: Line 1,188:
On the other hand a function such as ALLINORDER would show the sound of one hand clapping. It would also reveal the order in which comparisons were made, and whether the loop would quit on the first failure or blockheadedly slog on through the lot regardless. Alas, on these questions the documentation for ALL is suspiciously silent.
On the other hand a function such as ALLINORDER would show the sound of one hand clapping. It would also reveal the order in which comparisons were made, and whether the loop would quit on the first failure or blockheadedly slog on through the lot regardless. Alas, on these questions the documentation for ALL is suspiciously silent.


<syntaxhighlight lang="fortran">
<lang Fortran>
INTEGER MANY,LONG
INTEGER MANY,LONG
PARAMETER (LONG = 6,MANY = 4) !Adjust to suit.
PARAMETER (LONG = 6,MANY = 4) !Adjust to suit.
Line 1,207: Line 1,207:
END IF
END IF
END
END
</lang>
</syntaxhighlight>


And yes, if MANY is set to one and the extra texts are commented out, the results are both true, and ungrammatical statements are made. Honest. Possibly, another special function, as in <code>COUNT(STRINGS(1:MANY - 1) .LT. STRINGS(2:MANY)))</code> would involve less one-hand-clapping when there are no comparisons to make, but the production of a report that would use it is not in the specification.
And yes, if MANY is set to one and the extra texts are commented out, the results are both true, and ungrammatical statements are made. Honest. Possibly, another special function, as in <code>COUNT(STRINGS(1:MANY - 1) .LT. STRINGS(2:MANY)))</code> would involve less one-hand-clapping when there are no comparisons to make, but the production of a report that would use it is not in the specification.
Line 1,213: Line 1,213:
===F2003-F2008===
===F2003-F2008===
F2008 standard ([ISO 2010], 4.4.3) defines the character variable of the character type as a set of values composed of character strings and a character string is a sequence of characters, numbered from left to right 1, 2, 3, ... up to the number of characters in the string. The number of characters in the string is called the length of the string. The length is a type parameter; its kind is processor dependent and its value is greater than or equal to zero. I.e in declaration
F2008 standard ([ISO 2010], 4.4.3) defines the character variable of the character type as a set of values composed of character strings and a character string is a sequence of characters, numbered from left to right 1, 2, 3, ... up to the number of characters in the string. The number of characters in the string is called the length of the string. The length is a type parameter; its kind is processor dependent and its value is greater than or equal to zero. I.e in declaration
<syntaxhighlight lang="fortran">
<lang Fortran>
character (len=12) :: surname
character (len=12) :: surname
</syntaxhighlight>
</lang>
keyword len is NOT a size of array, it is an intrinsic parameter of character type, and character type is in fortran a [[first-class type]]: they can be assigned as objects or passed as parameters to a subroutine.
keyword len is NOT a size of array, it is an intrinsic parameter of character type, and character type is in fortran a [[first-class type]]: they can be assigned as objects or passed as parameters to a subroutine.


In summary, the character data type in Fortran is a real, first class data type. Fortran character strings are not hacked-up arrays!
In summary, the character data type in Fortran is a real, first class data type. Fortran character strings are not hacked-up arrays!
<syntaxhighlight lang="fortran">
<lang Fortran>
program compare_char_list
program compare_char_list
implicit none
implicit none
Line 1,237: Line 1,237:
end if
end if
end program compare_char_list
end program compare_char_list
</syntaxhighlight>
</lang>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>
<syntaxhighlight lang="freebasic">
' FB 1.05.0 Win64
' FB 1.05.0 Win64


Line 1,260: Line 1,260:
Return True
Return True
End Function
End Function
</syntaxhighlight>
</lang>


=={{header|Fōrmulæ}}==
=={{header|Fōrmulæ}}==
Line 1,271: Line 1,271:


=={{header|Go}}==
=={{header|Go}}==
<lang go>package cmp
<syntaxhighlight lang="go">package cmp


func AllEqual(strings []string) bool {
func AllEqual(strings []string) bool {
Line 1,289: Line 1,289:
}
}
return true
return true
}</lang>
}</syntaxhighlight>
See [[Compare_a_list_of_strings/GoTests]] for validation tests.
See [[Compare_a_list_of_strings/GoTests]] for validation tests.


Line 1,295: Line 1,295:


=={{header|Gosu}}==
=={{header|Gosu}}==
<lang gosu>var list = {"a", "b", "c", "d"}
<syntaxhighlight lang="gosu">var list = {"a", "b", "c", "d"}


var isHomogeneous = list.toSet().Count < 2
var isHomogeneous = list.toSet().Count < 2
var isOrderedSet = list.toSet().order().toList() == list</lang>
var isOrderedSet = list.toSet().order().toList() == list</syntaxhighlight>


=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>allEqual :: Eq a => [a] -> Bool
<syntaxhighlight lang="haskell">allEqual :: Eq a => [a] -> Bool
allEqual xs = and $ zipWith (==) xs (tail xs)
allEqual xs = and $ zipWith (==) xs (tail xs)
allIncr :: Ord a => [a] -> Bool
allIncr :: Ord a => [a] -> Bool
allIncr xs = and $ zipWith (<) xs (tail xs)</lang>
allIncr xs = and $ zipWith (<) xs (tail xs)</syntaxhighlight>




Alternatively, using folds:
Alternatively, using folds:


<lang haskell>allEqual
<syntaxhighlight lang="haskell">allEqual
:: Eq a
:: Eq a
=> [a] -> Bool
=> [a] -> Bool
Line 1,320: Line 1,320:
=> [a] -> Bool
=> [a] -> Bool
allIncreasing [] = True
allIncreasing [] = True
allIncreasing (h:t) = fst $ foldl (\(a, x) y -> (a && x < y, y)) (True, h) t</lang>
allIncreasing (h:t) = fst $ foldl (\(a, x) y -> (a && x < y, y)) (True, h) t</syntaxhighlight>


or seeking earlier exit (from longer lists) with '''until''', but in fact, perhaps due to lazy execution, the zipWith at the top performs best.
or seeking earlier exit (from longer lists) with '''until''', but in fact, perhaps due to lazy execution, the zipWith at the top performs best.


<lang haskell>allEq
<syntaxhighlight lang="haskell">allEq
:: Eq a
:: Eq a
=> [a] -> Bool
=> [a] -> Bool
Line 1,344: Line 1,344:
(\(x, xs) -> null xs || x >= head xs)
(\(x, xs) -> null xs || x >= head xs)
(\(_, x:xs) -> (x, xs))
(\(_, x:xs) -> (x, xs))
(h, t)</lang>
(h, t)</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon expressions either succeed and return a value (which may be &null) or fail.
Icon and Unicon expressions either succeed and return a value (which may be &null) or fail.


<lang unicon>#
<syntaxhighlight lang="unicon">#
# list-compare.icn
# list-compare.icn
#
#
Line 1,390: Line 1,390:
}
}
return
return
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 1,402: Line 1,402:
=={{header|J}}==
=={{header|J}}==


'''Solution''' (''equality test''):<lang j> allEq =: 1 = +/@~: NB. or 1 = #@:~. or -: 1&|. or }.-:}:</lang>
'''Solution''' (''equality test''):<syntaxhighlight lang="j"> allEq =: 1 = +/@~: NB. or 1 = #@:~. or -: 1&|. or }.-:}:</syntaxhighlight>
'''Solution''' (''order test''):<lang j> asc =: /: -: i.@# NB. or -: (/:~) etc.</lang>
'''Solution''' (''order test''):<syntaxhighlight lang="j"> asc =: /: -: i.@# NB. or -: (/:~) etc.</syntaxhighlight>
'''Notes''': <tt>asc</tt> indicates whether <tt>y</tt> is monotonically increasing, but not necessarily strictly monotonically increasing (in other words, it allows equal elements if they are adjacent to each other).
'''Notes''': <tt>asc</tt> indicates whether <tt>y</tt> is monotonically increasing, but not necessarily strictly monotonically increasing (in other words, it allows equal elements if they are adjacent to each other).


=={{header|Java}}==
=={{header|Java}}==
{{works with|Java|8}}
{{works with|Java|8}}
<lang java5>import java.util.Arrays;
<syntaxhighlight lang="java5">import java.util.Arrays;


public class CompareListOfStrings {
public class CompareListOfStrings {
Line 1,420: Line 1,420:
}
}
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>[AA, AA, AA, AA]
<pre>[AA, AA, AA, AA]
Line 1,432: Line 1,432:
===ES5===
===ES5===
====Iterative====
====Iterative====
<lang JavaScript>function allEqual(a) {
<syntaxhighlight lang="javascript">function allEqual(a) {
var out = true, i = 0;
var out = true, i = 0;
while (++i<a.length) {
while (++i<a.length) {
Line 1,455: Line 1,455:
console.log(azSorted(empty)); // true
console.log(azSorted(empty)); // true
console.log(azSorted(single)); // true
console.log(azSorted(single)); // true
</syntaxhighlight>
</lang>


===ES6===
===ES6===
Line 1,461: Line 1,461:


Using a generic zipWith, and functionally composed predicates:
Using a generic zipWith, and functionally composed predicates:
<lang JavaScript>(() => {
<syntaxhighlight lang="javascript">(() => {
'use strict';
'use strict';


Line 1,511: Line 1,511:
};
};


})();</lang>
})();</syntaxhighlight>


{{Out}}
{{Out}}
<syntaxhighlight lang="javascript">{
<lang JavaScript>{
"allEqual": [
"allEqual": [
false,
false,
Line 1,525: Line 1,525:
true
true
]
]
}</lang>
}</syntaxhighlight>


=={{header|jq}}==
=={{header|jq}}==
Line 1,532: Line 1,532:
For both the following functions, the input is assumed to be a (possibly empty) array of strings.
For both the following functions, the input is assumed to be a (possibly empty) array of strings.
In both cases also, the implementations are fast but could be improved at the expense of complexity.
In both cases also, the implementations are fast but could be improved at the expense of complexity.
<lang jq># Are the strings all equal?
<syntaxhighlight lang="jq"># Are the strings all equal?
def lexically_equal:
def lexically_equal:
. as $in
. as $in
Line 1,542: Line 1,542:
. as $in
. as $in
| reduce range(0;length-1) as $i
| reduce range(0;length-1) as $i
(true; if . then $in[$i] < $in[$i + 1] else false end);</lang>
(true; if . then $in[$i] < $in[$i + 1] else false end);</syntaxhighlight>
'''Examples''':
'''Examples''':
<lang jq>[] | lexically_equal #=> true</lang>
<syntaxhighlight lang="jq">[] | lexically_equal #=> true</syntaxhighlight>
<lang jq>["a", "ab"] | lexically_ascending #=> true</lang>
<syntaxhighlight lang="jq">["a", "ab"] | lexically_ascending #=> true</syntaxhighlight>


=={{header|Jsish}}==
=={{header|Jsish}}==
Code from Javascript, ES5.
Code from Javascript, ES5.


<lang javascript>/* Compare list of strings, in Jsish */
<syntaxhighlight lang="javascript">/* Compare list of strings, in Jsish */
function allEqual(a) {
function allEqual(a) {
var out = true, i = 0;
var out = true, i = 0;
Line 1,569: Line 1,569:


if (allAscending(strings)) puts("strings array in strict ascending order");
if (allAscending(strings)) puts("strings array in strict ascending order");
else puts("strings array not in strict ascending order");</lang>
else puts("strings array not in strict ascending order");</syntaxhighlight>


{{out}}
{{out}}
Line 1,577: Line 1,577:
{{works with|Julia|0.6}}
{{works with|Julia|0.6}}


<lang julia>allequal(arr::AbstractArray) = isempty(arr) || all(x -> x == first(arr), arr)
<syntaxhighlight lang="julia">allequal(arr::AbstractArray) = isempty(arr) || all(x -> x == first(arr), arr)


test = [["RC", "RC", "RC"], ["RC", "RC", "Rc"], ["RA", "RB", "RC"],
test = [["RC", "RC", "RC"], ["RC", "RC", "Rc"], ["RA", "RB", "RC"],
Line 1,586: Line 1,586:
println("The elements are $("not " ^ !allequal(v))all equal.")
println("The elements are $("not " ^ !allequal(v))all equal.")
println("The elements are $("not " ^ !issorted(v))strictly increasing.")
println("The elements are $("not " ^ !issorted(v))strictly increasing.")
end</lang>
end</syntaxhighlight>


{{out}}
{{out}}
Line 1,618: Line 1,618:


=={{header|Klong}}==
=={{header|Klong}}==
<syntaxhighlight lang="k">
<lang K>
{:[2>#x;1;&/=:'x]}:(["test" "test" "test"])
{:[2>#x;1;&/=:'x]}:(["test" "test" "test"])
1
1
{:[2>#x;1;&/<:'x]}:(["bar" "baz" "foo"])
{:[2>#x;1;&/<:'x]}:(["bar" "baz" "foo"])
1
1
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>// version 1.0.6
<syntaxhighlight lang="scala">// version 1.0.6


fun areEqual(strings: Array<String>): Boolean {
fun areEqual(strings: Array<String>): Boolean {
Line 1,645: Line 1,645:
else if (areAscending(args)) println("They are in strictly ascending order")
else if (areAscending(args)) println("They are in strictly ascending order")
else println("They are neither equal nor in ascending order")
else println("They are neither equal nor in ascending order")
}</lang>
}</syntaxhighlight>
Sample input/output:
Sample input/output:
{{out}}
{{out}}
Line 1,654: Line 1,654:


=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<lang scheme>
<syntaxhighlight lang="scheme">
{def allsame
{def allsame
{def allsame.r
{def allsame.r
Line 1,697: Line 1,697:
} -> true false false true true
} -> true false false true true


</syntaxhighlight>
</lang>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>function identical(t_str)
<syntaxhighlight lang="lua">function identical(t_str)
_, fst = next(t_str)
_, fst = next(t_str)
if fst then
if fst then
Line 1,739: Line 1,739:
check("AA,CC,BB")
check("AA,CC,BB")
check("AA,ACB,BB,CC")
check("AA,ACB,BB,CC")
check("single_element")</lang>
check("single_element")</syntaxhighlight>
{{out}}
{{out}}
<pre>ayu dab dog gar panda tui yak: not identical and ascending.
<pre>ayu dab dog gar panda tui yak: not identical and ascending.
Line 1,752: Line 1,752:


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Module CheckIt {
Function Equal(Strings){
Function Equal(Strings){
Line 1,792: Line 1,792:
}
}
Checkit
Checkit
</syntaxhighlight>
</lang>


=={{header|Maple}}==
=={{header|Maple}}==
<lang Maple>lexEqual := proc(lst)
<syntaxhighlight lang="maple">lexEqual := proc(lst)
local i:
local i:
for i from 2 to numelems(lst) do
for i from 2 to numelems(lst) do
Line 1,811: Line 1,811:
tst := ["abc","abc","abc","abc","abc"]:
tst := ["abc","abc","abc","abc","abc"]:
lexEqual(tst):
lexEqual(tst):
lexAscending(tst):</lang>
lexAscending(tst):</syntaxhighlight>
{{Out|Examples}}
{{Out|Examples}}
<pre>true
<pre>true
Line 1,821: Line 1,821:
This particular version of "Compare a list of strings" was created in Mathcad Prime Express 7.0, a free version of Mathcad Prime 7.0 with restrictions (such as no programming or symbolics). All Mathcad numbers are complex doubles. There is a recursion depth limit of about 4,500. Strings are a distinct data and are not conceptually a list of integers.
This particular version of "Compare a list of strings" was created in Mathcad Prime Express 7.0, a free version of Mathcad Prime 7.0 with restrictions (such as no programming or symbolics). All Mathcad numbers are complex doubles. There is a recursion depth limit of about 4,500. Strings are a distinct data and are not conceptually a list of integers.


<lang Mathcad>-- define list of list of strings (nested vector of vectors of strings)
<syntaxhighlight lang="mathcad">-- define list of list of strings (nested vector of vectors of strings)
-- Mathcad vectors are single column arrays.
-- Mathcad vectors are single column arrays.
-- The following notation is for convenience in writing arrays in text form.
-- The following notation is for convenience in writing arrays in text form.
Line 1,854: Line 1,854:


list:=[11,11,11],[11,22,33],[11,33,22],[33,22,11],[11,132,22,33],[11]]
list:=[11,11,11],[11,22,33],[11,33,22],[33,22,11],[11,132,22,33],[11]]
</syntaxhighlight>
</lang>


=={{header|Mathematica}}/{{header|Wolfram Language}}==
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>data1 = {"aaa", "aaa", "aab"};
<syntaxhighlight lang="mathematica">data1 = {"aaa", "aaa", "aab"};
Apply[Equal, data]
Apply[Equal, data]
OrderedQ[data]</lang>
OrderedQ[data]</syntaxhighlight>
{{out}}
{{out}}
<pre>False
<pre>False
Line 1,866: Line 1,866:
=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==
Only the first task is implemented.
Only the first task is implemented.
<lang Matlab>alist = {'aa', 'aa', 'aa'}
<syntaxhighlight lang="matlab">alist = {'aa', 'aa', 'aa'}
all(strcmp(alist,alist{1}))</lang>
all(strcmp(alist,alist{1}))</syntaxhighlight>


=={{header|Nanoquery}}==
=={{header|Nanoquery}}==
<lang Nanoquery>// a function to test if a list of strings are equal
<syntaxhighlight lang="nanoquery">// a function to test if a list of strings are equal
def stringsEqual(stringList)
def stringsEqual(stringList)
// if the list is empty, return true
// if the list is empty, return true
Line 1,906: Line 1,906:
// return whether the string were less than each other or not
// return whether the string were less than each other or not
return lessThan
return lessThan
end</lang>
end</syntaxhighlight>


=={{header|NetRexx}}==
=={{header|NetRexx}}==
<lang NetRexx>/* NetRexx */
<syntaxhighlight lang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
options replace format comments java crossref symbols nobinary


Line 1,955: Line 1,955:
return
return


</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,976: Line 1,976:
This is the obvious (and more efficient way) to compare strings in Nim:
This is the obvious (and more efficient way) to compare strings in Nim:


<syntaxhighlight lang="nim">
<lang Nim>
func allEqual(s: openArray[string]): bool =
func allEqual(s: openArray[string]): bool =


Line 1,998: Line 1,998:


doAssert allEqual(["abc"])
doAssert allEqual(["abc"])
doAssert ascending(["abc"])</lang>
doAssert ascending(["abc"])</syntaxhighlight>


For “allEqual”, there is another simple way using template “allIt” from standard module “sequtils”:
For “allEqual”, there is another simple way using template “allIt” from standard module “sequtils”:


<lang Nim>import sequtils
<syntaxhighlight lang="nim">import sequtils


func allEqual(s: openArray[string]): bool =
func allEqual(s: openArray[string]): bool =
Line 2,009: Line 2,009:
doAssert allEqual(["abc", "abc", "abc"])
doAssert allEqual(["abc", "abc", "abc"])
doAssert not allEqual(["abc", "abd", "abc"])
doAssert not allEqual(["abc", "abd", "abc"])
doAssert allEqual(["abc"])</lang>
doAssert allEqual(["abc"])</syntaxhighlight>


There are other less obvious and less efficient ways, using hash sets, sorting or “map” and “zip”.
There are other less obvious and less efficient ways, using hash sets, sorting or “map” and “zip”.


=={{header|OCaml}}==
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">
<lang Ocaml>
open List;;
open List;;


Line 2,044: Line 2,044:


List.iter test [lasc;leq;lnoasc];;
List.iter test [lasc;leq;lnoasc];;
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,069: Line 2,069:
=={{header|Oforth}}==
=={{header|Oforth}}==


<lang oforth>: lexEqual asSet size 1 <= ;
<syntaxhighlight lang="oforth">: lexEqual asSet size 1 <= ;
: lexCmp(l) l l right( l size 1- ) zipWith(#<) and ;</lang>
: lexCmp(l) l l right( l size 1- ) zipWith(#<) and ;</syntaxhighlight>


=={{header|ooRexx}}==
=={{header|ooRexx}}==
<lang oorexx>/* REXX ---------------------------------------------------------------
<syntaxhighlight lang="oorexx">/* REXX ---------------------------------------------------------------
* 28.06.2014 Walter Pachl
* 28.06.2014 Walter Pachl
*--------------------------------------------------------------------*/
*--------------------------------------------------------------------*/
Line 2,104: Line 2,104:
Say 'List' name': neither equal nor in increasing order'
Say 'List' name': neither equal nor in increasing order'
End
End
Return</lang>
Return</syntaxhighlight>
{{out}}
{{out}}
<pre>List ABC: elements are in increasing order
<pre>List ABC: elements are in increasing order
Line 2,112: Line 2,112:
=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
Easiest is to use <code>Set()</code>:
Easiest is to use <code>Set()</code>:
<lang parigp>allEqual(strings)=#Set(strings)<2
<syntaxhighlight lang="parigp">allEqual(strings)=#Set(strings)<2
inOrder(strings)=Set(strings)==strings</lang>
inOrder(strings)=Set(strings)==strings</syntaxhighlight>


More efficient:
More efficient:
<lang parigp>allEqual(strings)=for(i=2,#strings,if(strings[i]!=strings[i-1], return(0))); 1
<syntaxhighlight lang="parigp">allEqual(strings)=for(i=2,#strings,if(strings[i]!=strings[i-1], return(0))); 1
inOrder(strings)=for(i=2,#strings,if(strings[i]>strings[i-1], return(0))); 1</lang>
inOrder(strings)=for(i=2,#strings,if(strings[i]>strings[i-1], return(0))); 1</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==


<lang perl>use List::Util 1.33 qw(all);
<syntaxhighlight lang="perl">use List::Util 1.33 qw(all);


all { $strings[0] eq $strings[$_] } 1..$#strings # All equal
all { $strings[0] eq $strings[$_] } 1..$#strings # All equal
all { $strings[$_-1] lt $strings[$_] } 1..$#strings # Strictly ascending</lang>
all { $strings[$_-1] lt $strings[$_] } 1..$#strings # Strictly ascending</syntaxhighlight>


Alternatively, if you can guarantee that the input strings don't contain null bytes, the equality test can be performed by a regex like this:
Alternatively, if you can guarantee that the input strings don't contain null bytes, the equality test can be performed by a regex like this:


<lang perl>join("\0", @strings) =~ /^ ( [^\0]*+ ) (?: \0 \1 )* $/x # All equal</lang>
<syntaxhighlight lang="perl">join("\0", @strings) =~ /^ ( [^\0]*+ ) (?: \0 \1 )* $/x # All equal</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">allsame</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">allsame</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
Line 2,156: Line 2,156:
<span style="color: #000000;">test</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"AA"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ACB"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"BB"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"CC"</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"AA"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ACB"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"BB"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"CC"</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"single_element"</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"single_element"</span><span style="color: #0000FF;">})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 2,167: Line 2,167:


=={{header|Phixmonti}}==
=={{header|Phixmonti}}==
<lang Phixmonti>include ..\Utilitys.pmt
<syntaxhighlight lang="phixmonti">include ..\Utilitys.pmt


( "alpha" "beta" "gamma" "delta" "epsilon" "zeta"
( "alpha" "beta" "gamma" "delta" "epsilon" "zeta"
Line 2,177: Line 2,177:


dup len swap 1 get rot repeat == /# put 0 (false) in the pile, indicating that they are not repeated strings #/
dup len swap 1 get rot repeat == /# put 0 (false) in the pile, indicating that they are not repeated strings #/
</syntaxhighlight>
</lang>


=={{header|Picat}}==
=={{header|Picat}}==
<lang Picat>main =>
<syntaxhighlight lang="picat">main =>
Lists = [["AA","BB","CC"],
Lists = [["AA","BB","CC"],
["AA","AA","AA"],
["AA","AA","AA"],
Line 2,197: Line 2,197:
all_same([A,B|Rest]) :-
all_same([A,B|Rest]) :-
A == B,
A == B,
all_same([B|Rest]).</lang>
all_same([B|Rest]).</syntaxhighlight>


{{out}}
{{out}}
Line 2,209: Line 2,209:
=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
PicoLisp has the native operators =, > and < these can take an infinite number of arguments and are also able to compare Transient symbols (the Strings of PicoLisp).
PicoLisp has the native operators =, > and < these can take an infinite number of arguments and are also able to compare Transient symbols (the Strings of PicoLisp).
<lang PicoLisp>(= "AA" "AA" "AA")
<syntaxhighlight lang="picolisp">(= "AA" "AA" "AA")
-> T
-> T
(= "AA" "AA" "Aa")
(= "AA" "AA" "Aa")
Line 2,220: Line 2,220:
-> T
-> T
(> "A" "B" "Z" "C")
(> "A" "B" "Z" "C")
-> NIL</lang>
-> NIL</syntaxhighlight>
If you want a function which takes one list here are some straight-forward implementation:
If you want a function which takes one list here are some straight-forward implementation:
<syntaxhighlight lang="picolisp">
<lang PicoLisp>
(de same (List)
(de same (List)
(apply = List))
(apply = List))
Line 2,234: Line 2,234:
(same '("AA" "AA" "AA"))
(same '("AA" "AA" "AA"))
-> T
-> T
</syntaxhighlight>
</lang>
This would of course also work with <= and >= without any hassle.
This would of course also work with <= and >= without any hassle.


=={{header|PL/I}}==
=={{header|PL/I}}==
<lang pli>*process source xref attributes or(!);
<syntaxhighlight lang="pli">*process source xref attributes or(!);
/*--------------------------------------------------------------------
/*--------------------------------------------------------------------
* 01.07.2014 Walter Pachl
* 01.07.2014 Walter Pachl
Line 2,277: Line 2,277:
Put Skip List(name!!': '!!txt);
Put Skip List(name!!': '!!txt);
End;
End;
End;</lang>
End;</syntaxhighlight>
{{out}}
{{out}}
<pre>ABC: elements are in increasing order
<pre>ABC: elements are in increasing order
Line 2,284: Line 2,284:


=={{header|Plain English}}==
=={{header|Plain English}}==
<lang plainenglish>To decide if some string things are lexically equal:
<syntaxhighlight lang="plainenglish">To decide if some string things are lexically equal:
If the string things are empty, say yes.
If the string things are empty, say yes.
Get a string thing from the string things.
Get a string thing from the string things.
Line 2,302: Line 2,302:
If the string thing's string is less than the string thing's previous' string, say no.
If the string thing's string is less than the string thing's previous' string, say no.
Put the string thing's next into the string thing.
Put the string thing's next into the string thing.
Repeat.</lang>
Repeat.</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
{{works with|PowerShell|4.0}}
{{works with|PowerShell|4.0}}
<syntaxhighlight lang="powershell">
<lang PowerShell>
function IsAscending ( [string[]]$Array ) { ( 0..( $Array.Count - 2 ) ).Where{ $Array[$_] -le $Array[$_+1] }.Count -eq $Array.Count - 1 }
function IsAscending ( [string[]]$Array ) { ( 0..( $Array.Count - 2 ) ).Where{ $Array[$_] -le $Array[$_+1] }.Count -eq $Array.Count - 1 }
function IsEqual ( [string[]]$Array ) { ( 0..( $Array.Count - 2 ) ).Where{ $Array[$_] -eq $Array[$_+1] }.Count -eq $Array.Count - 1 }
function IsEqual ( [string[]]$Array ) { ( 0..( $Array.Count - 2 ) ).Where{ $Array[$_] -eq $Array[$_+1] }.Count -eq $Array.Count - 1 }
Line 2,317: Line 2,317:
IsEqual 'A', 'C', 'B', 'C'
IsEqual 'A', 'C', 'B', 'C'
IsEqual 'A', 'A', 'A', 'A'
IsEqual 'A', 'A', 'A', 'A'
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,330: Line 2,330:


=={{header|Prolog}}==
=={{header|Prolog}}==
<lang Prolog>los(["AA","BB","CC"]).
<syntaxhighlight lang="prolog">los(["AA","BB","CC"]).
los(["AA","AA","AA"]).
los(["AA","AA","AA"]).
los(["AA","CC","BB"]).
los(["AA","CC","BB"]).
Line 2,350: Line 2,350:
nl.
nl.


test :- forall(los(List), test_list(List)).</lang>
test :- forall(los(List), test_list(List)).</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 2,378: Line 2,378:


=={{header|PureBasic}}==
=={{header|PureBasic}}==
<lang purebasic>EnableExplicit
<syntaxhighlight lang="purebasic">EnableExplicit
DataSection
DataSection
Data.s ~"AA\tAA\tAA\nAA\tBB\tCC\nAA\tCC\tBB\nAA\tACB\tBB\tCC\nsingel_element"
Data.s ~"AA\tAA\tAA\nAA\tBB\tCC\nAA\tCC\tBB\nAA\tACB\tBB\tCC\nsingel_element"
Line 2,415: Line 2,415:
PrintN("")
PrintN("")
Next
Next
Input()</lang>
Input()</syntaxhighlight>
{{out}}
{{out}}
<pre>List : AA AA AA
<pre>List : AA AA AA
Line 2,440: Line 2,440:
A useful pattern is that when you need some function of an item in a list with its next item over possibly all items in the list then <code>f(a, nexta) for a, nexta in zip(alist, alist[1:]))</code> works nicely.
A useful pattern is that when you need some function of an item in a list with its next item over possibly all items in the list then <code>f(a, nexta) for a, nexta in zip(alist, alist[1:]))</code> works nicely.
(Especially if an index is not needed elsewhere in the algorithm).
(Especially if an index is not needed elsewhere in the algorithm).
<lang python>all(a == nexta for a, nexta in zip(strings, strings[1:])) # All equal
<syntaxhighlight lang="python">all(a == nexta for a, nexta in zip(strings, strings[1:])) # All equal
all(a < nexta for a, nexta in zip(strings, strings[1:])) # Strictly ascending
all(a < nexta for a, nexta in zip(strings, strings[1:])) # Strictly ascending


len(set(strings)) == 1 # Concise all equal
len(set(strings)) == 1 # Concise all equal
sorted(strings, reverse=True) == strings # Concise (but not particularly efficient) ascending
sorted(strings, reverse=True) == strings # Concise (but not particularly efficient) ascending
</syntaxhighlight>
</lang>




Line 2,452: Line 2,452:
and, if we wish, pass functional forms of standard operators to either of them:
and, if we wish, pass functional forms of standard operators to either of them:


<lang python>from operator import (eq, lt)
<syntaxhighlight lang="python">from operator import (eq, lt)




Line 2,469: Line 2,469:


all(map(lt, az, az[1:]))
all(map(lt, az, az[1:]))
)</lang>
)</syntaxhighlight>
{{Out}}
{{Out}}
<pre>True False True</pre>
<pre>True False True</pre>
Line 2,479: Line 2,479:
The word <code>$></code> compares two strings using the QACSFOT lexical ordering. (QACSFOT - Quackery Arbitrary Character Sequence For Ordered Text. It is less arbitrary than the ASCII sequence.)
The word <code>$></code> compares two strings using the QACSFOT lexical ordering. (QACSFOT - Quackery Arbitrary Character Sequence For Ordered Text. It is less arbitrary than the ASCII sequence.)


<lang Quackery> [ [ true swap
<syntaxhighlight lang="quackery"> [ [ true swap
dup size 1 > while
dup size 1 > while
behead swap
behead swap
Line 2,493: Line 2,493:
[ tuck $> if
[ tuck $> if
[ dip not conclude ] ] ]
[ dip not conclude ] ] ]
drop ] is allinorder ( [ --> b )</lang>
drop ] is allinorder ( [ --> b )</syntaxhighlight>


=={{header|R}}==
=={{header|R}}==
Line 2,501: Line 2,501:
function yields false.
function yields false.


<syntaxhighlight lang="r">
<lang R>
chunks <- function (compare, xs) {
chunks <- function (compare, xs) {
starts = which(c(T, !compare(head(xs, -1), xs[-1]), T))
starts = which(c(T, !compare(head(xs, -1), xs[-1]), T))
Line 2,507: Line 2,507:
function(i) xs[starts[i]:(starts[i+1]-1)] )
function(i) xs[starts[i]:(starts[i+1]-1)] )
}
}
</syntaxhighlight>
</lang>


Testing:
Testing:


<syntaxhighlight lang="r">
<lang R>
> chunks(`<`, c(0,4,8,1,3,5,7,9))
> chunks(`<`, c(0,4,8,1,3,5,7,9))
[[1]]
[[1]]
Line 2,518: Line 2,518:
[[2]]
[[2]]
[1] 1 3 5 7 9
[1] 1 3 5 7 9
</syntaxhighlight>
</lang>


R displays the results in a very prolix manner, so let's simplify it.
R displays the results in a very prolix manner, so let's simplify it.


<syntaxhighlight lang="r">
<lang R>
> toString(chunks(`<`, c(0,4,8,1,3,5,7,9,-2,0,88)))
> toString(chunks(`<`, c(0,4,8,1,3,5,7,9,-2,0,88)))
[1] "c(0, 4, 8), c(1, 3, 5, 7, 9), c(-2, 0, 88)"
[1] "c(0, 4, 8), c(1, 3, 5, 7, 9), c(-2, 0, 88)"
> toString(chunks(`==`, c(0,0,0,5,5,8)))
> toString(chunks(`==`, c(0,0,0,5,5,8)))
[1] "c(0, 0, 0), c(5, 5), 8"
[1] "c(0, 0, 0), c(5, 5), 8"
</syntaxhighlight>
</lang>


Defining the required functions:
Defining the required functions:


<syntaxhighlight lang="r">
<lang R>
all.eq <- function(xs) 1 == length( chunks(`==`, xs))
all.eq <- function(xs) 1 == length( chunks(`==`, xs))
ascending <- function(xs) 1 == length( chunks(`<`, xs))
ascending <- function(xs) 1 == length( chunks(`<`, xs))
</syntaxhighlight>
</lang>


Testing:
Testing:


<syntaxhighlight lang="r">
<lang R>
> all.eq(c('by'))
> all.eq(c('by'))
[1] TRUE
[1] TRUE
Line 2,553: Line 2,553:
> ascending(c("at"))
> ascending(c("at"))
[1] TRUE
[1] TRUE
</syntaxhighlight>
</lang>


=={{header|Racket}}==
=={{header|Racket}}==
Line 2,564: Line 2,564:


Hence the wrapper in the code below:
Hence the wrapper in the code below:
<lang racket>#lang racket/base
<syntaxhighlight lang="racket">#lang racket/base
(define ((list-stringX? stringX?) strs)
(define ((list-stringX? stringX?) strs)
(or (null? strs) (null? (cdr strs)) (apply stringX? strs)))
(or (null? strs) (null? (cdr strs)) (apply stringX? strs)))
Line 2,585: Line 2,585:
(list-string<? '("a" "a")) => #f
(list-string<? '("a" "a")) => #f
(list-string<? '("a" "b" "a")) => #f
(list-string<? '("a" "b" "a")) => #f
(list-string<? '("a" "b" "c")) => #t))</lang>
(list-string<? '("a" "b" "c")) => #t))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
Line 2,592: Line 2,592:
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 but 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)'':
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 but 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)'':


<lang perl6>[eq] @strings # All equal
<syntaxhighlight lang="raku" line>[eq] @strings # All equal
[lt] @strings # Strictly ascending</lang>
[lt] @strings # Strictly ascending</syntaxhighlight>


=={{header|Red}}==
=={{header|Red}}==
<lang Red>Red []
<syntaxhighlight lang="red">Red []


list1: ["asdf" "Asdf" "asdf"]
list1: ["asdf" "Asdf" "asdf"]
Line 2,613: Line 2,613:
print all-equal? list3
print all-equal? list3
print sorted? list3
print sorted? list3
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>false
<pre>false
Line 2,625: Line 2,625:
=={{header|REXX}}==
=={{header|REXX}}==
===version 1===
===version 1===
<lang rexx>/* REXX ---------------------------------------------------------------
<syntaxhighlight lang="rexx">/* REXX ---------------------------------------------------------------
* 28.06.2014 Walter Pachl
* 28.06.2014 Walter Pachl
*--------------------------------------------------------------------*/
*--------------------------------------------------------------------*/
Line 2,667: Line 2,667:
Say 'List' value(list)': neither equal nor in increasing order'
Say 'List' value(list)': neither equal nor in increasing order'
End
End
Return</lang>
Return</syntaxhighlight>
{{out}}
{{out}}
<pre>List ABC: elements are in increasing order
<pre>List ABC: elements are in increasing order
Line 2,679: Line 2,679:
:::::::* '''parse upper arg x'''
:::::::* '''parse upper arg x'''
:::::::* '''arg x'''
:::::::* '''arg x'''
<lang rexx>/*REXX program compares a list of (character) strings for: equality, all ascending. */
<syntaxhighlight lang="rexx">/*REXX program compares a list of (character) strings for: equality, all ascending. */
@.1= 'ayu dab dog gar panda tui yak' /*seven strings: they're all ascending.*/
@.1= 'ayu dab dog gar panda tui yak' /*seven strings: they're all ascending.*/
@.2= 'oy oy oy oy oy oy oy oy oy oy' /* ten strings: all equal. */
@.2= 'oy oy oy oy oy oy oy oy oy oy' /* ten strings: all equal. */
Line 2,702: Line 2,702:
if word(strings,k)<<=word(strings,k-1) then return 0 /*string>prev? */
if word(strings,k)<<=word(strings,k-1) then return 0 /*string>prev? */
end /*k*/ /* [↑] 0=false, [↓] 1=true. */
end /*k*/ /* [↑] 0=false, [↓] 1=true. */
return 1 /*indicate that strings are ascending. */</lang>
return 1 /*indicate that strings are ascending. */</syntaxhighlight>
{{out|output|text=&nbsp; when using the supplied lists:}}
{{out|output|text=&nbsp; when using the supplied lists:}}
<pre>
<pre>
Line 2,728: Line 2,728:
===version 3===
===version 3===
This REXX version is more idiomatic.
This REXX version is more idiomatic.
<lang rexx>/*REXX program compares a list of strings for: equality, all ascending. */
<syntaxhighlight lang="rexx">/*REXX program compares a list of strings for: equality, all ascending. */
@.1= 'ayu dab dog gar panda tui yak' /*seven strings: they're all ascending.*/
@.1= 'ayu dab dog gar panda tui yak' /*seven strings: they're all ascending.*/
@.2= 'oy oy oy oy oy oy oy oy oy oy' /* ten strings: all equal. */
@.2= 'oy oy oy oy oy oy oy oy oy oy' /* ten strings: all equal. */
Line 2,746: Line 2,746:
if how=='A' then if word(x,k) <<= word(x,k-1) then return 0 /*≤ prev.?*/
if how=='A' then if word(x,k) <<= word(x,k-1) then return 0 /*≤ prev.?*/
end /*k*/ /* [↓] 1=true. [↑] 0=false. */
end /*k*/ /* [↓] 1=true. [↑] 0=false. */
return 1 /*indicate strings have true comparison*/</lang>
return 1 /*indicate strings have true comparison*/</syntaxhighlight>
{{out|output|text=&nbsp; is identical to the above REXX version.}} <br><br>
{{out|output|text=&nbsp; is identical to the above REXX version.}} <br><br>


=={{header|Ruby}}==
=={{header|Ruby}}==
<lang ruby>strings.uniq.one? # all equal?
<syntaxhighlight lang="ruby">strings.uniq.one? # all equal?
strings == strings.uniq.sort # ascending?</lang>
strings == strings.uniq.sort # ascending?</syntaxhighlight>


Short circuiting:
Short circuiting:
<lang ruby>strings.all?{|str| str == strings.first} # all equal?
<syntaxhighlight lang="ruby">strings.all?{|str| str == strings.first} # all equal?
strings.each_cons(2).all?{|str1, str2| str1 < str2} # ascending?</lang>
strings.each_cons(2).all?{|str1, str2| str1 < str2} # ascending?</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==


<lang rust>fn strings_are_equal(seq: &[&str]) -> bool {
<syntaxhighlight lang="rust">fn strings_are_equal(seq: &[&str]) -> bool {
match seq {
match seq {
&[] | &[_] => true,
&[] | &[_] => true,
Line 2,773: Line 2,773:
_ => false
_ => false
}
}
}</lang>
}</syntaxhighlight>


=={{header|S-lang}}==
=={{header|S-lang}}==
"Simple Loop" and "Array Idiomatic" versions:
"Simple Loop" and "Array Idiomatic" versions:
<lang S-lang>define equal_sl(sarr)
<syntaxhighlight lang="s-lang">define equal_sl(sarr)
{
{
variable n = length(sarr), a0, i;
variable n = length(sarr), a0, i;
Line 2,827: Line 2,827:
atest(["single_element"]);
atest(["single_element"]);
atest(NULL);
atest(NULL);
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>"AA"
<pre>"AA"
Line 2,865: Line 2,865:
=={{header|Scala}}==
=={{header|Scala}}==
Functions implemented in Scala following a functional paradigm
Functions implemented in Scala following a functional paradigm
<syntaxhighlight lang="scala">
<lang Scala>
def strings_are_equal(seq:List[String]):Boolean = seq match {
def strings_are_equal(seq:List[String]):Boolean = seq match {
case Nil => true
case Nil => true
Line 2,878: Line 2,878:
}
}


</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 2,904: Line 2,904:
For known lists that are 'short-enough', the simplest solution uses 'apply', but that relies on the list being shorter than the maximum number of arguments a function can accept. Better is to write a simple loop:
For known lists that are 'short-enough', the simplest solution uses 'apply', but that relies on the list being shorter than the maximum number of arguments a function can accept. Better is to write a simple loop:


<lang scheme>
<syntaxhighlight lang="scheme">
(define (compare-strings fn strs)
(define (compare-strings fn strs)
(or (null? strs) ; returns #t on empty list
(or (null? strs) ; returns #t on empty list
Line 2,916: Line 2,916:
(compare-strings string=? strings) ; test for all equal
(compare-strings string=? strings) ; test for all equal
(compare-strings string<? strings) ; test for in ascending order
(compare-strings string<? strings) ; test for in ascending order
</syntaxhighlight>
</lang>


=={{header|Seed7}}==
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const func boolean: allTheSame (in array string: strings) is func
const func boolean: allTheSame (in array string: strings) is func
Line 2,945: Line 2,945:
end if;
end if;
end for;
end for;
end func;</lang>
end func;</syntaxhighlight>


=={{header|SenseTalk}}==
=={{header|SenseTalk}}==
<lang sensetalk>analyze ["AA","BB","CC"]
<syntaxhighlight lang="sensetalk">analyze ["AA","BB","CC"]
analyze ["AA","AA","AA"]
analyze ["AA","AA","AA"]
analyze ["AA","CC","BB"]
analyze ["AA","CC","BB"]
Line 2,971: Line 2,971:
end repeat
end repeat
return True
return True
end isAscending</lang>
end isAscending</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>
Line 2,993: Line 2,993:
=={{header|Sidef}}==
=={{header|Sidef}}==
Short-circuiting:
Short-circuiting:
<lang ruby>1..arr.end -> all{ arr[0] == arr[_] } # all equal
<syntaxhighlight lang="ruby">1..arr.end -> all{ arr[0] == arr[_] } # all equal
1..arr.end -> all{ arr[_-1] < arr[_] } # strictly ascending</lang>
1..arr.end -> all{ arr[_-1] < arr[_] } # strictly ascending</syntaxhighlight>


Non short-circuiting:
Non short-circuiting:
<lang ruby>arr.uniq.len == 1 # all equal
<syntaxhighlight lang="ruby">arr.uniq.len == 1 # all equal
arr == arr.uniq.sort # strictly ascending</lang>
arr == arr.uniq.sort # strictly ascending</syntaxhighlight>


=={{header|Tailspin}}==
=={{header|Tailspin}}==
Note that we choose here to use 1 as true and 0 as false since Tailspin doesn't (yet?) have booleans
Note that we choose here to use 1 as true and 0 as false since Tailspin doesn't (yet?) have booleans
<lang tailspin>
<syntaxhighlight lang="tailspin">
// matcher testing if the array contains anything not equal to the first element
// matcher testing if the array contains anything not equal to the first element
templates allEqual
templates allEqual
Line 3,026: Line 3,026:
otherwise 0 !
otherwise 0 !
end strictEqual
end strictEqual
</syntaxhighlight>
</lang>


=={{header|Tcl}}==
=={{header|Tcl}}==
The command form of the <code>eq</code> and <code>&lt;</code> operators (introduced in Tcl 8.5) handle arbitrarily many arguments and will check if they're all equal/ordered.
The command form of the <code>eq</code> and <code>&lt;</code> operators (introduced in Tcl 8.5) handle arbitrarily many arguments and will check if they're all equal/ordered.
Making the operators work with a list of values is just a matter of using the expansion syntax with them.
Making the operators work with a list of values is just a matter of using the expansion syntax with them.
<lang tcl>tcl::mathop::eq {*}$strings; # All values string-equal
<syntaxhighlight lang="tcl">tcl::mathop::eq {*}$strings; # All values string-equal
tcl::mathop::< {*}$strings; # All values in strict order</lang>
tcl::mathop::< {*}$strings; # All values in strict order</syntaxhighlight>


=={{header|VBA}}==
=={{header|VBA}}==
<syntaxhighlight lang="vb">
<lang vb>
Private Function IsEqualOrAscending(myList) As String
Private Function IsEqualOrAscending(myList) As String
Dim i&, boolEqual As Boolean, boolAsc As Boolean
Dim i&, boolEqual As Boolean, boolAsc As Boolean
Line 3,054: Line 3,054:
IsEqualOrAscending = "List : " & Join(myList, ",") & ", IsEqual : " & (Not boolEqual) & ", IsAscending : " & Not boolAsc
IsEqualOrAscending = "List : " & Join(myList, ",") & ", IsEqual : " & (Not boolEqual) & ", IsAscending : " & Not boolAsc
End Function
End Function
</syntaxhighlight>
</lang>
Call :
Call :
<syntaxhighlight lang="vb">
<lang vb>
Sub Main()
Sub Main()
Dim List
Dim List
Line 3,068: Line 3,068:
Debug.Print IsEqualOrAscending(List)
Debug.Print IsEqualOrAscending(List)
End Sub
End Sub
</syntaxhighlight>
</lang>
{{Out}}
{{Out}}
<pre>
<pre>
Line 3,081: Line 3,081:


=={{header|VBScript}}==
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Function string_compare(arr)
Function string_compare(arr)
lexical = "Pass"
lexical = "Pass"
Line 3,105: Line 3,105:
WScript.StdOut.WriteLine string_compare(Array("AA","ACB","BB","CC"))
WScript.StdOut.WriteLine string_compare(Array("AA","ACB","BB","CC"))
WScript.StdOut.WriteLine string_compare(Array("FF"))
WScript.StdOut.WriteLine string_compare(Array("FF"))
</syntaxhighlight>
</lang>


{{Out}}
{{Out}}
Line 3,132: Line 3,132:
=={{header|Vlang}}==
=={{header|Vlang}}==
{{trans|go}}
{{trans|go}}
<lang valng>fn all_equal(strings []string) bool {
<syntaxhighlight lang="valng">fn all_equal(strings []string) bool {
for s in strings {
for s in strings {
if s != strings[0] {
if s != strings[0] {
Line 3,148: Line 3,148:
}
}
return true
return true
}</lang>
}</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-sort}}
{{libheader|Wren-sort}}
<lang ecmascript>import "/sort" for Sort
<syntaxhighlight lang="ecmascript">import "/sort" for Sort


var areEqual = Fn.new { |strings|
var areEqual = Fn.new { |strings|
Line 3,168: Line 3,168:
System.print("%(b) are ascending : %(areAscending.call(b))")
System.print("%(b) are ascending : %(areAscending.call(b))")
System.print("%(c) are all equal : %(areEqual.call(c))")
System.print("%(c) are all equal : %(areEqual.call(c))")
System.print("%(d) are ascending : %(areAscending.call(d))")</lang>
System.print("%(d) are ascending : %(areAscending.call(d))")</syntaxhighlight>


{{out}}
{{out}}
Line 3,179: Line 3,179:


=={{header|XProfan}}==
=={{header|XProfan}}==
<lang XProfan>Proc allsame
<syntaxhighlight lang="xprofan">Proc allsame
Parameters long liste
Parameters long liste
var int result = 1
var int result = 1
Line 3,227: Line 3,227:
ClearList 0
ClearList 0
WaitKey
WaitKey
end</lang>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 3,249: Line 3,249:
=={{header|zkl}}==
=={{header|zkl}}==
These short circuit.
These short circuit.
<lang zkl>fcn allEQ(strings){ (not strings.filter1('!=(strings[0]))) }
<syntaxhighlight lang="zkl">fcn allEQ(strings){ (not strings.filter1('!=(strings[0]))) }
fcn monoUp(strings){
fcn monoUp(strings){
strings.len()<2 or
strings.len()<2 or
strings.reduce(fcn(a,b){ if(a>=b) return(Void.Stop,False); b }).toBool()
strings.reduce(fcn(a,b){ if(a>=b) return(Void.Stop,False); b }).toBool()
}</lang>
}</syntaxhighlight>
<lang zkl>allEQ(T("AA")).println(); //True
<syntaxhighlight lang="zkl">allEQ(T("AA")).println(); //True
allEQ(T("AA","AA","AA","AA")).println(); //True
allEQ(T("AA","AA","AA","AA")).println(); //True
allEQ(T("A", "AA","AA","AA")).println(); //False
allEQ(T("A", "AA","AA","AA")).println(); //False
Line 3,261: Line 3,261:
monoUp(T("a","aa","aaa","aaaa")).println(); //True
monoUp(T("a","aa","aaa","aaaa")).println(); //True
monoUp(T("a","aa","aaa","aaa")).println(); //False
monoUp(T("a","aa","aaa","aaa")).println(); //False
monoUp(T("a","b","c","cc")).println(); //True</lang>
monoUp(T("a","b","c","cc")).println(); //True</syntaxhighlight>


=={{header|zonnon}}==
=={{header|zonnon}}==
<lang zonnon>
<syntaxhighlight lang="zonnon">
module CompareStrings;
module CompareStrings;
type
type
Line 3,296: Line 3,296:
write("ascending?: ");writeln(ascending)
write("ascending?: ");writeln(ascending)
end CompareStrings.
end CompareStrings.
</syntaxhighlight>
</lang>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
{{trans|AWK}}
{{trans|AWK}}
<lang zxbasic>10 FOR j=160 TO 200 STEP 10
<syntaxhighlight lang="zxbasic">10 FOR j=160 TO 200 STEP 10
20 RESTORE j
20 RESTORE j
30 READ n
30 READ n
Line 3,319: Line 3,319:
180 DATA 3,"AA","CC","BB"
180 DATA 3,"AA","CC","BB"
190 DATA 4,"AA","ACB","BB","CC"
190 DATA 4,"AA","ACB","BB","CC"
200 DATA 1,"single_element"</lang>
200 DATA 1,"single_element"</syntaxhighlight>