To facilitate manipulation of terms as objects in themselves, XSB provides a number meta-logical predicates. These predicates include the standard meta-logical predicates of Prolog, along with their usual semantics. In addition are provided predicates which provide special operations on HiLog terms. For a full discussion of Prolog and HiLog terms see Section 4.1.
Term X is uninstantiated if it has not been bound to anything, except possibly another uninstantiated variable. Note in particular, that the HiLog term X(Y,Z) is considered to be instantiated. There is no distinction between a Prolog and a HiLog variable.
Examples:
| ?- var(X).
yes
| ?- var([X]).
no
| ?- var(X(Y,Z)).
no
| ?- var((X)).
yes
| ?- var((X)(Y)).
no
Examples:
| ?- atom(HiLog).
no
| ?- atom(10).
no
| ?- atom('HiLog').
yes
| ?- atom(X(a,b)).
no
| ?- atom(h).
yes
| ?- atom(+).
yes
| ?- atom([]).
yes
Examples:
| ?- atomic(10).
yes
| ?- atomic(p).
yes
| ?- atomic(h).
yes
| ?- atomic(h(X)).
no
| ?- atomic("foo").
no
| ?- atomic('foo').
yes
| ?- atomic(X).
no
| ?- atomic(X((Y))).
no
Examples:
| ?- compound(1).
no
| ?- compound(foo(1,2,3)).
yes
| ?- compound([foo, bar]).
yes
| ?- compound("foo").
yes
| ?- compound('foo').
no
| ?- compound(X(a,b)).
yes
| ?- compound((a,b)).
yes
Examples:
| ?- is_list([p(a,b,c), h(a,b)]).
yes
| ?- is_list([_,_]).
yes
| ?- is_list([a,b|X]).
no
| ?- is_list([a|b]).
no
| ?- is_charlist("abc").
yes
| ?- is_charlist(abc).
no
| ?- is_most_general_term(f(_,_,_,_)).
yes
| ?- is_most_general_term(abc).
yes
| ?- is_most_general_term(f(X,Y,Z,X)).
no
| ?- is_most_general_term(f(X,Y,Z,a)).
no
| ?- is_most_general_term([_|_]).
no
Examples:
| ?- callable(p).
yes
| ?- callable(p(1,2,3)).
yes
| ?- callable([_,_]).
yes
| ?- callable(_(a)).
yes
| ?- callable(3.14).
no
Examples: (In this example and the rest of the examples of this section we assume that h is the only parameter symbol that has been declared a HiLog symbol).
| ?- proper_hilog(X).
no
| ?- proper_hilog(foo(a,f(b),[A])).
no
| ?- proper_hilog(X(a,b,c)).
yes
| ?- proper_hilog(3.6(2,4)).
yes
| ?- proper_hilog(h).
no
| ?- proper_hilog([a, [d, e, X(a)], c]).
yes
| ?- proper_hilog(a(a(X(a)))).
yes
Error Cases
Examples:
| ?- functor(p(f(a),b,t), F, A).
F = p
A = 3
| ?- functor(T, foo, 3).
T = foo(_595708,_595712,_595716)
| ?- functor(T, 1.3, A).
T = 1.3
A = 0
| ?- functor(foo, F, 0).
F = foo
| ?- functor("foo", F, A).
F = .
A = 2
| ?- functor([], [], A).
A = 0
| ?- functor([2,3,4], F, A).
F = .
A = 2
| ?- functor(a+b, F, A).
F = +
A = 2
| ?- functor(f(a,b,c), F, A).
F = f
A = 3
| ?- functor(X(a,b,c), F, A).
F = apply
A = 4
| ?- functor(map(P)(a,b), F, A).
F = apply
A = 3
| ?- functor(T, foo(a), 1).
++Error: Wrong type in argument 2 of functor/3
Aborting...
| ?- functor(T, F, 3).
++Error: Uninstantiated argument 2 of functor/3
Aborting...
| ?- functor(T, foo, A).
++Error: Uninstantiated argument 3 of functor/3
Aborting...
Examples:
| ?- hilog_functor(f(a,b,c), F, A).
F = f
A = 3
| ?- hilog_functor(X(a,b,c), F, A).
X = _595836
F = _595836
A = 3
| ?- hilog_functor(map(P)(a,b), F, A).
P = _595828
F = map(_595828)
A = 2
| ?- hilog_functor(T, p, 2).
T = p(_595708,_595712)
| ?- hilog_functor(T, h, 2).
T = apply(h,_595712,_595716)
| ?- hilog_functor(T, X, 3).
T = apply(_595592,_595736,_595740,_595744)
X = _595592
| ?- hilog_functor(T, p(f(a)), 2).
T = apply(p(f(a)),_595792,_595796)
| ?- hilog_functor(T, h(p(a))(L1,L2), 1).
T = apply(apply(apply(h,p(a)),_595984,_595776),_596128)
L1 = _595984
L2 = _595776
| ?- hilog_functor(T, a+b, 3).
T = apply(a+b,_595820,_595824,_595828)
Examples:
| ?- arg(2, p(a,b), A).
A = b
| ?- arg(2, h(a,b), A).
A = a
| ?- arg(0, foo, A).
no
| ?- arg(2, [a,b,c], A).
A = [b,c]
| ?- arg(2, "HiLog", A).
A = [105,108,111,103]
| ?- arg(2, a+b+c, A).
A = c
| ?- arg(3, X(a,b,c), A).
X = _595820
A = b
| ?- arg(2, map(f)(a,b), A).
A = a
| ?- arg(1, map(f)(a,b), A).
A = map(f)
| ?- arg(1, (a+b)(foo,bar), A).
A = a+b
Initially, Index must be instantiated to a positive integer and
Term to any non-variable Prolog or HiLog term.
If the initial conditions are not satisfied or
is
out of range, the call quietly fails. Note that like arg/3
this predicate does not succeed for Index=0.
Examples:
| ?- hilog_arg(2, p(a,b), A).
A = b
| ?- hilog_arg(2, h(a,b), A).
A = b
| ?- hilog_arg(3, X(a,b,c), A).
X = _595820
A = c
| ?- hilog_arg(1, map(f)(a,b), A).
A = a
| ?- hilog_arg(2, map(f)(a,b), A).
A = b
| ?- hilog_arg(1, (a+b)(foo,bar), A).
A = foo
| ?- hilog_arg(1, apply(foo), A).
A = foo
| ?- hilog_arg(1, apply(foo,bar), A).
A = bar
Note the difference between the last two examples. The difference is due to the fact that apply/1 is a Prolog term, while apply/2 is a proper HiLog term.
Examples:
| ?- X - 1 =.. L.
X = _595692
L = [-,_595692,1]
| ?- p(a,b,c) =.. L.
L = [p,a,b,c]
| ?- h(a,b,c) =.. L.
L = [apply,h,a,b,c]
| ?- map(p)(a,b) =.. L.
L = [apply,map(p),a,b]
| ?- T =.. [foo].
T = foo
| ?- T =.. [3|X].
T = 3
X = []
| ?- T =.. [apply,X,a,b].
T = apply(X,a,b)
| ?- T =.. [1,2].
++Error: Wrong type(s) in argument 2 of =../2
Aborting...
| ?- T =.. [a+b,2].
++Error: Wrong type(s) in argument 2 of =../2
Aborting..
| ?- X =.. [foo|Y].
++Error: Argument 2 of =../2 is not a proper list
Aborting...
Error Cases
^=../2
succeeds unifying F to its HiLog functor and ArgList to the
list of the arguments to which this HiLog functor is applied. Like
=../2, the use of ^=../2 can nearly always be avoided
by using the more efficient predicates hilog_functor/3 and
hilog_arg/3. The behaviour of ^=../2, on HiLog terms
is as follows:
^=../2 must be instantiated to
a proper list (list of determinate length) whose head can
be any Prolog or HiLog term.
^=../2 are both uninstantiated,
or if the second of them is not what is expected,
^=../2 aborts, producing an appropriate error message.
| ?- p(a,b,c) ^=.. L.
L = [p,a,b,c]
| ?- h(a,b,c) ^=.. L.
L = [h,a,b,c]
| ?- map(p)(a,b) ^=.. L.
L = [map(p),a,b]
| ?- T ^=.. [X,a,b].
T = apply(X,a,b)
| ?- T ^=.. [2,2].
T = apply(2,2)
| ?- T ^=.. [a+b,2].
T = apply(a+b,2)
| ?- T ^=.. [3|X].
++Error: Argument 2 of ^=../2 is not a proper list
Aborting...
Error Cases
^=../2 is not a proper list.
Examples:
| ?- copy_term(X, Y).
X = _598948
Y = _598904
| ?- copy_term(f(a,X), Y).
X = _598892
Y = f(a,_599112)