These are chat archives for evhub/coconut

21st
Jun 2018
'jamin
@acdimalev
Jun 21 2018 04:41
@balajeerc is an implementation of bind something you would prefer / not prefer for this application?
Err... @eindiran is an implementation of bind something you would prefer / not prefer for this application? (sorry balajeerc, seriously a mental typo on my behalf)
balajeerc
@balajeerc
Jun 21 2018 04:44
@acdimalev Well, since you asked: absolutely! I have been toying with the idea of how implementing the bind operator in coconut could be achieved.
'jamin
@acdimalev
Jun 21 2018 04:45
Cool. A typo, but interesting to know. :)
On the subject, @evhub, do you have any opinions about using obj.__join__ in this way? I'm tempted to run with it if there aren't any obvious problems you foresee in this approach.
yggdr
@yggdr
Jun 21 2018 19:36

Is it considered a bug that the following gives you a TypeError? Or a known and accepted limitation?

def func():
    print('No arg version')

@addpattern(func)
def func(somearg):
    print('Received argument', somearg)

func()  # works
func('something')  # TypeError: func() takes 0 positional arguments but 1 was given

I didn't find anything about that in the docs.

Elliott Indiran
@eindiran
Jun 21 2018 19:47
Is this a case where you can use args/*kwargs?
*args
**kwargs
I think addpattern is meant to be used kind of like case + match
additionally, you can get this sort of functionality with the multimethod package in python
yggdr
@yggdr
Jun 21 2018 19:59

Sure, there are possibilities to work around this, but imho this should just work. It does e.g. in Elixir:

defmodule Test do
  def func() do
    1
  end
  def func(a) do
    a
  end
end

Test.func()  # returns 1
Test.func(42)  # returns 42

It it's hard to make it work, a short mentioning in the docs would be nice.