diff options
author | Fogus <fogusm@tsubasa.tena-sda.org> | 2010-05-05 12:07:25 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-07-27 16:50:27 -0400 |
commit | befba000e922dc261e8a23a826505847c2d4d01c (patch) | |
tree | e5bc0dea268d3c0f1d8155ec42c5d3f365b006d5 | |
parent | 02559a4aad442253b601870f7c9aa04c91baf235 (diff) |
Fixes missing this arg on the reify and defprotocol docstrings #340
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | src/clj/clojure/core_deftype.clj | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/clj/clojure/core_deftype.clj b/src/clj/clojure/core_deftype.clj index ffe3298f..b0604c9e 100644 --- a/src/clj/clojure/core_deftype.clj +++ b/src/clj/clojure/core_deftype.clj @@ -70,11 +70,11 @@ or more method bodies: protocol-or-interface-or-Object - (methodName [args*] body)* + (methodName [args+] body)* Methods should be supplied for all methods of the desired protocol(s) and interface(s). You can also define overrides for - methods of Object. Note that a parameter must be supplied to + methods of Object. Note that the first parameter must be supplied to correspond to the target object ('this' in Java parlance). Thus methods for interfaces will take one more argument than do the interface declarations. Note also that recur calls to the method @@ -97,12 +97,12 @@ (str (let [f \"foo\"] (reify Object - (toString [] f)))) + (toString [this] f)))) == \"foo\" (seq (let [f \"foo\"] (reify clojure.lang.Seqable - (seq [] (seq f))))) + (seq [this] (seq f))))) == (\\f \\o \\o))" {:added "1.2"} [& opts+specs] @@ -581,18 +581,18 @@ \"A doc string for AProtocol abstraction\" ;method signatures - (bar [a b] \"bar docs\") - (baz [a] [a b] [a b c] \"baz docs\")) + (bar [this a b] \"bar docs\") + (baz [this a] [this a b] [this a b c] \"baz docs\")) No implementations are provided. Docs can be specified for the protocol overall and for each method. The above yields a set of polymorphic functions and a protocol object. All are namespace-qualified by the ns enclosing the definition The resulting - functions dispatch on the type of their first argument, and thus - must have at least one argument. defprotocol is dynamic, has no - special compile-time effect, and defines no new types or classes - Implementations of the protocol methods can be provided using - extend. + functions dispatch on the type of their first argument, which is + required and corresponds to the implicit target object ('this' in + Java parlance). defprotocol is dynamic, has no special compile-time + effect, and defines no new types or classes. Implementations of + the protocol methods can be provided using extend. defprotocol will automatically generate a corresponding interface, with the same name as the protocol, i.e. given a protocol: @@ -604,23 +604,25 @@ reify, as they support the protocol directly: (defprotocol P - (foo [x]) - (bar-me [x] [x y])) + (foo [this]) + (bar-me [this] [this y])) (deftype Foo [a b c] P - (foo [] a) - (bar-me [] b) - (bar-me [y] (+ c y))) + (foo [this] a) + (bar-me [this] b) + (bar-me [this y] (+ c y))) - (bar-me (Foo 1 2 3) 42) + (bar-me (Foo. 1 2 3) 42) + => 45 (foo (let [x 42] (reify P - (foo [] 17) - (bar-me [] x) - (bar-me [y] x))))" + (foo [this] 17) + (bar-me [this] x) + (bar-me [this y] x)))) + => 17" {:added "1.2"} [name & opts+sigs] (emit-protocol name opts+sigs)) |