On Sep 20, 7:02 am, Chouser <chou...@gmail.com> wrote: > On Mon, Sep 19, 2011 at 2:20 PM, qhfgva <qhf...@gmail.com> wrote: > > I'm working through some puzzle problems to help get up to speed on > > clojure. Generally I've been able to pound on something for a while > > and get the moment of enlightenment but for some reason this seemingly > > simple item is stumping me. (FWIW, the puzzle in question is the > > crossing a bridge at night in pairs with one lantern problem). > > > Here is The output that is confusing me: > > > Using: > > > (defn not-seen-already? [states state] > > (not (some #{state} states))) > > > user=> path > > [{:left [1 2 3], :lamp :left, :right []} {:lamp :right, :left (2 > > 3), :right (1)}] > > user=> next-steps > > ({:lamp :left, :right (), :left (1 2 3)}) > > user=> next-steps2 > > [{:lamp :left, :right [], :left [1 2 3]}] > > user=> (filter #(not-seen-already? path %) next-steps) > > ({:lamp :left, :right (), :left (1 2 3)}) > > user=> (filter #(not-seen-already? path %) next-steps2) > > () > > user=> (filter #(not-seen-already? path %) '({:lamp :left, :right > > (), :left (1 2 3)})) > > () > > user=> (filter #(not-seen-already? path %) [{:lamp :left, :right > > [], :left [1 2 3]}]) > > () > > > As you can see above, passing in the variable next-steps and next- > > steps2 above into my expression I get two different results (I was > > expecting the second result). When I pass the data structures in > > explicitly I get the same result for each. > > I can't reproduce your results: > > user=> (filter #(not-seen-already? path %) next-steps) > () > > What does your REPL say if you: (= (first next-steps) (first path)) > What version of Clojure are you using? > > --Chouser
Thanks for your response. Here you go: (with extra info as well) user=> (first path) (first path) {:left [1 2 3], :lamp :left, :right []} user=> (first next-steps) (first next-steps) {:lamp :left, :right (), :left (1 2 3)} user=> (first next-steps2) (first next-steps2) {:lamp :left, :right [], :left [1 2 3]} user=> (class path) (class path) clojure.lang.PersistentVector user=> (class next-steps) (class next-steps) clojure.lang.LazySeq user=> (class next-steps2) (class next-steps2) clojure.lang.PersistentVector user=> (first path) (first path) {:left [1 2 3], :lamp :left, :right []} user=> (first next-steps) (first next-steps) {:lamp :left, :right (), :left (1 2 3)} user=> (first next-steps2) (first next-steps2) {:lamp :left, :right [], :left [1 2 3]} user=> (filter #(not-seen-already? path %) next-steps) (filter #(not-seen-already? path %) next-steps) ({:lamp :left, :right (), :left (1 2 3)}) user=> (= (first next-steps) (first path)) (= (first next-steps) (first path)) true user=> *clojure-version* *clojure-version* {:interim true, :major 1, :minor 2, :incremental 0, :qualifier "master"} -- 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