module Upl

Constants

VERSION

Public Instance Methods

Term(name, *args) click to toggle source

Nicer syntax for Term.functor. Construct a Term from a symbol and args that all respond to 'to_term_t'.

In other words:

Upl.query 'current_prolog_flag(A,B)'

is similar to

Upl.query Term :current_prolog_flag, Variable.new, Variable.new
# File lib/upl.rb, line 60
                def Term name, *args
  Term.predicate name, *args
end
asserta(term) click to toggle source
# File lib/upl.rb, line 64
                def asserta term
  Runtime.call Term :asserta, term
end
assertz(term) click to toggle source
# File lib/upl.rb, line 68
                def assertz term
  Runtime.call Term :assertz, term
end
call(term) click to toggle source

For semidet predicates, ie that have only one result. You have to extract values using Upl::Variable#to_ruby.

# File lib/upl.rb, line 40
                def call term
  Runtime::call term
end
consult(filename) click to toggle source
# File lib/upl.rb, line 44
                def consult filename
  p = Pathname filename
  Runtime::call %Q{["#{p.realpath.to_s}"]}
end
listing() click to toggle source
# File lib/upl.rb, line 77
                def listing
  (Upl.query 'with_output_to(string(Buffer),listing)').first[:Buffer]
end
query(string_or_term, vars = nil, &blk) click to toggle source

You probably want to use Query.new instead of this. an enumerator yielding hashes keyed by the variables, mapping to the term

# File lib/upl.rb, line 20
                def query string_or_term, vars = nil, &blk
  if string_or_term.is_a?(Term) && vars
    Runtime.query string_or_term, vars
  else
    case string_or_term
    when Term
      # TODO this returns an array of values without variable names.
      # So it doesn't really belong here.
      Runtime.query string_or_term
    when String
      term, vars = Runtime.term_vars string_or_term
      Runtime.query term, vars, &blk
    else
      raise "dunno about #{string_or_term.inspect}"
    end
  end
end
retract(term) click to toggle source

behaves as if run under once, cos of the way call works

# File lib/upl.rb, line 73
                def retract term
  Runtime.call Term :retract, term
end