Re: Find reference type on classpath

2010-10-12 Thread Michael Wood
On 11 October 2010 22:39, Phil Hagelberg  wrote:
> On Mon, Oct 11, 2010 at 12:21 PM, Ivan Willig  wrote:
>> I often run into this issue where I am follow a Java documentation where
>> they developers fail to explain where they import packages from.  In most
>> Java IDE's you can search your classpath for reference types. It would be
>> great is if was possible to do the same in slime. I looked around the docs
>> but was unable to find and insights on how do to this.
>>
>> Does anyone have a way of searching for reference types from within
>> slime/emacs?
>
> You can use M-. over an identifier to jump to its definition. This is
> totally unrelated to reference types, but sort of sounds like what you
> want. Your question is a bit muddled, though.

I think what he's saying is that if he finds a chunk of code somewhere
(e.g. on a blog or a tutorial) it often doesn't have the imports
listed, so he has to figure out which imports are needed.  Java IDEs
have a way to dig through your classpath looking for classes used in
the code and generate or suggest import statements for you.

I'm sure I've seen something on this list about someone doing
something similar for Clojure.

Ivan, perhaps digging through the list archives will turn up something.

-- 
Michael Wood 

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


help with a sexp to function macro ...

2010-10-12 Thread Sunil S Nandihalli
Hello everybody,
 I would like some help in writing a macro which accepts the return value
from mathematica and create a function in clojure which can be called. I am
kind of inexperienced writing macros.. I will try to describe what I have
done (does not work ) and request you all to help me modify it to do what I
was expecting of it.

I have set up clojure and clojuratica properly.

the results of evaluation of sexps are appended to the sexp

(mathematica-eval "D[x*x+y*x,x]") =>  (+ (* 2 x) y)  ;sexp1

(math (Variables (+ (* 2 x)  y))  => [x y] ;sexp2

and I was expecting the evaluation of the following

(math (Variables (mathematica-eval "D[x*x+y*x,x]")))

to return [x y] .. but I guess I am making a mistake with handling the
symbols.. I would like you to help me to make this work.

Finally, when I get a sexp from mathematica I would like to create a
function whose body is the returned sexp with all the unbound variables as
the arguments to the function. The following was my first attempt at
achieving the goal. which does not work.

(defmacro sexp2fn [sexp]
 `(fn ~(math `(Varaibles ~sexp))
~sexp))

assuming the above macro were correct .. I would like the macro expantion of
the following

(sexp2fn (mathematica-eval "D[x*x+y*x,x]"))

to return

(fn [x y] (+ (* 2 x) y)

can anybody help me achieve this.
Thanks for reading.
Sunil.

-- 
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: Screencast of the Emacs front end to the Clojure Debugging Toolkit:

2010-10-12 Thread Walter van der Laan
You were right, it was a classpath problem. But since I'm new to
classpaths it took me some time to get it right.

Thanks again, emacs+cdt makes development a lot easier :D

And, in case anyone needs to solve the same problems, these are the
steps to get cdt running for a leiningen-based project:

Suppose the project-root is in /my-home/my-project

First set up the target vm like this:
1. Start a new emacs session
2. M-x shell
3. cd /my-home/my-project
4. java -
agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8021 -
client -cp /path/to/clojure-contrib.jar:/path/to/clojure.jar:src
clojure.main --repl
5. (use 'my-project.my-source)
The thing to note is the "src" that has been added to the classpath in
step 4

Next set up the debug vm like this:
1. Start a new emacs session
2. M-x cdt
3. port: 8021
4. (set-source-path (str @source-path "/my-home/my-project/src:"))
5. (set-bp my-project.my-source/my-function)

Now invoke the function in the target vm:
(my-function args)

On Oct 6, 3:16 am, George Jahad  wrote:
> hmmm, it's not really different from setting your classpath.
>
> From thecdt-repl, enter:
> @source-path
>
> and see if that gives you any hints.  if not, send me the output of
> that command, and the full path and namespace of one of your source
> files, I'll see if I can see anything you are missing.
>
> g
>
> On Oct 5, 6:40 am, Walter van der Laan 
> wrote:
>
>
>
> > Thanks George, this is great. I tried the screencast instructions and
> > it all works, but I can't get it to work with my own source. I tried
> > several settings for (set-source-path) but I must be doing something
> > wrong. Can you perhaps give an example?
>
> > On Oct 1, 10:32 pm, George Jahad  wrote:
>
> > > For your delectation:http://www.vimeo.com/15462015

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


Leiningen hangs after finished tasks

2010-10-12 Thread Benjamin Teuber
Hi,

I'm recently having problems where leiningen hangs for like 20
secondes after everything is done (I've added print statements to a
custom task, so I'm pretty sure nothing has to be done anymore). I'm
using Mac OS Snow Leopard, but a friend of mine is experiencing the
same with Ubuntu.

Did anyone experience a similar behaviour yet? I'll try to come up
with a minimal example project for the problem..

Cheers,
Benjamin

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


Clojars SSH key change?

2010-10-12 Thread Saul Hazledine
Hello,
  I just got the following error back from ssh/scp when copying
something back to clojars.org:

@@@
@   WARNING: POSSIBLE DNS SPOOFING DETECTED!  @
@@@
The RSA host key for clojars.org has changed,
and the key for the corresponding IP address 173.230.139.200
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.

I'm guessing the server has been moved/upgraded but I thought it best
to check since I couldn't see a notice of this anywhere.

Saul

-- 
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: New Release of the Clojure Debugging Toolkit

2010-10-12 Thread leo
This works for me under Windows 7. I set all forward slashes paths in
my .emacs file like this:

(progn
  (setq cdt-dir "c:/msysgit/cdt")
  (setq cdt-source-path "c:/clj/clojure-1.2.0/src/jvm;c:/clj/
clojure-1.2.0/src/clj;c:/clj/clojure-contrib-1.2.0/src/main/clojure/
clojure/contrib;")
  (load-file (format "%s/ide/emacs/cdt.el" cdt-dir)))

And these are the diffs from George's current windows version
(hopefully George will be able to make them available in a more
convenient way) - and note the "file:///" with 3 slashes under
Windows:
-
diff --git a/.gitignore b/.gitignore
diff --git a/README b/README
diff --git a/docs/cdt.muse b/docs/cdt.muse
diff --git a/docs/emacs-cdt.muse b/docs/emacs-cdt.muse
diff --git a/ide/emacs/cdt.el b/ide/emacs/cdt.el
index 0560ab2..42e3e1a 100644
--- a/ide/emacs/cdt.el
+++ b/ide/emacs/cdt.el
@@ -25,13 +25,13 @@
   (gud-call (format "(reval-display '%s)" (thing-at-point 'sexp

 (defun strip-trail (path)
-  (if (= (elt path (- (length path) 1)) ?\\)
+  (if (= (elt path (- (length path) 1)) ?/)
   (substring path 0 (- (length path) 1))
 path))

 (defun cdt-query-cmdline ()
   (let ((path (strip-trail cdt-dir)))
-(format "java -classpath%s\\lib\\clojure-1.2.0.jar;%s\\lib\
\clojure-contrib-1.2.0.jar;%s\\lib\\debug-
repl-0.3.0-20091229.021828-3.jar;%s\\src clojure.main --repl"
+(format "java -classpath%s/lib/clojure-1.2.0.jar;%s/lib/clojure-
contrib-1.2.0.jar;%s/lib/debug-repl-0.3.0-20091229.021828-3.jar;%s/src
clojure.main --repl"
path path path path)))

 (defun cdt (port)
diff --git a/project.clj b/project.clj
diff --git a/src/com/georgejahad/cdt.clj b/src/com/georgejahad/cdt.clj
index d479877..d2d570f 100644
--- a/src/com/georgejahad/cdt.clj
+++ b/src/com/georgejahad/cdt.clj
@@ -21,10 +21,11 @@
 ;; add-classpath is ugly, but handles the fact that tools.jar and
 ;; sa-jdi.jar are platform dependencies that I can't easily put in a
 ;; repo:
-(with-out-str (add-classpath (format "file://%s/../lib/tools.jar"
+(with-out-str (add-classpath (format "file:///%s/../lib/tools.jar"
  (System/getProperty
"java.home"
-(with-out-str (add-classpath (format "file://%s/../lib/sa-jdi.jar"
+(with-out-str (add-classpath (format "file:///%s/../lib/sa-jdi.jar"
  (System/getProperty
"java.home"
+
 (import com.sun.jdi.Bootstrap
 com.sun.jdi.request.EventRequest
 com.sun.jdi.event.BreakpointEvent
@@ -90,7 +91,7 @@
 (defonce source-path (atom ""))

 (defn remove-trailing-slashes [s]
-  (str/replace s "\\;" ";"))
+  (str/replace s "/:" ":"))

 (defn set-source-path [path]
   (reset! source-path (remove-trailing-slashes path)))
@@ -98,10 +99,10 @@
 (defn get-source []
   (let [file (.sourcePath (.location (.frame (ct) (cf
 paths (.split @source-path ";")]
-(if (= (first file) \\)
+(if (= (first file) \/)
   file
   (first (filter #(.exists (java.io.File. %))
- (for [p paths] (str p "\\" file)))
+ (for [p paths] (str p "/" file)))

 (defmacro check-unexpected-exception [& body]
   `(try
@@ -325,11 +326,11 @@
 (re-pattern (str s "\\$"

 (defn fix-class [c]
-  (str/replace c "/" "."))
+  (str/replace c "\\" "."))

 (defn get-class* [fname]
   (->> (.split @source-path ";")
-   (map #(re-find (re-pattern (str % "\\(.*)(.clj|.java)"))
fname))
+   (map #(re-find (re-pattern (str % "/(.*)(.clj|.java)"))
fname))
(remove nil?)
first
second
@@ -426,7 +427,7 @@
 (defn get-file-name [frame]
   (let [sp (try (.sourcePath (.location frame))
 (catch Exception e "source not found"))]
-(last  (.split sp "\\"
+(last  (.split sp "/"

 (defn clojure-frame? [frame fields]
   (let [names (map #(.name %) fields)]

On Oct 11, 6:48 pm, atreyu  wrote:
> Hi folks and congrats to George Jahad for this great work.
> Hoewer the cdt dont work on my windows vista. After some changes on my
> own i get the same error of Greg Willams:
>
> java.lang.ClassNotFoundException: com.sun.jdi.Bootstrap (cdt.clj:28)
>
> i've tried add-classpath of tool.jar (where is the class in my jdk)
> with various formats,
> after testing the urls in browser with success but i get the
> ClassNotFound all the time
>
> Current directory is c:/Users/atreyu/AppData/Roaming/.emacs.d/
> Clojure 1.2.0
> user=> java.lang.ClassNotFoundException: com.sun.jdi.Bootstrap
> (cdt.clj:28)
> user=> java.lang.Exception: Unable to resolve symbol: set-source-path
> in this context (NO_SOURCE_FILE:2)
> user=> java.lang.Exception: Unable to resolve symbol: cdt-attach in
> this context (NO_SOURCE_FILE:3)
> user=> (def file-url (format "file://%s/../lib/tools.jar"
>                                      (System/getProperty
> "java.home")))
> #'user/file-url
> user=> file-url
> "file://c:\\Program Files\\Java\\jdk1.6.0_21\\jre/../lib/tools.jar"
> user=> (def file-path "c:\\Program Files\\Java\\jdk1.6.0_21\\jre/.

Re: Problems with clojure couchdb

2010-10-12 Thread Moritz Ulrich
I would also recommend using batch-write for this. It's *much* faster.

Regarding your error: Maybe you open too many sockets which don't get
closed and your process runs out of file descriptors.

On Tue, Oct 12, 2010 at 7:13 AM, David Nolen  wrote:
> On Tue, Oct 12, 2010 at 12:45 AM, Mark Engelberg 
> wrote:
>>
>> I'm playing around with couchdb.  I'm using the version that lein gets
>> with the following command:
>>  [clojure-couchdb "0.4.4"]
>> which as far as I can tell is the most recently maintained version.
>>
>> When I do a bunch of rapid calls to document-create in a tight loop,
>> after about 3000 or so documents have been created, I get the error
>> listed below.  Any idea how to resolve this?  Is there a different
>> version of the clojure-couchdb library that doesn't exhibit this
>> problem?
>>
>> Thanks,
>>
>> Mark
>>
>> Address already in use: connect
>>  [Thrown class java.net.BindException]
>
> You might want to look at the end of this thread:
> http://groups.google.com/group/aleph-lib/browse_thread/thread/d0feb5d784f05682/b81fd22a35bed316
> Also in my experiencing batching writes with CouchDB is a big performance
> gain.
> 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



-- 
Moritz Ulrich
Programmer, Student, Almost normal Guy

http://www.google.com/profiles/ulrich.moritz
BB5F086F-C798-41D5-B742-494C1E9677E8

-- 
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: Test-driven development in Clojure

2010-10-12 Thread Kyle R. Burton
>> For another point of view: take a look at what Brian Marick's been
>> doing with a framework called Midje to do outside-in TDD. It helps you
>> mock out function dependencies and might get you where you want to go.
>> It's just maturing now but I found his blog posts illuminating.
>
> I'll be doing a talk on this at Strange Loop, and would also be happy to show 
> people at clojure-conj.

Brian,

Does Midje integration with the usual test lifecycle for maven and Leiningen?

Thanks,

Kyle

-- 
Twitter: @kyleburton
Blog: http://asymmetrical-view.com/
Fun: http://snapclean.me/

-- 
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: strange bug in range or lazy-seq?

2010-10-12 Thread babui
On 12 oct, 03:56, Stuart Halloway  wrote:

I've tried your definition

> (def primes
>   (concat
>    [2]
>    (let [primes-from
>          (fn primes-from
>            [n]
>            (if (some #(zero? (rem n %))
>                      (take-while #(<= (* % %) n) primes))
>              (recur (+ n 2))
>              (lazy-seq (cons n (primes-from (+ n 2))]
>      (primes-from 2

using clojure 1.2 and I've got:

user=> java.lang.IllegalStateException: Var user/primes is unbound.
(NO_SOURCE_FILE:27)

Any idea of what is going on?

Thanks.

JM

-- 
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: strange bug in range or lazy-seq?

2010-10-12 Thread Jason Wolfe


On Oct 11, 6:56 pm, Stuart Halloway  wrote:
> When a var's definition has a "lazy reference" to itself, as primes does 
> below, then your results will be dependent on the lazy/chunky/strict-ness of 
> the calls leading to the lazy reference.

While I agree that this sort of reference is probably rare in non-
Euler problems, at best this behavior seems very confusing. Everywhere
else in Clojure (that I know of) seqs are immutable, so it is strange
to observe them changing out from under you here.  Perhaps it could be
an error to try to get the next of a lazy seq from within the
computation of that next, rather than just getting nil?

In fact, I can force a potentially more severe bug by modifying the
example slightly, making nums finite and computing the hash of
"primes" within the let:

(def nums (drop 2 (range 100)))
(def primes (cons (first nums)
  (lazy-seq (->>
(rest nums)
(remove
  (fn [x]
(let [dividors (take-while #(<= (* % %) x)
primes)]
  (hash primes)
  (some #(= 0 (rem x %)) dividors

Now, I can get Clojure to compute and cache an incorrect hash for
primes:

user> (take 5 primes)
(2 3 5 7 9)
user> (hash primes)
33
user> primes
(2 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 37 41 43 47 53 59 61 67 71
73 79 83 89 97)
user> (hash (vec primes))
-2057877582
user> (contains? #{primes} (vec primes))
false

-Jason

-- 
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: Clojars SSH key change?

2010-10-12 Thread Phil Hagelberg
On Tue, Oct 12, 2010 at 5:43 AM, Saul Hazledine  wrote:
> I'm guessing the server has been moved/upgraded but I thought it best
> to check since I couldn't see a notice of this anywhere.

This is correct; Clojars is now hosted on a new machine. Along with
the change of hardware comes the ability for more people to help out
with the maintenance of the site, so downtime and admin issues should
be dealt with more quickly now.

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


precise numbers

2010-10-12 Thread cej38
I keep running into this type of problem:

user=> (- 12.305 12.3049)
9.9976694E-5

The computer (probably the JVM) has just lied to me.  Any fourth grade
student will know that this does not equal 0.0001.  This would be less
of a problem is the JVM was consistent; if it were consistent then the
following equality would be true:

user=> (= 0.0001 (- 12.305 12.3049))
false

Now it has lied to me again!

I need a method to reliably compare two numbers.  My first choice
would be to have the JVM compute (- 12.305 12.3049) correctly.
Barring that, I need a way to, without fail, compute the truthfulness
of the following: =, <, >, <=, >=.

-- 
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: precise numbers

2010-10-12 Thread Felix H. Dahlke
You could use BigInteger, which was created to work around double's
rounding issues - among other things.

(- 12.305M 12.3049M)
0.0001M

On 12/10/10 18:17, cej38 wrote:
> I keep running into this type of problem:
> 
> user=> (- 12.305 12.3049)
> 9.9976694E-5
> 
> The computer (probably the JVM) has just lied to me.  Any fourth grade
> student will know that this does not equal 0.0001.  This would be less
> of a problem is the JVM was consistent; if it were consistent then the
> following equality would be true:
> 
> user=> (= 0.0001 (- 12.305 12.3049))
> false
> 
> Now it has lied to me again!
> 
> I need a method to reliably compare two numbers.  My first choice
> would be to have the JVM compute (- 12.305 12.3049) correctly.
> Barring that, I need a way to, without fail, compute the truthfulness
> of the following: =, <, >, <=, >=.
> 




signature.asc
Description: OpenPGP digital signature


Re: precise numbers

2010-10-12 Thread David Nolen
On Tue, Oct 12, 2010 at 12:17 PM, cej38  wrote:

> I keep running into this type of problem:
>
> user=> (- 12.305 12.3049)
> 9.9976694E-5


http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

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

Re: precise numbers

2010-10-12 Thread Alan
The JVM has no choice: it must faithfully implement the IEEE floating-
point spec (http://en.wikipedia.org/wiki/IEEE_754-2008), which
specifies limited precision. By asking it to use floats, you are
demanding that it accept rounding errors. If you want precision, there
are lots of ways to get it; the most common is to cast everything up
to integers and perform the computation there, then convert back down
later:

user=> (def numbers [12.305 12.3049])
#'user/numbers
user=> (/ (apply - (map #(int (* 1 %)) numbers)) 1)
1/1

Or you can tell Java to use BigDecimals, which have arbitrary
precision:
user=> (- 12.305M 12.3049M)
0.0001M

You could use clojure's excellent ratio type instead:
user=> (def nums (map #(/ % 1) [123050 123049]))
#'user/nums
user=> nums
(2461/200 123049/1)
user=> (apply - nums)
1/1

Computers don't lie; they just do what you tell them to.

On Oct 12, 9:17 am, cej38  wrote:
> I keep running into this type of problem:
>
> user=> (- 12.305 12.3049)
> 9.9976694E-5
>
> The computer (probably the JVM) has just lied to me.  Any fourth grade
> student will know that this does not equal 0.0001.  This would be less
> of a problem is the JVM was consistent; if it were consistent then the
> following equality would be true:
>
> user=> (= 0.0001 (- 12.305 12.3049))
> false
>
> Now it has lied to me again!
>
> I need a method to reliably compare two numbers.  My first choice
> would be to have the JVM compute (- 12.305 12.3049) correctly.
> Barring that, I need a way to, without fail, compute the truthfulness
> of the following: =, <, >, <=, >=.

-- 
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: strange bug in range or lazy-seq?

2010-10-12 Thread SpiderPig
Thank you all for explaining this to me but I still don't understand
clojures behavior in this case,

Try running this code:

(def nums (drop 2 (range)))
(def primes (cons (first nums)
  (lazy-seq (->>
(rest nums)
(remove
  (fn [x]
(let [dividors (take-while #(<= (* % %) x)
primes)]
  (println (str "primes = " primes))
  (some #(= 0 (rem x %)) dividors
(take 5 primes)

It prints out:
(primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
2 3 5 7 9)

How can (println primes) ever print out (2) ? That means that primes
must have length 1 and that should be impossible no matter how chunked
it is. It's hard to believe that that is intended behavior.
I don't insist that a recursive lazy definition needs to work. It
could also throw an error. But simply giving incorrect and
unpredictable results can't be a good solution in my opinion.

-- 
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: precise numbers

2010-10-12 Thread David Sletten
This discussion may help:
http://www.gettingclojure.com/cookbook:numbers#comparing-floats

Have all good days,
David Sletten

On Oct 12, 2010, at 12:17 PM, cej38 wrote:

> I keep running into this type of problem:
> 
> user=> (- 12.305 12.3049)
> 9.9976694E-5
> 
> The computer (probably the JVM) has just lied to me.  Any fourth grade
> student will know that this does not equal 0.0001.  This would be less
> of a problem is the JVM was consistent; if it were consistent then the
> following equality would be true:
> 
> user=> (= 0.0001 (- 12.305 12.3049))
> false
> 
> Now it has lied to me again!
> 
> I need a method to reliably compare two numbers.  My first choice
> would be to have the JVM compute (- 12.305 12.3049) correctly.
> Barring that, I need a way to, without fail, compute the truthfulness
> of the following: =, <, >, <=, >=.
> 
> -- 
> 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: Test-driven development in Clojure

2010-10-12 Thread Stuart Sierra
Datatypes that implement a single method can be more simply
represented as ordinary functions, e.g.

(defn real-provider ...)
(defn fake-provider ...)

(defn load-page [provider ...]
  (let [foo (provider)]
  ...))

That being said, you have other options: In clojure.test you can using
`binding` to stub out functions within your tests. Lazytest  has explicit support for stubbing
out functions during testing.

-S


On Oct 11, 6:06 pm, "Felix H. Dahlke"  wrote:
> Hi,
>
> I'm new to Clojure, using it for a reasonably sized project for the
> first time, and I'm trying to do test-driven development.
>
> While it does work well technically  - clojure.test is very nice to use
> and feels a lot like JUnit 4's assertThat() - I'm wondering if I'm
> trying to program Java in Clojure.
>
> Here's an example:
>
> I'm writing a class (Um. I mean, a ... namespace? Well, a horde of
> functions.) that accesses web pages from a backend, which can e.g. take
> these from the filesystem or from a database. In Java or C++, I'd use an
> interface for that and create one implementation for the filesystem and
> one for the database:
>
> interface Provider {
>     String loadPage(String name);
>
> }
>
> This is possible in Clojure:
>
> (defprotocol Provider
>   (load-page [this name])
>
> It can be implemented using deftype:
>
> (deftype DatabaseProvider []
>   Provider
>   (load-page [this name]
>     (have-fun-with-the-database)))
>
> And I can call it like this:
>
> (load-page (DatabaseProvider.) "foo")
>
> Feels a little weird (especially since all examples of defprotocol and
> deftype use camel case for type names), but works.
>
> Back to my question: Am I trying to do Java in Clojure? Is there a more
> Lisp-y way to do this?
>
> As you may have suspected, this design wasn't my initial intention, it
> was driven by TDD: This allows me to create a mock implementation
> against which I can write my test cases without having having to depend
> on external resources. Typical TDD design. In fact, there will only be
> one backend for now.
>
> This made me wonder if test-driven development was desirable in Clojure
> at all, or even in functional programming in general.
>
> There's a few articles on the issue. Many seem to be from Clojure
> newcomers, asking questions themselves, and none handles design issues
> like mock objects [1].
>
> One guy basically said that he stopped doing TDD because the REPL makes
> it possible to test specific functions directly [2]. I can see how he
> says that the *driven* aspect of TDD can be performed by the REPL, but I
> find it too inconvenient for extensive use.
>
> Bob Martin says that, because functional programming differs from
> object-oriented programming (In my opinion, these paradigms are
> compatible - did he mean imperative programming?), test-driven
> development has to start by testing the details, and work up to testing
> the big picture. TDD in e.g. Java starts with the big picture and moves
> down. I don't understand his points completely, but if he's right, this
> might be a fundamental problem for TDD in functional languages.
>
> One guy partly disagrees with him on some matters, but doesn't really
> mention the bottom-up thing [4].
>
> What are your thoughts on these issues? Is anybody here doing TDD in
> Clojure? Is anybody against it?
>
> [1]:http://www.magpiebrain.com/2010/02/16/struggling-with-test-driven-clo...
> [2]:http://s-expressions.com/2009/07/28/clojure-the-repl-and-test-driven-...
> [3]:http://blog.objectmentor.com/articles/2010/06/03/tdd-in-clojure
> [4]:http://ericlefevre.net/wordpress/2010/06/04/bob-martin-on-tdd-in-cloj...
>
>  signature.asc
> < 1KViewDownload

-- 
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: precise numbers

2010-10-12 Thread Alan
Also see (rationalize) to simplify my example of using ratios. I
couldn't remember the name of the function off the top of my head, so
I used a hacked-up-by-me version.

On Oct 12, 9:33 am, Alan  wrote:
> The JVM has no choice: it must faithfully implement the IEEE floating-
> point spec (http://en.wikipedia.org/wiki/IEEE_754-2008), which
> specifies limited precision. By asking it to use floats, you are
> demanding that it accept rounding errors. If you want precision, there
> are lots of ways to get it; the most common is to cast everything up
> to integers and perform the computation there, then convert back down
> later:
>
> user=> (def numbers [12.305 12.3049])
> #'user/numbers
> user=> (/ (apply - (map #(int (* 1 %)) numbers)) 1)
> 1/1
>
> Or you can tell Java to use BigDecimals, which have arbitrary
> precision:
> user=> (- 12.305M 12.3049M)
> 0.0001M
>
> You could use clojure's excellent ratio type instead:
> user=> (def nums (map #(/ % 1) [123050 123049]))
> #'user/nums
> user=> nums
> (2461/200 123049/1)
> user=> (apply - nums)
> 1/1
>
> Computers don't lie; they just do what you tell them to.
>
> On Oct 12, 9:17 am, cej38  wrote:
>
> > I keep running into this type of problem:
>
> > user=> (- 12.305 12.3049)
> > 9.9976694E-5
>
> > The computer (probably the JVM) has just lied to me.  Any fourth grade
> > student will know that this does not equal 0.0001.  This would be less
> > of a problem is the JVM was consistent; if it were consistent then the
> > following equality would be true:
>
> > user=> (= 0.0001 (- 12.305 12.3049))
> > false
>
> > Now it has lied to me again!
>
> > I need a method to reliably compare two numbers.  My first choice
> > would be to have the JVM compute (- 12.305 12.3049) correctly.
> > Barring that, I need a way to, without fail, compute the truthfulness
> > of the following: =, <, >, <=, >=.
>
>

-- 
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: strange bug in range or lazy-seq?

2010-10-12 Thread Stuart Halloway
Sorry, that should have been

(def primes
 (concat
  [2]
  (lazy-seq
   (let [primes-from
 (fn primes-from
   [n]
   (if (some #(zero? (rem n %))
 (take-while #(<= (* % %) n) primes))
 (recur (+ n 2))
 (lazy-seq (cons n (primes-from (+ n 2))]
 (primes-from 3)

Stu

> On 12 oct, 03:56, Stuart Halloway  wrote:
> 
> I've tried your definition
> 
>> (def primes
>>   (concat
>>[2]
>>(let [primes-from
>>  (fn primes-from
>>[n]
>>(if (some #(zero? (rem n %))
>>  (take-while #(<= (* % %) n) primes))
>>  (recur (+ n 2))
>>  (lazy-seq (cons n (primes-from (+ n 2))]
>>  (primes-from 2
> 
> using clojure 1.2 and I've got:
> 
> user=> java.lang.IllegalStateException: Var user/primes is unbound.
> (NO_SOURCE_FILE:27)
> 
> Any idea of what is going on?
> 
> Thanks.
> 
> JM
> 
> -- 
> 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: Test-driven development in Clojure

2010-10-12 Thread Brian Marick

On Oct 12, 2010, at 8:59 AM, Kyle R. Burton wrote:
> 
> Does Midje integration with the usual test lifecycle for maven and Leiningen?

If you type 'lein test', it'll run the Midje tests, but it doesn't hook into 
the reporting system (so you get 0 tests run, 0 failures reported). I want to 
see if I can live on top of lazytest's reporting.

If you want normal reporting, you can wrap Midje "facts" in deftest:

(deftest numerical-reverser-tests
  (fact
(numerical-reverser 103) => 301
(provided 
  (string-reverser "103") => "301")))

I do that in Midje's tests for itself. 

-
Brian Marick, independent consultant
Mostly on agile methods with a testing slant
Author of /Programming Cocoa with Ruby/
www.exampler.com, www.exampler.com/blog, www.twitter.com/marick

-- 
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: Test-driven development in Clojure

2010-10-12 Thread Felix H. Dahlke
The posts and Midje looks pretty interesting, but I'm not sure if I was
able to follow, being new to Clojure. I'll give it another try later :)

Meanwhile, I've adjourned TDD in my project and wrote some code without
it to see if it makes more sense to me that way. I have to say that,
although I dismissed the REPL earlier, I've used it heavily after
discovering JLine.

I basically had both Jetty (with hot deployment) and a REPL constantly
running. I ended up testing most of my changes by directly calling the
function I was working on in the REPL, only occasionally refreshing the
browser to see if everything was still working. It worked pretty well
for development, but I somehow miss the cosy feeling of confidence
created by TDD. I also noticed that I don't think about design and
refactor as much as I did with TDD in Java.

Will your talk be recorded? I'd be interested.

On 12/10/10 05:42, Brian Marick wrote:
> 
> On Oct 11, 2010, at 8:53 PM, John Stoneham wrote:
>> For another point of view: take a look at what Brian Marick's been
>> doing with a framework called Midje to do outside-in TDD. It helps you
>> mock out function dependencies and might get you where you want to go.
>> It's just maturing now but I found his blog posts illuminating.
> 
> I'll be doing a talk on this at Strange Loop, and would also be happy to show 
> people at clojure-conj.
> 
> -
> Brian Marick, independent consultant
> Mostly on agile methods with a testing slant
> Author of /Programming Cocoa with Ruby/
> www.exampler.com, www.exampler.com/blog, www.twitter.com/marick
> 




signature.asc
Description: OpenPGP digital signature


Re: precise numbers

2010-10-12 Thread Felix H. Dahlke
Um, I meant BigDecimal, not BigInteger.

On 12/10/10 18:24, Felix H. Dahlke wrote:
> You could use BigInteger, which was created to work around double's
> rounding issues - among other things.
> 
> (- 12.305M 12.3049M)
> 0.0001M
> 
> On 12/10/10 18:17, cej38 wrote:
>> I keep running into this type of problem:
>>
>> user=> (- 12.305 12.3049)
>> 9.9976694E-5
>>
>> The computer (probably the JVM) has just lied to me.  Any fourth grade
>> student will know that this does not equal 0.0001.  This would be less
>> of a problem is the JVM was consistent; if it were consistent then the
>> following equality would be true:
>>
>> user=> (= 0.0001 (- 12.305 12.3049))
>> false
>>
>> Now it has lied to me again!
>>
>> I need a method to reliably compare two numbers.  My first choice
>> would be to have the JVM compute (- 12.305 12.3049) correctly.
>> Barring that, I need a way to, without fail, compute the truthfulness
>> of the following: =, <, >, <=, >=.
>>
> 
> 




signature.asc
Description: OpenPGP digital signature


Re: precise numbers

2010-10-12 Thread ataggart
Welcome to floating point math.

As an alternative, try using arbitrary-precision numerics:
user=> (- 12.305M 12.3049M)
0.0001M
user=> (type *1)
java.math.BigDecimal



On Oct 12, 9:17 am, cej38  wrote:
> I keep running into this type of problem:
>
> user=> (- 12.305 12.3049)
> 9.9976694E-5
>
> The computer (probably the JVM) has just lied to me.  Any fourth grade
> student will know that this does not equal 0.0001.  This would be less
> of a problem is the JVM was consistent; if it were consistent then the
> following equality would be true:
>
> user=> (= 0.0001 (- 12.305 12.3049))
> false
>
> Now it has lied to me again!
>
> I need a method to reliably compare two numbers.  My first choice
> would be to have the JVM compute (- 12.305 12.3049) correctly.
> Barring that, I need a way to, without fail, compute the truthfulness
> of the following: =, <, >, <=, >=.

-- 
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: precise numbers

2010-10-12 Thread Nicolas Oury
If you want to be really precise, most real numbers are an infinite
number of decimals.
If you encode them as a lazy seq of decimals, + - and other ops are doable.

Comparison is semi-decidable only: it terminates only in certain case
(finite number of decimals)
or when the number are different.

big-decimal or fractions are a good approximation, though.

-- 
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: precise numbers

2010-10-12 Thread cej38
On Oct 12, 12:50 pm, David Sletten  wrote:
> This discussion may 
> help:http://www.gettingclojure.com/cookbook:numbers#comparing-floats

I originally tried something like float= described in the link, I give
the definition here

(defn float=
  ([x y] (float= x y 0.1))
  ([x y epsilon]
 (let [scale (if (or (zero? x) (zero? y)) 1 (Math/abs x))]
   (<= (Math/abs (- x y)) (* scale epsilon )

And the truth-table that was given with the function definition:

(float= 0.01 0.0) => false
(float= 0.001 0.0) => false
(float= 0.0001 0.0) => false
(float= 0.1 0.0) => true


And this works for the problem that I discussed before
user=> (float= 0.0001 (- 12.305 12.3049))
true


But I can come up with a use case where it fails:

user=> (float= 12.3049 12.305)
true


The problem is that the IEEE specification does a great job of
comparing floats, but does a crap job of doing simple math on them.


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


Help to optimize palindrome search from input file

2010-10-12 Thread tonyl
Hi, I just started to learn clojure in a more serious way and I am
doing the first level of the greplin challenge.

I made it to work with a short palindrome like the example they give
me, but when it comes to work with the input file, it takes for ever
and I have to stop it.

$ time clj level1.clj
^C
real11m35.477s
user1m44.431s
sys 9m3.878s

This is my code:

(defn palindrome? [s]
  (= s (reduce str (reverse s

(defn all-combs [in]
  (let [len (count in)]
(for [i (range 0 (- len 2)), j (range (+ i 1) len)]
  (subs in i j

(defn max-comp [x y]
  (let [lenx (count x), leny (count y)]
(cond (< lenx leny) 1
  (= lenx leny) 0
  (> lenx leny) -1)))

;;(let [input "I like racecars that go fast"]
(let [input (slurp "../_input/level1.in")]
(println (nth (sort max-comp (filter palindrome? (all-combs
input))) 0)))

The input file is this http://challenge.greplin.com/static/gettysburg.txt

It looks a bit procedural. It is long, but I don't think is the
biggest bottleneck, I think it is my approach to create all the
combinations possible for substrings. Maybe I should be using a lazy
seq? How would I go to do that?

-- 
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: precise numbers

2010-10-12 Thread Luka Stojanovic

On Tue, 12 Oct 2010 20:53:16 +0200, cej38  wrote:


On Oct 12, 12:50 pm, David Sletten  wrote:
This discussion may  
help:http://www.gettingclojure.com/cookbook:numbers#comparing-floats


I originally tried something like float= described in the link, I give
the definition here

(defn float=
  ([x y] (float= x y 0.1))
  ([x y epsilon]
 (let [scale (if (or (zero? x) (zero? y)) 1 (Math/abs x))]
   (<= (Math/abs (- x y)) (* scale epsilon )

And the truth-table that was given with the function definition:

(float= 0.01 0.0) => false
(float= 0.001 0.0) => false
(float= 0.0001 0.0) => false
(float= 0.1 0.0) => true


And this works for the problem that I discussed before
user=> (float= 0.0001 (- 12.305 12.3049))
true


But I can come up with a use case where it fails:

user=> (float= 12.3049 12.305)
true


The problem is that the IEEE specification does a great job of
comparing floats, but does a crap job of doing simple math on them.




and again it does exactly what it promises to do:

epsilon is maybe wrong-named here because it is not absolute value, but  
amount of significant figures. it is multiplied by x to get precision. so  
what you are asking is


|12.3049 - 12.305| <= 12.3049 * 0.1 which holds true

--
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: precise numbers

2010-10-12 Thread Angel Java Lopez
Short comment:

I remember Common Lisp has rational numbers (I'm not sure). Any rational
number library for Clojure?

Angel "Java" Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez


On Tue, Oct 12, 2010 at 4:14 PM, Luka Stojanovic  wrote:

> On Tue, 12 Oct 2010 20:53:16 +0200, cej38  wrote:
>
>

-- 
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: precise numbers

2010-10-12 Thread cej38
The more that I think about it, the more I would rather have a set of
equalities that always work.  float= was a good try.

-- 
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: precise numbers

2010-10-12 Thread David Sletten
I suggest you read the article a bit more closely. Here are the details of your 
specific case.

The number that you are typing as 12.305 is actually being stored in the 
computer as this:
1100.010011110100001011110100001011100

This number is actually this fraction:
1731774794212311/140737488355328

So here is the true value in decimal:
12.304715782905695959

It is not possible to represent 12.305 any closer than that on conventional 
hardware.

Likewise your 12.3049 is this:
1100.01001110110011010010100010001100111001110

Which is this fraction:
3463521440926951/281474976710656

Or in decimal:
12.304848840923025272

This is the best approximation for 12.3049.

When you scale epsilon (0.1) by about 12, you can see that these two 
numbers are "equal" as expected in the sense defined by float=.

Have all good days,
David Sletten

On Oct 12, 2010, at 2:53 PM, cej38 wrote:

> On Oct 12, 12:50 pm, David Sletten  wrote:
>> This discussion may 
>> help:http://www.gettingclojure.com/cookbook:numbers#comparing-floats
> 
> I originally tried something like float= described in the link, I give
> the definition here
> 
> (defn float=
>  ([x y] (float= x y 0.1))
>  ([x y epsilon]
> (let [scale (if (or (zero? x) (zero? y)) 1 (Math/abs x))]
>   (<= (Math/abs (- x y)) (* scale epsilon )
> 
> And the truth-table that was given with the function definition:
> 
> (float= 0.01 0.0) => false
> (float= 0.001 0.0) => false
> (float= 0.0001 0.0) => false
> (float= 0.1 0.0) => true
> 
> 
> And this works for the problem that I discussed before
> user=> (float= 0.0001 (- 12.305 12.3049))
> true
> 
> 
> But I can come up with a use case where it fails:
> 
> user=> (float= 12.3049 12.305)
> true
> 
> 
> The problem is that the IEEE specification does a great job of
> comparing floats, but does a crap job of doing simple math on them.
> 
> 
> -- 
> 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: Help to optimize palindrome search from input file

2010-10-12 Thread Sean Grove
I actually played with this on Saturday morning while waiting for a friend, and 
thought it was an interesting problem.

Your example is spending most of its time filtering with palindrome? across all 
682695 items generated by all-combs. To see, try:

(defn tony []
  (def source "I like racecars that go fast!")

  (def source2 
"FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth")

  (defn palindrome? [s]
(= s (reduce str (reverse s

  (defn all-combs [in]
(let [len (count in)]
  (for [i (range 0 (- len 2)), j (range (+ i 1) len)]
(do 
(subs in i j)

  (defn max-comp [x y]
(let [lenx (count x), leny (count y)]
  (cond (< lenx leny) 1
(= lenx leny) 0
(> lenx leny) -1)))

  (let [input source
ac1 (all-combs input)
ac2 (all-combs source2)
palindromes-1 (filter palindrome? ac1)
palindromes-2 (filter palindrome? ac2)]
(println "all-combs(input1):")
(time (println (count (all-combs input
(println "all-combs(input2):")
(time (println (count (all-combs source2
(println "Filter(input1):")
(time (println (count (filter palindrome? ac1
(println "Filter(input2):")
(time (println (count (filter palindrome? ac2
(println palindromes-1)
(println palindromes-2)))

(tony)


> It looks a bit procedural.
Looks pretty functional to me :)

Just as a comparison, my solution takes this long, and I highly doubt its 
efficiency:
$ time ./launch.sh 1.clj 
***output removed***
real1m19.176s
user1m13.830s
sys 0m1.636s


-- 
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: precise numbers

2010-10-12 Thread Mike Meyer
On Tue, 12 Oct 2010 12:35:24 -0700 (PDT)
cej38  wrote:

> The more that I think about it, the more I would rather have a set of
> equalities that always work.  float= was a good try.

Then you can't use floats.

As others have explained, floats are imprecise by nature, being
limited to finite binary fractions. To make matters worse, you don't
input the numbers in binary, but in decimal, which means most of the
fractions you can input can't be represented as a float - so you get
an approximation. Given that the numbers are "fuzzy", the concept of
equality also becomes "fuzzy" - whether two numbers are equal will
depend on the context. So you have to choose the equality that's
appropriate for the context.

If you want precise numbers, Clojure has three options:

1) If you can represent everything as integers, then BigInteger is
probably the easiest to use, with the obvious drawback that it can't
handle fractional values, nor can it represent as large a value as a
float since you run out of memory. Letting units represent 1/1000's:

user> (- 123050 123049)
1


2) If you're going to stay in the world of decimal fractions, use
BigDecimal. This has some of the problems of floats, but between
allowing arbitrary precision and the input representation matching the
internal representation, they're not nearly as obnoxious.

user> (- 12.305M 12.3049M)
0.0001M


3) Clojure's rationals let you represent all rational values, until
you run out of memory. If you want a decimal approximation after the
calculation is done, that's easy to get as well:

user> (- 12305/1000 123049/1)
1/1
user> (float (- 12305/1000 123049/1))
1.0E-4

 http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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: Test-driven development in Clojure

2010-10-12 Thread Armando Blancas
> Back to my question: Am I trying to do Java in Clojure? Is there a more
> Lisp-y way to do this?

You can hide the types so your client code is more lispy:
(defn load-page [prov] (.loadPage prov))
;;test
(def mp (make-mock-provider)) ... (load-page mp)
;;production
(def prov (make-provider)) ... (load-page prov)

Depending on your app the provider could be a singleton and need not
be passed to each function. Another option is multimethods, in which
case you'd be using mock functions with an argument that would
indicate which version to dispatch to.

As for the repl, I think it works just as well for bottom-up and top-
down development. I use it for both all the time and to avoid throw-
away tests I write them top-down, black-box for only what's visible to
client/interop code first, then move down the layers as the code is
more mature and stable. I'm not really into TDD but I depend on a test
suite as complete as I can get it.

-- 
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: Help to optimize palindrome search from input file

2010-10-12 Thread tonyl
So for returns a lazy-seq of the combinations and I am forcing it to
process the values by filtering.
mmm...
I still tried your approach and nothing changed in processing time.
I changed the for form to filter as it is pairing the combinations, I
didn't think it would make any difference since I just moved the
filtering to another position, but I still tried:

(defn all-pals [in]
  (let [len (count in)]
(for [i (range 0 (dec (dec len))), j (range (inc i) len) :when
(palindrome? (subs in i j))]
  (do (subs in i j)

it didn't work with the long input.
So how can I filter without processing the values, quite a
contradiction.

-- 
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: error on a project using clj-processing

2010-10-12 Thread Vilson Vieira
2010/10/12 Stephen C. Gilardi 

> That may be related to having compiled code from different versions of
> Clojure trying to mix.  Do you know what the deps of rosado.processing are?
> It may help to use clojure and contrib 1.2.0 rather than snapshots.
>

Thanks Steve. I've pushed a new rosado.processing jar on [1] solving the
problem.

Cheers.

[1] http://clojars.org/org.clojars.automata/rosado.processing

-- 
Vilson Vieira

vil...@void.cc

((( http://automata.cc )))

((( http://musa.cc )))

-- 
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: Help to optimize palindrome search from input file

2010-10-12 Thread Justin Kramer
The 'palindrome?' function can be made much faster. Your version --
which is idiomatic and fine when perf isn't a factor -- turns the test
string into a sequence, reverses it, turns it back into a string, then
checks for full equality with the original. There are faster (if
uglier) ways to check for palindromes. This version finds the Level 1
answer in about 150ms on my machine:

(defn palindrome?
  [^String s]
  (let [len (.length s)
mid (quot len 2)]
(loop [i 0
   j (dec len)]
  (if (= i mid)
true
(when (= (.charAt s i) (.charAt s j))
  (recur (inc i) (dec j)))

Also, the built-in function max-key will do what your sort/max-comp
code is doing more concisely:

(apply max-key count (filter palindrome? (all-combs input)))

HTH,

Justin

On Oct 12, 3:02 pm, tonyl  wrote:
> Hi, I just started to learn clojure in a more serious way and I am
> doing the first level of the greplin challenge.
>
> I made it to work with a short palindrome like the example they give
> me, but when it comes to work with the input file, it takes for ever
> and I have to stop it.
>
> $ time clj level1.clj
> ^C
> real    11m35.477s
> user    1m44.431s
> sys     9m3.878s
>
> This is my code:
>
> (defn palindrome? [s]
>   (= s (reduce str (reverse s
>
> (defn all-combs [in]
>   (let [len (count in)]
>     (for [i (range 0 (- len 2)), j (range (+ i 1) len)]
>       (subs in i j
>
> (defn max-comp [x y]
>   (let [lenx (count x), leny (count y)]
>     (cond (< lenx leny) 1
>           (= lenx leny) 0
>           (> lenx leny) -1)))
>
> ;;(let [input "I like racecars that go fast"]
> (let [input (slurp "../_input/level1.in")]
>     (println (nth (sort max-comp (filter palindrome? (all-combs
> input))) 0)))
>
> The input file is thishttp://challenge.greplin.com/static/gettysburg.txt
>
> It looks a bit procedural. It is long, but I don't think is the
> biggest bottleneck, I think it is my approach to create all the
> combinations possible for substrings. Maybe I should be using a lazy
> seq? How would I go to do that?

-- 
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: Help to optimize palindrome search from input file

2010-10-12 Thread tonyl
I new the palindrome? function wasn't good in performance, but I
didn't think it would be that bad. The type hinting does improve
performance plus a mid way to compare.
Thanks for pointing that out and the max-key function.

On Oct 12, 4:15 pm, Justin Kramer  wrote:
> The 'palindrome?' function can be made much faster. Your version --
> which is idiomatic and fine when perf isn't a factor -- turns the test
> string into a sequence, reverses it, turns it back into a string, then
> checks for full equality with the original. There are faster (if
> uglier) ways to check for palindromes. This version finds the Level 1
> answer in about 150ms on my machine:
>
> (defn palindrome?
>   [^String s]
>   (let [len (.length s)
>         mid (quot len 2)]
>     (loop [i 0
>            j (dec len)]
>       (if (= i mid)
>         true
>         (when (= (.charAt s i) (.charAt s j))
>           (recur (inc i) (dec j)))
>
> Also, the built-in function max-key will do what your sort/max-comp
> code is doing more concisely:
>
> (apply max-key count (filter palindrome? (all-combs input)))
>
> HTH,
>
> Justin
>
> On Oct 12, 3:02 pm, tonyl  wrote:
>
>
>
> > Hi, I just started to learn clojure in a more serious way and I am
> > doing the first level of the greplin challenge.
>
> > I made it to work with a short palindrome like the example they give
> > me, but when it comes to work with the input file, it takes for ever
> > and I have to stop it.
>
> > $ time clj level1.clj
> > ^C
> > real    11m35.477s
> > user    1m44.431s
> > sys     9m3.878s
>
> > This is my code:
>
> > (defn palindrome? [s]
> >   (= s (reduce str (reverse s
>
> > (defn all-combs [in]
> >   (let [len (count in)]
> >     (for [i (range 0 (- len 2)), j (range (+ i 1) len)]
> >       (subs in i j
>
> > (defn max-comp [x y]
> >   (let [lenx (count x), leny (count y)]
> >     (cond (< lenx leny) 1
> >           (= lenx leny) 0
> >           (> lenx leny) -1)))
>
> > ;;(let [input "I like racecars that go fast"]
> > (let [input (slurp "../_input/level1.in")]
> >     (println (nth (sort max-comp (filter palindrome? (all-combs
> > input))) 0)))
>
> > The input file is thishttp://challenge.greplin.com/static/gettysburg.txt
>
> > It looks a bit procedural. It is long, but I don't think is the
> > biggest bottleneck, I think it is my approach to create all the
> > combinations possible for substrings. Maybe I should be using a lazy
> > seq? How would I go to do that?

-- 
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: precise numbers

2010-10-12 Thread Brian Hurt
On Tue, Oct 12, 2010 at 3:35 PM, cej38  wrote:

> The more that I think about it, the more I would rather have a set of
> equalities that always work.  float= was a good try.
>
>
>


Every fucking language I've ever worked on has had this problem- "floats are
broken!"  And every single one, people keep coming up with the same wrong
answers to this.  C, Java, Ocaml, Haskell, SQL, now Clojure.  Makes me
wonder what language you are coming from where floats *aren't* broken.  Some
languages patch their print methods to hide the errors in the simple cases,
but I've yet to see one where 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1
+ 0.1 + 0.1 = 1.0.  Try it in the language of your choice.

First of all, the base of the floating point number just changes what
fractions "break".  For example, in base 10, 1/3 * 3 = 0.9...  So no,
going to base-10 doesn't save you.  IEEE 754 floats are base-2, so 1/10th is
impossible to represent precisely, the same way 1/3 is impossible to
represent precisely in base-10.  Oh, and Clojure has, from it's Java roots,
a BigDecimal class which does do base-10 arithmetic.

And no, going to rationals doesn't save you either.  Take the vector [1, 0,
1], and normalize it so it's euclidean length is 1, without error.  Have a
nice day.  *Any* finite precision representation is going to have round off
error.  Oh, and Clojure does have a rational class.

And once you have round-off, you're going to have numeric errors.  At which
point, how you deal with those errors is important.  Numeric algorithms fall
into two broad categories- stable and unstable.  With stable algorithms,
errors tend to cancel each other, so your final answer is going to be pretty
close to correct.  With unstable algorithms, errors tend to accumulate (I'm
simplifying here for the newbies, for those who know what I'm talking
about).

No, throwing more bits at the problem won't save an unstable algorithm,
it'll just take longer for the unstable algorithm to finally destroy any and
all accuracy.  Double precision numbers give you enough precision to measure
the distance from here to the moon- in multiples of the wavelength of red
light.  Precisely.  Also note there is a difference between precision and
accuracy- if I say pi is equal to 3.179830482027405068272948472, that's very
precise- but not very accurate.  Unstable algorithms destroy accuracy, not
precision.

And no, ranged floats don't help either- as they grossly overestimate the
error of stable algorithms.  A classic example of a super-stable algorithm
is Newton's method- generally, the number of bits of precision is doubled
(or more) every iteration, as the algorithm converges to the answer. But
ranged floats have the error increasing every iteration.

Oh, and double precision floating point numbers (especially if they're
unboxed) are between 10x and 1000x as fast as other representations- thanks
to hardware acceleration.  Your CPU can execute one floating point operation
a clock cycle, two if it's vectorized code.

Floating point is not broken.



Brian

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

Creating a new library

2010-10-12 Thread Vilson Vieira
Hello,

I want to create a Clojure wrapper for Minim and push to clojars. So I have
a bunch of jar files from Minim as deps and I want to put them on my lib/.
How  can I add a non-clojure jar file on my lein project?

Or I need to create a specific lein project for every jar? Like there's a
processing.core for Processing jar [1].

Thanks.

PS: who is the user fyuryu from clojars? I think he could help me.

[1] http://clojars.org/org.clojars.fyuryu/processing.core

-- 
Vilson Vieira

vil...@void.cc

((( http://automata.cc )))

((( http://musa.cc )))

-- 
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: precise numbers

2010-10-12 Thread Mike Meyer
On Tue, 12 Oct 2010 17:44:20 -0400
Brian Hurt  wrote:

> On Tue, Oct 12, 2010 at 3:35 PM, cej38  wrote:
> 
> > The more that I think about it, the more I would rather have a set of
> > equalities that always work.  float= was a good try.
> 

Maybe initially, but not later on...

> Floating point is not broken.
> 

Well, no more broken than any other representation of numbers on the
computer. All of them have problems of one sort or another.  For
almost any problem you're going to solve with a computer, picking the
right representation for your data is a crucial step!

While you may understand the mathematics of numbers quite well, no
computerized representation will give you that behavior (even integers
are usually weird, either having a number which has no additive
inverse, or having two zeros). You can expect every mathematical
entity to have this problem: pretty much every computer representation
will not have some property or properties of the original, so you have
to figure out which properties you really care about, and pick the
representation that has those properties.

That picking the right representation of numbers is a crucial step may
be surprising, but it's still true. Most languages have settled on the
same set of choices (in order of decreasing use): integers, either
with or without size limits; floats; decimals, either with or without
explicit lengths; and rationals. You can expect that most problems can
be dealt with adequately by one of these. If not - well, there are
lots of other choices out there that you can play with as well.

  http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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: strange bug in range or lazy-seq?

2010-10-12 Thread Paul Mooser
Any chance someone could walk us through how this visibility issue
occurs (where the range-based version of primes consumes numbers
before they are visible). This really looks like a case where side
effects and implementation details are causing what appear to be
strange behaviors, based on multiple things that appear to be
equivalent (but which clearly are not). I've never gotten things set
up yet to be able to debug into clojure internals - maybe this would
be a good excuse to do so.

On Oct 11, 6:56 pm, Stuart Halloway  wrote:
> When a var's definition has a "lazy reference" to itself, as primes does 
> below, then your results will be dependent on the lazy/chunky/strict-ness of 
> the calls leading to the lazy reference.
>
> The functions range, rest, and remove are chunk-aware, so the range-based 
> version of primes consumes a bunch of numbers before its changes become 
> self-visible. Other functions, such as iterate, are not chunked, so the 
> results are visible to primes sooner.

-- 
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: Creating a new library

2010-10-12 Thread lprefontaine
a) Assuming all the dependencies are published in a maven repo out there:

  If you put all your deps in project.clj, the pom.xml file generated by
  leiningen will reference all of them as dependencies to your own lib.
  You only need to publish your own library and the pom.xml to Clojars.

  Anyone pulling your lib using lein deps (and of course specifying your lib
  as a dependcy in project.clj) will pull them also from the maven repos 

b1) Assuming some of your dependencies are not published in a maven repo:

   You could create a uberjar using leiningen and then publish it to Clojars.
   But that would include all the dependencies in your lib. Including
   the Clojure runtime... You may have to be careful maintaining multiple
   versions to comply with different version of Clojure and contrib.
   A bit ugly..

b2) There's a third alternative but that requires some scripting outside of 
leiningen. You may prefer to avoid this one :))) I assume you
use U*X but it's essentially the same steps under Windows:

   - create a temp folder in your project.
   - expand every dependency not available in maven into this temp folder:
 (cd temp; jar -xf ../lib/.jar)
   - expand your own library into this folder:
 (cd temp; jar -xf ../.jar)
   - recreate your library jar file:
 (cd temp; jar -cf ../.jar)

The above should include all the class files, resource, ... from all
the dependencies you want to include.

You would have to run this manually after every new build you want
to publish to Clojars. Do notmix up the steps. You library has to be the
last to get expanded in the temporary folder.

Luc P.

Vilson Vieira  wrote ..
> Hello,
> 
> I want to create a Clojure wrapper for Minim and push to clojars. So I have
> a bunch of jar files from Minim as deps and I want to put them on my lib/.
> How  can I add a non-clojure jar file on my lein project?
> 
> Or I need to create a specific lein project for every jar? Like there's a
> processing.core for Processing jar [1].
> 
> Thanks.
> 
> PS: who is the user fyuryu from clojars? I think he could help me.
> 
> [1] http://clojars.org/org.clojars.fyuryu/processing.core
> 
> -- 
> Vilson Vieira
> 
> vil...@void.cc
> 
> ((( http://automata.cc )))
> 
> ((( http://musa.cc )))
> 
> -- 
> 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: Problems with clojure couchdb

2010-10-12 Thread Mark Engelberg
On Tue, Oct 12, 2010 at 6:41 AM, Moritz Ulrich
 wrote:
> Regarding your error: Maybe you open too many sockets which don't get
> closed and your process runs out of file descriptors.

Yes, I think that's the problem.  I found a blurb on the net about how
to expand the range of usable ports for sockets, but instead I went
the route of writing my documents in batches of 50 as both of you
suggested.  This didn't entirely solve the problem, but it definitely
helped and I was able to get much further.  But after entering about
2,000,000 small documents, the database size was nearing 4GB and couch
seemed to really crawl to add new documents.  I like couch's
ease-of-use alongside Clojure, but I think I need something that isn't
quite so space-hungry and remains fast for largish collections.  So
I'm thinking I'm going to have to punt on couch db.  Any other tips on
what I might be doing wrong, or does this sound typical?

Thanks,

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: Help to optimize palindrome search from input file

2010-10-12 Thread pkw
I'm just replying because I also do this in clojure and my level is
also
really slow:

http://github.com/krsanky/greplin-challenge/blob/master/greplin-challenge/src/greplin_challenge/level1.clj

:)

--paul wisehart

-- 
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: Creating a new library

2010-10-12 Thread Vilson Vieira
2010/10/12 

> a) Assuming all the dependencies are published in a maven repo out there:
>
>  If you put all your deps in project.clj, the pom.xml file generated by
>  leiningen will reference all of them as dependencies to your own lib.
>  You only need to publish your own library and the pom.xml to Clojars.
>
>  Anyone pulling your lib using lein deps (and of course specifying your lib
>  as a dependcy in project.clj) will pull them also from the maven repos
>

How can I publish a dependency in a maven repo like rosejn did for
jsyntaxpane, for example [1]?

I think this way can help other people that will need the non-clojure jar in
the future, right?


> b1) Assuming some of your dependencies are not published in a maven repo:
>
>   You could create a uberjar using leiningen and then publish it to
> Clojars.
>   But that would include all the dependencies in your lib. Including
>   the Clojure runtime... You may have to be careful maintaining multiple
>   versions to comply with different version of Clojure and contrib.
>   A bit ugly..
>

I agree. It's tricky. Maintaning multiple versions will be a pain.


> b2) There's a third alternative but that requires some scripting outside of
>leiningen. You may prefer to avoid this one :))) I assume you
>use U*X but it's essentially the same steps under Windows:
>
>   - create a temp folder in your project.
>   - expand every dependency not available in maven into this temp folder:
> (cd temp; jar -xf ../lib/.jar)
>   - expand your own library into this folder:
> (cd temp; jar -xf ../.jar)
>   - recreate your library jar file:
> (cd temp; jar -cf ../.jar)
>
>The above should include all the class files, resource, ... from all
>the dependencies you want to include.
>
>You would have to run this manually after every new build you want
>to publish to Clojars. Do notmix up the steps. You library has to be the
>last to get expanded in the temporary folder.
>

Maybe I can do that for every dependency library, generate a pom and push to
clojars, can I?

All the best.

[1] http://clojars.org/org.clojars.rosejn/jsyntaxpane

-- 
Vilson Vieira

vil...@void.cc

((( http://automata.cc )))

((( http://musa.cc )))

-- 
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: Creating a new library

2010-10-12 Thread Nurullah Akkaya
For each non-clojure jar file you have, you need to create a pom.xml
file using the instructions here,

http://github.com/ato/clojars-web/wiki/POM

and scp the pom file and the jar to clojars, then you can include them
in your project.clj.

So if Minim.jar depends on A.jar, B.jar, upload A.jar and B.jar and
make Minim.jar depend on A and B then when you add Minim as your
dependency in project.clj it will pull A, B and Minim.

Regards...
--
Nurullah Akkaya
http://nakkaya.com



On Wed, Oct 13, 2010 at 12:52 AM, Vilson Vieira  wrote:
> Hello,
> I want to create a Clojure wrapper for Minim and push to clojars. So I have
> a bunch of jar files from Minim as deps and I want to put them on my lib/.
> How  can I add a non-clojure jar file on my lein project?
> Or I need to create a specific lein project for every jar? Like there's a
> processing.core for Processing jar [1].
> Thanks.
> PS: who is the user fyuryu from clojars? I think he could help me.
> [1] http://clojars.org/org.clojars.fyuryu/processing.core
>
> --
> Vilson Vieira
>
> vil...@void.cc
>
> ((( http://automata.cc )))
>
> ((( http://musa.cc )))
>
> --
> 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: Creating a new library

2010-10-12 Thread lprefontaine
Normally the people maintaining the Minim project should publish their
stuff in a maven public repo. There are the ones in control of their
releases.

As far a publishing to Clojars, I do not know the policy.
Uploading various jars maintained by other teams not involved in
Clojure may "pollute" the repo along the way.

Here we have our own internal repo and we publish stuff there when it's not 
available elsewhere.

When it comes to packaging we use uberjars so all the dependencies are
bundled in one target. But we do not publish public stuff yet so we are
not facing this problem either.

Option b2 would be a better compromise but others may have different opinions.
Comments ? 

Luc P.

Nurullah Akkaya  wrote ..
> For each non-clojure jar file you have, you need to create a pom.xml
> file using the instructions here,
> 
> http://github.com/ato/clojars-web/wiki/POM
> 
> and scp the pom file and the jar to clojars, then you can include them
> in your project.clj.
> 
> So if Minim.jar depends on A.jar, B.jar, upload A.jar and B.jar and
> make Minim.jar depend on A and B then when you add Minim as your
> dependency in project.clj it will pull A, B and Minim.
> 
> Regards...
> --
> Nurullah Akkaya
> http://nakkaya.com
> 
> 
> 
> On Wed, Oct 13, 2010 at 12:52 AM, Vilson Vieira  wrote:
> > Hello,
> > I want to create a Clojure wrapper for Minim and push to clojars. So I have
> > a bunch of jar files from Minim as deps and I want to put them on my lib/.
> > How  can I add a non-clojure jar file on my lein project?
> > Or I need to create a specific lein project for every jar? Like there's a
> > processing.core for Processing jar [1].
> > Thanks.
> > PS: who is the user fyuryu from clojars? I think he could help me.
> > [1] http://clojars.org/org.clojars.fyuryu/processing.core
> >
> > --
> > Vilson Vieira
> >
> > vil...@void.cc
> >
> > ((( http://automata.cc )))
> >
> > ((( http://musa.cc )))
> >
> > --
> > 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: evaluation of a function via mathematica from clojure using the clojuratica bridge...

2010-10-12 Thread Sunil S Nandihalli
Thanks Garth.. That works well .. mathematica->clojure function has been
quiet usefull.
Sorry for the delayed response..
Sunil.

On Fri, Oct 8, 2010 at 9:54 AM, Garth Sheldon-Coulson  wrote:

> Sorry, the Needs call isn't quite right. Do this instead:
>
> << ClojurianScopes`
>
> Garth
>
>
> On Fri, Oct 8, 2010 at 12:23 AM, Garth Sheldon-Coulson wrote:
>
>> Hi Sunil,
>>
>> Double check that you have the .m files from the Clojuratica distribution
>> in your Mathematica $Path. The error message you received makes me think
>> that the file ClojurianScopes.m is not being properly loaded by
>> Mathematica/Clojuratica.
>>
>> You can check this by firing up Mathematica and calling
>>
>> Needs["ClojurianScopes`"]
>>
>> Also, try
>>
>> *   (With [(= f 10) (= g 20)]*
>> *  (* f (+ g x*
>>
>>
>> Best,
>> Garth
>>
>>
>> On Mon, Oct 4, 2010 at 11:11 AM, Sunil S Nandihalli <
>> sunil.nandiha...@gmail.com> wrote:
>>
>>> I am sorry for reposting .. I realized that the subject line was not very
>>> intelligible .. so I  am changing the subject line and reposting the same
>>> message.
>>>
>>> Hello everybody,
>>> I am trying to use clojure along with mathematica. Thanks to Clojuratica,
>>> the integration is seamless..
>>>  when I try to execute the following code
>>> *(math (SetDelayed (func1 (Pattern x (Blank)))*
>>> *(With [f 10 g 20]*
>>> *  (* f (+ g x)*
>>> *(math (func1 30))*
>>> I got
>>> *(ClojurianScopes/With [f 10 g 20] (* f (+ 30 g)))*
>>>
>>> and when I evaluated
>>>
>>> *(math (Set (func2 (Pattern x (Blank)))*
>>> *(With [f 10 g 20]*
>>> *  (* f (+ g x)*
>>> *
>>> *
>>> *(math (func2 30))*
>>>
>>>
>>> I got ...
>>>
>>> *(ClojurianScopes/With [f 10 g 20] (* f (+ 30 g)))*
>>>
>>> Adding N/Simplify did not make any difference..
>>>
>>> I was expecting 500 in both of those tries..
>>>  Can anybody help?
>>> Sunil.
>>>
>>>  --
>>> 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

a macro

2010-10-12 Thread Sunil S Nandihalli
Hello Everybody,
 I think I was not clear about things in my previous email.. I am reposting
simplifying things...

Variables is a macro which works in the following way..

(Variables (+ x (* 2 y))

returns
 [x y]

now let us say we have a function

(defn f []
  '(+ x (* 2 y)))

now I would like to do something like

(Variables (f))

which would return
[x y]

I know if is a function and will not be evaluated before the macro expands..
may be there is a way to wrap it in a macro (since f is already defined
which I would like to use) and have the macro Variables apply on the result
of evaluation of f

any help is greatly appreciated.
Thanks,
Sunil.

-- 
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: Creating a new library

2010-10-12 Thread Saul Hazledine
On Oct 13, 5:31 am, lprefonta...@softaddicts.ca wrote:
> As far a publishing to Clojars, I do not know the policy.
> Uploading various jars maintained by other teams not involved in
> Clojure may "pollute" the repo along the way.
>

As I understand it, its fine to put jars from other projects on
Clojars. If you do this, it is recommended to use your own groupid or
org.clojars. as the groupid. That way people know that
the jar files aren't from the originating team. If the originating
team ever puts their package on the central maven repository the
clojars package won't be picked up by mistake by people who want the
official package.

Saul

-- 
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: a macro

2010-10-12 Thread Sunil S Nandihalli
as a follow up with further clarifications, I would like to mention that
Variables is already a predefined macro and I don't want have to execute it
at run-time since it uses mathematica and we cannot distribute mathematica
to the end user.

and also please read my last sentence as

I know f is a function and will not be evaluated before the macro expands..
may be there is a way to wrap it in a macro (since f is already defined
which I would like to use) and have the macro Variables apply on the result
of evaluation of f

it was a typo in my earlier email.

On Wed, Oct 13, 2010 at 11:25 AM, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> Hello Everybody,
>  I think I was not clear about things in my previous email.. I am reposting
> simplifying things...
>
> Variables is a macro which works in the following way..
>
> (Variables (+ x (* 2 y))
>
> returns
>  [x y]
>
> now let us say we have a function
>
> (defn f []
>   '(+ x (* 2 y)))
>
> now I would like to do something like
>
> (Variables (f))
>
> which would return
> [x y]
>
> I know if is a function and will not be evaluated before the macro
> expands.. may be there is a way to wrap it in a macro (since f is already
> defined which I would like to use) and have the macro Variables apply on the
> result of evaluation of f
>
> any help is greatly appreciated.
> Thanks,
> Sunil.
>

-- 
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: a macro

2010-10-12 Thread Robert McIntyre
I'm still a little confused as to what you're trying to do,
but is this what you're looking for?

(defmacro zzz [form]
(first form))

(defmacro eval-zzz [form]
`(zzz ~(eval form)))

rlm.play-all> (zzz (range 1 2))
#

rlm.play-all> (macroexpand-1 '(eval-zzz (range 5)))
(rlm.play-all/zzz (0 1 2 3 4))

rlm.play-all> (eval-zzz (range 5))
0

--Robert

On Wed, Oct 13, 2010 at 1:55 AM, Sunil S Nandihalli
 wrote:
> Hello Everybody,
>  I think I was not clear about things in my previous email.. I am reposting
> simplifying things...
> Variables is a macro which works in the following way..
> (Variables (+ x (* 2 y))
> returns
>  [x y]
> now let us say we have a function
> (defn f []
>   '(+ x (* 2 y)))
> now I would like to do something like
> (Variables (f))
> which would return
> [x y]
> I know if is a function and will not be evaluated before the macro expands..
> may be there is a way to wrap it in a macro (since f is already defined
> which I would like to use) and have the macro Variables apply on the result
> of evaluation of f
> any help is greatly appreciated.
> Thanks,
> Sunil.
>
> --
> 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: a macro

2010-10-12 Thread Meikel Brandmeyer
Hi,

On 13 Okt., 07:55, Sunil S Nandihalli 
wrote:

> I know if is a function and will not be evaluated before the macro expands..
> may be there is a way to wrap it in a macro (since f is already defined
> which I would like to use) and have the macro Variables apply on the result
> of evaluation of f

This is not possible. Macros cannot use information which is not
available at compile time. You should investigate whether it is
possible to split the Variables macro in two parts. A function doing
the work and a convenience macro.

(defn Variables*
  [form]
  ...)

(defmacro Variables
  [form]
  `(Variables* (quote ~form)))

Then you can call (Variables (+ x (* 2 y))) without quoting and
(Variables* (f)) at runtime with your function result.

Sincerely
Meikel

-- 
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: a macro

2010-10-12 Thread Laurent PETIT
2010/10/13 Sunil S Nandihalli 

> as a follow up with further clarifications, I would like to mention that
> Variables is already a predefined macro and I don't want have to execute it
> at run-time since it uses mathematica and we cannot distribute mathematica
> to the end user.
>
> and also please read my last sentence as
>
> I know f is a function
>

Here lies the problem. The f that is passed as an argument to the call to
the macro Variable is not a function. It's the plain symbol f , within a
plain list . If you want the macro to interpret the symbol f as a function
(or rather the datastructure '(f) as a function call, then you'll have to
evaluate it from the macro (which is probably possible and justified in you
case because you do not want to distribute the mathematica stuff for the
runtime, but it will be available when evaluating from inside the macro at
compile time => I assume you will AOT compile things, of course).

So in short: calling eval from the macro, on its argument.

HTH,

-- 
Laurent


> and will not be evaluated before the macro expands.. may be there is a way
> to wrap it in a macro (since f is already defined which I would like to use)
> and have the macro Variables apply on the result of evaluation of f
>




>
> it was a typo in my earlier email.
>
> On Wed, Oct 13, 2010 at 11:25 AM, Sunil S Nandihalli <
> sunil.nandiha...@gmail.com> wrote:
>
>> Hello Everybody,
>>  I think I was not clear about things in my previous email.. I am
>> reposting simplifying things...
>>
>> Variables is a macro which works in the following way..
>>
>> (Variables (+ x (* 2 y))
>>
>> returns
>>  [x y]
>>
>> now let us say we have a function
>>
>> (defn f []
>>   '(+ x (* 2 y)))
>>
>> now I would like to do something like
>>
>> (Variables (f))
>>
>> which would return
>> [x y]
>>
>> I know if is a function and will not be evaluated before the macro
>> expands.. may be there is a way to wrap it in a macro (since f is already
>> defined which I would like to use) and have the macro Variables apply on the
>> result of evaluation of f
>>
>> any help is greatly appreciated.
>> Thanks,
>> Sunil.
>>
>
>  --
> 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