Thank you everyone, for the replies:
- The macro expansion was helpful - Andy, thanks for pointing out where the lines are -- very helpful - Ambrose, both (number? %) and number? are valid post-condition forms; the issue is that the post-condition check bumps the recur out of tail position I guess the real question: is this worth filing a ticket for? Thanks all, Michael On Thursday, July 24, 2014 9:17:23 PM UTC-6, Ambrose Bonnaire-Sergeant wrote: > > Hi Michael, > > I believe your post condition should read {:post [(number? %)]}. > > Thanks, > Ambrose > > > On Fri, Jul 25, 2014 at 6:56 AM, Michael O'Keefe <michael....@gmail.com > <javascript:>> wrote: > >> Hello All, >> >> I encountered the following behavior in Clojure 1.6 and wanted to check >> if it should be considered a bug or not. I would say yes but wanted to >> double check on the list first. >> >> Here's a minimal test case that elicited the error: >> >> (defn f >> >> [xs acc] >> (if (nil? xs) >> acc >> (recur (next xs) (+ (first xs) acc)))) >> >> (f [1 2 3 4] 0) => 10 >> >> >> Now, if I want to add pre/post conditions, the following happens: >> >> (defn g >> >> [xs acc] >> {:pre [(or (nil? xs) (sequential? xs)) (number? acc)] >> :post [number?]} >> (if (nil? xs) >> acc >> (recur (next xs) (+ (first xs) acc)))) >> >> >> => this fails to compile with "CompilerException >> java.lang.UnsupportedOperationException: Can only recur from tail position" >> >> >> In fact, it is only the post-condition that triggers the issue. >> >> My guess would be that the recur statement is being knocked out of tail >> position by the mechanism for handling the post-condition assertion. It can >> be fixed in the code by adding an explicit loop: >> >> (defn g2 [xs acc] >> {:pre [(or (nil? xs) (sequential? xs)) (number? acc)] >> :post [number?]} >> (loop [xs xs >> acc acc] >> (if (nil? xs) >> acc >> (recur (next xs) (+ (first xs) acc))))) >> >> >> Thanks, >> >> Michael O'Keefe >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Clojure" group. >> To post to this group, send email to clo...@googlegroups.com >> <javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> 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+u...@googlegroups.com <javascript:>. >> 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.