Sha256: 7b8287831b8f273b0461e9373e7fb1c2073e3f67a537ca4ef2a61d8ae54266e1

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

class Proc
  attr_accessor :form
  
  def compare_form(form, obj)
    if(form)
      unless obj[1] == form[1]
        return false
      else
        if form[0] == :literal
          unless form == obj
            return false
          end
        else
          if form[2].length == obj[2].length
            form[2].each_with_index do |p, i|
              unless p[0] == :id
                unless p == obj[2][i]
                  if p[0] == :object
                    return compare_form(p, obj[2][i])
                  else
                    return false
                  end
                end
              end
            end
          else
            return false
          end
        end
      end
    end
    return true
  end

  def call?(params)
    if @form.length == params.length
      params.each_with_index do |param, i|
        unless param.class == Array
          unless compare_form(@form[i], param.form)
            return false
          end
        else
          if @form[i]
            return false
          end
        end
      end
      return true
    else
      return false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
p-lang-0.0.4 lib/vm/proc.rb