Can a protocol method have the same name as a clojure.core function?

2013-02-07 Thread Don Jackson

I'd like to name a protocol method to be the same name as a clojure.core 
function, for example, get.

Is this possible, and if so, how?

user= (ns ptest.protocol
(:refer-clojure :exclude [get]))
nil

ptest.protocol= (defprotocol TestProtocol
(get
   [_ key]
Returns the contents of field :key) )

TestProtocol

ptest.protocol= (ns ptest.core
  (:require [ptest.protocol :as testp])
  (:refer-clojure :exclude [get]))

ptest.core= (defrecord TF
 [a
 b
 ]
   testp/TestProtocol
   (get
[this key]
   Doesn't work!))

CompilerException java.lang.ClassFormatError: Duplicate method namesignature 
in class file ptest/core/TF, compiling:(NO_SOURCE_PATH:1) 


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Can a protocol method have the same name as a clojure.core function?

2013-02-07 Thread Ben Wolfson
You just can't use defrecord, because defrecord macroexpands into a
deftype that implements a *different* protocol with a function *also*
named get.

On Thu, Feb 7, 2013 at 9:24 PM, Don Jackson
cloj...@clark-communications.com wrote:

 I'd like to name a protocol method to be the same name as a clojure.core
 function, for example, get.

 Is this possible, and if so, how?

 user= (ns ptest.protocol
 (:refer-clojure :exclude [get]))
 nil

 ptest.protocol= (defprotocol TestProtocol
 (get
[_ key]
 Returns the contents of field :key) )

 TestProtocol

 ptest.protocol= (ns ptest.core
   (:require [ptest.protocol :as testp])
   (:refer-clojure :exclude [get]))

 ptest.core= (defrecord TF
  [a
  b
  ]
testp/TestProtocol
(get
 [this key]
Doesn't work!))

 CompilerException java.lang.ClassFormatError: Duplicate method
 namesignature in class file ptest/core/TF, compiling:(NO_SOURCE_PATH:1)


 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.





-- 
Ben Wolfson
Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure. [Larousse, Drink entry]

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Can a protocol method have the same name as a clojure.core function?

2013-02-07 Thread Don Jackson

That makes perfect sense, and I should have figured that out since defrecord is 
implementing
a bunch of useful protocols underneath….

Thanks for the quick response!

On Feb 7, 2013, at 9:38 PM, Ben Wolfson wolf...@gmail.com wrote:

 You just can't use defrecord, because defrecord macroexpands into a
 deftype that implements a *different* protocol with a function *also*
 named get.
 
 On Thu, Feb 7, 2013 at 9:24 PM, Don Jackson
 cloj...@clark-communications.com wrote:
 
 I'd like to name a protocol method to be the same name as a clojure.core
 function, for example, get.
 
 Is this possible, and if so, how?
 
 user= (ns ptest.protocol
(:refer-clojure :exclude [get]))
 nil
 
 ptest.protocol= (defprotocol TestProtocol
(get
   [_ key]
Returns the contents of field :key) )
 
 TestProtocol
 
 ptest.protocol= (ns ptest.core
  (:require [ptest.protocol :as testp])
  (:refer-clojure :exclude [get]))
 
 ptest.core= (defrecord TF
 [a
 b
 ]
   testp/TestProtocol
   (get
[this key]
   Doesn't work!))
 
 CompilerException java.lang.ClassFormatError: Duplicate method
 namesignature in class file ptest/core/TF, compiling:(NO_SOURCE_PATH:1)
 
 
 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google Groups
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 
 
 
 
 -- 
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks,
 which may be sweet, aromatic, fermented or spirit-based. ... Family
 and social life also offer numerous other occasions to consume drinks
 for pleasure. [Larousse, Drink entry]
 
 -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google Groups 
 Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Can a protocol method have the same name as a clojure.core function?

2013-02-07 Thread Meikel Brandmeyer (kotarak)
Hi,

you can still use a defrecord. Just don't implement the protocol inline.

Clojure
user= (ns foo.bar (:refer-clojure :exclude [get]))
nil
foo.bar= (defprotocol FooBar (get [this]))
FooBar
foo.bar= (ns foo.baz)
nil
foo.baz= (alias 'fb 'foo.bar) ; this is due to working only in the repl. 
Normally you would use :require in the ns clause.
nil
foo.baz= (defrecord Baz [a b c])
foo.baz.Baz
foo.baz= (extend-type Baz
fb/FooBar
(get [{:keys [a b c]}] (str a b c)))
nil
foo.baz= (fb/get (-Baz fo ob ar))
foobar

Implementing a protocol inline is an optimisation, not a requirement.

Meikel

-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
Clojure group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.