?- ( current_prolog_flag(double_quotes, chars), atom_chars('jim', "jim") ; current_prolog_flag(double_quotes, codes), atom_codes('jim', "jim") ; current_prolog_flag(double_quotes, atom), 'jim' == "jim" ). true. ?- ( current_prolog_flag(double_quotes, chars), [] == "" ; current_prolog_flag(double_quotes, codes), [] == "" ; current_prolog_flag(double_quotes, atom), '' == "" ). true. ?- true. true. ?- fail. false. b(X) :- Y = (write(X), X), call(Y). a(1). a(2). ?- call(!). true. ?- call(fail). false. ?- call( (fail,X)). false. ?- call( (fail, call(1)) ). false. ?- b(_). outputs(['_'|_]), instantiation_error. ?- b(3). outputs("3"), type_error(callable, 3), unexpected. % Error in 13211-1:1995 ?- b(3). type_error(callable, (write(3),3)). % Cor.2:2012#C12 ?- Z = !, call( (Z=!, a(X), Z) ). Z = !, X = 1. ?- call( (Z=!, a(X), Z) ). Z = !, X = 1 ; Z = !, X = 2. ?- call((write(3), X)). outputs("3"), instantiation_error. ?- call((write(3), call(1))). % corr. outputs("3"), type_error(callable, 1). ?- call((1;true)). type_error(callable, (1;true)). twice(!) :- write('C '). twice(true) :- write('Moss '). goal((twice(_), !)). goal(write('Three ')). ?- !. true. ?- (!, fail; true). false. ?- (call(!), fail; true). true. ?- twice(_), !, write('Forwards '), fail. outputs("C Forwards "), false. ?- (! ; write('No ')), write('Cut disjunction'), fail. outputs("Cut disjunction"), false. ?- twice(_), (write('No '); !), write('Cut '), fail. outputs("C No Cut Cut "), false. ?- twice(_), (!, fail; write('No ')). outputs("C "), false. ?- twice(X), call(X), write('Forwards '), fail. outputs("C Forwards Moss Forwards "), false. ?- goal(X), call(X), write('Forwards '), fail. outputs("C Forwards Three Forwards "), false. ?- twice(_), \+(\+(!)), write('Forwards '), fail. outputs("C Forwards Moss Forwards "), false. ?- twice(_), once(!), write('Forwards '), fail. outputs("C Forwards Moss Forwards "), false. ?- twice(_), call(!), write('Forwards '), fail. outputs("C Forwards Moss Forwards "), false. ?- ','(X=1, var(X)). false. ?- ','(var(X), X=1). X = 1. ?- ','(X = true, call(X)). X = true. ?- ';'(true, fail). true. ?- ';'((!, fail), true). false. % [Equivalent to (!, fail).] ?- ';'(!, call(3)). true. % [Equivalent to !.] ?- ';'((X = 1, !), X = 2). X = 1. ?- ','(';'(X=1, X=2), ';'(true, !)). X = 1 ; X = 1. ?- '->'(true, true). true. ?- '->'(true, fail). false. ?- '->'(fail, true). false. ?- '->'(true, X=1). X = 1. ?- '->'(';'(X=1, X=2), true). X = 1. ?- '->'(true, ';'(X=1, X=2)). X = 1 ; X = 2. ?- ';'('->'(true, true), fail). Succeeds. ?- ';'('->'(fail, true), true). true. ?- ';'('->'(true, fail), fail). false. ?- ';'('->'(fail, true), fail). false. ?- ';'('->'(true, X=1), X=2). X = 1. ?- ';'('->'(fail, X = 1), X = 2). X = 2. ?- ';'('->'(true, ';'(X=1, X=2)), true). X = 1 ; X = 2. ';'('->'(';'(X=1, X=2), true), true). X = 1. ';'('->'(!,fail), true), true). true. foo(X) :- Y is X * 2, throw(test(Y)). bar(X) :- X = Y, throw(Y). coo(X) :- throw(X). car(X) :- X = 1, throw(X). g :- catch(p, B, write(h2)), coo(c). p. p :- throw(b). ?- catch(foo(5), test(Y), true). Y = 10. ?- catch(bar(3), Z, true). Z = 3. ?- catch(true, _, 3). true. ?- catch(true, C, write(demoen)), throw(bla). throw(bla). % system_error. ?- catch(car(X), Y, true). Y = 1. ?- catch(number_chars(X, ['1', 'a', '0']), error(syntax_error(_), _), fail). false. % number_chars raises a syntax error. ?- catch(g, C, write(h1)). outputs("h1"), C = c. ?- catch(coo(X), Y, true). Y = error(instantiation_error, Imp_def). ?- '='(1, 1). true. ?- '='(X, 1). X = 1. ?- '='(X, Y). X = Y. ?- '='(_, _). true. ?- '='(X, Y), '='(X, abc). X = abc, Y = abc. ?- '='(f(X, def), f(def, Y)). X = def, Y = def. ?- '='(1, 2). false. ?- '='(1, 1.0). false. ?- '='( g(X), f(f(X)) ). false. ?- '='( f(X, 1), f(a(X) ) ). false. ?- '='( f(X, Y, X ), f(a(X), a(Y), Y, 2) ). false. ?- '='( X, a(X) ). sto. ?- '='( f(X, 1), f(a(X), 2) ). sto. ?- '='( f(1, X, 1), f(2, a(X), 2) ). sto. ?- '='( f(1, X ), f(2, a(X)) ). sto. ?- '='( f(X, Y, X, 1), f(a(X), a(Y), Y, 2) ). sto. ?- unify_with_occurs_check(1, 1). true. ?- unify_with_occurs_check(X, 1). X = 1. ?- unify_with_occurs_check(X, Y). X = Y. ?- unify_with_occurs_check(_, _). true. ?- unify_with_occurs_check(X, Y), unify_with_occurs_check(X, abc). X = abc, Y = abc. ?- unify_with_occurs_check(f(X, def), f(def, Y)). X = def, Y = def. ?- unify_with_occurs_check(1, 2). false. ?- unify_with_occurs_check(1, 1.0). false. ?- unify_with_occurs_check( g(X), f(f(X)) ). false. ?- unify_with_occurs_check( f(X, 1), f(a(X) ) ). false. ?- unify_with_occurs_check( f(X, Y, X ), f(a(X), a(Y), Y, 2) ). false. ?- unify_with_occurs_check( X, a(X) ). false. ?- unify_with_occurs_check( f(X, 1), f(a(X), 2) ). false. ?- unify_with_occurs_check( f(1, X, 1), f(2, a(X), 2) ). false. ?- unify_with_occurs_check( f(1, X), f(2, a(X)) ). false. ?- unify_with_occurs_check( f(X, Y, X, 1), f(a(X), a(Y), Y, 2) ). false. ?- '\\='(1, 1). false. ?- \=(X, 1). false. ?- '\\='(X, Y). false. ?- \=(_, _). false. ?- \=(f(X, def), f(def, Y)). false. ?- '\\='(1, 2). true. ?- \=(1, 1.0). true. ?- '\\='( g(X), f(f(X)) ). true. ?- \=( f(X, 1), f(a(X) ) ). true. ?- '\\='( f(X, Y, X ), f(a(X), a(Y), Y, 2) ). true. ?- \=( X, a(X) ). sto. ?- '\\='( f(X, 1), f(a(X), 2) ). sto. ?- '\\='( f(1, X, 1), f(2, a(X), 2) ). sto. ?- \=( f(2, X), f(2, a(X)) ). sto. ?- '\\='( f(X, Y, X, 1), f(a(X), a(Y), Y, 2) ). sto. ?- var(foo). false. ?- var(Foo). true. ?- foo=Foo, var(Foo). false. ?- var(_). true. ?- atom(atom). true. ?- atom('string'). true. ?- atom(a(b)). false. ?- atom(Var). false. ?- atom([]). true. ?- atom(6). false. ?- atom(3.3). false. ?- integer(3). true. ?- integer(-3). true. ?- integer(3.3). false. ?- integer(X). false. ?- integer(atom). false. ?- float(3.3). true. ?- float(-3.3). true. ?- float(3). false. ?- float(atom). false. ?- float(X). false. ?- atomic(atom). true. ?- atomic(a(b)). false. ?- atomic(Var). false. ?- atomic(6). true. ?- atomic(3.3). true. ?- compound(33.3). false. ?- compound(-33.3). false. ?- compound(-a). true. ?- compound(_). false. ?- compound(a). false. ?- compound(a(b)). true. ?- compound([]). false. ?- compound([a]). true. ?- nonvar(33.3). true. ?- nonvar(foo). true. ?- nonvar(Foo). false. ?- foo = Foo, nonvar(Foo). true. ?- nonvar(_). false. ?- nonvar(a(b)). true. ?- number(3). true. ?- number(3.3). true. ?- number(-3). true. ?- number(a). false. ?- number(X). false. ?- '@=<'(1.0, 1). true. ?- '@<'(1.0, 1). true. ?- '\\=='(1, 1). false. ?- '@=<'(aardvark, zebra). true. ?- '@=<'(short, short). true. ?- '@=<'(short, shorter). true. ?- '@>='(short, shorter). false. ?- '@<'(foo(a, b), north(a)). false. ?- '@>'(foo(b), foo(a)). true. ?- '@<'(foo(a, X), foo(b, Y)). true. ?- '@<'(foo(X, a), foo(Y, b)). true | false. ?- '@=<'(X, X). true. ?- '=='(X, X). true. ?- '@=<'(X, Y). true | false. ?- '=='(X, Y). false. \==(_, _). true. ?- '=='(_, _). false. ?- '@=<'(_, _). true | false. ?- '@=<'(foo(X, a), foo(Y, b)). true | false. ?- functor(foo(a, b, c), foo, 3). true. ?- functor(foo(a, b, c), X, Y). X = foo, Y = 3. ?- functor(X, foo, 3). X = foo(_, _, _). ?- functor(X, foo, 0). X = foo. ?- functor(mats(A, B), A, B). A = 'mats', B = 2. ?- functor(foo(a), foo, 2). false. ?- functor(foo(a), fo, 1). false. ?- functor(1, X, Y). X = 1, Y = 0. ?- functor(X, 1.1, 0). X = 1.1. ?- functor([_|_], '.', 2). true. ?- functor([], [], 0). true. ?- functor(X, Y, 3). instantiation_error. ?- functor(X, foo, N). instantiation_error. ?- functor(X, foo, a). type_error(integer, a). ?- functor(F, 1.5, 1). type_error(atom, 1.5). ?- functor(F, foo(a), 1). type_error(atomic, foo(a)). ?- current_prolog_flag(max_arity, A), X is A + 1, functor(T, foo, X). representation_error(max_arity) | type_error(evaluable,unbounded/0). ?- Minus_1 is 0 - 1, functor(F, foo, Minus_1). domain_error(not_less_than_zero, -1). ?- arg(1, foo(a, b), a). true. ?- arg(1, foo(a, b), X). X = a. ?- arg(1, foo(X, b), a). X = a. ?- arg(1, foo(X, b), Y). X = Y. ?- arg(1, foo(a, b), b). false. ?- arg(0, foo(a, b), foo). false. ?- arg(3, foo(3, 4), N). false. ?- arg(X, foo(a, b), a). instantiation_error. ?- arg(1, X, a). instantiation_error. ?- arg(0, atom, A). type_error(compound, atom). ?- arg(0, 3, A). type_error(compound, 3). ?- arg(1, foo(X), u(X)). sto. ?- '=..'(foo(a, b), [foo, a, b]). true. ?- '=..'(X, [foo, a, b]). X = foo(a, b). ?- '=..'(foo(a, b), L). L = [foo, a, b]. ?- '=..'(foo(X, b), [foo, a, Y]). X = a, Y = b. ?- '=..'(1, [1]). true. ?- '=..'(foo(a, b), [foo, b, a]). false. ?- '=..'(X, Y). instantiation_error. ?- '=..'(X, [foo, a | Y]). instantiation_error. ?- '=..'(X, [foo|bar]). type_error(list, [foo|bar]). ?- '=..'(X, [Foo, bar]). instantiation_error. ?- '=..'(X, [3, 1]). type_error(atom, 3). ?- '=..'(X, [1.1, foo]). type_error(atom, 1.1). ?- '=..'(X, [a(b), 1]). type_error(atom, a(b)). ?- '=..'(X, 4). type_error(list, 4). ?- '=..'(f(X), [f, u(X)]). sto. ?- copy_term(X, Y). true. ?- copy_term(X, 3). true. ?- copy_term(_, a). true. ?- copy_term(a+X, X+b). X = a. ?- copy_term(_, _). true. ?- copy_term(X+X+Y, A+B+B). A = B. ?- copy_term(a, b). false. ?- copy_term(a+X, X+b), copy_term(a+X, X+b). false. ?- copy_term(demoen(X, X), demoen(Y, f(Y))). sto. ?- 'is'(Result, 3+11.0). Result = 14.0. ?- X = 1+2, Y is X * 3. X = 1+2, Y = 9. ?- 'is'(3, 3). true. ?- 'is'(3, 3.0). false. ?- 'is'(foo, 77). false. ?- 'is'(77, N). instantiation_error. ?- '=:='(0, 1). false. ?- '=\\='(0, 1). true. ?- '<'(0, 1). true. ?- '>'(0, 1). false. ?- '>='(0, 1). false. ?- '=<'(0, 1). true. ?- '=:='(1.0, 1). true. ?- =\=(1.0, 1). false. ?- '<'(1.0, 1). false. ?- '>'(1.0, 1). false. ?- '>='(1.0, 1). true. ?- '=<'(1.0, 1). true. ?- '=:='(3*2, 7-1). true. ?- '=\\='(3*2, 7-1). false. ?- '<'(3*2, 7-1). false. ?- '>'(3*2, 7-1). false. ?- '>='(3*2, 7-1). true. ?- '=<'(3*2, 7-1). true. ?- '=:='(X, 5). instantiation_error. ?- =\=(X, 5). instantiation_error. ?- '<'(X, 5). instantiation_error. ?- '>'(X, 5). instantiation_error. ?- '>='(X, 5). instantiation_error. ?- '=<'(X, 5). instantiation_error. :- dynamic(cat/0). cat. :- dynamic(dog/0). dog :- true. elk(X) :- moose(X). :- dynamic(legs/2). legs(A, 6) :- insect(A). legs(A, 7) :- A, call(A). :- dynamic(insect/1). insect(ant). insect(bee). ?- clause(cat, true). true. ?- clause(dog, true). true. ?- clause(legs(I, 6), Body). Body = insect(I). ?- clause(legs(C, 7), Body). Body = (call(C), call(C)). ?- clause(insect(I), T). I = ant, T = true ; I = bee, T = true. ?- clause(x, Body). false. ?- clause(_, B). instantiation_error. ?- clause(4, X). type_error(callable, 4). ?- clause(elk(N), Body). permission_error(access, private_procedure, elk/1). ?- clause(atom(_), Body). permission_error(access, private_procedure, atom/1). ?- clause(legs(A, 6), insect(f(A))). sto. ?- current_predicate(dog/0). true. ?- current_predicate(current_predicate/1). false. ?- current_predicate(elk/Arity). Arity = 1. ?- current_predicate(foo/A). false. ?- current_predicate(Name/1). Name = elk ; Name = insect | other_answer_sequence. ?- current_predicate(4). type_error(predicate_indicator, 4). ?- abolish(foo/2). true. /* also undefines foo/2 if there exists a dynamic procedure with predicate indicator foo/2. */ ?- abolish(foo/_). instantiation_error. ?- abolish(foo). type_error(predicate_indicator, foo). ?- abolish(foo(_)). type_error(predicate_indicator, foo(_)). ?- abolish(abolish/1). permission_error(modify, static_procedure, abolish/1). ?- findall(X, (X=1; X=2), S). S = [1, 2]. ?- findall(X+Y, (X=1), S). S = [1+_]. ?- findall(X, fail, L). S = []. ?- findall(X, (X=1; X=1), S). S = [1, 1]. ?- findall(X, (X=2; X=1), [1, 2]). false. ?- findall(X, (X=1;X=2), [X, Y]). X = 1, Y = 2. ?- findall(X, Goal, S). instantiation_error. ?- findall(X, 4, S). type_error(callable, 4). ?- bagof(X, (X=1 ; X=2), S). % Free variables set: {}. S = [1,2]. ?- bagof(X, (X=1 ; X=2), X). % Free variables set: {}. X = [1,2]. ?- bagof(X, (X=Y ; X=Z), S). % Free variables set: {Y, Z}. S = [Y, Z]. ?- bagof(X, fail, S). % Free variables set: {}. false. ?- bagof(1, (Y=1 ; Y=2), L). % Free variables set: {Y}. Y = 1, L = [1] ; Y = 2, L = [1] | other_answer_sequence. ?- bagof(f(X, Y), (X=a ; Y=b), L). % Free variables set: {}. L = [f(a, _A), f(_B, b)]. ?- bagof(X, Y^((X=1, Y=1) ; (X=2, Y=2)), S). % Free variables set: {}. S = [1, 2]. ?- bagof(X, Y^((X=1 ; Y=1) ; (X=2, Y=2)), S). % Free variables set: {}. S = [1, _, 2]. ?- bagof(X, (Y^(X=1 ; Y=2) ; X=3), S). % Free variables set: {Y}. existence_error(procedure,(^)/2) | S = [3] | S = [1,3] ; Y = 2, S = [_A]. ?- bagof(X, (X=Y ; X=Z ; Y=1), S). % Free variables set: {Y, Z}. S = [Y,Z] ; Y = 1, S = [_A] | other_answer_sequence. a(1, f(_)). a(2, f(_)). ?- bagof(X, a(X, Y), L). % Free variables set: {Y}. Y = f(_), L = [1, 2]. b(1, 1). b(1, 1). b(1, 2). b(2, 1). b(2, 2). b(2, 2). ?- bagof(X, b(X, Y), L). % Free variables set: {Y}. Y = 1, L = [1,1,2] ; Y = 2, L = [1,2,2] | other_answer_sequence. ?- bagof(X, Y^Z, L). instantiation_error. ?- bagof(X, 1, L). type_error(callable, 1). ?- setof(X, (X=1; X=2), S). % Free variables set: {}. S = [1,2]. ?- setof(X, (X=1; X=2), X). % Free variables set: {}. X = [1,2]. ?- setof(X, (X=2; X=1), S). % Free variables set: {}. S = [1,2]. ?- setof(X, (X=2; X=2), S). % Free variables set: {}. S = [2]. ?- setof(X, (X=Y; X=Z), S). % Free variables set: {Y, Z}. S = [Y, Z] | S = [Z, Y]. ?- setof(X, fail, S). % Free variables set: {}. false. ?- setof(1, (Y=2 ; Y=1), L). % Free variables set: {Y}. Y = 1, L = [1] ; Y = 2, L = [1] | other_answer_sequence. ?- setof(f(X,Y), (X=a ; Y=b), L). % Free variables set: {}. L = [f(_A,b),f(a,_B)]. ?- setof(X, Y^((X=1, Y=1) ; (X=2, Y=2)), S). % Free variables set: {}. S = [1,2]. ?- setof(X, Y^((X=1 ; Y=1) ; (X=2, Y=2)), S). % Free variables set: {}. S = [_,1,2]. ?- setof(X, (Y^(X=1 ; Y=2) ; X=3), S). % Free variables set: {Y}. existence_error(procedure, (^)/2) | S = [3] | S = [1,3] ; Y = 2, S = [_A] | other_answer_sequence. ?- setof(X, (X=Y ; X=Z ; Y=1), S). % Free variables set: {Y, Z}. S = [Y,Z] ; Y = 1, S = [_] | S = [Z,Y] ; Y = 1, S = [_] | Y = 1, S = [_] ; S = [Y,Z] | Y = 1, S = [_] ; S = [Z,Y]. ?- setof(X, (X=Y ; X=Z ; Y=1), S). % Free variables set: {Y, Z}. ( S = [Y,Z] | S = [Z,Y] ) ; Y = 1, S = [_] | Y = 1, S = [_] ; ( S = [Y,Z] | S = [Z,Y] ). ?- setof(X, a(X, Y), L). % Free variables set: {Y}. Y = f(_), L = [1, 2]. ?- setof(X, (X=Y; X=Z), S). S = [Y,Z] | S = [Z,Y]. ?- setof(X, member(X,[f(U,b),f(V,c)]), L). % Free variables set: {U, V}. L = [f(U,b),f(V,c)] | L = [f(V,c),f(U,b)]. ?- setof(X, member(X,[f(U,b),f(V,c)]), [f(a,c),f(a,b)]). % Free variables set: {U, V}. false | U = a, V = a. ?- setof(X, member(X,[f(b,U),f(c,V)]), [f(b,a),f(c,a)]). % Free variables set: {U, V}. U = a, V = a. ?- setof(X, member(X,[V,U,f(U),f(V)]), L). % Free variables set: {U, V}. L = [U,V,f(U),f(V)] | L = [V,U,f(V),f(U)]. ?- setof(X, member(X,[V,U,f(U),f(V)]), [a,b,f(a),f(b)]). % Free variables set: {U, V}. V = a, U = b | V = b, U = a. ?- setof(X, member(X,[V,U,f(U),f(V)]), [a,b,f(b),f(a)]). % Free variables set: {U, V}. false. ?- setof(X, (exists(U,V)^member(X,[V,U,f(U),f(V)])), [a,b,f(b),f(a)]). % Free variables set: {}. true. ?- setof(X, b(X, Y), L). % Free variables set: {Y}. Y = 1, L = [1, 2] ; Y = 2, L = [1, 2] | Y = 2, L = [1, 2] ; Y = 1, L = [1, 2]. ?- setof(X-Xs,Y^setof(Y,b(X,Y),Xs),L). % Free variables set: {}. L = [1-[1,2],2-[1,2]]. ?- setof(X-Xs,setof(Y,b(X,Y),Xs),L). % Free variables set: {Y}. L = [1-[1,2],2-[1,2]]. d(1,1). d(1,2). d(1,1). d(2,2). d(2,1). d(2,2). ?- setof(X-Xs,bagof(Y,d(X,Y),Xs),L). % Free variables set: {Y}. L = [1-[1,2,1],2-[2,1,2]]. % 8.11.5.4 open/4 % 8.12.1.4 get_char/1 % 8.12.2.4 peek_char/1 % 8.12.3.4 put_char/1 ?- put_char(t). outputs("t"). % 8.13.3.4 put_byte/1 % 8.14.1.4 ?- read(T). inputs("term1."), T = term1. ?- read(T), read(U). inputs("term1. term2."), T = term1, U = term2. ?- read_term(T,[variables(VL), variable_names(VN), singletons(VS)]). inputs("foo(A+Roger, A+_)."), T = foo(X1+X2, X1+X3), VL = [X1, X2, X3], VN = ['A' = X1, 'Roger' = X2], VS = ['Roger' = X2]. ?- read(4.1). inputs("3.1"), false. ?- write_term([1,2,3], []). outputs("[1,2,3]"). ?- write_canonical([1,2,3]). outputs("'.'(1,'.'(2,'.'(3,[])))"). ?- write_term('1<2', []). outputs("1<2"). ?- writeq('1<2'). outputs("'1<2'"). ?- writeq('$VAR'(0)). outputs("A"). ... % 8.13.3.4 op/3 ?- current_op(1000, xfy, ','). true. ?- current_op(1100, xfy, ;). true. ?- current_op(1050, xfy, ->). true. ?- current_op(200, xfy, ^). true. ?- current_op(P, xfy, OP). ... ; P = 1100, OP = (;) ; ... . % 8.14.5.4 char_conversion/2 ?- '\\+'(true). false. ?- \+(!). false. % the cut has no effect. ?- '\\+'((!, fail)). true. % the cut has no effect. ?- (X=1; X=2), \+((!, fail)). X = 1 ; X = 2. ?- '\\+'(4 = 5). true. ?- \+(3). type_error(callable, 3). ?- '\\+'(X). instantiation_error. ?- \+(X = f(X)). sto. ?- once(!). true. % (the same as true). ?- once(!), (X=1; X=2). X = 1 ; X = 2. ?- once(repeat). true. ?- once(fail). false. ?- once(X = f(X)). sto. ?- repeat, write('hello '). outputs("hello ") ; outputs("hello ") ; outputs("hello ") ; ... . ?- repeat, write('hello '), fail. outputs("hello "), outputs("hello "), outputs(_), loops. ?- repeat, !, fail. false. % equivalent to (!, fail). ?- atom_concat(T1, T2, 'hello'). T1 = '', T2 = hello ; T1 = h, T2 = ello ; T1 = he, T2 = llo ; T1 = hel, T2 = lo ; T1 = hell, T2 = o ; T1 = hello, T2 = ''. ?- atom_length('enchanted evening', N). N = 17. ?- atom_length('enchanted\ evening', N). N = 17. ?- atom_length('', N) N = 0. ?- atom_length('scarlet', 5). false. ?- atom_length(Atom, 4). instantiation_error. ?- atom_length(1.23, 4). type_error(atom, 1.23). ?- atom_length(atom, '4'). type_error(integer, '4'). ?- atom_concat('hello', ' world', S3). S3 = 'hello world'. ?- atom_concat(T, ' world', 'small world'). T = 'small'. ?- atom_concat('hello', ' world', 'small world'). false. ?- atom_concat(T1, T2, 'hello'). T1 = '', T2 = 'hello' ; T1 = 'h', and T2 = 'ello' ; ... . ?- sub_atom(abracadabra, 0, 5, _, S2). S2 = 'abrac'. ?- sub_atom(abracadabra, _, 5, 0, S2). S2 = 'dabra'. ?- sub_atom(abracadabra, 3, L, 3, S2). L = 5, S2 = 'acada'. ?- atom_concat(small, V2, V4). instantiation_error. ?- sub_atom(abracadabra, B, 2, A, ab). B = 0, A = 9 ; B = 7, A = 2. ?- sub_atom('Banana', 3, 2, _, S2). S2 = 'an'. ?- sub_atom('charity', _, 3, _, S2). S2 = cha ; S2 = har ; S2 = ari ; S2 = rit ; S2 = ity. ?- sub_atom('ab', Start, Length, _, Sub_atom). Start = 0, Length = 0, Sub_atom = '' ; Start = 0, Length = 1, Sub_atom = a ; Start = 0, Length = 2, Sub_atom = ab ; Start = 1, Length = 0, Sub_atom = '' ; Start = 1, Length = Start, Sub_atom = b ; Start = 2, Length = 0, Sub_atom = ''. ?- atom_chars('', L). L = []. ?- atom_chars([], L). L = ['[', ']']. ?- atom_chars('''', L). L = ['''']. ?- atom_chars('ant', L). L = ['a', 'n', 't']. ?- atom_chars(Str, ['s', 'o', 'p']). Str = 'sop'. ?- atom_chars('North', ['N' | X]). X = ['o', 'r', 't', 'h']. ?- atom_chars('soap', ['s', 'o', 'p']). false. ?- atom_chars(X, Y). instantiation_error. ?- atom_codes('', L). L = []. ?- atom_codes([], L). L = [0'[, 0']]. ?- atom_codes('''', L). L = [0''']. ?- atom_codes('ant', L). L = [0'a, 0'n, 0't]. ?- atom_codes(Str, [0's, 0'o, 0'p]). Str = 'sop'. ?- atom_codes('North', [0'N | X]). X = [0'o, 0'r, 0't, 0'h]. ?- atom_codes('soap', [0's, 0'o, 0'p]). false. ?- atom_codes(X, Y). instantiation_error. ?- char_code('a', Code). Code = 0'a. ?- char_code(Str, 99). Str = '\x63\'. ?- char_code(Str, 0'c). Str = c. ?- char_code(Str, 163). Str ='\xa3\' % cannot use the pound sign | representation_error(character_code). ?- char_code('b', 98). true. ?- char_code('b', 84). false. % iff the character 'b' has the character code 84. ?- char_code('ab', Int). type_error(character, ab). ?- char_code(C, I). instantiation_error. ?- C=['0', '.', '1'], number_chars(X,C), number_chars(X,C). C = "0.1", X = _. ?- number_chars(33, L). L = ['3', '3']. ?- number_chars(33, ['3', '3']). true. ?- number_chars(33.0, L). L = ['3', '.', '3', 'E', +, '0', '1'] | L = "33.0" | L = _. % an implementation dependent list of characters, ?- N = 33.0, number_chars(N, L), number_chars(M, L), N \== M. false. ?- number_chars(X, ['3', '.', '3', 'E', +, '0']). X = 3.3 | X = a value approximately equal to 3.3. ?- number_chars(3.3, ['3', '.', '3', 'E', +, '0']). true | false. ?- number_chars(A, [-, '2', '5']). A = -25. ?- number_chars(A, ['\n', ' ', '3']). [The new line and space characters are not significant.] A = 3. ?- number_chars(A, ['3', ' ']). syntax_error(_). ?- number_chars(A, ['3', ' ']). syntax_error(imp_dep_atom) where 'imp_dep_atom' is an implementation dependent atom. ?- number_chars(A, ['0', x, f]) A = 15. ?- number_chars(A, ['0', '''', a]) A = 0'a. ?- number_chars(A, ['4', '.', '2']). A = 4.2. ?- number_chars(A, ['4', '2', '.', '0', 'e', '-', '1']). A = 4.2. ?- number_codes(33, L). L = [0'3, 0'3]. ?- number_codes(33, [0'3, 0'3]). true. ?- number_codes(33.0, L). L = [0'3,0'3,0'.,0'0] | L = [0'3, 0'., 0'3, 0'E, 0'+, 0'0, 0'1] | L = [0'3|_]. ?- number_codes(33.0, [0'3, 0'., 0'3, 0'E, 0'+, 0'0, 0'1]). true|false. ?- number_codes(A, [0'-, 0'2, 0'5]). A = -25. ?- number_codes(A, [0' , 0'3]). A = 3. % The space character is not significant. ?- number_codes(A, [0'0, 0'x, 0'f]) A = 15. ?- number_codes(A, [0'0, 0''', 0'a]) A = 0'a. ?- number_codes(A, [0'4, 0'., 0'2]). A = 4.2. ?- number_codes(A, [0'4, 0'2, 0'., 0'0, 0'e, 0'-, 0'1]). A = 4.2. % ?- set_prolog_flag(unknown, fail). ?- set_prolog_flag(X, off). instantiation_error. ?- set_prolog_flag(5, decimals). type_error(atom, 5). ?- set_prolog_flag(date, 'July 1988'). domain_error(flag, date). ?- set_prolog_flag(debug, trace). domain_error(flag_value, debug+trace). ?- current_prolog_flag(debug, off). true. ?- current_prolog_flag(F, V). Succeeds, unifying 'F' with one of the flags supported by the processor, and 'V' with the value currently associated with the flag 'F'. On re-execution, successively unifies 'F' and 'V' with each other flag supported by the processor and its associated value. ?- current_prolog_flag(5, _). type_error(atom, 5). % halt(1). ?- halt(a). type_error(integer, a). % 9 Evaluable functors ?- Value is '+'(7, 35). Value = 42. ?- Value is '+'(0, 3+11). Value = 14. ?- Value is '+'(0, 3.2+11). Evaluates to a value approximately equal to 14.2000. ?- Value is '+'(77, N). instantiation_error. ?- Value is '+'(foo, 77). type_error(number, foo). ?- Value is '-'(7). Value = -7. ?- Value is '-'(3-11). Value = 8. ?- Value is '-'(3.2-11). Evaluates to a value approximately equal to 7.8000. ?- Value is '-'(N). instantiation_error. ?- Value is '-'(foo). type_error(number, foo). ?- Value is '-'(7, 35). Value = -28. ?- Value is '-'(20, 3+11). Value = 6. ?- Value is '-'(0, 3.2+11). Evaluates to a value approximately equal to -14.2000. ?- Value is '-'(77, N). instantiation_error. ?- Value is '-'(foo, 77). type_error(number, foo). ?- Value is '*'(7, 35). Value = 245. ?- Value is '*'(0, 3+11). Value = 0. ?- Value is '*'(1.5, 3.2+11). Evaluates to a value approximately equal to 21.3000. ?- Value is '*'(77, N). instantiation_error. ?- Value is '*'(foo, 77). type_error(number, foo). ?- Value is '/'(7, 35). Value = 0.2. ?- Value is '/'(7.0, 35). Value = 0.2. ?- Value is '/'(140, 3+11). Value = 10. ?- Value is '/'(20.164, 3.2+11), Max is max(Value-1.42,3.0e-16). Value = 14.2 | Max = 3.0e-16. ?- Value is '/'(7, -3). Value = -2.3333333333333335. ?- Value is '/'(-7, 3). Value = -2.3333333333333335. ?- Value is '/'(77, N). instantiation_error. ?- Value is '/'(foo, 77). type_error(number, foo). ?- Value is '/'(3, 0). evaluation_error(zero_divisor). ?- Value is mod(7, 3). Value = 1. ?- Value is mod(0, 3+11). Value = 0. ?- Value is mod(7, -2). Value = -1. ?- Value is mod(77, N). instantiation_error. ?- Value is mod(foo, 77). type_error(number, foo). ?- Value is mod(7.5, 2). type_error(integer, 7.5). ?- Value is mod(7, 0). evaluation_error(zero_divisor). ?- Value is floor(7.4). Value = 7. ?- Value is floor(-0.4). Value = -1. ?- Value is round(7.5). Value = 8. ?- Value is round(7.6). Value = 8. ?- Value is round(-0.6). Value = -1. ?- Value is round(N). instantiation_error. ?- Value is ceiling(-0.5). Value = 0. ?- Value is truncate(-0.5). Value = 0. ?- Value is truncate(foo). type_error(number, foo). ?- Value is float(7). Value = 7.0. ?- Value is float(7.3). Value = 7.3. ?- Value is float(5 / 3). Value = 1.0. ?- Value is float(N). instantiation_error. ?- Value is float(foo). type_error(number, foo). ?- Value is abs(7). Value = 7. ?- Value is abs(3-11). Value = 8. ?- Value is abs(3.2-11.0). Value = 7.8000. ?- Value is abs(N). instantiation_error. ?- Value is abs(foo). type_error(number, foo). ?- current_prolog_flag(max_integer, MI), X is '+'(MI, 1). evaluation_error(int_overflow). ?- current_prolog_flag(max_integer, MI), X is '-'('+'(MI, 1), 1). evaluation_error(int_overflow) | false. ?- current_prolog_flag(max_integer, MI), X is '-'(-1, MI). evaluation_error(int_overflow) | false. ?- current_prolog_flag(max_integer, MI), X is '*'(MI, 2). evaluation_error(int_overflow) | false. ?- current_prolog_flag(max_integer, MI), R is float(MI) * 2, X is floor(R). evaluation_error(int_overflow) | false. ?- Value is '**'(5, 3). Value = 125.0. ?- Value is '**'(-5.0, 3). Value = -125.0. ?- Value is '**'(5, -1). Value ~ '0.20000'. ?- Value is '**'(77, N). instantiation_error. ?- Value is '**'(foo, 2). type_error(number, foo). ?- Value is '**'(5, 3.0). Value = 125.0. ?- Value is '**'(0.0, 0). Value = 1.0. ?- Value is sin(0.0). Value = 0.0. ?- Value is sin(N). instantiation_error. ?- Value is sin(0). Value = 0.0. ?- Value is sin(foo). type_error(number, foo). ?- PI is atan(1.0) * 4, X is sin(PI / 2.0). PI ~ '3.14159', X ~ '1.00000'. ?- Value is cos(0.0). Value = 1.0. ?- Value is cos(N). instantiation_error. ?- Value is cos(0). Value = 1.0. ?- Value is cos(foo). type_error(number, foo). ?- PI is atan(1.0) * 4, X is cos(PI / 2.0). PI ~ '3.14159', X ~ '0.00000'. ?- Value is atan(0.0). Value = 0.0. ?- PI is atan(1.0) * 4. PI ~ '3.14159'. ?- Value is atan(N). instantiation_error. ?- Value is atan(0). Value = 0.0. ?- Value is atan(foo). type_error(number, foo). ?- Value is exp(0.0). Value = 1.0. ?- Value is exp(1.0). Value ~ '2.71828'. ?- Value is exp(N). instantiation_error. ?- Value is exp(0). Value = 1.0. ?- Value is exp(foo). type_error(number, foo). ?- Value is log(1.0). Value = 0.0. ?- Value is log(2.71828). % cor. Value ~ '1.00000'. ?- Value is log(exp(1.0)). Value = 1.0. ?- Value is log(N). instantiation_error. ?- Value is log(0). evaluation_error(undefined). ?- Value is log(foo). type_error(number, foo). ?- Value is log(0.0). evaluation_error(undefined). ?- Value is sqrt(0.0). Value = 0.0. ?- Value is sqrt(1). Value = 1.0. ?- Value is sqrt(1.21). Value = 1.10000. ?- Value is sqrt(N). instantiation_error. ?- Value is sqrt(-1.0). evaluation_error(undefined). ?- Value is sqrt(foo). type_error(number, foo). ?- Value is '>>'(16, 2). Value = 4. ?- Value is '>>'(19, 2). Value = 4. ?- Value is '>>'(-16, 2). Value = -4. % implementation defined ?- Value is '>>'(77, N). instantiation_error. ?- Value is '>>'(foo, 2). type_error(integer, foo). ?- Value is '<<'(16, 2). Value = 64. ?- Value is '<<'(19, 2). Value = 76. ?- Value is '<<'(-16, 2). Value = -64. ?- Value is '<<'(77, N). instantiation_error. ?- Value is '<<'(foo, 2). type_error(integer, foo). ?- Value is '/\\'(10, 12). Value = 8. ?- Value is /\(10, 12). Value = 8. ?- Value is '/\\'(17 * 256 + 125, 255). Value = 125. ?- Value is /\(-10, 12). Value = 4. % implementation defined ?- Value is '/\\'(77, N). instantiation_error. ?- Value is '/\\'(foo, 2). type_error(integer, foo). ?- Value is '\\/'(10, 12). Value = 14. ?- Value is \/(10, 12). Value = 14. ?- Value is '\\/'(125, 255). Value = 255. ?- Value is \/(-10, 12). Value = -2. % implementation defined ?- Value is '\\/'(77, N). instantiation_error. ?- Value is '\\/'(foo, 2). type_error(integer, foo). ?- Value is '\\'('\\'(1)). Value = 10. ?- Value is \(\(10)). Value = 10. ?- Value is \(10). Value = -11. % implementation defined ?- Value is '\\'(N). instantiation_error. ?- Value is '\\'(2.5). type_error(integer, 2.5).