Skip to content

TCOs in functions with keywords #1

@nijoakim

Description

@nijoakim

Hey,

I'm trying to make the accumulator argument, k, in the simple factorial example implicit by using it as a keyword argument like so:

@with_continuations()
def factorial_kw(n, k=1, self=None):
	return self(n-1, k=n*k) if n > 1 else k
print(factorial_kw(10))

However, this results in the following error:

Traceback (most recent call last):
  File "./test.py", line 12, in <module>
    print(factorial_kw(10))
  File "/usr/local/lib/python3.6/dist-packages/tco/__init__.py", line 41, in __call__
    return f(*args)
  File "/usr/local/lib/python3.6/dist-packages/tco/__init__.py", line 86, in <lambda>
    f(*args, self=kself, **dict(zip(keys, conts)))) (*k)
  File "./test.py", line 11, in factorial_kw
    return self(n-1, k=n*k) if n > 1 else k
TypeError: t() got an unexpected keyword argument 'k'

Not sure whether this is expected or if it's a bug, so I figured I'd submit an issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions