Class: SWIPL::Term
- Inherits:
-
Object
- Object
- SWIPL::Term
- Defined in:
- lib/swipl/term.rb
Instance Method Summary collapse
- #as_atom ⇒ Object
- #atom? ⇒ Boolean
- #ground? ⇒ Boolean
- #id ⇒ Object
-
#initialize(term_id) ⇒ Term
constructor
A new instance of Term.
- #term_id ⇒ Object
- #to_s ⇒ Object
- #unify_with(other_term) ⇒ Object
Constructor Details
#initialize(term_id) ⇒ Term
Returns a new instance of Term.
4 5 6 |
# File 'lib/swipl/term.rb', line 4 def initialize( term_id ) @term_id = term_id end |
Instance Method Details
#as_atom ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/swipl/term.rb', line 23 def as_atom str_ptr = FFI::MemoryPointer.new( :pointer, 1 ) if CFFI.PL_get_atom_chars( @term_id, str_ptr ) == PL_FALSE raise "failed to get term #{@term_id} as an atom" end str_ptr.read_pointer.read_string end |
#atom? ⇒ Boolean
19 20 21 |
# File 'lib/swipl/term.rb', line 19 def atom? CFFI.PL_is_atom( @term_id ) end |
#ground? ⇒ Boolean
15 16 17 |
# File 'lib/swipl/term.rb', line 15 def ground? CFFI.PL_is_ground( @term_id ) == PL_TRUE end |
#id ⇒ Object
8 |
# File 'lib/swipl/term.rb', line 8 def id; self.term_id; end |
#term_id ⇒ Object
9 |
# File 'lib/swipl/term.rb', line 9 def term_id; @term_id; end |
#to_s ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/swipl/term.rb', line 31 def to_s if self.ground? if self.atom? self.as_atom else "ground" end else "variable" end end |