You can write a protocol, then extend it:

(defprotocol IBufferLength
  (buffer-length [this]))

(extend-protocol IBufferLength
  (Class/forName "[B")
  (buffer-length [this] ...)

  ByteBuffer
  (buffer-length [this] ...))

On Fri, Jul 1, 2016 at 9:15 AM, Erik Assum <e...@assum.net> wrote:

> A multimethod which dispatches on type, or maybe extend the counted(?)
> protocol to these two types?
>
> Erik.
> --
> i farta
>
> > Den 1. jul. 2016 kl. 17.12 skrev lvh <_...@lvh.io>:
> >
> > Hi,
> >
> >
> > I have some code that wants to know the appropriate length of a byte
> buffer. These can be byte arrays (as in [B) or java.nio.ByteBuffers. For
> the former, I can call (alength ^bytes buf), for the latter I call
> (.remaining ^ByteBuffer buf). Is there a way to just write a fn or macro
> that picks the right one at compile time? I wrote some simple test fns, but
> there doesn’t appear to be a way to access that type hinting information.
> >
> >
> > thanks
> > lvh
> >
> > --
> > 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/d/optout.
>
> --
> 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/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
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/d/optout.

Reply via email to