On Wed, Nov 18, 2009 at 06:06:52AM -0800, Sean Devlin wrote:
>Do you mean the bean fn?
>
>http://clojure.org/api#toc120
This does appear to be lazy, although only partially. Things like
(keys mybean) invokes the beans, but I think that's more just a
consequence of how iterators work in Java/Cloju
Do you mean the bean fn?
http://clojure.org/api#toc120
On Nov 18, 4:23 am, David Brown wrote:
> On Tue, Nov 17, 2009 at 03:24:46PM -0800, Richard Newman wrote:
> >Baby, bathwater. Making a persistent map out of a Java map is
> >expensive. Not everything that implements Map is concrete; e.g.,
> >
On Tue, Nov 17, 2009 at 03:24:46PM -0800, Richard Newman wrote:
>Baby, bathwater. Making a persistent map out of a Java map is
>expensive. Not everything that implements Map is concrete; e.g.,
>spending several seconds making a local persistent Clojure map out of
>a distributed hash table proxy, j
On Tue, Nov 17, 2009 at 6:24 PM, Richard Newman wrote:
> > I wonder if perhaps (into {} a-java-map) should work but no other
> > substitutions of a potentially-mutable map for a Clojure map.
>
> Baby, bathwater. Making a persistent map out of a Java map is
> expensive. Not everything that impleme
> I wonder if perhaps (into {} a-java-map) should work but no other
> substitutions of a potentially-mutable map for a Clojure map.
Baby, bathwater. Making a persistent map out of a Java map is
expensive. Not everything that implements Map is concrete; e.g.,
spending several seconds making a
On Tue, Nov 17, 2009 at 5:06 PM, Sean Devlin wrote:
> Heh. Learn something new every day.
>
> This also works
>
> (into {} (System/getProperties))
And I'd much prefer it. Passing a mutable Java map around to functions that
expect a map but assume it will never change out from under them creates
> The only catch is putAll return void (WHY!)
Apparently Java people like having more LOC :)
> (defn put-all
> [java-map clj-map]
> (doto java-map
>(.putAll clj-map)))
Note that this isn't limited to Clojure maps, so 'clj-map' is probably
a bad variable name. It works just as well for co
Very awesome. So this means you can (almost) use the putAll method.
The only catch is putAll return void (WHY!)
(defn put-all
[java-map clj-map]
(doto java-map
(.putAll clj-map)))
Sean
On Nov 17, 5:29 pm, Alex Osborne wrote:
> Sean Devlin wrote:
> > Okay golfers. Is there a better way
Alex Osborne wrote:
> Sean Devlin wrote:
>> Okay golfers. Is there a better way to do this?
>>
>> (defn put-all!
>> [java-map clj-map]
>> (do
>> (doseq [entry clj-map]
>> (.put java-map (key entry) (val entry)))
>> java-map))
>>
>> user=>(put-all (java.util.HashMap. ) {:a 1 :b
How about?:
(java.util.HashMap. {:a 1 :b 2 :c 3})
=> #
Mark
Sean Devlin writes:
> Okay golfers. Is there a better way to do this?
>
> (defn put-all!
> [java-map clj-map]
> (do
> (doseq [entry clj-map]
> (.put java-map (key entry) (val entry)))
> java-map))
>
> user
Sean Devlin wrote:
> Okay golfers. Is there a better way to do this?
>
> (defn put-all!
> [java-map clj-map]
> (do
> (doseq [entry clj-map]
> (.put java-map (key entry) (val entry)))
> java-map))
>
> user=>(put-all (java.util.HashMap. ) {:a 1 :b 2 :c 3})
> #
>
> I already
Okay golfers. Is there a better way to do this?
(defn put-all!
[java-map clj-map]
(do
(doseq [entry clj-map]
(.put java-map (key entry) (val entry)))
java-map))
user=>(put-all (java.util.HashMap. ) {:a 1 :b 2 :c 3})
#
I already tried into :)
On Nov 17, 5:14 pm, Sean De
Wow.
So this works
user=>(get (System/getProperties) "os.arch")
"x86_64"
And this does not
user=>((System/getProperties) "os.arch")
java.lang.ClassCastException: java.util.Properties cannot be cast to
clojure.lang.IFn (NO_SOURCE_FILE:0)
but this does
user=>((into {} (System/getProperties)) "o
Sean Devlin wrote:
> Hey everyone,
> I was working with an object that implements java.util.Map today, and
> I had to turn it into a Clojure map.
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/Map.html
>
> I cam up with this utility fn
>
> (defn read-map
> "Designed to turn a java.util.
> Heh. Learn something new every day.
Heh.
Incidentally, because of this property there are only three situations
in which you need conversion at all:
* To get some additional interface that Clojure's maps provides (e.g.,
to use them as functions)
* To get persistence
* To have them print r
user=> (import 'java.util.HashMap)
java.util.HashMap
user=> (def m (doto (HashMap.) (.put 'a :a) (.put 'b :b)))
#'user/m
user=> m
#
user=> (into {} m)
{b :b, a :a}
user=> (class *1)
clojure.lang.PersistentArrayMap
user=>
On Tue, Nov 17, 2009 at 1:56 PM, Richard Newman wrote:
> Sean,
>
> If the c
Heh. Learn something new every day.
This also works
(into {} (System/getProperties))
On Nov 17, 4:56 pm, Richard Newman wrote:
> Sean,
>
> If the class implements Map, then it already behaves as an associative
> data structure in Clojure. E.g.,
>
> (map (fn [[k v]] (println v))
> (doto
Sean,
If the class implements Map, then it already behaves as an associative
data structure in Clojure. E.g.,
(map (fn [[k v]] (println v))
(doto (java.util.HashMap.)
(.put "foo" "bar")
(.put "baz" "noo")))
(get (doto (java.util.HashMap.)
(.put "foo" "bar")
Hey everyone,
I was working with an object that implements java.util.Map today, and
I had to turn it into a Clojure map.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Map.html
I cam up with this utility fn
(defn read-map
"Designed to turn a java.util.Map into a Clojure map."
[a-map]
(i
19 matches
Mail list logo