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

Lambda Expressions #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions A1/submission/part1.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,62 @@ def minimum_cost_member_of_extension(self):
def version_space_size(self):
assert False, "implement as part of homework"

# Lambda calculus
class Application(Expression):
def __init__(self, exp1, exp2):
self.exp1 = exp1
self.exp2 = exp2

def pretty_print(self, indent, bool_ind, bool_nln):
ret_string = ""
if bool_ind:
for x in range(indent):
ret_string += tab
ret_string += "(" + self.exp1.pretty_print(indent, False, False) + ") " + self.exp2.pretty_print(indent, False, True)
if bool_nln:
ret_string += "\n"
return ret_string

def evaluate(self, environment):
assert False, "not implemented"

class Lambda(Expression):
def __init__(self, var, exp):
self.var = var # type: NumberVariable
self.exp = exp # type: Expression

def pretty_print(self, indent, bool_ind, bool_nln):
ret_string = ""
if bool_ind:
for x in range(indent):
ret_string += tab
ret_string += "lambda " + self.var.pretty_print(indent, False, False) + " = " + self.exp1.pretty_print(indent, False, False) + " in\n" + self.exp2.pretty_print(indent + 1, True, True)
if bool_nln:
ret_string += "\n"
return ret_string

def evaluate(self, environment):
assert False, "not implemented"
class Let(Expression):
def __init__(self, var, exp1, exp2):
self.var = var
self.exp1 = exp1
self.exp2 = exp2

def pretty_print(self, indent, bool_ind, bool_nln):
ret_string = ""
if bool_ind:
for x in range(indent):
ret_string += tab
ret_string += "let " + self.var.pretty_print(indent, False, False) + " = " + self.exp1.pretty_print(indent, False, False) + " in\n" + self.exp2.pretty_print(indent + 1, True, True)
if bool_nln:
ret_string += "\n"
return ret_string

def evaluate(self, environment):
assert False, "not implemented"


class FALSE(Expression):
return_type = "bool"
argument_types = []
Expand Down