Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-arity methods in defprotocol / reify / extend-type #406

Closed
2 tasks done
borkdude opened this issue Sep 14, 2020 · 0 comments
Closed
2 tasks done

Support multi-arity methods in defprotocol / reify / extend-type #406

borkdude opened this issue Sep 14, 2020 · 0 comments

Comments

@borkdude
Copy link
Collaborator

borkdude commented Sep 14, 2020

TODO:

  • test for defining multi-arity protocol and implementing it with defrecord
  • test for multi-arity multi-method defs

In defprotocol/reify/defrecord there's this syntax for multi-arity methods:

(deftype Foo [a b c]
  P
  (foo [x] a)
  (bar-me [x] b)
  (bar-me [x y] (+ c y)))

whereas extend-type has this:

(extend-type MyType
  Countable
    (cnt [c] ...)
  Foo
    (bar [x y] ...)
    (baz ([x] ...) ([x y zs] ...)))
What's the official syntax? (edited) 

Example:

user=> (defprotocol IFruit (subtotal [item] [item subtotal]))
IFruit
user=> (defrecord Apple [price] IFruit (subtotal [_] price) (subtotal [_ discount] (- price discount)))
user.Apple
user=> (subtotal (->Apple 100))
100
user=> (subtotal (->Apple 100) 5)
95

Also see #401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant