Hi,
user= (defrecord Bar [x])
user.Bar
user= (into (Bar. nil) {:x 1 :y 2})
#:user.Bar{:x 1, :y 2}
One still has to know, that Bar takes an argument, but one could provide
and API function which takes care of that.
user= (defrecord Bar [x])
user.Bar
user= (defn empty-bar [] (Bar. nil))
Good point. I keep falling into the trap of treating types like
classes. Types don't have inline constructors, because normal
functions perform that task well enough. If I want to coerce a map
into a type, I really need just a constructor function, rather than
the type itself.
In this case,
James Reeves wrote:
Hi folks,
I've been experimenting with the new type system in Clojure 1.2, but
I've hit something of a problem. If I define a record:
user= (defrecord Foo [])
user.Foo
Then I can coerce a map into a type Foo like so:
user= (def m {:x 1, :y 2})
#'/user/m
user= (Foo. {} m)
'into' is one easy way:
(reduce into #{#{[3 2] [5 4] [3 3] } #{[4 3] [5 4] [3 3] } #{[3 2] [2
2] [3 3] } })
= #{[3 2] [4 3] [5 4] [2 2] [3 3]}
Stu
Hi, from a newbie!! Any help appreciated
Trying to get from here:
#{#{[3 2] [5 4] [3 3] } #{[4 3] [5 4] [3 3] } #{[3 2] [2 2] [3 3] } }
to
On May 22, 2010, at 10:00 AM, mikel wrote:
Trying to get from here:
#{#{[3 2] [5 4] [3 3] } #{[4 3] [5 4] [3 3] } #{[3 2] [2 2] [3 3] } }
to here:
#{[3 2] [5 4] [4 3] [2 2] [3 3] }
that is, combining the set of sets into one set.
(apply clojure.set/union #{#{[3 2] [5 4] [3 3]} #{[4 3] [5
Hi folks,
I am just asking you guy's input to following:
(defn- k-filter [el coll]
(filter #(not (= el %)) coll))
(defn combinations [n coll]
(if (= n 0)
nil
(for [el coll nlis (combinations (- n 1) (k-filter el coll))]
[el nlis])))
It is not working now. Here is an example I
On 22 May 2010, at 20:38, Kasim wrote:
Hi folks,
I am just asking you guy's input to following:
(defn- k-filter [el coll]
(filter #(not (= el %)) coll))
(defn combinations [n coll]
(if (= n 0)
nil
(for [el coll nlis (combinations (- n 1) (k-filter el coll))]
[el
agree
2010/5/22 Chris Riddoch riddo...@gmail.com:
I have a rather small patch I'd like to propose for Clojure:
*read-eval* should default to false, rather than true. Security
implications? Aside from the 'read' function, are other operations on
strings safe from unintended evaluation?
--
(I tried to post this to clojure-dev, but don't have permission to
post messages there)
At a repl the following works:
(defprotocol Base
(foo [o]))
(defprotocol Base)
(defprotocol Base
(foo [o]))
However, a file containing only those three forms, causes the
following when loaded:
loader
user= (defn foo [_] foo)
user= (defprotocol IFoo
(foo [_]))
Warning: protocol #'user/IFoo is overwriting function foo
IFoo
user= (extend-protocol IFoo nil (foo [_] IFoo))
nil
user= (foo nil)
IFoo
user= (foo 1)
java.lang.IllegalArgumentException: No implementation of method: :foo
user= (defn foo [_] foo)
user= (defprotocol IFoo
(foo [_]))
Warning: protocol #'user/IFoo is overwriting function foo
IFoo
user= (extend-protocol IFoo nil (foo [_] IFoo))
nil
user= (foo nil)
IFoo
user= (foo 1)
java.lang.IllegalArgumentException: No implementation of method: :foo
of
Sorry for the duplicate messages.
--
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
On 22 May 2010 04:03, Ben Mabey b...@benmabey.com wrote:
How about merging?
user= (merge (Bar. {}) m)
#:user.Bar{:x 1, :y 2}
This approach at least doesn't require that you know in advance the keys of
Bar.
No, you still do:
user= (defrecord Foo [x y z])
user.Foo
user= (merge (Foo. {}) m)
As Steve said, better look at the combinatorics-api.
As for your original code, the idea you have gives all permutations
not combinations! Few changes will make it functioning -
(defn permutations [n coll]
(if (= n 1)
(map #(vector %) coll)
(for [el coll nlis (permutations (- n
1:6 user= (use '[clojure.set])
nil
1:7 user= (reduce union #{} #{#{[3 2] [5 4] [3 3] } #{[4 3] [5 4] [3
3] } #{[3 2] [2 2] [3 3] } } )
#{[3 2] [4 3] [5 4] [2 2] [3 3]}
1:8 user=
Thx
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this
Hey Meikel,
Thank you for your suggestions!
I changed the dereferencing and looked at swing-utils in contrib. It
doesn't seem like there's a lot I can use straight, but I did get an
idea to write a function add-component-listener, that I can use.
Who's in charge of swing-utils? I just thought
Hi, any responses?
--
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,
I only got it to half work. Using elpa, have done the same as
others. Using mvn w/clojure plugin to do mvn clojure:swank;
changed to use swank 1.2.1.
C-c C-k works fine...
C-c C-c bombs with Java.lang.exception (No such namespace) like so:
Backtrace:
0: swank.commands.basic
18 matches
Mail list logo