class RubyProlog::Goal

Attributes

args[R]
pred_id[R]
pred_name[R]

Public Class Methods

new(pred_id, pred_name, args) click to toggle 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

inspect() click to toggle source
# File lib/ruby-prolog/ruby-prolog.rb, line 114
def inspect
  return @pred_name.to_s + @args.inspect.to_s
end
to_prolog() click to toggle 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