(defn prefix->postfix [expr] (if (coll? expr) (let [ [op arg1 arg2] expr] [ (prefix->postfix arg1) (prefix->postfix arg2) op])) ;; HERE: 2 closing brackets first one close the let. second close the if. expr)
In Clojure, (if test expr else) is the if expression. Here, you do (if test then) , which is valid Clojure and add nil as else. So here what happens is you execute the if and after that, whatever eas the value of (coll? expr) you return expr. That's why I told you the indentation was wrong. expr should be at the same level than (if.... , which would make the error apparent. Best, Nicolas. On Thu, Sep 9, 2010 at 2:27 PM, Stefan Rohlfing <stefan.rohlf...@gmail.com> wrote: > The indentation was correct by got messed up when I copying the code. > > This is how I interpret the function: > 'expr' is only returned if (coll? expr) returns 'false', with is not > the case with an argument such as '(+ 2 4). > Next, this expression is destructured in the 'let' and 'prefix- >>postfix called again: > > [ (prefix->postfix 2) (prefix->postfix 4) +] > > As 2 and 4 are both not a collection, their values are just returned. > This should lead to this final result: > > [2 4 +] > > However, no vector is returned, just the initial argument to the > function. > > I really want to understand what I did wrong here :-) > > Stefan > > > > On Sep 9, 9:08 pm, Nicolas Oury <nicolas.o...@gmail.com> wrote: >> Yes. >> >> Have someone (for example your editor), do your indentation for you. >> By typing on tab on a good editor, you would have has: >> (defn prefix->postfix [expr] >> (if (coll? expr) >> (let [ [op arg1 arg2] expr] >> [ (prefix->postfix arg1) (prefix->postfix arg2) op])) >> expr) >> >> which is easier to diagnose. (At least for me) >> >> Have fun with recursion, >> >> Nicolas. > > -- > 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 -- Sent from an IBM Model M, 15 August 1989. -- 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