Module: Upl
- Defined in:
- lib/upl.rb,
lib/upl/atom.rb,
lib/upl/dict.rb,
lib/upl/term.rb,
lib/upl/tree.rb,
lib/upl/inter.rb,
lib/upl/query.rb,
lib/upl/extern.rb,
lib/upl/foreign.rb,
lib/upl/functor.rb,
lib/upl/version.rb,
lib/upl/variable.rb,
lib/upl/variables.rb,
lib/upl/term_vector.rb,
lib/upl/runtime.rb
Defined Under Namespace
Modules: Extern, Foreign, Inter, Runtime Classes: Atom, Dict, Functor, Query, Term, TermVector, Tree, Variable, Variables
Constant Summary collapse
- VERSION =
'0.2.0'
Class Method Summary collapse
- .asserta(term) ⇒ Object
- .assertz(term) ⇒ Object
- .consult(filename) ⇒ Object
- .listing ⇒ Object
-
.query(string_or_term, vars = nil, &blk) ⇒ Object
an enumerator yielding hashes keyed by the variables, mapping to the term.
-
.retract(term) ⇒ Object
behaves as if run under once, cos of the way call works.
-
.Term(name, *args) ⇒ Object
Nicer syntax for Term.functor.
Class Method Details
.asserta(term) ⇒ Object
59 60 61 |
# File 'lib/upl.rb', line 59 module_function def asserta term Runtime.call Term :asserta, term end |
.assertz(term) ⇒ Object
63 64 65 |
# File 'lib/upl.rb', line 63 module_function def assertz term Runtime.call Term :assertz, term end |
.consult(filename) ⇒ Object
39 40 41 42 |
# File 'lib/upl.rb', line 39 module_function def consult filename p = Pathname filename Runtime::call %Q{["#{p.realpath.to_s}"]} end |
.listing ⇒ Object
72 73 74 |
# File 'lib/upl.rb', line 72 module_function def listing (Upl.query 'with_output_to(string(Buffer),listing)').first[:Buffer] end |
.query(string_or_term, vars = nil, &blk) ⇒ Object
an enumerator yielding hashes keyed by the variables, mapping to the term
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/upl.rb', line 21 module_function def query string_or_term, vars = nil, &blk if string_or_term.is_a?(Term) && vars Runtime.term_vars_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.term_vars_query term, vars, &blk else raise "dunno about #{string_or_term.inspect}" end end end |
.retract(term) ⇒ Object
behaves as if run under once, cos of the way call works
68 69 70 |
# File 'lib/upl.rb', line 68 module_function def retract term Runtime.call Term :retract, term end |
.Term(name, *args) ⇒ Object
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
55 56 57 |
# File 'lib/upl.rb', line 55 module_function def Term name, *args Term.predicate name, *args end |