Iterating through two seqs at once for side-effects

2010-09-25 Thread HiHeelHottie

What are good ways to iterate through two seqs at once for side-
effects?

This doesn't seem so great since I'm not interested in the collection
that's built by map.  I also learned the hard way that map is lazy.
Hence, the dorun.

(dorun (map #(println %1 %2) [1 2 3] [11 22 33]))

-- 
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


Re: Iterating through two seqs at once for side-effects

2010-09-25 Thread Per Vognsen
I would use something like this:

(defn zip [& xss]
  (apply map vector xss))

(doseq [[x y] (zip [1 2 3] [11 22 33])]
  (println x y))

Most of the time I use parallel mapping directly. But in cases like
this one I think the intention of the code is better expressed by the
above separation of concerns.

-Per

On Sat, Sep 25, 2010 at 2:00 PM, HiHeelHottie  wrote:
>
> What are good ways to iterate through two seqs at once for side-
> effects?
>
> This doesn't seem so great since I'm not interested in the collection
> that's built by map.  I also learned the hard way that map is lazy.
> Hence, the dorun.
>
> (dorun (map #(println %1 %2) [1 2 3] [11 22 33]))
>
> --
> 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


Does 'lein repl' session give slow processing for you, too?

2010-09-25 Thread Andy Fingerhut
This happens for me on a Mac OS X system, and an Ubuntu Linux system,  
and with Clojure 1.2.0 and 1.3.0-alpha1.  Here are steps for me to  
reproduce with Clojure 1.2.0.


Install Leiningen.

% lein new clj-1.2.0
% cd clj-1.2.0

[ Optionally edit project.clj to remove dependency on contrib, leaving  
only clojure 1.2.0.  This is only necessary if you want to convince  
yourself that contrib has nothing to do with it. ]


% ls -l lib
-rw-rw-r-- 1 andy andy 3237168 Sep 24 23:47 clojure-1.2.0.jar

% cat swapping.clj
(defn swapping [#^ints a n]
  (let [n (long n)
size-1 (int (dec (count a)))]
(loop [i (long n)
   j 0
   k 1]
  (if (zero? i)
a
(let [temp (int (aget a j))]
  (aset a j (aget a k))
  (aset a k temp)
  (recur (dec i)
 (if (zero? j) size-1 (dec j))
 (if (zero? k) size-1 (dec k

(def a1 (int-array 12 (reverse (list 5 7 3 8 2 9 12 10 4 1 6 11

(time (vec (swapping a1 10)))

% java -server -cp lib/clojure-1.2.0.jar clojure.main

[ At this point, regardless of whether I copy and paste the forms in  
swapping.clj into this session one by one to evaluate them, or if I do  
load-file on it, the forms evaluate and the time reported for the last  
one is about 60 msec. ]


% java -client -cp lib/clojure-1.2.0.jar clojure.main

[ Same results as above, again, whether I copy and paste the forms, or  
use load-file.  The timing results are a little bit different because  
of -client vs. -server on the command line, but not much different. ]


% lein repl

[ Here, if I do load-file, the timing results are about the same as  
above.  But if I copy and paste the forms one at a time, then I get a  
time like the one below for the last form:


user=> (time (vec (swapping a1 10)))
"Elapsed time: 12683.523 msecs"

This is easily reproducible on my system Mac and Linux systems.   
Happens every time.  This is about 200 times longer than all of the  
previously mentioned timing results. ]


Anyone else see this?  Or even better, know why it happens?

I normally use SLIME within Emacs to interact with a Clojure session,  
but since I was doing some performance analysis of 1.3.0-alpha1 vs.  
1.2.0, and swank-clojure doesn't seem to be there yet for 1.3.0- 
alpha1, I tried using 'lein repl' instead and copying and pasting  
forms into it from the text editor.  That is when I noticed something  
funny going on.


I can avoid it now that I know about it, but was curious if it was  
just me, and if not, how to correct it.


Thanks,
Andy

--
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


Re: German Clojure Book Available

2010-09-25 Thread Stefan Kamphausen


On Sep 24, 10:33 am, Thomas Wagner  wrote:

> I've just ordered my copy.

:-)
Hope, you'll like it.

Best regards,
Stefan

-- 
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


Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-25 Thread Nicolas Oury
> Your code was simple enough for me to make a couple of educated guesses. For
> more complex code I'd use VisualVM, https://visualvm.dev.java.net/
> David
>


I use that too.
Sampling for a first look, profiling with instrumentation for a more
precise answer.
(Here, the sampling gives even? and the profiling gives the reflection methods)

-- 
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


defining a function ...

2010-09-25 Thread Sunil S Nandihalli
Hi everybody,
 The following is a

http://pastebin.com/0r9BBdmK

code which is using clojuratica.

I am trying to write a function .. But when evaluated it is not behaving as
expected.
 The function definition is
(defn irreducibleQ [x]
  (With [f 10 g 20]
(* f (+ g x

The output expected out of

(irreducibleQ 30)

was 500 but instead I got

(ClojurianScopes/With [f 10 g 20] (* f (+ g x)))

can anybody tell me as to what is happening here...

I am not able to find any examples in the clojuratica examples which
describe how I would create a function. Can anybody help me figure out what
is going wrong here?
Thanks
Sunil.



*BY CLOJURATICA FUNCTION DEFI... ON THE 25TH OF SEP 2010 05:29:13 AM*
DOWNLOAD  |
RAW
 | EMBED  |
REPORT
 | DELETE 

   1.  (ns clojuratica-exp.core
   2.(:use clojuratica)
   3.(:require [clojure.contrib.str-utils2 :as str])
   4.(:import [com.wolfram.jlink MathLinkFactory]))
   5.
   6.  (defn init-mathematica
   7."initialize mathematica"
   8.[mathematica-command]
   9.(defonce math-evaluate (math-evaluator
   10.(doto (MathLinkFactory/createKernelLink
   mathematica-command)
   11.  (.discardAnswer)
   12.
   13.  (init-mathematica "-linkmode launch -linkname
   '/usr/local/Wolfram/Mathematica/7.0/Executables/math'")
   14.
   15.  (def-math-macro math math-evaluate)
   16.  (math-intern math-evaluate "System`*")
   17.  (math-intern math-evaluate :scopes)
   18.
   19.  (D (Plus (* 4 x) (+ 20 2) (nfunc 3)) x)
   20.  (defn irreducibleQ [x]
   21.(With [f 10 g 20]
   22.  (* f (+ g x
   23.  (irreducibleQ 30)

-- 
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

Re: Lazytest 1.0.0 (beta)

2010-09-25 Thread Sean Grove
Looks very awesome - I'll be giving this a try in my current projects.

Thanks for such a cool library!

sg

On Sep 24, 2010, at 12:38 PM, Stuart Sierra wrote:

> http://github.com/stuartsierra/lazytest
> 
> My attempt to steal all the good ideas from clojure.test, Circumspec,
> ClojureCheck, RSpec, Spock, ScalaTest, etc.  Kudos to all those
> authors for all their great work.
> 
> -S
> 
> -- 
> 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


Re: Iterating through two seqs at once for side-effects

2010-09-25 Thread Jeff Palmucci
I'd use my clj-iterate library at http://github.com/jpalmucci/clj-iterate.

user> (iter {for x in [1 2 3]}
{for y in [11 22 33]}
(println x y))
1 11
2 22
3 33
nil

Won't collect the sequence if you don't ask for it, and its eager (and
fast).

It's also available at clojars. From leiningen:

[clj-iterate "0.91"]

-- 
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


Re: Does 'lein repl' session give slow processing for you, too?

2010-09-25 Thread meric
I got the same results. lein repl vs cake repl

eric-mans-macbook-2:perfect-number Eric$ lein repl
"REPL started; server listening on localhost:64419."
user=> (defn swapping [#^ints a n]
   (let [n (long n)
 size-1 (int (dec (count a)))]
 (loop [i (long n)
j 0
k 1]
   (if (zero? i)
 a
 (let [temp (int (aget a j))]
   (aset a j (aget a k))
   (aset a k temp)
   (recur (dec i)
  (if (zero? j) size-1 (dec j))
  (if (zero? k) size-1 (dec k
#'user/swapping
user=> (def a1 (int-array 12 (reverse (list 5 7 3 8 2 9 12 10 4 1 6
11
#'user/a1
user=> (time (vec (swapping a1 10)))
"Elapsed time: 13219.589 msecs"


-


eric-mans-macbook-2:perfect-number Eric$ cake repl
user=> (defn swapping [#^ints a n]
user=*(let [n (long n)
user=*  size-1 (int (dec (count a)))]
user=*  (loop [i (long n)
user=* j 0
user=* k 1]
user=*(if (zero? i)
user=*  a
user=*  (let [temp (int (aget a j))]
user=*(aset a j (aget a k))
user=*(aset a k temp)
user=*(recur (dec i)
user=*   (if (zero? j) size-1 (dec j))
user=*   (if (zero? k) size-1 (dec k
#'user/swapping
user=> (def a1 (int-array 12 (reverse (list 5 7 3 8 2 9 12 10 4 1 6
11
#'user/a1
user=> (time (vec (swapping a1 10)))
"Elapsed time: 57.03 msecs"
[12 9 2 8 3 7 5 11 1 6 4 10]



On Sep 25, 6:20 pm, Andy Fingerhut  wrote:
> This happens for me on a Mac OS X system, and an Ubuntu Linux system,  
> and with Clojure 1.2.0 and 1.3.0-alpha1.  Here are steps for me to  
> reproduce with Clojure 1.2.0.
>
> Install Leiningen.
>
> % lein new clj-1.2.0
> % cd clj-1.2.0
>
> [ Optionally edit project.clj to remove dependency on contrib, leaving  
> only clojure 1.2.0.  This is only necessary if you want to convince  
> yourself that contrib has nothing to do with it. ]
>
> % ls -l lib
> -rw-rw-r-- 1 andy andy 3237168 Sep 24 23:47 clojure-1.2.0.jar
>
> % cat swapping.clj
> (defn swapping [#^ints a n]
>    (let [n (long n)
>          size-1 (int (dec (count a)))]
>      (loop [i (long n)
>             j 0
>             k 1]
>        (if (zero? i)
>          a
>          (let [temp (int (aget a j))]
>            (aset a j (aget a k))
>            (aset a k temp)
>            (recur (dec i)
>                   (if (zero? j) size-1 (dec j))
>                   (if (zero? k) size-1 (dec k
>
> (def a1 (int-array 12 (reverse (list 5 7 3 8 2 9 12 10 4 1 6 11
>
> (time (vec (swapping a1 10)))
>
> % java -server -cp lib/clojure-1.2.0.jar clojure.main
>
> [ At this point, regardless of whether I copy and paste the forms in  
> swapping.clj into this session one by one to evaluate them, or if I do  
> load-file on it, the forms evaluate and the time reported for the last  
> one is about 60 msec. ]
>
> % java -client -cp lib/clojure-1.2.0.jar clojure.main
>
> [ Same results as above, again, whether I copy and paste the forms, or  
> use load-file.  The timing results are a little bit different because  
> of -client vs. -server on the command line, but not much different. ]
>
> % lein repl
>
> [ Here, if I do load-file, the timing results are about the same as  
> above.  But if I copy and paste the forms one at a time, then I get a  
> time like the one below for the last form:
>
> user=> (time (vec (swapping a1 10)))
> "Elapsed time: 12683.523 msecs"
>
> This is easily reproducible on my system Mac and Linux systems.  
> Happens every time.  This is about 200 times longer than all of the  
> previously mentioned timing results. ]
>
> Anyone else see this?  Or even better, know why it happens?
>
> I normally use SLIME within Emacs to interact with a Clojure session,  
> but since I was doing some performance analysis of 1.3.0-alpha1 vs.  
> 1.2.0, and swank-clojure doesn't seem to be there yet for 1.3.0-
> alpha1, I tried using 'lein repl' instead and copying and pasting  
> forms into it from the text editor.  That is when I noticed something  
> funny going on.
>
> I can avoid it now that I know about it, but was curious if it was  
> just me, and if not, how to correct it.
>
> Thanks,
> Andy

-- 
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


Re: Genetic Algorithm Example

2010-09-25 Thread Goran Jovic
Thank you for your reply.

> Perhaps you'd be interested in a related but slightly different approach to 
> solving a related but slightly different problem.

The game from my program is from Serbian TV quiz Slagalica (http://
en.wikipedia.org/wiki/TV_Slagalica). As you said Krypto is only
slightly different from one in my example, so it is very interesting
to see your approach.

My initial goal was to use GP. However, it seemed to me that Lisp's
code-as-data style makes a much smaller difference between standard
genetic algorithms and genetic programming then imperative languages,
e.g. Java, so I decided to try this way first.

>Using this to solve Krypto, which is quite simple, is a bit like using a 
>sledgehammer to kill a fly..

Maybe, but so is every other "Hello word" ever written :)

I will definitively try using Clojush too, especially since GP was my
initial intention, so thanks again.

>
> Also, just for kicks I recently wrote Clojure code to solve Krypto instances 
> directly, since it's pretty easy. I'll paste in the code below. People will 
> yell that I shouldn't use eval or non-recur recursive calls, but I think 
> they're fine in this (toy) case.
>
>  -Lee
>
> ;; kryptosolve.clj
> ;; Clojure code for solving instances of the game of Krypto.
> ;; Seehttp://en.wikipedia.org/wiki/Krypto_(game)
> ;; Lee Spector, lspec...@hampshire.edu, 2010
>
> (ns kryptosolve
>   (:use clojure.contrib.combinatorics))
>
> (defn safe-eval
>   "Returns the result of evaluating e, or :error if it throws an exception."
>   [e]
>   (try (eval e) (catch java.lang.Exception _ :error)))
>
> (defn all-splits
>   "Returns a sequence of all ways of splitting values into 2 subsequences."
>   [values]
>   (map #(split-at (inc %) values) (range (dec (count values)
>
> (defn expressions
>   "Returns a sequence of all of the arithmetic expressions that can be formed
> with the provided values in the given order."
>   [values]
>   (if (< (count values) 2)
>     values
>     (mapcat
>       (fn [[left-values right-values]]
>         (mapcat
>           (fn [[left-expression right-expression]]
>             (map #(list % left-expression right-expression) '(+ - * /)))
>           (cartesian-product (expressions left-values) (expressions 
> right-values
>       (all-splits values
>
> (defn solve-krypto
>   "Returns a solution expression if one can be found for the given
> values and target."
>   [values target]
>   (first (filter
>            #(= (safe-eval %) target)
>            (mapcat expressions (lex-permutations values)
>
> (solve-krypto [1 2 3 4 5] 25)

It seems that you used brute force calculation to get the result in
this code. May I use the code you pasted in my project (modified to
fit the specific rules of my game) to test the performance of my code
against it? It would be nice to see the gain of using a genetic
algorithm over brute force (if there is any in this example, of
course).

-- 
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


Re: Genetic Algorithm Example

2010-09-25 Thread Lee Spector

On Sep 25, 2010, at 7:14 AM, Goran Jovic wrote:
> I will definitively try using Clojush too, especially since GP was my
> initial intention, so thanks again.

Great -- I'd love to hear about your experiences. You can find more about 
Push/PushGP at http://hampshire.edu/lspector/push.html.


>> Also, just for kicks I recently wrote Clojure code to solve Krypto instances 
>> directly, since it's pretty easy. I'll paste in the code below. People will 
>> yell that I shouldn't use eval or non-recur recursive calls, but I think 
>> they're fine in this (toy) case.
>> [code omitted]
> 
> It seems that you used brute force calculation to get the result in
> this code. May I use the code you pasted in my project (modified to
> fit the specific rules of my game) to test the performance of my code
> against it? It would be nice to see the gain of using a genetic
> algorithm over brute force (if there is any in this example, of
> course).


Yes indeed, this was brute force, and certainly, feel free to use it.

 -Lee

--
Lee Spector, Professor of Computer Science
School of Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspec...@hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438

Check out Genetic Programming and Evolvable Machines:
http://www.springer.com/10710 - http://gpemjournal.blogspot.com/

-- 
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


finding value nearest x

2010-09-25 Thread Glen Rubin
I have a list of numbers and I want to find the one that is closest to
136.  Is there an operator for performing this kind of operation or do
I need to to do it algorithmically?

thanks!

-- 
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


Re: Literal collection of numbers - prefer list or vector?

2010-09-25 Thread Joop Kiefte
the vector form. in idiomatic clojure, lists are practically only used
for code and macro's.

2010/9/25 HiHeelHottie :
> For a literal collection of numbers which would be more idiomatic and
> why?
>
> (reduce + '(1 2 3)) vs (reduce + [1 2 3])
>
> --
> 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



-- 
Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004

Demandoj en aŭ pri Esperanto? Questions about Esperanto? Vragen over
Esperanto? Perguntas sobre o Esperanto? - http://demandoj.tk

-- 
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


Re: finding value nearest x

2010-09-25 Thread Jules
Maybe this: (min-key #(abs (- % 136)) xs)

On Sep 25, 3:41 pm, Glen Rubin  wrote:
> I have a list of numbers and I want to find the one that is closest to
> 136.  Is there an operator for performing this kind of operation or do
> I need to to do it algorithmically?
>
> thanks!

-- 
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


Re: finding value nearest x

2010-09-25 Thread Nicolas Oury
On Sat, Sep 25, 2010 at 3:40 PM, Jules  wrote:
> Maybe this: (min-key #(abs (- % 136)) xs)
>
Wouldn't that be (apply min-key #(abs (- % 136)) xs)?

-- 
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


Re: finding value nearest x

2010-09-25 Thread Jules
Yes, you're right.

On Sep 25, 4:44 pm, Nicolas Oury  wrote:
> On Sat, Sep 25, 2010 at 3:40 PM, Jules  wrote:
> > Maybe this: (min-key #(abs (- % 136)) xs)
>
> Wouldn't that be (apply min-key #(abs (- % 136)) xs)?

-- 
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


Re: finding value nearest x

2010-09-25 Thread Eivind Magnus Hvidevold
(use 'clojure.contrib.math) ; for abs
(apply min-key #(abs (- 136 %)) [1 3 137 -137 135 0 50 75])

A recent thread in this group noted that min-key applies the function
multiple times and there's a better replacement. Also, if you're looking up
many such numbers you might want to sort and do binary search.

-- 
Eivind Magnus Hvidevold
Cell: +47 926 78 423



On Sat, Sep 25, 2010 at 3:41 PM, Glen Rubin  wrote:

> I have a list of numbers and I want to find the one that is closest to
> 136.  Is there an operator for performing this kind of operation or do
> I need to to do it algorithmically?
>
> thanks!
>
> --
> 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

Re: finding value nearest x

2010-09-25 Thread Chouser
On Sat, Sep 25, 2010 at 10:44 AM, Nicolas Oury  wrote:
> On Sat, Sep 25, 2010 at 3:40 PM, Jules  wrote:
>> Maybe this: (min-key #(abs (- % 136)) xs)
>>
> Wouldn't that be (apply min-key #(abs (- % 136)) xs)?

Where's your 'abs' function coming from?  This works for me:

(apply min-key #(Math/abs (- % 136)) xs)

Or if you want something slower when building the collection but
faster when looking it up, you can use a sorted set:

(let [ss (sorted-set 1 2 134 139 4),
  asc (subseq ss >= 136),
  desc (rsubseq ss <= 136)]
  (min-key #(Math/abs (- % 136)) (first asc) (first desc)))

That's O(log n) instead the simpler (apply min-key ...) which is O(n).

--Chouser
http://joyofclojure.com/

-- 
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


Re: Clojure for VS2010

2010-09-25 Thread Will Kennedy
Thanks for the great feedback, Shawn.

On Sep 23, 3:09 pm, Shawn Hoover  wrote:
> On Thu, Sep 23, 2010 at 4:20 PM, Will Kennedy  wrote:
> > Some background: I've been spending some of my free time providing by
> > basic Clojure support in VS 2010. To be honest, I'm a bit of a Clojure
> > newbie, so I figured something that would require me to build a lexer
> > and parser for the language and delve into the clojure source would be
> > a great way to learn while creating something other people might find
> > valuable. For adoption, having first-class support in VS for clojure-
> > clr would be huge.
>
> > I've built syntax highlighting, brace matching, and some basic
> > formatting helpers. I'm working on the REPL window and project/build
> > system next. My hope is to get it to the point where a user can
> > download the plugin, create a new project, get some basic boilerplate,
> > build, execute and debug all from within Visual Studio. People who are
> > using emacs won't be abandoning it, but I hope it'll help people with
> > a .Net background get going quickly.
>
> > I'm looking for input about what features I should focus on and just
> > general comments on the worthiness of the project. I figure I'm bound
> > to make mistakes by approaching this from a C/C++/C# programmer's
> > perspective, and this might preclude that.
>
> > Thanks.
>
> Hi Will,
>
> This is absolutely worthy. It's VS or die in the .NET world. Syntax
> highlighting, indentation, the REPL (including sending expressions from the
> editor), and the project system are most important. After that, I think some
> combination of integrating the editor with the REPL's doc function, .NET
> intellisense, and Clojure intellisense. There's some effort going on to
> potentially unify the REPL servers used by the IDEs, so keep an eye on that,
> as well.
>
> Shawn

-- 
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


Re: finding value nearest x

2010-09-25 Thread Glen Rubin
min-key looks good!  thx guys!!!

On Sep 25, 10:44 am, Nicolas Oury  wrote:
> On Sat, Sep 25, 2010 at 3:40 PM, Jules  wrote:
> > Maybe this: (min-key #(abs (- % 136)) xs)
>
> Wouldn't that be (apply min-key #(abs (- % 136)) xs)?

-- 
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


Re: Clojure for VS2010

2010-09-25 Thread Mike K
Wow, really cool.  I'm looking forward to seeing this!

   Mike

-- 
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


Re: ANN: textmate-clojure, SLIME for TextMate (sorta)

2010-09-25 Thread Greg
On Sep 23, 2010, at 10:08 PM, David Nolen wrote:

> On Fri, Sep 24, 2010 at 1:06 AM, Greg  wrote:
> Thanks! What about single files though? (i.e. no project.clj)
> 
> 
> cake has a global project.clj - ~/.cake/project.clj. Change this and single 
> files will get access to those dependencies.

Great, thanks!

- Greg

> David
>  
> On Sep 23, 2010, at 9:22 PM, David Nolen wrote:
> 
>> On Thu, Sep 23, 2010 at 11:55 PM, Greg  wrote:
>> Awesome! Great job on this, I was hoping the TM Clojure bundle would get 
>> some much needed loving. :-)
>> 
>> Quick question: how does this bundle get clojure.jar and clojure-contrib.jar 
>> (and any additional dependencies), and is there a way to tell it to use a 
>> specific clojure[-contrib].jar file(s)?
>> 
>> Thanks,
>> Greg
>> 
>> Same way you do with lein. Just set that in your project.clj and run 'cake 
>> deps', or even 'lein deps' if you like.
>> 
>> David 
>> 
>> -- 
>> 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
> 
> 
> -- 
> 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

Re: clojure-contrib 1.3.0-alpha1

2010-09-25 Thread Sean Corfield
Thanx Mark. I'll try again today.

On Fri, Sep 24, 2010 at 11:07 PM, Mark Derricutt  wrote:
> Looking at the repository now the poms don't seem to include the variable
> reference anymore so if you're still getting that it might be cached
> somewhere?

-- 
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


Re: Does 'lein repl' session give slow processing for you, too?

2010-09-25 Thread Phil Hagelberg
On Sat, Sep 25, 2010 at 1:20 AM, Andy Fingerhut
 wrote:
> % lein repl
>
> [ Here, if I do load-file, the timing results are about the same as above.
>  But if I copy and paste the forms one at a time, then I get a time like the
> one below for the last form:
>
> user=> (time (vec (swapping a1 10)))
> "Elapsed time: 12683.523 msecs"
>
> This is easily reproducible on my system Mac and Linux systems.  Happens
> every time.  This is about 200 times longer than all of the previously
> mentioned timing results. ]
>
> Anyone else see this?  Or even better, know why it happens?

It appears to be related to a problem with ant. Loading the exact same
repl code by manually starting a subprocess has no problem at all.

I'm about fed up with ant; it seems that over half the problems with
Leiningen these days are either bugs in ant or problems in code that
Leiningen must include to work around bugs in ant. I'm brainstorming
ways to remove this dependency, but the JVM is pretty crippled when it
comes to things like unix process management.

-Phil

-- 
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


Re: clojure-contrib wiki on Google Code

2010-09-25 Thread Sean Corfield
On Fri, Sep 24, 2010 at 9:26 AM, Miki  wrote:
> The clojure-contrib on Google code still points to the "old"
> richkickey github project. The download jars are for the 1.1 release.
>
> For me, this is one of the top hits in Google - it'll probably confuse
> new users.

On a similar note, I noticed that the source links in the
clojuredocs.org site for contrib files are all broken now because they
point to things like:

http://github.com/clojure/clojure-contrib/blob/master/src/main/clojure/clojure/contrib/datalog/util.clj#L49

but contrib has been broken into modules.

I don't know how those links get generated / attached to the docs
project but changing master to 1.2.x in the URLs would fix it.
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

-- 
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


Re: Building from source - great improvements today! Thank you!

2010-09-25 Thread Sean Corfield
On Fri, Sep 24, 2010 at 8:13 AM, Stuart Sierra
 wrote:
> The version string in the Clojure build was set incorrectly.  It has
> now been restored to "1.3.0-master-SNAPSHOT"

Yup, confirmed. Thanx Stuart.

> If you depend on "-SNAPSHOT" versions, then Maven / Leiningen will
> always give you the latest version from build.clojure.org.

Ah, my lack of Maven knowledge...

I confirmed that if I have this in Leiningen, it works with the latest
built versions from build.clojure.org:

  :dependencies
[[org.clojure/clojure "1.3.0-master-SNAPSHOT"]
  [org.clojure.contrib/complete "1.3.0-SNAPSHOT" :classifier "bin"]]

I noticed it pulls .pom files from clojars?

Downloading: 
org/clojure/contrib/complete/1.3.0-SNAPSHOT/complete-1.3.0-20100924.200511-42.pom
from clojars
Downloading: 
org/clojure/contrib/complete/1.3.0-SNAPSHOT/complete-1.3.0-20100924.200511-42.pom
from clojars

BTW, I did one last source build this morning... I cleaned everything
out of my local repo and updated my local contrib git tree and did mvn
install and still got ${clojure.contrib.version} in the .pom files (so
things still failed). Since Mark said it looked good to him, I'll
leave this alone for now since it sounds like something I'm doing
wrong on my end.
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

-- 
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


Re: clojure-contrib 1.3.0-alpha1

2010-09-25 Thread Mark Derricutt
Take a look at:

http://github.com/talios/clojure-contrib/commit/58e4e49d569d285ef3dd5b64c80454a22743e1b4

I changed the "complete" artifact to use the maven-shape-plugin [1] which
embeds upstream dependencies into your jar, making an uber-jar, and
optionally "shading" those artifacts into a different package ( not needed
here, but quite useful ).

The artifact is now a "jar" dependency which means you won't need to specify
the  or the .

Mark

[1] http://maven.apache.org/plugins/maven-shade-plugin/index.html


-- 
Pull me down under...



On Sun, Sep 26, 2010 at 8:27 AM, Sean Corfield wrote:

> Thanx Mark. I'll try again today.

-- 
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

Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-25 Thread Btsai
Thanks Eric :)  Have you considered submitting that change as a patch?

On Sep 24, 5:35 pm, Eric Lavigne  wrote:
> > I think I read somewhere that max-key applies f more times than is
> > necessary, so should not be pass any f that takes significant time to
> > compute.
>
> Yes, max-key calls f more times than necessary.
>
> http://code.google.com/p/clojure/issues/detail?id=95
>
> We ran into this problem yesterday on a tic-tac-toe project, in which
> f was a function that determines who is winning for a given board
> position. Tests that previously ran in under a minute now took over 10
> minutes (that's roughly how long I waited before stopping it). We
> fixed our program by replacing max-key with the alternative
> implementation from the above link.
>
> http://github.com/ericlavigne/tic-tac-toe/commit/0d172c45c9d462620af8...

-- 
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


Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-25 Thread Btsai
I went through the rest of my Project Euler code.  In addition to
even?, there are some functions in clojure.contrib that are also much
slower in 1.3 Alpha 1.

clojure.contrib.math -> expt

  (Clojure 1.2)
  user=> (time (doseq [x (range 10)] (expt x 2)))
  "Elapsed time: 119.417971 msecs"

  (Clojure 1.3)
  user=> (time (doseq [x (range 10)] (expt x 2)))
  "Elapsed time: 10314.24357 msecs"

clojure.contrib.math -> sqrt

  (Clojure 1.2)
  user=> (time (doseq [x (range 10)] (sqrt x)))
  "Elapsed time: 176.063438 msecs"

  (Clojure 1.3)
  user=> (time (doseq [x (range 10)] (sqrt x)))
  "Elapsed time: 16323.254492 msecs"

For now, I've switched to using sqrt in the
clojure.contrib.generic.math-functions module (no slow-down in 1.3).
That module also has a pow function, which I was going to use as a
replacement for expt.  But pow doesn't seem to handle very large
numbers:

user=> (pow 999 999)
Infinity

So for now I'm using this as a temporary stop-gap:

(defn expt [base pow]
  (reduce *' (repeat pow base)))

Also found that sequences from clojure.contrib.lazy-seqs that used to
produce arbitrarily large numbers in 1.2 no longer do so in 1.3:

  (Clojure 1.2)
  user=> (nth (fibs) 100)
  354224848179261915075
  user=> (nth (powers-of-2) 100)
  1267650600228229401496703205376

  (Clojure 1.3)
  user=> (nth (fibs) 100)
  ArithmeticException integer overflow
clojure.lang.Numbers.throwIntOverflow (Numbers.java:1575)
  user=> (nth (powers-of-2) 100)
  0

... probably also because of 1.3's changes to numeric operations
(http://dev.clojure.org/display/doc/Enhanced+Primitive+Support).

I guess the take-away is that while playing with 1.3, be prepared to
deal with performance and/or overflow issues when using existing
numeric code (whether your own or someone else's) that doesn't yet
take into account the changes to numeric operations.

-- 
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


Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-25 Thread Mark Engelberg
>> http://code.google.com/p/clojure/issues/detail?id=95

I just looked over this code.  You can speed it up even more by
manually encoding the loop, rather than using reduce.
(defn faster-max-key
  ([k x] x)
  ([k x &  more]
 (loop [x x,
kx (k x)
s more]
   (if-not s x
 (let [y (first s),
   ky (k y)]
   (if (> kx ky)
 (recur x kx (next s))
 (recur y ky (next s

5x faster than the one at the code.google.com link above in my own benchmarks.

-- 
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


Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-25 Thread Mark Engelberg
On Sat, Sep 25, 2010 at 7:02 PM, Btsai  wrote:
> I went through the rest of my Project Euler code.  In addition to
> even?, there are some functions in clojure.contrib that are also much
> slower in 1.3 Alpha 1.
>
> clojure.contrib.math -> expt
>
>  (Clojure 1.2)
>  user=> (time (doseq [x (range 10)] (expt x 2)))
>  "Elapsed time: 119.417971 msecs"
>
>  (Clojure 1.3)
>  user=> (time (doseq [x (range 10)] (expt x 2)))
>  "Elapsed time: 10314.24357 msecs"

Actually, I'd expect that expt would no longer be guaranteed to
produce the right results for large integers in 1.3.
The whole point of clojure.contrib.math is to extend math operations
to the full numeric tower supported by Clojure and 1.3 breaks that.

I haven't tried 1.3 yet, but I'd recommend downloading a copy of
clojure.contrib.math locally and replace any instances of +, -, *,
inc, dec with +', -', *', inc', dec'.  This should at least make the
functions produce the correct results.  I'd be curious to know whether
performance continues to be bad after making those changes, so if you
do this experiment, please report your results.

--Mark

-- 
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


Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-25 Thread Btsai
Awesome, thanks :)

On Sep 25, 8:44 pm, Mark Engelberg  wrote:
> >>http://code.google.com/p/clojure/issues/detail?id=95
>
> I just looked over this code.  You can speed it up even more by
> manually encoding the loop, rather than using reduce.
> (defn faster-max-key
>   ([k x] x)
>   ([k x &  more]
>      (loop [x x,
>             kx (k x)
>             s more]
>        (if-not s x
>          (let [y (first s),
>                ky (k y)]
>            (if (> kx ky)
>              (recur x kx (next s))
>              (recur y ky (next s
>
> 5x faster than the one at the code.google.com link above in my own benchmarks.

-- 
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


Re: Some code dramatically slower in Clojure 1.3 Alpha 1?

2010-09-25 Thread Btsai
> I haven't tried 1.3 yet, but I'd recommend downloading a copy of
> clojure.contrib.math locally and replace any instances of +, -, *,
> inc, dec with +', -', *', inc', dec'.  This should at least make the
> functions produce the correct results.  I'd be curious to know whether
> performance continues to be bad after making those changes, so if you
> do this experiment, please report your results.

I'd be happy to try this out.  Will report back later.

-- 
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


Re: Clojure for VS2010

2010-09-25 Thread eyeris
This sounds fantastic! Integrating the (doc) function with the F1 help
system in some way would be helpful.


On Sep 23, 3:20 pm, Will Kennedy  wrote:
> Some background: I've been spending some of my free time providing by
> basic Clojure support in VS 2010. To be honest, I'm a bit of a Clojure
> newbie, so I figured something that would require me to build a lexer
> and parser for the language and delve into the clojure source would be
> a great way to learn while creating something other people might find
> valuable. For adoption, having first-class support in VS for clojure-
> clr would be huge.
>
> I've built syntax highlighting, brace matching, and some basic
> formatting helpers. I'm working on the REPL window and project/build
> system next. My hope is to get it to the point where a user can
> download the plugin, create a new project, get some basic boilerplate,
> build, execute and debug all from within Visual Studio. People who are
> using emacs won't be abandoning it, but I hope it'll help people with
> a .Net background get going quickly.
>
> I'm looking for input about what features I should focus on and just
> general comments on the worthiness of the project. I figure I'm bound
> to make mistakes by approaching this from a C/C++/C# programmer's
> perspective, and this might preclude that.
>
> Thanks.

-- 
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