Default arguments
jjl opened this issue · 3 comments
It would be nice to be able to define a function in a protocol that uses optional arguments with \\
I've thought of that but the issue is such way to consider things. First, should defaults just be allowed on the protocol? Or second, should I allow implementations to have their own default args, which may have some corner cases that I considered a while back but can't remember currently. Is the first sufficient?
I was considering only protocols having default args here. I imagine it would work like this:
defprotocolEx FooBar, %Foo{}, for: Bar do
def bar(x, y \\ nil)
endWould be the equivalent of this:
defprotocolEx FooBar, %Foo{}, for: Bar do
def bar(x), do: bar(x,nil)
def bar(x, y)
endAdded it in, and I allowed protocols to override the defaults as well if so wanted. :-)
I did not implement the second style (allowing implementations to have defaults without the protocol having it set up first, it breaks the interface I'd think).