class RubyProlog::Goal
Attributes
Public Class Methods
Source
# File lib/ruby-prolog/ruby-prolog.rb, line 110 def initialize(pred_id, pred_name, args) @pred_id, @pred_name, @args = pred_id, pred_name, args end
Public Instance Methods
Source
# File lib/ruby-prolog/ruby-prolog.rb, line 114 def inspect return @pred_name.to_s + @args.inspect.to_s end
Source
# File lib/ruby-prolog/ruby-prolog.rb, line 118 def to_prolog args_out = @args.map do |arg| case arg when Symbol if arg == :_ "_" elsif /[[:upper:]]/.match(arg.to_s[0]) arg.to_s else "_#{arg.to_s}" end when String "'#{arg}'" when Cons, Goal arg.to_prolog when Numeric arg.to_s else raise "Unknown argument: #{arg.inspect}" end end.join(', ') if @pred_name == :not_ "\\+ #{args_out}" else "#{@pred_name}(#{args_out})" end end