Class: SWIPL::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/swipl/term.rb

Instance Method Summary collapse

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_atomObject



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

Returns:

  • (Boolean)


19
20
21
# File 'lib/swipl/term.rb', line 19

def atom?
	CFFI.PL_is_atom( @term_id ) 
end

#ground?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/swipl/term.rb', line 15

def ground?
	CFFI.PL_is_ground( @term_id ) == PL_TRUE
end

#idObject



8
# File 'lib/swipl/term.rb', line 8

def id; self.term_id; end

#term_idObject



9
# File 'lib/swipl/term.rb', line 9

def term_id; @term_id; end

#to_sObject



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

#unify_with(other_term) ⇒ Object



11
12
13
# File 'lib/swipl/term.rb', line 11

def unify_with( other_term )
	CFFI.PL_unify( @term_id, other_term.term_id ) != PL_FAIL
end