Re: :arglists metadata on defmulti/defmethod forms

2015-08-23 Thread James Reeves
I tend to add the metadata in manually when I write multimethods. (defmulti foo "Does some foo to x." {:arglists '([x])} :type) - James On 23 August 2015 at 16:51, Dave Tenny wrote: > defmulti+detmethod doesn't seem to maintain any :arglists metadata with > the Var filled by defmulti. >

:arglists metadata on defmulti/defmethod forms

2015-08-23 Thread Dave Tenny
defmulti+detmethod doesn't seem to maintain any :arglists metadata with the Var filled by defmulti. How can I look up arglist information for multimethods like I can for regular function vars? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To p

Re: defmethod inside of a (stuart sierra) component?

2015-02-25 Thread Colin Yates
I see where you are going. You don't actually need to store the system in an atom as it can be directly referenced from reloaded.repl.system, but I get your point (i.e. adapters). Thanks Marc. On 25 February 2015 at 14:26, Marc Limotte wrote: > Hi Colin, > > Nesting defmethod in t

Re: defmethod inside of a (stuart sierra) component?

2015-02-25 Thread Marc Limotte
Hi Colin, Nesting defmethod in the start fn of the Component does have a bad smell. This actually seems counter to the intention of Component, which is to make these dependencies explicit and external. I might do it like this: 1. Create a "pure" implementation using Component as it wa

Re: defmethod inside of a (stuart sierra) component?

2015-02-25 Thread Colin Yates
gt; wrote: >> > So I guess another question is where "handle-command" is being called. >> > What >> > about providing the component as argument to the multimethod (there are >> > other approaches too depending on your need). So: >> > >>

Re: defmethod inside of a (stuart sierra) component?

2015-02-25 Thread Jeroen van Dijk
gt; So I guess another question is where "handle-command" is being called. > What > > about providing the component as argument to the multimethod (there are > > other approaches too depending on your need). So: > > > > (defmulti handle-command(fn

Re: defmethod inside of a (stuart sierra) component?

2015-02-25 Thread Colin Yates
ending on your need). So: > > (defmulti handle-command(fn [component command] (first command))) > > (defmethod handle-command :add-customer [{:keys [db eventstore} [[_ > customer]]] > ... ) > > Isn't something like this enough? > > Jeroen > > On Wed, Feb

Re: defmethod inside of a (stuart sierra) component?

2015-02-25 Thread Jeroen van Dijk
So I guess another question is where "handle-command" is being called. What about providing the component as argument to the multimethod (there are other approaches too depending on your need). So: (defmulti handle-command(fn [component command] (first command))) (defmethod handle-co

Re: defmethod inside of a (stuart sierra) component?

2015-02-25 Thread Colin Yates
and so on. One way of achieving this is (assuming commands are of the form [:command-discriminator payload]: (defmulti handle-command first) (defn add-customer [db eventstore customer] ...) (defrecord AddCustomerComponent [db eventstore] ... (start [this] (defmethod handle-comman

Re: defmethod inside of a (stuart sierra) component?

2015-02-25 Thread Jeroen van Dijk
ed, Feb 25, 2015 at 12:08 PM, Colin Yates wrote: > Hi, > > I have a number of commands flying around which need to be handled. > defmulti/defmethod seem a nice answer. The problem is that each command > handler will need different collaborators (those with long memories will > r

defmethod inside of a (stuart sierra) component?

2015-02-25 Thread Colin Yates
Hi, I have a number of commands flying around which need to be handled. defmulti/defmethod seem a nice answer. The problem is that each command handler will need different collaborators (those with long memories will realise this isn't new ground here ;)). I want to do something like:

Re: defmethod/require race condition

2013-05-09 Thread Brandon Bloom
This is an unfortunate ugly side effect of def and def-like forms being, um, side effectual. In the particular case of defmethod, I think that the general recommendation would be to structure your namespaces such that methods are defined along side the code that could produce dispatch values

Re: defmethod/require race condition

2013-05-09 Thread sdegutis
2013 at 5:19 PM, Steven Degutis > > wrote: > >> In my app, sometimes a file containing a defmethod hasn't been >> required yet by the time some other function calls the multi-method. >> So naturally it throws an exception. >> >> But later, as the app con

Re: defmethod/require race condition

2013-05-09 Thread Gary Trakhman
13 at 5:19 PM, Steven Degutis wrote: > In my app, sometimes a file containing a defmethod hasn't been > required yet by the time some other function calls the multi-method. > So naturally it throws an exception. > > But later, as the app continues to run, the file containing the

defmethod/require race condition

2013-05-09 Thread Steven Degutis
In my app, sometimes a file containing a defmethod hasn't been required yet by the time some other function calls the multi-method. So naturally it throws an exception. But later, as the app continues to run, the file containing the proper defmethod eventually gets required by another file.

Re: defmethod/defmulti should dispatch on the new arguments when we call the recur..?

2010-12-19 Thread Meikel Brandmeyer
Hi, Am 19.12.2010 um 19:35 schrieb Robert McIntyre: > @Ken Wesson: do you mean something like this: > https://gist.github.com/747571 Maybe I'm missing something, but why don't you just call the multimethod itself again in the trampoline fn? Sincerely Meikel -- You received this message becau

Re: defmethod/defmulti should dispatch on the new arguments when we call the recur..?

2010-12-19 Thread Robert McIntyre
@Ken Wesson: do you mean something like this: https://gist.github.com/747571 My fists stab at this technique looks kinda ugly though... Is there a way to somehow embed the trampoline inside the recursive definition? Is there a way to get the actual dispatch function other than (.dispatchFn multime

Re: defmethod/defmulti should dispatch on the new arguments when we call the recur..?

2010-12-19 Thread Meikel Brandmeyer
Hi, Am 19.12.2010 um 16:46 schrieb Ken Wesson: > If we had a (resolve-method multi & args) that resolved dispatch and > then returned a fn that would call the method with those same args -- > so ((resolve-method multi & args)) <=> (multi & args) -- then this > could be used with trampoline in cas

Re: defmethod/defmulti should dispatch on the new arguments when we call the recur..?

2010-12-19 Thread Ken Wesson
On Sun, Dec 19, 2010 at 10:34 AM, Sunil S Nandihalli wrote: > thanks Meikel for your clarification.. I used to think loop recur almost > removed the need for TCO .. but here is a case where true TCO could be > really helpfull.. If we had a (resolve-method multi & args) that resolved dispatch and

Re: defmethod/defmulti should dispatch on the new arguments when we call the recur..?

2010-12-19 Thread Sunil S Nandihalli
andihalli: > > > Hello everybody, > > It would be nice if calling recur inside a defmethod redispatched on the > new arguments.. I have shown a simple use-case in the following gist. > > https://gist.github.com/747171 > > > > It might be naive .. but I feel IMHO that t

Re: defmethod/defmulti should dispatch on the new arguments when we call the recur..?

2010-12-19 Thread Meikel Brandmeyer
Hi, Am 19.12.2010 um 08:30 schrieb Sunil S Nandihalli: > Hello everybody, > It would be nice if calling recur inside a defmethod redispatched on the new > arguments.. I have shown a simple use-case in the following gist. > https://gist.github.com/747171 > > It might be n

defmethod/defmulti should dispatch on the new arguments when we call the recur..?

2010-12-18 Thread Sunil S Nandihalli
Hello everybody, It would be nice if calling recur inside a defmethod redispatched on the new arguments.. I have shown a simple use-case in the following gist. https://gist.github.com/747171 It might be naive .. but I feel IMHO that this should be the default behaviour and not have any

Re: defmethod hangs

2010-11-02 Thread Jarl Haggerty
tch function should match your methods in arity. It may take > more if they are "don't cares" for the dispatch. > > > (defmulti projection (fn [shape & _] (type shape))) > > (println 2) > > As I said, some cleanup with let (hopefully without messing things

Re: defmethod hangs

2010-11-02 Thread Jarl Haggerty
(fn [shape & _] (type shape))) > > (println 2) > > As I said, some cleanup with let (hopefully without messing things > up). Also you cannot "call" integers with vectors. You have to use > nth. > > > > > (defmethod projection :polygon >

Re: defmethod hangs

2010-11-01 Thread Meikel Brandmeyer
me cleanup with let (hopefully without messing things up). Also you cannot "call" integers with vectors. You have to use nth. > (defmethod projection :polygon > [shape plane] > (let [points (:points shape) > npoints (int (count points)) >

defmethod hangs

2010-10-31 Thread Jarl Haggerty
I'm not sure what to do here, my program hangs at the following defmethod. all my brackets seem to be balanced and I'm not receiving any errors about undefined symbols. This sample prints 2 but never gets to 3, (my poor man's debugging). This code is for the collision detecti

Re: defmethod question....

2009-12-28 Thread Mike Meyer
struct bar :c :d :e) (defn struct-dispatch ([{_ :a _ :b _ :c}] ::foo) ([{_ :c _ :d _ :e}] ::bar)) (defmulti struct-method struct-dispatch) (defmethod struct-method ::foo ; work on struct foo ) (defmethod struct-method ::bar ; work on struct bar ) Other supported destructurings wou

Re: defmethod question....

2009-12-27 Thread Jason Wolfe
> That doesn't seem to be possible - I can't find a function that > accepts a PersistentStructMap and returns the symbol passed to struct > so it knows the keylist to use for the arguments. Nor could I find the > magic incantation to let me use those symbol names with derive, which > would let me u

defmethod question....

2009-12-27 Thread Mike Meyer
seem to follow POLA. I want to have a multimethod dispatch on structure types. Specifically, if I define two structures: (defstruct A :a :b :c) (defstruct B :b :d :e) I want a multimethod that uses different methods for A & B. I'd *like* to be able to write them like: (defmethod meth

defmethod

2009-07-27 Thread Timothy Pratley
eness: (defmacro defmethod "Creates and installs a new method of multimethod associated with dispatch-value. " [multifn dispatch-val & fn-tail] `(. ~multifn addMethod ~dispatch-val (fn ~(symbol (str multifn "-" dispatch-val)) ~...@fn-tail))) ; just added ~(symbol (str mul