hmmm, seems like you, me and rayne all fail to handle the overlapping
node case correctly.
this is the best solution i've come up with that actually seems to
work:
(apply
merge-with
concat
{}
(for [nd d nd-pair nd face nd-pair]
{fa
Actually my solution is wrong! It works for this particular example,
but not if there are nodes with overlapping values.
Doh!
My main point was just that "into" is a under used gem, that I wanted
to publicize a bit. Next time I'll try to find an example that is
actually correct!
On Dec 3, 12:4
Yes,
though I've always found 'into a little bit too magical for me.
For example, I find it hard to follow the doc to see what 'adding' will mean
for maps.
2010/12/3 George Jahad
>
> > (apply
> > merge-with
> > conj
> > {}
> > (for [nd d nd-pair nd face nd-pair]
> > {face nd}))
>
>
> (apply
> merge-with
> conj
> {}
> (for [nd d nd-pair nd face nd-pair]
> {face nd}))
I like to use into for cases like this:
(into {} (for [nd d nd-pair nd face nd-pair] [face nd]))
seems clearer to me.
g
--
You received this message because you are subscribed to the Google
As a general rule, if you have something that has the semantics of a
pure function, and you can see how to implement it by banging on an
atom with swap! in a loop that consumes a sequence, then you can
transform it to use reduce.
If you have:
(defn foo [coll]
(let [x (atom bar)]
(dorun [y c
thanks Rayne.
On Fri, Dec 3, 2010 at 4:02 PM, Rayne wrote:
> Here is what I came up with.
>
> (let [d [#{#{1 2} #{3 4}} #{#{5 6} #{7 8}}]]
> (reduce
> (fn [mp nd]
> (apply merge
>(for [nd-pair nd face nd-pair] (update-in mp [face] #(conj
> % nd) {} d))
>
> On Dec 3, 3:42 a
Here is what I came up with.
(let [d [#{#{1 2} #{3 4}} #{#{5 6} #{7 8}}]]
(reduce
(fn [mp nd]
(apply merge
(for [nd-pair nd face nd-pair] (update-in mp [face] #(conj
% nd) {} d))
On Dec 3, 3:42 am, Sunil S Nandihalli
wrote:
> Hello everybody,
> I would like to know as
Thanks Laurent.. That really helps and also thanks for the tip of how to try
to do it in general.
Sunil.
On Fri, Dec 3, 2010 at 3:48 PM, Laurent PETIT wrote:
> Hello,
>
> one way:
>
> (apply
> merge-with
> conj
> {}
> (for [nd d nd-pair nd face nd-pair]
> {face nd}))
>
> The idea is (
Hello,
one way:
(apply
merge-with
conj
{}
(for [nd d nd-pair nd face nd-pair]
{face nd}))
The idea is (as is generally the case for me when trying to move from
imperative code to functional), is to try not to do too many things in a
single step.
So here, first I extract from the "for
Hello everybody,
I would like to know as to how I would write the following code in a
more idiomatic way.
(let [mp (atom {})
d [#{#{1 2}
#{3 4}} ;node1
#{#{5 6}
#{7 8}} ;node2]]
(dorun (for [nd d nd-pair nd face nd-pair]
(swap! mp update-in [face]
Yup, literal syntax for vectors are very convenient and heavily used
in Clojure code.
And (let) bindings are evaluated left to right. It's analogous to
Scheme's let* i think?
Only thing to watch out for is that (binding) bindings are not
evaluated left to right. It's for performance reasons I thi
The (list) comes from my dabblings with other lisps, using a vector
does make more sense and I quite like it
I was unaware that, unless I am mistaken from your above code that let
bindings are evaluated left to right, that is I was under the
impression (incorrectly) that you could not use say vm i
Most of that java code is just pasting together library function
calls. I'm not sure if there's any more elegant ways of doing that.
Your clojure code looks fine for the most part I think. It's mostly
just a question of style. The only thing that sticks out is the call
to (list). That's generally n
Sorry, you are not commenting out a line of code but ignoring the next
form.
On Feb 11, 12:49 pm, Brenton wrote:
> You can also you #_ to comment out a line of code
>
> #_(.vm detach)
>
> so that you don't have to put )) on the next line.
>
> Brenton
>
> On Feb 11, 10:39 am, Greg Bowyer wrote:
>
You can also you #_ to comment out a line of code
#_(.vm detach)
so that you don't have to put )) on the next line.
Brenton
On Feb 11, 10:39 am, Greg Bowyer wrote:
> Hi all, long time lurker first time irritant.
>
> I have been playing with clojure for a little while, and finding it most
> exc
You can use get on Properties. Use .foo for method calls. Use literal
vec syntax, not list. Use or for conditional branches instead of (if
foo foo ...).
Untested:
(defn obtain-local-connection [vmid]
(let [vm (VirtualMachine/attach vmid)
props (.getSystemProperties vm)
acqu
Hi all, long time lurker first time irritant.
I have been playing with clojure for a little while, and finding it most
excellent; however my lack of lisp thinking keeps leading me to write
ugly code.
I have the following code in java:
--
static final String CONNECTOR_ADDRESS =
"com.sun.
17 matches
Mail list logo