Clojure for the Brave and True - infix notation exercise

2016-06-24 Thread Botond Balázs
Hi, I'm working through Clojure for the Brave and True and there's a little exercise at the end of Chapter 7 : Create an infix function that takes a list like (1 + 3 * 4 - 5) and > transforms it into the lists that Clojure needs in order to correctly

Re: Clojure for the Brave and True - infix notation exercise

2016-06-26 Thread Botond Balázs
repeatedly so long as next operator is * or / > [list] > ... > [l2-expr remaining-tokens]) > > (defn parse-level3 ;; numbers > [list] > (if (number? list) > [(first list) (rest list)])) > > > > On Fri, Jun 24, 2016 at 2:28 PM, Botond Balázs > w

Re: Clojure for the Brave and True - infix notation exercise

2016-06-26 Thread Botond Balázs
(recur (list a b (infix (list* c d e m > (recur (list* (list b a c) d e m))) >:else a)) > > ;; example > (infix '[1 + 3 * 4 - 5]) > ;=> (+ 1 (- (* 3 4) 5)) > > > > On Jun 24, 2016, at 2:28 PM, Botond Balázs > wrote: > > &

Avoiding repetition while still using 'recur'

2016-06-26 Thread Botond Balázs
Hi, Here is my solution to 4clojure problem #177: Write a function that takes in a string and returns truthy if all square [ > ] round ( ) and curly { } brackets are properly paired and legally nested, > or returns falsey otherwise. > (defn valid-parens? [s] (loop [[ch & chs] s stack []]

Re: Avoiding repetition while still using 'recur'

2016-06-26 Thread Botond Balázs
(recur cs stack))) > > Another way you could do it is to replace your recursive call with a > continuation. > > - James > > On 26 June 2016 at 13:43, Botond Balázs > > wrote: > >> Hi, >> >> Here is my solution to 4clojure problem #177: >> &

Re: Avoiding repetition while still using 'recur'

2016-06-26 Thread Botond Balázs
g-brackets c)] > (if (= (peek stack) b) > (pop stack) > (reduced [false])) > stack))) > [] > (seq s))))) > > > HTH > > On Sunday, June 26, 2016 at 4:06:27 PM UTC+2, Botond Balázs wrote: >> >>