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
Exceptions:
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 I 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...
Exceptions:
^=../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...
Exceptions:
^=../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)
'18')
which cannot be constructed by using name/2.
If conversion to an atom is preferred in these cases, the
standard predicate atom_codes/2 should be used instead. The
syntax for numbers that is accepted by name/2 is exactly the one
which read/1 accepts. Predicate name/2 is provided for
backwards compatibility. It is advisable that new programs use
the predicates atom_codes/2 and number_codes/2 described
below.
In Version 2.5 predicate name/2 is not yet implemented for converting from a real number to its character list representation, and if the representation of a real is provided as CharList, it will be converted to an atom.
If both of the arguments of name/2 are uninstantiated or CharList is not a proper list of ASCII characters, name/2 will abort and an error message will be sent to the standard error stream.
Examples:
| ?- name('Foo', L).
L = [70,111,111]
| ?- name([], L).
L = [91,93]
| ?- name(431, L).
L = [52,51,49]
| ?- name(X, [102,111,111]).
X = foo
| ?- name(X, []).
X = ''
| ?- name(X, "Foo").
X = 'Foo'
| ?- name(X, [52,51,49]).
X = 431
| ?- name(X, [45,48,50,49,51]), integer(X).
X = -213
| ?- name(3.14, L).
++Error: Predicate name/2 for reals is not implemented yet
Aborting...
Exceptions:
If both of the arguments of atom_codes/2 are uninstantiated or CharList is not a proper list of ASCII characters, atom_codes/2 aborts, and an error message will be sent to the standard error stream.
Examples:
| ?- atom_codes('Foo', L).
L = [70,111,111]
| ?- atom_codes([], L).
L = [91,93]
| ?- atom_codes(X, [102,111,111]).
X = foo
| ?- atom_codes(X, []).
X = ''
| ?- atom_codes(X, "Foo").
X = 'Foo'
| ?- atom_codes(X, [52,51,49]).
X = '431'
| ?- atom_codes(X, [52,51,49]), integer(X).
no
| ?- atom_codes(X, [52,Y,49]).
! Instantiation error in argument 2 of atom_codes/2
! Aborting...
| ?- atom_codes(431, L).
! Type error: in argument 1 of atom_codes/2
! atom expected, but something else found
! Aborting...
| ?- atom_codes(X, [52,300,49]).
! Range error: in argument 2 of atom_codes/2
! ASCII code expected, but 300 found
! Aborting...
Exceptions:
atom_codes, but the list returned (or input) is a list of
characters as atoms rather than ASCII codes. For instance,
atom_chars(abc,X) binds X to the list [a,b,c]
instead of [97,98,99].
If both of the arguments of number_codes/2 are uninstantiated or CharList is not a proper list of ASCII characters, number_codes/2 aborts, and an error message will be sent to the standard error stream.
Examples:
| ?- number_codes(123, L).
L = [49,50,51];
| ?- number_codes(N, [49,50,51]), integer(N).
N = 123
| ?- number_codes(31.4e+10, L).
L = [51,46,49,51,57,57,57,55,69,43,49,48]
| ?- number_codes(N, "314e+8").
N = 3.14e+10
| ?- number_codes(foo, L).
! Type error: in argument 1 of number_codes/2
! number expected, but something else found
! Aborting...
Exceptions:
number_codes, but the list returned (or input) is a list of
characters as atoms rather than ASCII codes. For instance,
number_chars(123,X) binds X to the list ['1','2','3']
instead of [49,50,51].
number_chars, but the list returned (or input) is a list of
digits as numbers rather than ASCII codes (for floats, the atom
'.', '+' or '-', and 'e' will also be present in the list). For instance,
number_digits(123,X) binds X to the list [1,2,3]
instead of ['1','2','3'], and number_digits(123.45,X)
binds X to [1,.,2,3,4,5,0,0,e,+,0,2].