Sorting gotcha

2011-08-23 Thread Mark Engelberg
I had always assumed that vectors were sorted lexicographically. In other words, you sort on the first element, and then refine by the second element, and so on. I was surprised tonight to discover that is not the case. (compare abc b); Strings are compared lexicographically -1

Re: a question about using the delay macro

2011-08-23 Thread faenvie
perfect answer. thank you ! btw: my snippet is taken out of the docs for java.jdbc. On Aug 22, 12:04 pm, Meikel Brandmeyer (kotarak) m...@kotka.de wrote: Hope, I'm not too far off. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group.

Re: Sorting gotcha

2011-08-23 Thread Ben Smith-Mannschott
On Tue, Aug 23, 2011 at 09:44, Mark Engelberg mark.engelb...@gmail.com wrote: I had always assumed that vectors were sorted lexicographically.  In other words, you sort on the first element, and then refine by the second element, and so on.  I was surprised tonight to discover that is not the

How to import libs in Clojure?

2011-08-23 Thread Wanderfels
Hello, win XP, clojure 1.2.1 and clojure.contrib-1.2.0.jar here. i want to learn clojure (background python and javascript and a bit Haskell) and are currently reading the pdf 'Programming Clojure' from 2009. In Chapter 1.3: 'Exploring Clojure Libraries' it says: Clojure code is packaged in

Re: How to import libs in Clojure?

2011-08-23 Thread Michael Wood
Hi On 23 August 2011 12:10, Wanderfels wanderf...@web.de wrote: Hello, win XP, clojure 1.2.1 and clojure.contrib-1.2.0.jar here. i want to learn clojure (background python and javascript and a bit Haskell) and are currently reading the pdf 'Programming Clojure' from 2009. In Chapter 1.3:

Re: Video Slides on Pattern Matching and Predicate Dispatch in Clojure

2011-08-23 Thread Brent Millare
In the ClojureScript case, you can do lazy compile time compilation instead, where the predicate call is really a macro that always expands into a predicate call but during compile time can check if the tree needs to be updated. This isn't as lazy as the runtime version but at least groups of

Re: a question about using the delay macro

2011-08-23 Thread Sean Corfield
I was trying to construct a simple example of what I actually have in my apps that use pooling on top of java.jdbc. My actual code *does* work to create a singleton but you're right, I've contracted my code too far in trying to create a simple example of it... I'll have another attempt! Sean On

Cron algorithm challenge

2011-08-23 Thread Michael Jaaka
Hi! I have some challenge for you, sine it is easy express it in imperative language I would like to ask you if is it possible to create DSL to express such algorithm in clojure or if is it too complicated just write it in functional manner. The challenge is to write cron algorithm. I can express

Re: Cron algorithm challenge

2011-08-23 Thread Michael Jaaka
After the post I suddenly saw the code in my mind: http://pastebin.com/kYYYirdb The expression abilities are truly near the mind. Clojure rox :-) On Aug 23, 6:01 pm, Michael Jaaka michael.ja...@googlemail.com wrote: Hi! I have some challenge for you, sine it is easy express it in imperative

Re: Cron algorithm challenge

2011-08-23 Thread Meikel Brandmeyer
Hi, Am 23.08.2011 um 18:01 schrieb Michael Jaaka: I have some challenge for you, sine it is easy express it in imperative language I would like to ask you if is it possible to create DSL to express such algorithm in clojure or if is it too complicated just write it in functional manner. The

Odp: Re: Cron algorithm challenge

2011-08-23 Thread Michael Jaaka
Wow nice! :-) Of course wait-till can be done with Timers build-in JDK. And here is a proposition for cron parsing function: (defn parse-cron-expr[ pattern ] (let[ cal (Calendar/getInstance) ] (let [[min-pat hour-pat day-pat month-pat week-pat] (letfn[ (parse-cron[ val pos cal ] (letfn[

Re: How to import libs in Clojure?

2011-08-23 Thread Paul Lam
Did you use the -cp option to include the contrib when running java.exe on clojure.jar? The error shows that it's looking in a subdirectory with a .class rather than the packaged jar file. I'd suggest using leiningen to avoid build problems like this. On Aug 23, 6:10 am, Wanderfels

why is it necessary to use identity to check for nils in an if statement

2011-08-23 Thread Andrew Xue
this doesn't work: user= (defn if-a [a b] (if (a) (str a) (str b))) #'user/if-a user= (if-a nil b) java.lang.NullPointerException (NO_SOURCE_FILE:0) user= (if-a a nil) user= java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0) this does work:

Re: why is it necessary to use identity to check for nils in an if statement

2011-08-23 Thread Dave Ray
You have an extra set of parens around a, treating it as a function call. Try: (defn if-a [a b] (if a (str a) (str b))) Hope that helps, Dave On Tue, Aug 23, 2011 at 4:37 PM, Andrew Xue and...@lumoslabs.com wrote: this doesn't work: user= (defn if-a [a b] (if (a) (str a) (str b)))

Re: why is it necessary to use identity to check for nils in an if statement

2011-08-23 Thread Matthew Gilliard
user= (defn if-a [a b] (if (a) (str a) (str b))) The problem is (a) - it tries to call a as a function, which throws NullPointer if a is nil. You meant: user= (defn if-a [a b] (if a (str a) (str b))) mg On Tue, Aug 23, 2011 at 9:37 PM, Andrew Xue and...@lumoslabs.com wrote: this

Creating a Clojure Record from a string

2011-08-23 Thread Timothy Baldridge
Given: test=(defrecord Foo [A B]) test=(class (Foo. 1 2)) test.Foo How do I: test=(new test.Foo 1 2) #:test.Foo{:A 1, :B 2} Currently I get Unable to resolve classname: test/Foo. Thanks, Timothy -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no

Re: Creating a Clojure Record from a string

2011-08-23 Thread Stuart Halloway
Given: test=(defrecord Foo [A B]) test=(class (Foo. 1 2)) test.Foo How do I: test=(new test.Foo 1 2) #:test.Foo{:A 1, :B 2} Currently I get Unable to resolve classname: test/Foo. Thanks, Timothy (Class/forName java.lang.String) Be mindful of the performance... Stu

Re: Creating a Clojure Record from a string

2011-08-23 Thread Craig Andera
Given: test=(defrecord Foo [A B]) test=(class (Foo. 1 2)) test.Foo How do I: test=(new test.Foo 1 2) #:test.Foo{:A 1, :B 2} Currently I get Unable to resolve classname: test/Foo. Check out

Re: Creating a Clojure Record from a string

2011-08-23 Thread Craig Andera
(Class/forName java.lang.String) Oh, does that work in 1.3? Because (new (Class/forName user.Foo)) was the first thing I tried (under 1.2) and it doesn't work. Perhaps unsurprisingly given that new is a special form. -- You received this message because you are subscribed to the Google Groups

Re: Creating a Clojure Record from a string

2011-08-23 Thread Alan Malloy
On Aug 23, 3:39 pm, Craig Andera cand...@wangdera.com wrote: (Class/forName java.lang.String) Oh, does that work in 1.3? Because (new (Class/forName user.Foo)) was the first thing I tried (under 1.2) and it doesn't work. Perhaps unsurprisingly given that new is a special form. No. But you

clojure.java.jdbc: mapping BigDecimal to double

2011-08-23 Thread HiHeelHottie
Hi, It looks like Oracle NUMBER types get mapped to BigDecimal in a result seq from clojure.java.jdbc. Is there an easy way to configure clojure.java.jdbc/ResultSet to map Oracle NUMBERS to doubles? The resultset-seq from

Re: Creating a Clojure Record from a string

2011-08-23 Thread rfhayashi
test= (def foo-class-symbol (load-string test.Foo)) test= (def foo (eval (list 'new foo-class-symbol 1 2))) test= foo #:test.Foo{:A 1, :B 2} Is that what you want? On Aug 23, 6:24 pm, Timothy Baldridge tbaldri...@gmail.com wrote: Given: test=(defrecord Foo [A B]) test=(class (Foo. 1 2))

Re: clojure.java.jdbc: mapping BigDecimal to double

2011-08-23 Thread Sean Corfield
No, you'd have to do it yourself. Since not all BigDecimal values would fit correctly in double, it would be dangerous for resultset-seq to do it. I expect there are all sorts of JDBC data types that don't quite match Clojure types but I don't think automatically mapping them would be a good

Re: clojure.java.jdbc: mapping BigDecimal to double

2011-08-23 Thread HiHeelHottie
Hey Sean, I really appreciate the quick response and your work with java.jdbc. Completely agree with you that it shouldn't automatically map out of the box. As a newbie to clojure and jdbc, do you have any advice on how I can get into resultset-seq* to do the mapping? I think it would be better

Re: clojure.java.jdbc: mapping BigDecimal to double

2011-08-23 Thread Ken Wesson
On Tue, Aug 23, 2011 at 9:54 PM, HiHeelHottie hiheelhot...@gmail.com wrote: Are there any future plans to add a mapping api to resultset-seq or is the pattern just to chain any custom mappings after resultset-seq? Is wrapping in (map double ...) too much typing? :) -- Protege: What is this

Re: clojure.java.jdbc: mapping BigDecimal to double

2011-08-23 Thread Sean Corfield
On Tue, Aug 23, 2011 at 6:54 PM, HiHeelHottie hiheelhot...@gmail.com wrote: Completely agree with you that it shouldn't automatically map out of the box. As a newbie to clojure and jdbc, do you have any advice on how I can get into resultset-seq* to do the mapping? I think it would be better

Re: clojure.java.jdbc: mapping BigDecimal to double

2011-08-23 Thread gaz jones
the oracle jdbc adapter returns a whole host of strange datatypes. for instance, it returns bigdecimals for numbers you have mapped to be numbers (with a precision, without a scale) in the table. it also returns its own custom time classes. these generally have a toJdbc() method to convert them to