These are chat archives for evhub/coconut

Aug 2017
Aug 09 2017 09:25
Coconut looks interesting. Can I use with Django?
Tobias Ammann
Aug 09 2017 15:23
Why the add/pre pattern decorator syntax. Coconut could collect multiple def into one.
Evan Hubinger
Aug 09 2017 17:40
@kentaro0919 Yes, absolutely! Just write your Django app in Coconut, and compile it whenever you need to run it. See how to release a Coconut package and how to run Coconut in a production environment (one word of warning: using cPyparsing as that answer suggests currently won't work unless you pip install coconut-develop). Also feel free to ask here again about any issues you encounter!
@betabrain Coconut adheres very strictly to the rule that all valid Python 3 is valid Coconut, which means Coconut is very strict about never invalidating anything possible in Python 3. That includes multiple defs in sequence, which, in Python, overwrite each other. Thus, they overwrite each other in Coconut as well. addpattern is the way Coconut provides to get around that, allowing the use of the more functional style of multiple definitions with different patterns.
Aug 09 2017 21:47

Hey, I ran into a weird problem when I was trying to create a data block.

data DictWrapper(d, label):

DictWrapper({}, None) |> print

works fine.

However, I wanted to add the new constructor, so I did this:

data DictWrapper(d, label):
    def __new__(cls, d, label):
        return datamaker(cls, d, label)

DictWrapper({}, None) |> print

This ran into a TypeError, claiming that I passed 4 positional arguments while the function expected 2.

TypeError                                 Traceback (most recent call last)
<ipython-input-39-1115261c8e1a> in <module>()
     13         raise _coconut_tail_call(datamaker, cls, d, label)  # line 3:         return datamaker(cls, d, label)
---> 15 a = DictWrapper({}, None)  # line 5: a = DictWrapper({}, None)
     16 (print)(a)  # line 6: a |> print

[...]/venv/lib/python3.6/site-packages/coconut/ in tail_call_optimized_func(*args, **kwargs)

TypeError: __new__() takes 2 positional arguments but 4 were given

I managed to find a solution that solved this by doing this:

data DictWrapper(d, label):
    def __new__(cls, d, label):
        return (d, label) |*> datamaker(cls)

But obviously this feels less than ideal. I do not really understand why the first way of doing it would not work.

I am running
Coconut: Version 1.2.3 [Colonel] running on Python 3.6.1
In a Jupyter Notebook with jupyter version 4.3.0 and notebook version 5.0.0.

Any idea? Am I doing something stupid or is this a bug?