blob: 0e70abf1eedaa4acdf3afd007e14748cab768712 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "dat.h"
#include "fns.h"
/* Type tests */
int
islist(Term *t)
{
return (isemptylist(t) || isnonemptylist(t));
}
int
ispartiallist(Term *t)
{
if(t->tag == VariableTerm)
return 1;
else if(t->tag == CompoundTerm && runestrcmp(t->text, L".") == 0 && t->arity == 2)
return ispartiallist(listtail(t));
else
return 0;
}
int
isemptylist(Term *t)
{
return (t->tag == AtomTerm && runestrcmp(t->text, L"[]") == 0);
}
int
isnonemptylist(Term *t)
{
if(t->tag == CompoundTerm && runestrcmp(t->text, L".") == 0 && t->arity == 2)
return islist(listtail(t));
else
return 0;
}
int
ispredicateindicator(Term *t, int allowvars)
{
if(t->tag == CompoundTerm && runestrcmp(t->text, L"/") == 0 && t->arity == 2){
Term *f = t->children;
Term *a = f->next;
if(allowvars)
return (f->tag == VariableTerm || f->tag == AtomTerm) && (a->tag == VariableTerm || a->tag == IntegerTerm);
else
return (f->tag == AtomTerm) && (a->tag == IntegerTerm);
}else
return 0;
}
/* Other functions */
Term *
listhead(Term *t)
{
if(t->tag == CompoundTerm && runestrcmp(t->text, L".") == 0 && t->arity == 2)
return t->children;
else
return nil;
}
Term *
listtail(Term *t)
{
if(t->tag == CompoundTerm && runestrcmp(t->text, L".") == 0 && t->arity == 2)
return t->children->next;
else
return nil;
}
|