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
atom_length(A,N). instantiation_error OK OK OK OK OK OK OK OK OK
atom_length(a,a). type_error(integer,a) OK OK OK OK OK OK OK OK OK
atom_length(a,1.1). type_error(integer,1.1) OK OK OK OK OK OK OK OK OK
atom_length(a,-1). domain_error(not_less_than_zero,-1) OK fails OK new OK OK OK OK OK fails
atom_length(1,N). type_error(atom,1) OK N = 1 N = 1 reg OK OK OK OK OK OK
length(L,N). L = [], N = 0 ;
L = [_], N = 1 ...
in._e. * OK OK OK OK OK OK OK OK
length(L,0). L = []. in._e. * OK OK OK OK OK OK OK OK
length([_|L],0). fails in._e. * OK OK OK OK OK OK OK OK
length(2,0). fails ty._e.(list,2) ty._e.(list,2) OK new OK OK OK OK OK OK
length([_|2],0). fails ty._e.(list,[_213|2]) ty._e.(list,[_|2]) new OK OK OK OK OK OK OK
length([_|2],N). fails ty._e.(list,[_|2]) ty._e.(list,[_|2]) OK OK OK OK OK OK OK
length([_|2],2). fails ty._e.(list,[_213|2]) ty._e.(list,[_|2]) new OK OK OK OK OK OK OK
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
length([],-1). domain_error(not_less_than_zero,-1) OK OK new OK new OK new OK new fails OK new OK new fails
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
length([],-0.1). type_error(integer,-0.1) OK OK new OK new OK new OK fails OK OK new fails
length(L,-0.1). type_error(integer,-0.1) in._e. * OK OK new OK new OK fails OK OK new fails
length([a],1.0). type_error(integer,1.0) OK OK new OK new OK new OK fails OK OK new fails
length(L,1.0). type_error(integer,1.0) in._e. * OK new OK new OK new OK fails OK OK new fails
length(L,1.1). type_error(integer,1.1) in._e. * OK OK new OK new OK fails OK OK new fails
length(L,1.0e99). type_error(integer,1.0e99) in._e. * OK OK new OK new OK res._e. OK OK new res._e.
length([],0+0). type_error(integer,0+0) OK OK new OK new OK new OK fails OK OK new fails
length([],-_). type_error(integer,-_) OK OK new OK new OK new OK fails OK OK new fails
length([a],-_). type_error(integer,-_) OK OK new OK new OK new OK in._e. OK OK new in._e.
length([a,b|X],X). ? loops fails new loops loops loops loops loops ty._e.(integer,[]) new loops
length(L,L). ? loops fails loops loops loops loops loops ty._e.(integer,[]) new loops
L = [_|_], length(L,L). type_error(integer,[_|_]) OK OK OK new OK OK ty._e.(eval.,_) OK OK ty._e.(eval.,_)
L = [_], length(L,L). type_error(integer,[_]) OK OK new OK new OK OK in._e. OK OK ty._e.(eval.,_)
L = [1], length(L,L). type_error(integer,[1]) OK OK new OK new OK OK fails OK OK fails
L = [a|L], length(L,N). undefined loops ty._e.(list,[a|...]) fails new loops loops loops res._e.(mem.) new loops loops
L = [a|L], length(L,0). undefined loops ty._e.(list,[a|...])) new fails fails fails fails fails fails fails
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