Re: get all record instances

2011-11-07 Thread Mark Fredrickson
user=> (defrecord Foo [a])user.Foouser=> (def a (Foo. 1))#'user/ auser=> (def b (Foo. 2))#'user/b user=> (defrecord Other [b]) user.Other user=> (def q (Other. 123)) #'user/q user=> (def p (Other. 456)) #'user/puser=> (filter #(= (class %) user.Foo) (map var-get (vals (ns- publics 'user (#:user

Re: get all record instances

2011-11-05 Thread Colin Taylor
Actually that does seem the most idiomatic approach (def sources {:bcc source("bbc.. ), :google source("), } (defn all-sources [] (vals sources)) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to c

Re: get all record instances

2011-11-05 Thread Colin Taylor
Actually that does seem the most idiomatic approach (def sources {:bcc source("bbc.. ), :google source("), } (defn all-sources [] -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegr

Re: get all record instances

2011-11-05 Thread Mark Derricutt
I think Colin's record may be more detailed that just a key/value, he mentioned 'simplified definitions' so I'm guessing there things elided from the post. -- "Great artists are extremely selfish and arrogant things" — Steven Wilson, Porcupine Tree On Sun, Nov 6, 2011 at 6:03 AM, gaz jones wro

Re: get all record instances

2011-11-05 Thread gaz jones
could you not just use a map? (def sources {:bbc "bbc.co.uk" :google "google.com" ...}) On Sat, Nov 5, 2011 at 6:14 AM, Mark Derricutt wrote: > Would something like: > (def ^:dynamic *SOURCES* (ref [])) > (defrecord Source [name url]) > (defmacro defsource [name url] >   `(dosync (alter *SOURCE

Re: get all record instances

2011-11-05 Thread Mark Derricutt
Would something like: (def ^:dynamic *SOURCES* (ref [])) (defrecord Source [name url]) (defmacro defsource [name url] `(dosync (alter *SOURCES* conj (Source. ~name ~url (defn get-all-sources [] @*SOURCES*) (defsource "Google" "google.com") do ok? Man - it's been too long since I've done c

get all record instances

2011-11-05 Thread Colin Taylor
Hi, given a namespace sources with [simplified definitions] (defrecord Source [name url]) (def google (source "Google" "google.com")) (def bbc (source "BBC" "bbc.co.uk")) (def nbc ... etc. what would be the idiomatic way to implement (defn get-all-sources) cheers Colin -- You received this