Class: LyambdaGem::Application

Inherits:
Term
  • Object
show all
Defined in:
lib/lyambda_gem/application.rb

Overview

Implementation of an application (function application) in the lambda calculus

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ Application

Returns a new instance of Application.



6
7
8
9
# File 'lib/lyambda_gem/application.rb', line 6

def initialize(left, right)
  @left = left
  @right = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



4
5
6
# File 'lib/lyambda_gem/application.rb', line 4

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



4
5
6
# File 'lib/lyambda_gem/application.rb', line 4

def right
  @right
end

Instance Method Details

#free_variablesObject

Список свободных переменных



12
13
14
# File 'lib/lyambda_gem/application.rb', line 12

def free_variables 
  return @left.free_variables + @right.free_variables
end

#reduce(strategy: :normal_order) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/lyambda_gem/application.rb', line 24

def reduce(strategy: :normal_order)
  #puts "  app:#{self.to_s} | r-able: #{reduceable?}"
  return self unless reduceable?
  #puts @left.body.substitute(@right, @left.parameter)
  return @left.body.substitute(@right, @left.parameter) if @left.is_a?(Abstraction)

  return Application.new(@left.reduce, @right) if @left.reduceable? 

  return Application.new(@left, @right.reduce) if @right.reduceable? 
end

#reduceable?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/lyambda_gem/application.rb', line 20

def reduceable?
  return @left.is_a?(Abstraction) || @left.reduceable? || @right.reduceable?
end

#substitute(term, variable) ⇒ Object



16
17
18
# File 'lib/lyambda_gem/application.rb', line 16

def substitute(term, variable)
  return Application.new(@left.substitute(term, variable), @right.substitute(term, variable))
end

#to_sObject



35
36
37
# File 'lib/lyambda_gem/application.rb', line 35

def to_s
  "(#{@left.to_s} #{@right.to_s})"
end