--- /dev/null
+def get_incrementer(n) do
+ def foo(m) do
+ m + n
+ end
+
+ foo
+end
+
+def get_multiplier(n) do
+ def foo(m) do
+ m * n
+ end
+
+ foo
+end
+
+print(get_incrementer(2)(3), '\n')
+print(get_multiplier(2)(3), '\n')
)
def generate_lambda_expression(expression):
- return '(Object){{ CLOSURE, (Instance)(Closure){{ environment, user${}$implementation }} }}'.format(
+ return '(Object){{ CLOSURE, (Instance)(Closure){{ environment, user${}${}$implementation }} }}'.format(
expression.name,
+ expression.index,
)
def generate_list_construct_expression(expression):
template = ENV.get_template('function_definition.c')
return template.render(
name=definition.name,
+ index=definition.index,
argument_name_list=definition.argument_name_list,
statement_list=list(generate_statement(s) for s in definition.statement_list),
)
'CFunctionDefinition',
[
'name',
+ 'index',
'argument_name_list',
'statement_list',
],
'CLambdaExpression',
(
'name',
+ 'index',
),
)
)
def transform_lambda_expression(accumulators, expression):
- # TODO This function feels hacky
- if len(accumulators.lambda_number_list) == 0:
- accumulators.lambda_number_list.append(0)
- else:
- accumulators.lambda_number_list.append(accumulators.lambda_number_list[-1] + 1)
-
if expression.name is None:
- name = '__lambda_{}'.format(accumulators.lambda_number_list[-1])
+ name = '__lambda'
else:
name = expression.name
+ index = accumulators.function_name_iterators.get(name, 0)
+ accumulators.function_name_iterators[name] = index + 1
+
accumulators.function_definition_list.append(CFunctionDefinition(
name=name,
+ index=index,
argument_name_list=expression.argument_name_list,
statement_list=tuple(transform_statement(accumulators, s) for s in expression.statement_list),
))
- return CLambdaExpression(name=name)
+ return CLambdaExpression(
+ name=name,
+ index=index,
+ )
def transform_list_construct_expression(accumulators, expression):
[
'builtin_set',
'function_definition_list',
- 'lambda_number_list',
+ 'function_name_iterators',
'operator_set',
'symbol_list',
'string_literal_list',
accumulators = Accumulators(
builtin_set=set(),
function_definition_list=[],
- lambda_number_list=[],
+ function_name_iterators={},
operator_set=set(),
symbol_list=[],
string_literal_list=[],