forked from mndrix/golog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforeignreturn.go
49 lines (37 loc) · 1.42 KB
/
foreignreturn.go
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
package golog
// simulate an algebraic datatype representing the return value
// of foreign predicates
import "github.com/mndrix/golog/term"
// ForeignReturn represents the return type of ForeignPredicate functions.
// Values of ForeignReturn indicate certain success or failure conditions
// to the Golog machine. If you're writing a foreign predicate, see
// functions named Foreign* for possible return values.
type ForeignReturn interface {
IsaForeignReturn() // useless method to restrict implementations
}
// ForeignTrue indicates a foreign predicate that succeeds deterministically
func ForeignTrue() ForeignReturn {
t := true
return (*foreignTrue)(&t)
}
type foreignTrue bool
func (*foreignTrue) IsaForeignReturn() {}
// ForeignFail indicates a foreign predicate that failed
func ForeignFail() ForeignReturn {
f := false
return (*foreignFail)(&f)
}
type foreignFail bool
func (*foreignFail) IsaForeignReturn() {}
// ForeignUnify indicates a predicate that succeeds or fails depending
// on the results of a unification. The list of arguments must have
// an even number of elements. Each pair is unified in turn. Variables
// bound during unification become part of the Golog machines's bindings.
func ForeignUnify(ts ...term.Term) ForeignReturn {
if len(ts)%2 != 0 {
panic("Uneven number of arguments to ForeignUnify")
}
return (*foreignUnify)(&ts)
}
type foreignUnify []term.Term
func (*foreignUnify) IsaForeignReturn() {}