recur doesn't work well with multimethods:
(defmulti foo identity)
(defmethod foo 1 [n]
(recur (dec n)))
(defmethod foo 0 [n]
:ok)
(foo 1) ;; runs forever
Jonas
On Monday, December 17, 2012 6:56:34 PM UTC+2, juan.facorro wrote:
>
> What about recur <http://clojure.org/special_forms#recur>?
>
> It's a special form used for tail call optimizations.
>
> Juan
>
> On Monday, December 17, 2012 1:32:31 PM UTC-3, bruce li wrote:
>>
>> Hello, everyone.
>>
>> I'm currently trying to model an automata using multi-method. So in my
>> code, I have something like:
>>
>> (defmethod trans :state
>> [state]
>> ; .......
>> (trans ......))))
>>
>> In the last line, the trans will be called with some different state.
>>
>> However, it seems that such call still consumes stack and I quickly come
>> to a stack overflow error when the states are reached multiple times.
>>
>> I'm wondering if there is some ways to optimize the code.
>>
>> Thanks!
>>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en