Class: SWIPL::Predicate
- Inherits:
-
Object
- Object
- SWIPL::Predicate
- Defined in:
- lib/swipl/predicate.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id, arity) ⇒ Predicate
constructor
A new instance of Predicate.
- #query_normally(frame) ⇒ Object
- #query_normally_with(frame, inputs) ⇒ Object
Constructor Details
#initialize(id, arity) ⇒ Predicate
Returns a new instance of Predicate.
4 5 6 7 |
# File 'lib/swipl/predicate.rb', line 4 def initialize( id, arity ) @pred_id = id @arity = arity end |
Class Method Details
.find(name, arity) ⇒ Object
9 10 11 12 13 |
# File 'lib/swipl/predicate.rb', line 9 def self.find( name, arity ) name_ptr = FFI::MemoryPointer.from_string( name.to_s ) id = CFFI.PL_predicate( name_ptr, arity, nil ) Predicate.new( id, arity ) end |
Instance Method Details
#query_normally(frame) ⇒ Object
16 17 18 19 20 |
# File 'lib/swipl/predicate.rb', line 16 def query_normally( frame ) params = frame.refs( @arity ) query_id = CFFI.PL_open_query( nil, PL_Q_NORMAL, @pred_id, params[0].id ) Query.new( query_id, params ) end |
#query_normally_with(frame, inputs) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/swipl/predicate.rb', line 22 def query_normally_with( frame, inputs ) raise "insufficent parameters for arity" if inputs.length != @arity params = frame.refs( @arity ) (0..(@arity-1)).each do |index| source = inputs[ index ] if source params[index].unify_with( inputs[index] ) end end query_id = CFFI.PL_open_query( nil, PL_Q_NORMAL, @pred_id, params[0].id ) Query.new( query_id, params ) end |