On Jul 31, 2014, at 7:19 PM, Flea Wong <globalf...@gmail.com> wrote: > (ns crecords.trec > (:require [crecords.tproc :refer [Fruit]]))
You'll need to :refer subtotal here as well: (ns crecords.trec (:require [crecords.tproc :refer [Fruit]])) Then this will work: (defn f1 [] (println "Banana Subtotal:" (subtotal (Banana. 2)))) Note: Banana. not Banana I think it's more idiomatic to use ->RecordName rather than RecordName. BTW. I can't answer your questions directly but here's what I understand is happening so maybe this will answer them indirectly: defprotocol creates both the type and the top-level functions. Those top-level functions expect to call methods on their argument (I think) but those methods are defined elsewhere (in defrecord, extend-type, etc). defrecord creates a class that has methods. I think that those methods can be resolved as function calls that give the impression you really have a top-level function. extend-type provides implementations of methods that can be invoked on objects of the extended type. (subtotal ..) is a regular function call - which for a record can be mapped to a method call automatically it seems - and (.subtotal ..) is a Java interop call invoking a method directly on an object. Looking at what Vars are defined in each of your namespaces gives some insight into this: user=> (require 'crecords.tproc) nil user=> (ns crecords.tproc) nil crecords.tproc=> (ns-publics *ns*) {Fruit #'crecords.tproc/Fruit, map->Orange #'crecords.tproc/map->Orange, subtotal #'crecords.tproc/subtotal, -main #'crecords.tproc/-main, ->Orange #'crecords.tproc/->Orange} crecords.tproc=> (require 'crecords.trec) nil crecords.tproc=> (ns crecords.trec) nil crecords.trec=> (ns-publics *ns*) {f2 #'crecords.trec/f2, ->Apple #'crecords.trec/->Apple, ->Banana #'crecords.trec/->Banana, map->Banana #'crecords.trec/map->Banana, -main #'crecords.trec/-main, f1 #'crecords.trec/f1, map->Apple #'crecords.trec/map->Apple} Hope that helps? Sean Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "Perfection is the enemy of the good." -- Gustave Flaubert, French realist novelist (1821-1880)
signature.asc
Description: Message signed with OpenPGP using GPGMail