class SWIPL::Term

Constants

PL_ATOM
PL_BLOB
PL_INTEGER
PL_NIL
PL_STRING
PL_VARIABLE

Public Class Methods

new( term_id ) click to toggle source
# File lib/swipl/term.rb, line 4
def initialize( term_id )
        @term_id = term_id
end

Public Instance Methods

as_atom() click to toggle source
# File lib/swipl/term.rb, line 69
def as_atom
        raise "not na atom" unless 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 (type: #{term_type})"
        end
        str_ptr.read_pointer.read_string
end
atom?() click to toggle source
# File lib/swipl/term.rb, line 38
def atom?
        CFFI.PL_is_atom( @term_id ) == PL_TRUE 
end
ground?() click to toggle source
# File lib/swipl/term.rb, line 33
def ground?
        str_ptr = FFI::MemoryPointer.new( :pointer, 1 )
        CFFI.PL_is_ground( @term_id ) == PL_TRUE
end
id() click to toggle source
# File lib/swipl/term.rb, line 8
def id; self.term_id; end
put_atom( string ) click to toggle source
# File lib/swipl/term.rb, line 29
def put_atom( string )
        raise "Failed to put atom" if CFFI.PL_put_atom_chars( @term_id, string ) == PL_FALSE
end
put_string( string ) click to toggle source
# File lib/swipl/term.rb, line 25
def put_string( string )
        CFFI.PL_put_string_chars( @term_id, string )
end
term_id() click to toggle source
# File lib/swipl/term.rb, line 9
def term_id; @term_id; end
term_type() click to toggle source
# File lib/swipl/term.rb, line 49
def term_type
        type_id = CFFI.PL_term_type( @term_id )
        case type_id
                when PL_VARIABLE
                        :variable
                when PL_ATOM
                        :atom
                when PL_NIL
                        :nil
                when PL_BLOB
                        :blob
                when PL_STRING
                        :string
                when PL_INTEGER
                        :integer
                else
                        :unknown
        end
end
to_s() click to toggle source
# File lib/swipl/term.rb, line 78
def to_s
        if self.ground?
                if self.atom?
                        self.as_atom
                else
                        "ground (#{term_type})"
                end
        else
                "variable"
        end
end
unify_atom_chars( string ) click to toggle source
# File lib/swipl/term.rb, line 21
def unify_atom_chars( string )
        CFFI.PL_unify_atom_chars( @term_id, string )
end
unify_string( string ) click to toggle source
# File lib/swipl/term.rb, line 17
def unify_string( string )
        CFFI.PL_unify_string_chars( @term_id, string )
end
unify_with( other_term, control = nil ) click to toggle source
# File lib/swipl/term.rb, line 11
def unify_with( other_term, control = nil )
        result = CFFI.PL_unify( @term_id, other_term.term_id ) != PL_FAIL
        control.failed if control and !result
        result
end