ISO/IEC JTC1 SC22 WG17
Comparison of implementations of length/2 and atom_length/2

A general comparison of syntax, number_chars/2, ISO Prolog works.
#QueryCodexIFSWIYAPBGNUSICStus 3SICStusXSBCiaoECLiPSeScryerTreallaTauIchiban
# Query, quads Expected result according to
[ standard ] [ draft prologue p.p.3 ]
IF
V5.1B
SWI
6.3.7-13
YAP
7.4.0
B
7.5#5
GNU
1.5.1
SICStus
3.12.5
SICStus
4.8.0β2
XSB
3.3.6
Ciao
1.13.0
ECLiPSe
7.0#42
Scryer
0.9.0
new
Trealla
1.22.41
new
Tau
0.3.2
new
Ichiban
0.10.0
new
a1 atom_length(A,N). instantiation_error OK OK OK OK OK OK OK OK OK OK OK OK OK OK
a2 atom_length(a,a). type_error(integer,a) OK OK OK OK OK OK OK OK OK OK OK OK OK OK
a3 atom_length(a,1.1). type_error(integer,1.1) OK OK OK OK OK OK OK OK OK OK OK OK OK OK
a4 atom_length(a,-1). domain_error(not_less_than_zero,-1) OK fails OK new OK OK OK OK OK fails OK OK OK OK OK
a5 atom_length(1,N). type_error(atom,1) OK N = 1 OK new OK OK OK OK OK OK OK OK OK OK OK
1 length(L,N). L=[],N=0 ; L=[_A],N=1 ; L=[_A,_B],N=2 ; ... . in._e. * OK OK OK OK OK OK OK OK OK OK OK OK OK
2 length(L,0). L = []. in._e. * OK OK OK OK OK OK OK OK OK OK OK OK OK
3 length([_|L],0). fails in._e. * OK OK OK OK OK OK OK OK OK OK OK OK OK
4 length(2,0). fails ty._e.(list,2) ty._e.(list,2) OK new OK OK OK OK OK OK OK OK OK OK OK
5 length([_|2],0). fails ty._e.(list,[_213|2]) ty._e.(list,[_|2]) new OK OK OK OK OK OK OK OK OK OK OK OK
6 length([_|2],N). fails ty._e.(list,[_|2]) ty._e.(list,[_|2]) OK OK OK OK OK OK OK OK OK OK OK OK
7 length([_|2],2). fails ty._e.(list,[_213|2]) ty._e.(list,[_|2]) new OK OK OK OK OK OK OK OK OK OK OK OK
8 length(L,-1). domain_error(not_less_than_zero,-1) in._e. * OK new OK new OK new OK new fails OK new OK new fails fails OK OK OK OK
9 length([],-1). domain_error(not_less_than_zero,-1) OK OK new OK new OK new OK new fails OK new OK new fails fails OK OK OK OK
10 length(a,-1). domain_error(not_less_than_zero,-1) ty._e.(list,a) OK new OK new OK new OK new fails OK new OK new fails fails OK OK OK OK
11 length([],-0.1). type_error(integer,-0.1) OK OK new OK new OK new OK fails OK OK new fails fails OK OK OK OK
12 length(L,-0.1). type_error(integer,-0.1) in._e. * OK OK new OK new OK fails OK OK new fails fails OK OK OK OK
13 length([a],1.0). type_error(integer,1.0) OK OK new OK new OK new OK fails OK OK new fails fails OK OK OK OK
14 length(L,1.0). type_error(integer,1.0) in._e. * OK new OK new OK new OK fails OK OK new fails fails OK OK OK OK
15 length(L,1.1). type_error(integer,1.1) in._e. * OK OK new OK new OK fails OK OK new fails fails OK OK OK OK
16 length(L,1.0e99). type_error(integer,1.0e99) in._e. * OK OK new OK new OK res._e. OK OK new res._e. fails OK OK OK OK
17 N is 2^52, length([], N). fails OK OK OK new OK ** OK OK ** OK OK ** OK OK OK OK OK OK
18 length([],0+0). type_error(integer,0+0) OK OK new OK new OK new OK fails OK OK new fails fails OK OK OK OK
19 length([],-_). type_error(integer,-_) OK OK new OK new OK new OK fails OK OK new fails fails OK OK OK OK
20 length([a],-_). type_error(integer,-_) OK OK new OK new OK new OK in._e. OK OK new in._e. fails OK OK OK OK
21 length([a,b|X],X). loops or ressource_error(Impd) loops fails new loops loops r._e.( finite_m.) new loops r._e.( m.) new ty._e.(integer,[]) new loops g._t._o. r._e.( finite_m.) r._e.( finite_m.) loops r._e.( finite_m.)
22 length(L,L). loops or ressource_error(Impd) loops fails loops loops r._e.( finite_m.) new loops r._e.( m.) new ty._e.(integer,[]) new loops g._t._o. r._e.( finite_m.) r._e.( finite_m.) loops r._e.( finite_m.)
23 L = [_|_], length(L,L). type_error(integer,[_|_]) OK OK OK new OK OK ty._e.(eval.,_) OK OK ty._e.(eval.,_) fails OK OK OK OK
24 L = [_], length(L,L). type_error(integer,[_]) OK OK new OK new OK OK in._e. OK OK ty._e.(eval.,_) fails OK OK OK OK
25 L = [1], length(L,L). type_error(integer,[1]) OK OK new OK new OK OK fails OK OK fails fails OK OK OK OK
26 L = [a|L], length(L,N). STO, loops or ressource_error(Impd) loops ty._e.(list,[a|...]) fails new loops loops loops r._e.( mem.) new loops loops loops r._e.( finite_m.) r._e.( finite_m.) L=[a,a],N=2
;L=[a,a,_],N=3 ...
r._e.( finite_m.)
27 L = [a|L], length(L,0). STO, fails loops ty._e.(list,[a|...])) new fails fails fails fails fails fails fails fails fails fails fails fails
28 L = [a|L], length(L,7). STO, fails loops ty._e.(list,[a|...])) new fails fails fails fails fails fails fails fails fails fails L=[a,a,
_,_,_,_,_]
fails
29 freeze(L,L=[]), length(L,L). fails
30 freeze(L,L=[_|L]), length(L,N). STO, loops or ressource_error(Impd)
31 freeze(L,L=[_|L]), N is 2^64, length(L,N). fails
Remarks:
* ... using list_length in place of length
new... progress after WG17 resolution Lexington 2011
Template and Modes: length(?term, ?integer) vs. length(?list, ?integer). A similar case in 13211-1:1995 is (is)/2.
Validated HTML