Module: SWIPL
- Defined in:
- lib/swipl.rb,
lib/swipl/cffi.rb,
lib/swipl/term.rb,
lib/swipl/query.rb,
lib/swipl/version.rb,
lib/swipl/predicate.rb,
lib/swipl/prologframe.rb
Defined Under Namespace
Modules: CFFI
Classes: Predicate, PrologFrame, Query, Term
Constant Summary
collapse
- PL_TRUE =
1
- PL_FALSE =
2
- PL_FAIL =
PL_FALSE
- PL_Q_NORMAL =
2
- VERSION =
"0.3.0"
Class Method Summary
collapse
Class Method Details
.query(predicateName, arity) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/swipl.rb', line 22
def self.query( predicateName, arity )
solutions = []
PrologFrame.on do |frame|
predicate = Predicate.find( predicateName, arity)
query = predicate.query_normally( frame )
begin
query.each_solution do |p|
solutions.push([ p[0].as_atom ] )
end
ensure
query.close
end
end
solutions
end
|
.truth(fact) ⇒ Object
38
39
40
41
42
|
# File 'lib/swipl.rb', line 38
def self.truth( fact )
unless self.verify( fact )
raise "Truth '#{fact}' failed"
end
end
|
.verify(fact) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/swipl.rb', line 14
def self.verify( fact )
CFFI.init
PrologFrame.on do |frame|
atom = frame.atom_from_string( fact )
CFFI.PL_call( atom.term_id, nil ) == PL_TRUE
end
end
|