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.

# Query Expected result according to
[ standard ] [ draft prologue ]
IF
V5.1B
SWI
6.3.7-13
YAP
6.3.2
B
7.5#5
GNU
1.4.0
SICStus
3.12.5
SICStus
4.3beta1
XSB
3.3.6
Ciao
1.13.0
a1 atom_length(A,N). instantiation_error 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
a3 atom_length(a,1.1). type_error(integer,1.1) 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
a5 atom_length(1,N). type_error(atom,1) OK N = 1 N = 1 reg OK OK OK OK OK OK
1 length(L,N). L = [], N = 0 ;
L = [_], N = 1 ...
in._e. * OK OK OK OK OK OK OK OK
2 length(L,0). L = []. in._e. * OK OK OK OK OK OK OK OK
3 length([_|L],0). fails in._e. * 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
5 length([_|2],0). fails ty._e.(list,[_213|2]) ty._e.(list,[_|2]) new 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
7 length([_|2],2). fails ty._e.(list,[_213|2]) ty._e.(list,[_|2]) new 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
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
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
11 length([],-0.1). type_error(integer,-0.1) OK OK new OK new OK new OK fails OK OK new fails
12 length(L,-0.1). type_error(integer,-0.1) in._e. * OK OK new OK new OK fails OK OK new fails
13 length([a],1.0). type_error(integer,1.0) OK OK new OK new OK new OK fails OK OK new fails
14 length(L,1.0). type_error(integer,1.0) in._e. * OK new OK new OK new OK fails OK OK new fails
15 length(L,1.1). type_error(integer,1.1) in._e. * OK OK new OK new OK fails OK OK new fails
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.
17 N is 2^64, length([], N). fails OK OK ty._e.(integer,18..) OK ** N = 0 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
19 length([],-_). type_error(integer,-_) OK OK new OK new OK new OK fails OK OK new fails
20 length([a],-_). type_error(integer,-_) OK OK new OK new OK new OK in._e. OK OK new in._e.
21 length([a,b|X],X). ? loops fails new loops loops loops loops loops ty._e.(integer,[]) new loops
22 length(L,L). ? loops fails loops loops loops loops loops ty._e.(integer,[]) new loops
23 L = [_|_], length(L,L). type_error(integer,[_|_]) OK OK OK new OK OK ty._e.(eval.,_) OK OK ty._e.(eval.,_)
24 L = [_], length(L,L). type_error(integer,[_]) OK OK new OK new OK OK in._e. OK OK ty._e.(eval.,_)
25 L = [1], length(L,L). type_error(integer,[1]) OK OK new OK new OK OK fails OK OK fails
26 L = [a|L], length(L,N). undefined loops ty._e.(list,[a|...]) fails new loops loops loops res._e.(mem.) new loops loops
27 L = [a|L], length(L,0). undefined loops ty._e.(list,[a|...])) new fails fails fails fails fails fails fails
28 L = [a|L], length(L,7). undefined loops ty._e.(list,[a|...])) new fails fails fails fails fails fails fails
Remarks:
* ... using list_length in place of length
new... progress after Lexington 2011
Template and Modes: length(?term, ?integer) vs. length(?list, ?integer). A similar case in 13211-1:1995 is (is)/2.
Validated HTML