Hi Bill, There are several issues here:
(1) A confusion of record and instance. You are asking for the :list1 field from foo, the record type, not from an instance of the type. (:list1 foo) s/b (:list1 MyFoo) (2) You are ignoring the return value of assoc. Remember, Clojure data structures are immutable. To actually assign something you need to hold on to the return value of the expression (or use a reference type if you really want an identity). (3) The capitalization choices facilitate confusion. You are using "foo" for a record/class name, where both Java and Clojure style would dictate "Foo". Then you use "MyFoo" for a top-level def, where Clojure style would encourage "my-foo". The following code demonstrates these ideas. ;; stubbed so example can be run (defn load-data-from-file [x] :stub) (defrecord Foo [list1 list2]) (defn get-data [path] (let [list1Data (load-data-from-file path) f (Foo. nil nil) f (assoc f :list1 list1Data)] (:list1 f))) (get-data "fakepath") Regards, Stu Stuart Halloway Clojure/core http://clojure.com > All the examples of defrecord I see seem simple enough and when I > experiment in the REPL I get things to work as they should. However, > when I move to 'real' code I can't get it to work at all. > > The problem at hand is simple enough - I want to create a record that > hold records. For example I have (defrecord foo [list1, list2]) > where list1 and list2 are defined records themselves. The issue is > that the data in list1 and list2 is dynamic - it is loaded from a file > at run time. So I do the following: > > (def MyFoo (foo. nil nil)) > > (defn get-data [path] > (let [list1Data (load-data-from-file path)] ; fill in the record > for list 1 > (assoc MyFoo :list1 list1Data) ; assign the data > record to the foo record > (:list1 foo) > )) > > As I say, if I do this non-dynamically in the REPL I get the proper > result. > > In my program (using let) (:list1 foo) always remains nil. What am > I doing wrong? And how can I get the fields of foo to take on the > dynamic data. > > Bill > > -- > 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 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