Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no need two kind of machine in small-step. #6

Open
aQuaYi opened this issue Jun 15, 2019 · 1 comment
Open

no need two kind of machine in small-step. #6

aQuaYi opened this issue Jun 15, 2019 · 1 comment

Comments

@aQuaYi
Copy link

aQuaYi commented Jun 15, 2019

Add class as example

change

class Add
  def reduce(environment)
    if left.reducible?
      Add.new(left.reduce(environment), right)
    elsif right.reducible?
      Add.new(left, right.reduce(environment))
    else
      Number.new(left.value + right.value)
    end
  end
end

to

class Add < Struct.new(:left, :right)
   def reduce(environment)
    if left.reducible?
      left_reduce,  environment = left.reduce(environment)
      [Add.new(left_reduce, right), environment]
    elsif right.reducible?
      right_reduce, environment = right.reduce(environment)
      [Add.new(left, right_reduce), environment]
    else
      [Number.new(left.value + right.value), environment]
    end
  end
end
@aQuaYi
Copy link
Author

aQuaYi commented Jun 15, 2019

here is my small-step code

https://github.com/aQuaYi/computation/tree/master/small_step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant