Re: Picking a code path if a type is known at compile time (e.g. through hint)

2016-07-01 Thread lvh
> On Jul 1, 2016, at 10:34 AM, Timothy Baldridge wrote: > > You can write a protocol, then extend it: ... Ah! I completely blanked on protocol dispatch being resolved at compile time if possible. Thanks! Does this only work if the type hint is exactly the extended type, or does this underst

Re: Picking a code path if a type is known at compile time (e.g. through hint)

2016-07-01 Thread Timothy Baldridge
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 wrote: > A multimethod which

Re: Picking a code path if a type is known at compile time (e.g. through hint)

2016-07-01 Thread Erik Assum
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 (

Picking a code path if a type is known at compile time (e.g. through hint)

2016-07-01 Thread lvh
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 pic