>
> It looks like it expects the keyword :osx, not the symbol osx. Could 
> that be the issue? 


Thanks for the suggestion, but when I try that instead, I get this error:

java.lang.IllegalArgumentException: No method in multimethod 'compiler' for 
dispatch value: null


I kind of feel it might be a typo in the compile-cmd function, cause 
instead of a sybol it is listing a vector with a name-spaced symbol and a 
string: * [::osx "gcc"]*. I think this form might have to do something with 
juxt in  *(defmulti compile-cmd (juxt :os compiler)) *. 
But I admit that I don't really understand what is going on here, as the 
book doesn't go all that far in explaining juxt, using keys as functions 
and how it relates to the defmethod syntax taking a vector in the beginning.

J 

On Monday, May 19, 2014 10:44:12 PM UTC+9, Rob Day wrote:
>
> It looks like it expects the keyword :osx, not the symbol osx. Could 
> that be the issue? 
>
> On 19 May 2014 16:39, gamma235 <jessel...@gmail.com <javascript:>> wrote: 
> > Hi guys, I am working through the pre-release second edition of Joy of 
> > Clojure's section on multi-methods (section 9.2.~ : pg. 313), and am 
> getting 
> > different outputs from what they have printed in the book. I could just 
> skip 
> > over it, but I really want to understand this stuff. Could someone tell 
> me 
> > how to get the (compile-cmd osx) call at the end of the code to produce 
> the 
> > expected output:  "/usr/bin/gcc" ? I have commented out redundancy and 
> moved 
> > a couple of lines for readability. Thanks in advance! 
> > 
> > J 
> >> 
> >> (ns joy.udp 
> >>   (:refer-clojure :exclude [get])) 
> >> 
> >> (defn beget [this proto] 
> >>   (assoc this ::prototype proto)) 
> >> 
> >> (defn get [m k] 
> >>   (when m 
> >>     (if-let [[_ v] (find m k)] 
> >>       v 
> >>       (recur (::prototype m) k)))) 
> >> 
> >> (def put assoc) 
> >> 
> >> ;;;;;;; compiler 
> >> (defmulti compiler :os) 
> >> (defmethod compiler ::unix [m] (get m :c-compiler)) 
> >> (defmethod compiler ::osx [m] (get m :llvm-compiler)) 
> >> 
> >> (def clone (partial beget {})) 
> > 
> > 
> >> 
> >> (def unix {:os ::unix, :c-compiler "cc", :home "/home", :dev "/dev"}) 
> > 
> > 
> >> 
> >> (def osx (-> (clone unix) 
> >>              (put :os ::osx) 
> >>              (put :llvm-compiler "clang") 
> >>              (put :home "/Users"))) 
> >> 
> >> ;;;;;;; home 
> >> (defmulti home :os) 
> >> (defmethod home ::unix [m] (get m :home)) 
> >> (defmethod home ::bsd [m] "/home") 
> > 
> > 
> >> 
> >> ;; the error on the call to (home osx) is contingent upon toggling the 
> >> following lines. 
> >> 
> >> ;(derive ::osx ::unix) 
> >> ;(derive ::osx ::bsd) 
> >> (prefer-method home ::unix ::bsd) 
> >> ;(remove-method home ::bsd) 
> >> (derive (make-hierarchy) ::osx ::unix) 
> >> 
> >> ;;;;;;; compile-cmd 
> >> (defmulti compile-cmd (juxt :os compiler)) 
> >> 
> >> (defmethod compile-cmd [::osx "gcc"] [m] 
> >>   (str "/usr/bin/" (get m :c-compiler))) 
> >> 
> >> (defmethod compile-cmd :default [m] 
> >>   (str "Unsure where to locate " (get m :c-compiler))) 
> >> ;;;;;;;;;;;;;;;;;;;;;; 
> >> 
> >> (home osx) 
> >> 
> >> ;=> java.lang.IllegalArgumentException: No method in multimethod 'home' 
> >> for dispatch value: :joy.udp/osx … 
> >> 
> >>  ;; Should be: ;=> "/Users" 
> > 
> > 
> >> (compile-cmd osx) 
> >> 
> >> ;=> "Unsure where to locate cc" 
> >> 
> >>  ;; Should be: ;=> "/usr/bin/gcc" 
> > 
> > 
> >> 
> >> (compile-cmd unix) 
> >> 
> >> ;=> "Unsure where to locate cc" 
> >> 
> >> ;; this is the expected output 
> > 
> > -- 
> > 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. 
>
>
>
> -- 
> Robert K. Day 
> rober...@merton.oxon.org <javascript:> 
>

-- 
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.

Reply via email to