Re: STM style disk persistance

2010-06-24 Thread Laurent PETIT
Hi,

What are the use cases you have in mind ?

2010/6/23 Timothy Baldridge :
> I'm wondering if we're going about this slightly the wrong way. Let's
> take a look at CouchDB. CouchDB prefers to keep all data on the disk
> at all times. As docs (or items) are added to a database they extend
> that database, but never overwrite it. In addition all changes are
> written instantly to disk, with no in memory cache.
>
> Here's what I'm thinking. We develop a new set of sequence compatible
> maps and vectors, that are immutable, yet stored on disk. Each
> vector/map would be stored in a separate file, and changes to this
> file would need to be serialized, but reading from the file could be
> performed co-currently. Instead of syncing in-memory structures to
> disk, the structures themselves are stored on disk. If the user wants
> to cache that data they must perform the caching themselves.
>
> I think I may give this a try tonight with vectors as a starting point.
>
> Timothy
>
> On Wed, Jun 23, 2010 at 3:26 PM, Daniel Werner
>  wrote:
>> On Jun 22, 7:57 pm, Timothy Baldridge  wrote:
>>> system it uses. Has anyone tried marrying the two system systems to
>>> create a truly persistent data primitive where any "updates" to a map
>>> is written to the disk?
>>
>> There has been an attempt at integrating STM transactions with DB
>> transactions, even including a patch, but sadly discontinued and very
>> outdated by now:
>>
>> http://groups.google.com/group/clojure/browse_thread/thread/aa22a709501a64ac
>> http://clojure.googlegroups.com/web/external_transactions.patch?hl=en&gda=-S5y8U0AAADrLV-d6p24hYFcam_S99IgyJE26GXST0R-7SyR1V01WgTsgF1Et-2mKd4f9I_2PzGxx-qQneGAYu2No43QZpeq5Tb_vjspK02CR95VRrtmeQ&gsc=RG-y6gsAAAB4ToW0PqQMv0ZY_YCRY_xk
>>
>> --
>> 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
>
>
>
> --
> “One of the main causes of the fall of the Roman Empire was
> that–lacking zero–they had no way to indicate successful termination
> of their C programs.”
> (Robert Firth)
>
> --
> 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: State of Clojure web development

2010-06-24 Thread Adrian Cuthbertson
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?

I am and have been extending an existing production java web
application environment with all new server work now being done in
clojure. It is a complex jvm server running tomcat and other threaded
proprietary services and integration paths into back-end feed systems.
Front-end stuff, previously jsp is now all being replaced by
javascript/jquery and ajax.

I am also working on a netty/clojure setup to create some distributed
event-driven processes for scaling up the services and in the future
replacing most of the the above in-jvm/threaded routines. Down the
line I hope to release some of this as open-source.

> 2. Which libraries or frameworks are you using? Which versions?

In the early stages, I tried compojure, but my setup needed much
tighter java/clojure interop and hence most of my effort has gone in
that direction. I do use enlive, joda-time, jfreechart and a bit of
clj-html/hiccup. Java libs - tomcat, log4j, apache-commons,
postgresql-jdbc. Plus many person-years of various proprietary java
and unix utility libraries for (hosted) infrastructure and operations
management. Generally I have found most of the other java frameworks
too "heavy" for my rather close-to-the-wire preferences.

> 3. What made you choose Clojure to develop web applications in? What
> are the strengths of Clojure web development?

I learnt a bit of lisp way back but career-wise all my work has
generally been c/c++/java based. I spent about 9 months with scala
hoping for an improved jvm capability, but found it too tedious when
trying to work on the complex setup mentioned above. Happened upon
clojure 18 months ago and this was the holy-grail incarnate. You
really can get pretty close to expressing directly what's in your
mind. Haven't looked back since.

> 4. What do you think are the current weaknesses of web development in
> Clojure? What could be improved?

Plenty of room for event-driven techniques, javascript/jquery
generation stuff, distributed processing, disk-based persistence, etc.
The new protocols/types/records and the coming primitives improvements
are very exciting.

> 5. Anything else you want to comment on?

Performance, performance, performance and by the way, performance.
When you run server applications, especially non-blocking, event
driven, every little milli-second per function counts hugely when
scaling up to thousands, tens of thousands or more asynchronously
accessed services. Clojure has done wonders in eliminating boilerplate
tedium and maintenance grovel, so generally I would now like to focus
on improving my reality of 30% coding, 70%
tuning/benchmarking/refactoring.

- Regards, Adrian.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure.contrib.logging in "side-effect free" functions?

2010-06-24 Thread ka
To my naive inexperienced eyes, there doesn't seem to be something
obviously wrong with your code.

> Since FOR returns a lazy sequence of the results, is this function
> safe?  (Seeing that it is not side-effect free?)

I'm not getting this, do you foresee any safety issues?  I think that
the logs will be created as you're writing to the out.csv.  If you
want the logs be written before you start writing to out.csv, you may
realize the lazy-seq for returns.

> BTW:
>   clojure.contrib.logging indicates that it can use an agent for
>   logging. Is my assumption that invoking the logger (with or without
>   an agent) within a function would still mean that the function has
>   side-effects correct?

Yes, any change in state or IO means side effect.

- Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure.contrib.logging in "side-effect free" functions?

2010-06-24 Thread Laurent PETIT
Hi,

2010/6/17 William Wadsworth :
> Hi.
>
> I have just started learning Clojure and I am really enjoying
> myself. However, I am still getting to grips with the workings of its
> concurrency model, so please excuse me if my question seems too
> obvious.
>
> I have some code that reads data from a file, parses it and generates
> a CSV file. The flow is as follows:
>
> 
> (use 'clojure.contrib.duck-streams)
> (use 'clojure.contrib.pprint)
>
> (defn parse-line [s]
>  (cl-format nil "~{\"~A\"~^,~}" (into [] (.split s ";"
>
> (let [input-seq (for [line (read-lines "input.dat")]
>                  (parse-line line))]
>  (write-lines "out.CSV" input-seq))
> 
>
> Now the question:
>
> I would like to generate log entries for any malformed lines occurring
> in the input file. Once of the ways might be to do this in parse-line
> using clojure.contrib.logging as follows:
>
> 
> (use 'clojure.contrib.logging)
>
> (defn parse-line [s]
>  (let [cs (into [] (.split s ";"))]
>    (if (= (count cs) 5)
>      (cl-format nil "~{\"~A\"~^,~}" cs)
>      (error "Incorrect number of columns in file."
> 
>
> Since FOR returns a lazy sequence of the results, is this function
> safe?  (Seeing that it is not side-effect free?)

You have to acknowledge that the calls to parse-line will not
necessarily occur during the call to for, but maybe not before calling
write-lines, maybe partly if chunked-seqs are in play (sequences
preloading items in chunks of 32 items for example). And, if there is
an exception that is not thrown in write-lines, your logs may miss the
error logs for some of the remaining items not yet consumed by
write-lines.

> BTW:
>  clojure.contrib.logging indicates that it can use an agent for
>  logging. Is my assumption that invoking the logger (with or without
>  an agent) within a function would still mean that the function has
>  side-effects correct?

Technically speaking, yes. Imagine there's an I/O exception thrown
from the logging call (disk full, no write access, network access,
etc.), then your function would not be "safe" anymore.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure.contrib.logging in "side-effect free" functions?

2010-06-24 Thread Laurent PETIT
2010/6/24 Laurent PETIT :
> Hi,
>
> 2010/6/17 William Wadsworth :
>> Hi.
>>
>> I have just started learning Clojure and I am really enjoying
>> myself. However, I am still getting to grips with the workings of its
>> concurrency model, so please excuse me if my question seems too
>> obvious.
>>
>> I have some code that reads data from a file, parses it and generates
>> a CSV file. The flow is as follows:
>>
>> 
>> (use 'clojure.contrib.duck-streams)
>> (use 'clojure.contrib.pprint)
>>
>> (defn parse-line [s]
>>  (cl-format nil "~{\"~A\"~^,~}" (into [] (.split s ";"
>>
>> (let [input-seq (for [line (read-lines "input.dat")]
>>                  (parse-line line))]
>>  (write-lines "out.CSV" input-seq))
>> 
>>
>> Now the question:
>>
>> I would like to generate log entries for any malformed lines occurring
>> in the input file. Once of the ways might be to do this in parse-line
>> using clojure.contrib.logging as follows:
>>
>> 
>> (use 'clojure.contrib.logging)
>>
>> (defn parse-line [s]
>>  (let [cs (into [] (.split s ";"))]
>>    (if (= (count cs) 5)
>>      (cl-format nil "~{\"~A\"~^,~}" cs)
>>      (error "Incorrect number of columns in file."
>> 
>>
>> Since FOR returns a lazy sequence of the results, is this function
>> safe?  (Seeing that it is not side-effect free?)
>
> You have to acknowledge that the calls to parse-line will not
> necessarily occur during the call to for, but maybe not before calling
> write-lines, maybe partly if chunked-seqs are in play (sequences
> preloading items in chunks of 32 items for example). And, if there is
> an exception that is not thrown in write-lines, your logs may miss the
> error logs for some of the remaining items not yet consumed by
> write-lines.

s/if there is an exception that is not thrown in write-lines/if there is
an exception that *is* thrown in write-lines/
>
>> BTW:
>>  clojure.contrib.logging indicates that it can use an agent for
>>  logging. Is my assumption that invoking the logger (with or without
>>  an agent) within a function would still mean that the function has
>>  side-effects correct?
>
> Technically speaking, yes. Imagine there's an I/O exception thrown
> from the logging call (disk full, no write access, network access,
> etc.), then your function would not be "safe" anymore.
>

-- 
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: Can't send from agent error handler?

2010-06-24 Thread ka
I'm also facing the same problem -

(let [handler (agent 50)
a (agent 42
:error-handler
(fn [_ ex]
  (do
(println "Inside agent a error handler fn" (Thread/
currentThread))
(send handler
  (fn [_] (do (println ex (Thread/currentThread)))
60))
(println "Inside agent a error handler fn - after
sending to the handler agent")
(await handler)
(println "CODE DOESN'T REACH HERE ??")
(println "State of handler agent:" @handler]
(send a (fn [_]
  (println "Inside agent a function" (Thread/
currentThread))
  (throw (Exception. "bad news"
(Thread/sleep 1000)
;(println "Errors with a:" (agent-error a))
;(println "Errors with handler:" (agent-error handler))
(shutdown-agents)
(println "Errors with a:" (agent-error a))
(println "Errors with handler:" (agent-error handler))
(println @a)
(println @handler))

- Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Compiling a namespace causes subsequent uses of it to fail.

2010-06-24 Thread philip.hazel...@gmail.com
On Jun 23, 12:29 pm, Stuart Halloway 
wrote:
> I think the behavior you are seeing here is reasonable. When you mix 
> compilation and dynamic access to vars, you need to reason carefully about 
> the order in which things will happen.

In general I would say that code working differently depending on
whether it's compiled or not is a bug. But I understand that as bugs
go, this one is probably not a big deal, and may be more trouble than
it's worth to fix. At the least I think a note should be added
somewhere to the docs about it though.

> More usefully: you can write a test in your var-get expression that will make 
> it do what you want in all scenarios. Just add a bound? test before trying to 
> get the value out of variable.

Thanks. I'll bear this in mind if I ever pick up the code again.

Phil

>
> Sorry this was missed earlier.
>
> Cheers,
> Stu
>
> > (ns testcomp)
> > (var-get (or (ns-resolve *ns* 'foo)
> >         (intern *ns* 'foo :foo)))
> > ;; foo                       ;(1)
> > ;; (println foo)             ;(2)
> > ;; (do foo 3)                ;(3)
> > ;; (fn [] foo)               ;(4)
> > ;; ((fn [] foo))             ;(5)
> > ;; ((fn [] (println foo)))   ;(6)
>
> > With (1)-(6) all commented out, behaviour is as expected: you can
> > compile and use testcomp, and foo is bound to :foo.
>
> > With any of (1)-(3) uncommented, you can use testcomp with no problems
> > as long as it's uncompiled. If you compile it and subsequently attempt
> > to use it, you get an ExceptionInInitializerError caused by an
> > IllegalStateException due to Var testcomp/foo being unbound. What
> > seems to be happening (according to my limited understanding of
> > compilation) is that testcomp__init.class contains a reference to foo
> > which causes it to be interned (but unbound) before the body code is
> > run. ns-resolve then sees this Var, returns it, and var-get raises an
> > exception.
>
> > With (1)-(3) commented out, (4)-(6) can be uncommented and expected
> > behaviour returns. testcomp__init.class no longer contains a reference
> > to foo (I checked with grep).
>
> > I'm doing something like this in a library, and (5)/(6) provide a
> > workaround, but is this something that can be fixed at the language
> > level? I recognise it's not an issue that will commonly be run into,
> > and that the complexities of compilation might make it unavoidable.
>
> > java version "1.6.0_14", clojure commit
> > 5f1e6ed540eab11281b7bfb19f831b7e445ed0d0 (1 Sep 09).
> > --~--~-~--~~~---~--~~
> > 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: scala

2010-06-24 Thread Saul Hazledine
On Jun 18, 11:56 pm, cageface  wrote:
>
> Unfortunately there seems to be a lot more commercial momentum for
> Scala though. It's still a blip compared to the mainstream languages
> but I'm seeing more and more job posts mentioning it, and hardly any
> for Clojure. I don't think Scala is a bad language overall, but I'm
> not sure I'd dump Ruby for it. On the other hand, I can imagine
> migrating most of my dev work over to Clojure with the right project.
> Has anybody else wrestled with this choice? Any thoughts?

I started playing with Scala before I decided to make a long term
commitment to learning and using Clojure. I think Scala is both
exciting and awesome. The only thing that bothered me about it was the
community's choice of a two space indent (its very tiring to look
after a few hours).

I ended up choosing Clojure for my own needs because the availability
of macros and I enjoy programming in Clojure more than other
languages. Personally I feel big corporate style projects destroy a
language - I've seen simple elegant Java code but the culture went in
a different direction entirely. So I personally would be happier if
Scala goes mainstream and Clojure doesn't.

The really cool thing though, is that with the JVM, Clojure and Scala
can interoperate.

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: Enhanced Primitive Support

2010-06-24 Thread Heinz N. Gies
Another thing I noticed, clojures array functions are using int's as index, so 
to get best performance from them you currently need to cast every counter you 
use to a int by hand so you have (loop [i (int 0)] ... since otherwise there 
will be a lot of type casting when accessing arrays. So a good course of 
action, in regards of this changes might be to change aget and aset to use long 
indices.

Regards,
Heinz

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


calling an overloaded java method

2010-06-24 Thread Martin DeMello
This works:

  (. JOptionPane showMessageDialog frame "Hello World")

This does not:

  (. JOptionPane showMessageDialog frame "Hello World" "Title"
JOptionPane/PLAIN_MESSAGE)

Even though JOptionPane.showMessage supports both signatures. How do I
call the second one from clojure?

martin

-- 
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: calling an overloaded java method

2010-06-24 Thread Meikel Brandmeyer
Hi,

On Jun 24, 3:53 pm, Martin DeMello  wrote:

> This works:
>
>   (. JOptionPane showMessageDialog frame "Hello World")
>
> This does not:
>
>   (. JOptionPane showMessageDialog frame "Hello World" "Title"
> JOptionPane/PLAIN_MESSAGE)
>
> Even though JOptionPane.showMessage supports both signatures. How do I
> call the second one from clojure?

Both work for me. What's the error you get?

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: calling an overloaded java method

2010-06-24 Thread Martin DeMello
On Thu, Jun 24, 2010 at 7:32 PM, Meikel Brandmeyer  wrote:
> Hi,
>
> On Jun 24, 3:53 pm, Martin DeMello  wrote:

> Both work for me. What's the error you get?

Looks like my mistake, I tried it now and it works. No idea what I did
wrong the last time (I got the No matching method: showMessageDialog
error).

martin

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


Weird problem with lazy seqs and throwing exceptions

2010-06-24 Thread Steve Molitor
I'm having trouble throwing an exception with the error message I want from
a list of error codes.  Here's a simple example of the problem:

(def messages (map #(str %) [1 2 3]))
(println messages)
(throw (java.lang.Exception. (str "Whoops: " messages)))

The println prints the messages just fine - I see "1 2 3".  However the
exception message contains something like 'clojure.lang.lazy...@13291'
instead of "1 2 3".  Here's a REPL session:

user=> (def messages (map #(str %) [1 2 3]))
#'user/messages
user=> (println messages)
(1 2 3)
nil
user=> (throw (java.lang.Exception. (str "Whoops: " messages)))
java.lang.Exception: Whoops: clojure.lang.lazy...@13291 (NO_SOURCE_FILE:0)


What am I missing?  I want the exception message to display as "Whoops: 1 2
3".

This happens with clojure 1.1 and a recent snapshot of 1.2.

Thanks.

Steve

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

Is it possible to define custom atom/data types?

2010-06-24 Thread Tim Robinson
Is it possible to define custom atom/data types?

Example: I would like an atom prefixed with $ to maintain it's own
type/class.

i.e.
> (class $myatom)
clojure.lang.CustomeName

Thanks,
Tim

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


Data Access Layer design

2010-06-24 Thread michaelr524
Hi,

I've started developing a web application using Compojure. I use
CouchDB for storing data.
Currently I've just created a dal.clj file to contain all the CRUD
functions.
I might later decide that I want to switch to other Database so I want
to make the ground ready for this.

So my question is, how would you design a DAL in Clojure?
Can protocols be exploited here?

Thanks
Michael

-- 
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: Question about "every?"

2010-06-24 Thread michele

Ok, then I understand why it didn't work, but that means that the
struct (that is sent by the add-message function) is put in a sequence
somewhere on the way to being validated. Is this right, and where does
this happen?


;All the relevant code

(defstruct message :sender :text)

(def validate-message-list
  (partial every? #(and (:sender %) (:text %

(def messages (ref [] :validator validate-message-list))

(defn add-message [msg]
  (dosync (alter messages conj msg)))

(add-message (struct message "mm" "first message"))





On Jun 23, 12:58 pm, Stuart Halloway 
wrote:
> Hi Michele,
>
> Pass a sequence of maps, not just a map:
>
> (every? #(:x %) [{:x "s"}])
> -> true
>
> Cheers,
> Stu
>
>
>
> > In the book "Programming Clojure" (p2_0, pdf, page 185) "Adding
> > Validation to Refs" there is this code:
>
> > (def validate-message-list (partial every? #(and (:sender %) (:text
> > %
>
> > This works fine as a validator, but when I try the code directly - not
> > as a validator - it returns false. I also tested with a simple "if" to
> > see the difference.
>
> > (every? #(:x %) {:x "s"})
> > -> false
>
> > (if (#(:x %) {:x "s"}) "TRUE" "FALSE")
> > -> "TRUE"
>
> > What do I not understand?
>
> > --
> > 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: State of Clojure web development

2010-06-24 Thread Jimmy
Hi James,
For me the big missing item is Comet/Websockets support. More and more
of the web
development I do requires near real time communication and to have
that feature integrated
in the framework (like lift) would be great.
thanks
Jimmy

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure.contrib.logging in "side-effect free" functions?

2010-06-24 Thread William Wadsworth
Hi!

On Jun 24, 12:04 pm, ka  wrote:
> To my naive inexperienced eyes, there doesn't seem to be something
> obviously wrong with your code.
>
> > Since FOR returns a lazy sequence of the results, is this function
> > safe?  (Seeing that it is not side-effect free?)
>
> I'm not getting this, do you foresee any safety issues?  I think that
> the logs will be created as you're writing to the out.csv.  If you
> want the logs be written before you start writing to out.csv, you may
> realize the lazy-seq for returns.
>

I am creating log entries as I read the lines. My worry was that I
might
get the log writer being interrupted in the middle of a line write.
This
I figure will be easily handled by the agent in the logger package.
(I have perused the logging code and found that the agent is used to
serialize write requests. So the code will work fine.)

> > BTW:
> >   clojure.contrib.loggingindicates that it can use an agent for
> >  logging. Is my assumption that invoking the logger (with or without
> >   an agent) within a function would still mean that the function has
> >   side-effects correct?
>
> Yes, any change in state or IO means side effect.
>
> - Thanks

Thanks.

Martin.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure.contrib.logging in "side-effect free" functions?

2010-06-24 Thread William Wadsworth
Hi!

On Jun 24, 12:16 pm, Laurent PETIT  wrote:
> 2010/6/24 Laurent PETIT :
>
>
>
> > Hi,
>
> > 2010/6/17 William Wadsworth :
> >> Hi.
>
> >> I have just started learning Clojure and I am really enjoying
> >> myself. However, I am still getting to grips with the workings of its
> >> concurrency model, so please excuse me if my question seems too
> >> obvious.
>
> >> I have some code that reads data from a file, parses it and generates
> >> a CSV file. The flow is as follows:
>
> >> 
> >> (use 'clojure.contrib.duck-streams)
> >> (use 'clojure.contrib.pprint)
>
> >> (defn parse-line [s]
> >>  (cl-format nil "~{\"~A\"~^,~}" (into [] (.split s ";"
>
> >> (let [input-seq (for [line (read-lines "input.dat")]
> >>                  (parse-line line))]
> >>  (write-lines "out.CSV" input-seq))
> >> 
>
> >> Now the question:
>
> >> I would like to generate log entries for any malformed lines occurring
> >> in the input file. Once of the ways might be to do this in parse-line
> >> using clojure.contrib.loggingas follows:
>
> >> 
> >> (use 'clojure.contrib.logging)
>
> >> (defn parse-line [s]
> >>  (let [cs (into [] (.split s ";"))]
> >>    (if (= (count cs) 5)
> >>      (cl-format nil "~{\"~A\"~^,~}" cs)
> >>      (error "Incorrect number of columns in file."
> >> 
>
> >> Since FOR returns a lazy sequence of the results, is this function
> >> safe?  (Seeing that it is not side-effect free?)
>
> > You have to acknowledge that the calls to parse-line will not
> > necessarily occur during the call to for, but maybe not before calling
> > write-lines, maybe partly if chunked-seqs are in play (sequences
> > preloading items in chunks of 32 items for example). And, if there is
> > an exception that is not thrown in write-lines, your logs may miss the
> > error logs for some of the remaining items not yet consumed by
> > write-lines.
>
> s/if there is an exception that is not thrown in write-lines/if there is
> an exception that *is* thrown in write-lines/
>
>

That is clear. Thanks.

While on the same topic: using read-lines on a large file (~80MB)
results
in an OutOfMemoryException. (I am running the JVM with -client rather
than
-server). To me, this is unexpected since read-lines lazily reads the
file
contents (and I also presume that the lines are not being cached in
memory).
Is there any way of being more memory efficient other than iteratively
reading
file contents using using .readLine?

>
> >> BTW:
> >>  clojure.contrib.loggingindicates that it can use an agent for
> >>  logging. Is my assumption that invoking the logger (with or without
> >>  an agent) within a function would still mean that the function has
> >>  side-effects correct?
>
> > Technically speaking, yes. Imagine there's an I/O exception thrown
> > from theloggingcall (disk full, no write access, network access,
> > etc.), then your function would not be "safe" anymore.
>
>

-- 
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: Weird problem with lazy seqs and throwing exceptions

2010-06-24 Thread Meikel Brandmeyer
Hi,

On Jun 24, 6:34 am, Steve Molitor  wrote:

> user=> (throw (java.lang.Exception. (str "Whoops: " messages)))
> java.lang.Exception: Whoops: clojure.lang.lazy...@13291 (NO_SOURCE_FILE:0)

Wrap messages into a call to seq.

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: Question about "every?"

2010-06-24 Thread Stuart Halloway
You are correct. The struct is a single message. The messages object holds a 
ref to N of them (initially an empty vector).

Individual messages are added by alter ... conj in add-message.

Stu

> 
> Ok, then I understand why it didn't work, but that means that the
> struct (that is sent by the add-message function) is put in a sequence
> somewhere on the way to being validated. Is this right, and where does
> this happen?
> 
> 
> ;All the relevant code
> 
> (defstruct message :sender :text)
> 
> (def validate-message-list
>  (partial every? #(and (:sender %) (:text %
> 
> (def messages (ref [] :validator validate-message-list))
> 
> (defn add-message [msg]
>  (dosync (alter messages conj msg)))
> 
> (add-message (struct message "mm" "first message"))
> 
> 
> 
> 
> 
> On Jun 23, 12:58 pm, Stuart Halloway 
> wrote:
>> Hi Michele,
>> 
>> Pass a sequence of maps, not just a map:
>> 
>> (every? #(:x %) [{:x "s"}])
>> -> true
>> 
>> Cheers,
>> Stu
>> 
>> 
>> 
>>> In the book "Programming Clojure" (p2_0, pdf, page 185) "Adding
>>> Validation to Refs" there is this code:
>> 
>>> (def validate-message-list (partial every? #(and (:sender %) (:text
>>> %
>> 
>>> This works fine as a validator, but when I try the code directly - not
>>> as a validator - it returns false. I also tested with a simple "if" to
>>> see the difference.
>> 
>>> (every? #(:x %) {:x "s"})
>>> -> false
>> 
>>> (if (#(:x %) {:x "s"}) "TRUE" "FALSE")
>>> -> "TRUE"
>> 
>>> What do I not understand?
>> 
>>> --
>>> 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: Question about "every?"

2010-06-24 Thread Meikel Brandmeyer
Hi,

alter calls conj on [] (which is kept as a vector) since it is the
initial content of the messages ref. So the content of messages is a
seqable thing and not a single message.

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: State of Clojure web development

2010-06-24 Thread Wilson MacGyver
On Wed, Jun 23, 2010 at 5:23 PM, James Reeves
 wrote:
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?

we are currently developing a game server backend using clojure.

> 2. Which libraries or frameworks are you using? Which versions?
>

we are using grails for the web app aspect, and uses the grails
plugin to call clojure code.

> 3. What made you choose Clojure to develop web applications in? What
> are the strengths of Clojure web development?

in this case, we are really using grails for the web aspect, but uses
clojure for AI and game logic. clojure is very good at that.

>
> 4. What do you think are the current weaknesses of web development in
> Clojure? What could be improved?
>

too many scattered libraries and approaches. For me, it's about
problem solving. I would like to be able to just grab something, and
get it started. Right now, if a new clojure user ask, I want to develop
a web app, what should I use? Compojure? Ring? What template
system should I use? enlive? str html? hiccup? How do you deal with
database? clj-record? clojuresql? How do you make outbound
REST request?

> 5. Anything else you want to comment on?

clojure is still young. I hope in time, a web dev approach that's
more clojure-ish. lift has done a good way to show what a web
framework using scala and functional style would look like.

I look forward to see something like this for clojure one day.

-- 
Omnem crede diem tibi diluxisse supremum.

-- 
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: ops' macro to tidy +', -', *', /' operations?

2010-06-24 Thread miner
I'd call it with-auto-promotion.

-- 
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: State of Clojure web development

2010-06-24 Thread Daniel Gagnon
I don't use Clojure for web development and I thought sharing why could be
useful too.

For web development, my favourite tool is
Django.
It comes as a fullstack framework which means I have everything I need out
of the box. Templates, caching, ORM, a kick-ass autogenerated admin section,
cross-domain request forgery protection etc. and the documentation is really
top notch.

I'd rather have Clojure than Python but all the goodness that Django
provides is such a time saver that I feel I'd lose too much time with
Clojure.

If I had a full-stack, well-documented clojure framework, I'd jump to 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: State of Clojure web development

2010-06-24 Thread MarkSwanson

>
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?

I've created a commercial app that has the server side written start
to finish in Clojure. It leverages the existing calendaring and
scheduling functionality of ScheduleWorld - which was written in Java.
(It was trivial to do this using
Clojure)

http://www.ScheduleWorld.com/em
(It came out of beta last week.)

> 2. Which libraries or frameworks are you using? Which versions?

Compojure - patched from git now and then to work with Clojure 1.2.

> 3. What made you choose Clojure to develop web applications in? What
> are the strengths of Clojure web development?

It's difficult to answer this in a couple of sentences - all of
strengths of Clojure come into play here. Rich's videos that explain
the strengths of Clojure all turn out to be true.
I've been coding enterprise server-side services for ~20 years using C/
C++/Java.
Compared to C/C++/Java I've found the strengths of Clojure beget:

1. better designs
2. less bugs: immutable data, better designs, STM, atoms, ...
3. faster code given the same effort: lazy sequences, memoization,
clojure.[core,contrib],
4. better productivity: the REPL, the Clojure language, etc. it all
snowballs here.

> 4. What do you think are the current weaknesses of web development in
> Clojure? What could be improved?

weaknesses: none really. I sometimes miss the perfect command
completion (with auto import generation) provided by Eclipse/Java when
I do Java interop. But this is an editor issue. (And I'm really happy
with vimclojure.)

Improved: I think I'd be happy with Clojure and Compojure as they
stand for a long time. But since you asked:

LOGGING: The current logging capabilities are not useful to people
creating services with lots of users. The only way logging is useful
is to have one file peruser logging. We wrote our own logging system
that does this and it works great. At midnight the logging system
creates a new directory (based on the date) andstarts using that. So
if someone emails and says at this date/time operation X failed we can
easily analyze the logs around that time.
(A while back ScheduleWorld was signing up 800 people / day with 8000
simultaneous established http connections doing work. Imagine the
intertwined logging data...Per user logging is the best way.)


> 5. Anything else you want to comment on?

Thank you for creating Compojure.
1. defroutes = excellent way of defining our services.
2. decorate = fantastic fine-grained way for us to decorate our
services.
3. requests just have to return a map. Excellent.

Compojure is simple to use and never gets in the way. We have nginx
fronting a cluster of boxes. Our Compojure services respond to
requests, and sometimes theyalso dynamically create and manage static
responses (nginx returns a static file if the request has been seen
before and no other request invalidates the cached response).

(The other Clojure web frameworks might be as good. I don't meant to
take anything away from them. I have only used Compojure.)

Cheers.

-- 
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: State of Clojure web development

2010-06-24 Thread Brenton
1. Have you written, or are you writing, a web application that uses
Clojure? What does it do?

I am an independent contractor and do a lot of corporate intranet web
applications. All of my clients support Java. Each year I write a few
new applications and spend a lot of time maintaining old Java
applications. The first new application that I wrote this year was
pure Clojure. It was a very simple application for collecting ideas
from employees. It was great to be able to use Lisp and yet integrate
and deploy into a Java environment. The application was deployed to
WebSphere as a war file, connects to an SQL Server database and uses
the company's LDAP Java libraries. I plan to use Clojure for all new
projects.

I also work for a research group with a bunch of statisticians
building web based tools based on the work that they do. Usually
taking some nasty spreadsheet that someone has created and turning it
into a web application. Clojure (functional programming) with Incanter
will be a perfect fit for this type of project.

2. Which libraries or frameworks are you using? Which versions?

[org.clojure/clojure "1.1.0"]
[org.clojure/clojure-contrib "1.1.0"]
[compojure "0.4.0-RC3"]
[hiccup "0.2.3"]
[sandbar "0.2.4"]
[enlive "1.0.0-SNAPSHOT"]
[carte "0.1.0"]
[inflections "0.3"]

I am also working on Sandbar and Carte. Sandbar provides middleware to
allow one to work with the session as if it were a global map with put
and get functions. It also provides middleware for authentication and
authorization. Carte is non-object oriented relational mapping. Both
are very new.

3. What made you choose Clojure to develop web applications in? What
are the strengths of Clojure web development?

1. Functional programming is a better fit than OO for web
applications.
2. Lisp is as DRY as you can get. Every other environment that I have
worked in, you get to some point where you can no longer create
abstractions and have to resort to design patterns, code generation or
non-primary language configuration. I don't see this ever happening
with Clojure.
3. It is just Java. Easy deployment into any Java container. Clients
get a Java app and there is much rejoicing.
4. Mutable objects as a default are bad, even for web applications.
5. Interactive REPL development.
6. Ring and Compojure are exactly what I want as the foundation for my
web applications: simple, small and extensible. Middleware is
wonderful.

4. What do you think are the current weaknesses of web development in
Clojure? What could be improved?

Packaging and deployment seem to be the big problem at this point. I
have a lot experience with Java web applications so it is not that
difficult for me to create a war for deployment but I can see that
someone without a Java background would be completely confused by
this. I would love to see a tool that can package my app into a war
including a REPL server.

It would also be nice to have easily accessible, thorough,
documentation for Ring and Compojure with example code that goes
beyond the most simple cases. The community is young and so there is a
lack of shared knowledge about best practices when developing larger
applications.

One of the things that I like about Clojure web development (the
flexibility) also causes some concern. In my opinion, the best thing
about Rails is that any developer who knows Rails can go to any Rails
project and know where everything is. The conventions of Rails have
also contributed greatly to Rails' ability to grow and innovate. I
don't know what the solution is, just wanted to bring this up.

5. Anything else you want to comment on?

Many thanks to Mark and James for all of your work on Ring and
Compojure. Without these two libraries there wouldn't be much Clojure
web development going on. Also, thanks for keeping it simple and not
trying to do too much.

On Jun 23, 2:23 pm, James Reeves  wrote:
> Hello there!
>
> Chas Emerick's recent "State of Clojure" survey [http://bit.ly/dtdAwb]
> indicated that a significant proportion of Clojure users are beginning
> to use Clojure for web development. A recent Hacker News posting
> [http://bit.ly/91Bu5J] seems to corroborate these results, with
> several Clojure-based web applications already out in the wild.
>
> As one of the main developers of Ring and Compojure, I'd be very
> interested to hear more about how people are using Clojure to build
> web apps. To this end, I have a few questions I'd like to quiz Clojure
> web developers about:
>
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?
>
> 2. Which libraries or frameworks are you using? Which versions?
>
> 3. What made you choose Clojure to develop web applications in? What
> are the strengths of Clojure web development?
>
> 4. What do you think are the current weaknesses of web development in
> Clojure? What could be improved?
>
> 5. Anything else you want to comment on?
>
> Please reply to this thread with your answers, and thank you very much
>

Re: Is it possible to define custom atom/data types?

2010-06-24 Thread Meikel Brandmeyer
Hi,

Am 24.06.2010 um 07:36 schrieb Tim Robinson:

> Is it possible to define custom atom/data types?
> 
> Example: I would like an atom prefixed with $ to maintain it's own
> type/class.
> 
> i.e.
>> (class $myatom)
> clojure.lang.CustomeName

You can use the old way of "defining" types: by adding a tag to the metadata of 
the atom.

user=> (def a (atom nil :meta {:type ::MyType}))
#'user/a
user=> (type a)
:user/MyType
user=> (def b (atom nil))
#'user/b
user=> (type b)
clojure.lang.Atom

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: State of Clojure web development

2010-06-24 Thread Chas Emerick
Good point.  I have a todo waiting for me to figure out how to deliver  
some services that HTTP might not be cut out for.  It looks like v3.0  
servlets have a variety of enhancements in this area, so hopefully  
compojure/ring can stand on those shoulders.  I've no idea about the  
container support in that area though.


- Chas

On Jun 24, 2010, at 8:12 AM, Jimmy wrote:


Hi James,
For me the big missing item is Comet/Websockets support. More and more
of the web
development I do requires near real time communication and to have
that feature integrated
in the framework (like lift) would be great.
thanks
Jimmy

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient  
with your first post.

To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure.contrib.logging in "side-effect free" functions?

2010-06-24 Thread Laurent PETIT
2010/6/24 William Wadsworth :
> Hi!
>
> On Jun 24, 12:16 pm, Laurent PETIT  wrote:
>> 2010/6/24 Laurent PETIT :
>>
>>
>>
>> > Hi,
>>
>> > 2010/6/17 William Wadsworth :
>> >> Hi.
>>
>> >> I have just started learning Clojure and I am really enjoying
>> >> myself. However, I am still getting to grips with the workings of its
>> >> concurrency model, so please excuse me if my question seems too
>> >> obvious.
>>
>> >> I have some code that reads data from a file, parses it and generates
>> >> a CSV file. The flow is as follows:
>>
>> >> 
>> >> (use 'clojure.contrib.duck-streams)
>> >> (use 'clojure.contrib.pprint)
>>
>> >> (defn parse-line [s]
>> >>  (cl-format nil "~{\"~A\"~^,~}" (into [] (.split s ";"
>>
>> >> (let [input-seq (for [line (read-lines "input.dat")]
>> >>                  (parse-line line))]
>> >>  (write-lines "out.CSV" input-seq))
>> >> 
>>
>> >> Now the question:
>>
>> >> I would like to generate log entries for any malformed lines occurring
>> >> in the input file. Once of the ways might be to do this in parse-line
>> >> using clojure.contrib.loggingas follows:
>>
>> >> 
>> >> (use 'clojure.contrib.logging)
>>
>> >> (defn parse-line [s]
>> >>  (let [cs (into [] (.split s ";"))]
>> >>    (if (= (count cs) 5)
>> >>      (cl-format nil "~{\"~A\"~^,~}" cs)
>> >>      (error "Incorrect number of columns in file."
>> >> 
>>
>> >> Since FOR returns a lazy sequence of the results, is this function
>> >> safe?  (Seeing that it is not side-effect free?)
>>
>> > You have to acknowledge that the calls to parse-line will not
>> > necessarily occur during the call to for, but maybe not before calling
>> > write-lines, maybe partly if chunked-seqs are in play (sequences
>> > preloading items in chunks of 32 items for example). And, if there is
>> > an exception that is not thrown in write-lines, your logs may miss the
>> > error logs for some of the remaining items not yet consumed by
>> > write-lines.
>>
>> s/if there is an exception that is not thrown in write-lines/if there is
>> an exception that *is* thrown in write-lines/
>>
>>
>
> That is clear. Thanks.
>
> While on the same topic: using read-lines on a large file (~80MB)
> results
> in an OutOfMemoryException. (I am running the JVM with -client rather
> than
> -server). To me, this is unexpected since read-lines lazily reads the
> file
> contents (and I also presume that the lines are not being cached in
> memory).
> Is there any way of being more memory efficient other than iteratively
> reading
> file contents using using .readLine?

You're probably holding the head. Can you share the code ?

-- 
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: slow raw io

2010-06-24 Thread cageface
Has anyone else had a chance to try this? I'm surprised to see manual
buffering behaving so much better than the BufferedReader
implementation but it does seem to make quite a difference.

-- 
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: Weird problem with lazy seqs and throwing exceptions

2010-06-24 Thread Steve Molitor
That did the trick, thanks.

Steve

On Thu, Jun 24, 2010 at 9:43 AM, Meikel Brandmeyer  wrote:

> Hi,
>
> On Jun 24, 6:34 am, Steve Molitor  wrote:
>
> > user=> (throw (java.lang.Exception. (str "Whoops: " messages)))
> > java.lang.Exception: Whoops: clojure.lang.lazy...@13291(NO_SOURCE_FILE:0)
>
> Wrap messages into a call to seq.
>
> 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
>

-- 
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: Is it possible to define custom atom/data types?

2010-06-24 Thread Tim Robinson
Thanks! I think that should do it for me.

I've been writing my own custom *semi* JSON parser/combinator (JSON
only hacked to  let me to include js functions).
My first cut works, but I had implemented string searches for js
qualifiers. I didn't like the implementation since it string searches
every string, js-fn or not.
And since I have to check type already I can use that without adding
any real overhead.

Thanks.
Tim


On Jun 24, 11:42 am, Meikel Brandmeyer  wrote:
> Hi,
>
> Am 24.06.2010 um 07:36 schrieb Tim Robinson:
>
> > Is it possible to define custom atom/data types?
>
> > Example: I would like an atom prefixed with $ to maintain it's own
> > type/class.
>
> > i.e.
> >> (class $myatom)
> > clojure.lang.CustomeName
>
> You can use the old way of "defining" types: by adding a tag to the metadata 
> of the atom.
>
> user=> (def a (atom nil :meta {:type ::MyType}))
> #'user/a
> user=> (type a)
> :user/MyType
> user=> (def b (atom nil))
> #'user/b
> user=> (type b)
> clojure.lang.Atom
>
> 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: State of Clojure web development

2010-06-24 Thread Martin Jul
We have written a currency trading app in Clojure in my company.
It has an embedded web server with a compojure app that provides an
administration interface.

2. Which libraries or frameworks are you using? Which versions?

Some relevant dependencies are:


 [compojure "0.4.0-SNAPSHOT"]
 [hiccup "0.2.1"]
 [ring/ring-devel "0.2.0"]
 [ring/ring-httpcore-adapter "0.2.0"]
 [ring/ring-jetty-adapter "0.2.0"]
 [ring/ring-servlet "0.2.0"]
 [commons-fileupload/commons-fileupload "1.2.1"]]

3. What made you choose Clojure to develop web applications in? What
are the strengths of Clojure web development?

The entire app is Clojure and Compjure/Hiccup is very powerful so we
could build the web UI surprisingly quickly and in very little code.
The order of magnitude simplification reminds me of switching to Rails
and how it made everything prior to that look bloated and complex by
comparison. Compojure is to Rails what Rails is to ASP.NET.


4. What do you think are the current weaknesses of web development in
Clojure? What could be improved?

At the time we needed an easy way to bind configuration information to
the routes (we ended up wrapping each request with the configuration
data which is a bit cumbersome). A more explicit way would be to use
some kind of partial evaluation to bind the relevant settings to each
route.

5. Anything else you want to comment on?

Clojure and Compojure rock! Thanks for your work on the library :-)

-- 
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: State of Clojure web development

2010-06-24 Thread Tim Robinson


1. Have you written, or are you writing, a web application that uses
Clojure? What does it do?

I am new to Clojure, I've ported over most of my code for an ad-hoc
application creator / with reporting and GIS integration.
I'm pretty much finished. I benchmarking speed.

2. Which libraries or frameworks are you using? Which versions?

My own custom frameworks. I use some contrib stuff.

3. What made you choose Clojure to develop web applications in? What
are the strengths of Clojure web development?

Strengths:
* Allows for creating succinct code to manage complex data.
* Access to many libraries (that are current and active).
* Not forced to include BS code for OO abstractions.

Weakness:

REPL errors. Seems fragile. If I hit an error, some errors corrupt
something under the hood,
ie. reloading the corrections doesn't help I have to close the REPL
then restart.
I'm familiar with REPLs - This is odd, but it's probably a JVM issue.

4. What do you think are the current weaknesses of web development in
Clojure? What could be improved?

Nothing big yet.

5. Anything else you want to comment on?

Only one week into Clojure I could be too green, but:

I would like some chaining to less the brackets.
i.e.

> (def stuff {:key1 {:item1 {:sub1 val1}})
> (((stuff :key1) :item1) sub1)  <--- YUCK
val1

Instead do this:
> stuff:key1:item1:sub1
val1

Also, some of the function names don't make sense:
(def stuff (list 1 2 3 4 5))
> (rest stuff)
(2 3 4 5)
> (next stuff)
(2 3 4 5) < this can be done with rest.

In my mind 'next' should:
> (next stuff)
2
> (next 2 stuff)
(2 3)

etc etc..

Tim
On Jun 23, 3:23 pm, James Reeves  wrote:
> Hello there!
>
> Chas Emerick's recent "State of Clojure" survey [http://bit.ly/dtdAwb]
> indicated that a significant proportion of Clojure users are beginning
> to use Clojure for web development. A recent Hacker News posting
> [http://bit.ly/91Bu5J] seems to corroborate these results, with
> several Clojure-based web applications already out in the wild.
>
> As one of the main developers of Ring and Compojure, I'd be very
> interested to hear more about how people are using Clojure to build
> web apps. To this end, I have a few questions I'd like to quiz Clojure
> web developers about:
>
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?
>
> 2. Which libraries or frameworks are you using? Which versions?
>
> 3. What made you choose Clojure to develop web applications in? What
> are the strengths of Clojure web development?
>
> 4. What do you think are the current weaknesses of web development in
> Clojure? What could be improved?
>
> 5. Anything else you want to comment on?
>
> Please reply to this thread with your answers, and thank you very much
> in advance for your time. I really appreciate any feedback you can
> provide.
>
> - James

-- 
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: State of Clojure web development

2010-06-24 Thread David Nolen
On Thu, Jun 24, 2010 at 3:12 PM, Tim Robinson wrote:

>
> > (def stuff {:key1 {:item1 {:sub1 val1}})
> > (((stuff :key1) :item1) sub1)  <--- YUCK
> val1
>

(get-in m [:key1 :item1 :sub1]) <--- YUM ;)


> > (rest stuff)
> (2 3 4 5)
> > (next stuff)
> (2 3 4 5) < this can be done with rest.
>

There are subtle but important differences between next and rest. You should
refer to their documentation.

Oh yeah, and web development with Clojure rocks:

[enlive "1.0.0-SNAPSHOT"]
[net.cgrand/moustache "1.0.0-SNAPSHOT"]
[ring "0.2.3"]
[clj-time "0.1.0-SNAPSHOT"]
[com.twinql.clojure/clj-apache-http "2.1.0"]

At the moment I use nginx proxying to embedded Jetty. Works fine for me,
though I'm interested in hearing or reading documentation about what other
people are doing.

-- 
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: State of Clojure web development

2010-06-24 Thread David Nolen
On Thu, Jun 24, 2010 at 12:27 PM, Daniel Gagnon wrote:

> I don't use Clojure for web development and I thought sharing why could be
> useful too.
>
> For web development, my favourite tool is 
> Django.
> It comes as a fullstack framework which means I have everything I need out
> of the box. Templates, caching, ORM, a kick-ass autogenerated admin section,
> cross-domain request forgery protection etc. and the documentation is really
> top notch.
>
> I'd rather have Clojure than Python but all the goodness that Django
> provides is such a time saver that I feel I'd lose too much time with
> Clojure.
>
> If I had a full-stack, well-documented clojure framework, I'd jump to that
>

full-stack frameworks take time to evolve, and even then for many projects
they aren't a good fit since they impose a both narrow perspective and a
heavy cognitive load (massive APIs). In my experience development in Clojure
is just as fast as it is in Django. The main thing lacking is documentation
of the Clojure goodies that are currently available.

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

Protocols and visitor pattern

2010-06-24 Thread Brent Millare
Are there any good articles on clojure double dispatch using protocols
(not multimethods) via the visitor pattern or whatever would be
appropriate? I feel like that after single dispatch on type, double
dispatch on type is the next common use case for multimethods. I
somewhat recall Rich talking about this on the internet somewhere
(including discussion of adding/not-adding language support) but I
can't seem to find 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: State of Clojure web development

2010-06-24 Thread Tim Robinson

Thanks for both the replies.

(get-in m [:key1 :item1 :sub1]) <--- YUM ;)

(-> stuff :key1 :item1 sub1)

are better than what I've been doing!

Re: (next...)

I still like mine better, fortunately I can create my own functions,
but I was just highlighted that some of the function names are not
intuitive (to me).
Most of them are good.

Along this vein, I find the documentation is great, but a little hard
to navigate around.
Example to find a list of predicates requires hunting. Is there a
trick?  I know ' source' and 'find-doc', but I'm constantly
searching :)
This is a really niggly point since relatively speaking it's well
done.

As I said, I'm green. I'll get there soon I promise :)

Tim



On Jun 24, 1:48 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> Am 24.06.2010 um 21:12 schrieb Tim Robinson:
>
> > I would like some chaining to less the brackets.
> > i.e.
>
> >> (def stuff {:key1 {:item1 {:sub1 val1}})
> >> (((stuff :key1) :item1) sub1)  <--- YUCK
> > val1
>
> > Instead do this:
> >> stuff:key1:item1:sub1
> > val1
>
> (-> stuff :key1 :item1 sub1)
>
> > Also, some of the function names don't make sense:
> > (def stuff (list 1 2 3 4 5))
> >> (rest stuff)
> > (2 3 4 5)
> >> (next stuff)
> > (2 3 4 5) < this can be done with rest.
>
> next and rest are not the same. Seehttp://clojure.org/lazy.
>
> 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: Hiring again - need 3 devs before fall 2010

2010-06-24 Thread Steve Molitor
Tim,

I just sent my resume to j...@sonian.net.

Thanks!

Steve Molitor

On Wed, Jun 23, 2010 at 12:02 PM, Tim Dysinger  wrote:

> Sorry I didn't provide enough detail on that last post.  Please send
> your interest to jobs on sonian.net with "clojure" in the subject.
>
> On Wed, Jun 23, 2010 at 8:24 AM, Tim Dysinger  wrote:
> > Hello,
> >
> > It's that time again.  I need to hire some more full-time
> > work-from-home pair-programming emacs/unix/math-loving clojure devs.
> > Join our team of 7 devs who write clojure full time.  We will be
> > bringing on a dev a month over the summer.  The ideal candidate has
> > some unix, jvm & coljure/lisp/fp experience under his/her belt (her! -
> > we need more diversity) and is a fun person to work with (no grumpy or
> > solo types).
> >
> > Job comes with a macbook pro & 3g so you can work anywhere (in the
> > US).  We aren't hiring out-of-country right now.
> >
> > Tim Dysinger, VP Eng.
> > Sonian Networks [ http://sonian.com ]
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
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: State of Clojure web development

2010-06-24 Thread j-g-faustus
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?

Recently started writing a webapp to display financial data, along the
lines of Google finance. Although somewhat less ambitious :).

> 2. Which libraries or frameworks are you using? Which versions?

Enlive, latest version. (Downloaded last week, don't know the version
number.) Aiming for mostly static HTML, JavaScript/JSON, a few
servlets and CouchDB.


> 3. What made you choose Clojure to develop web applications in? What
> are the strengths of Clojure web development?

* I've been doing Java/JSP web development for years, it is stable,
has tons of libraries and performs well, but is somewhat cumbersome do
develop in.
* I've been doing a little web development in Ruby/Ruby on Rails.
Development is much quicker and nicer, especially with HAML (a
templating library). The disadvantage is performance issues - Ruby is
lousy on numerical computation.
* I had just started looking into server-side JavaScript (like
Node.js). The primary disadvantage is that it is very new and
unproven, and there are few libraries available yet.
* I also considered Google's Go, and was aiming for a combination of
Go for the heavy lifting and Ruby for templates and display.

I think Clojure hits a sweet spot with better performance than purely
dynamic languages like Ruby and less verbosity than Java. For me that
means I can stick with one language, which is always less hassle than
using several.

I used Common Lisp several years back, and liked it a lot, so I
welcome a modern Lisp on a mature platform.

The REPL is very helpful in allowing quick iterations.

Libraries are not an issue with Java underneath, and the Clojure-
specific libraries seem to be in decent shape as well.
The Enlive template system is simply brilliant, I know of nothing even
close in conveniently separating HTML/design and application logic.

All in all, I can't think of a better option at the moment.


> 4. What do you think are the current weaknesses of web development in
> Clojure? What could be improved?

In general Clojure web development is in early stages yet, it can't
compete with the maturity of Java or Ruby frameworks. But that goes
with the territory, it's one of the costs of trying something new. And
I can always drop down to Java if needed.

Documentation is highly variable, I'm not entirely happy with having
to read source code to figure out an API.

For anything more specific, it's too early for me to tell, I can
probably say more about it in a month or two. Perhaps database
connections, although since there is plenty of DB support in Java,
writing a small Clojure wrapper seems manageable.


> 5. Anything else you want to comment on?

Not really. Keep up the good work :)

-- 
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: Trying to make my code extensible

2010-06-24 Thread Brent Millare
If anyone is curious, I ended up learning about and using protocols.
It was pretty trivial to convert since it was basically what I was
already doing, although I wasn't really using protocols for
dispatching but for grouping of functions together with shared data.

On Jun 1, 7:09 pm, Brent Millare  wrote:
> I'm trying to make my code extensible and I'm having trouble deciding
> what is the best way to do this.
>
> The algorithm is a tree walker that modifies a few data structures
> before, post, and during the traversal of each node. The code detects
> circular dependencies, resolves dependencies once, and ignores
> exclusions. However, there are different ways to determine what
> qualifies as an exclusion and an already resolved dependency such as
> matching only the artifact id to prevent multiple versions, which
> motivates me to make the code extensible. After all, there are
> additional possibilities which may need to be accounted for in the
> future.
>
> The code is the following:
>
> note:
> a dependency takes the form [groupid/artifactid "1.3.0-version"]
> get-direct-dependencies-parse! downloads and parses a pom.xml file
> extract-dependencies converts a dependency in parse data into the form
> [groupid/artifactid "1.3.0-version"]
> qualify-dependency ensures a dependency-form is well-formed
> extract-exclusions does the same as extract-dependencies but gets
> exclusions instead
>
> (defn get-all-dependencies! [dependency-list & options]
>   ([dependency-list exclusions]
>      (let [ ;; circular dependency detection
>            seen (ref #{})
>            ;; needed to preserve order
>            resolved (ref [])
>            resolved-set (ref #{})
>            exclusions (ref (set exclusions))
>            ;; may want to do something with this in the future
>            optional (ref #{})]
>        (letfn [(get-direct-dependencies!
>                 ;; create list of direct dependencies and update exclusions
>                 [d]
>                 (for [{dependency :dependency} 
> (get-direct-dependencies-parse! d)]
>                   (let [dependency-map (apply merge dependency)
>                         dependency-form (extract-dependency dependency-map)]
>                     (dosync (alter exclusions set/union (extract-exclusions
> dependency-map)))
>                     (when (and (:verbose options)
>                                (:optional dependency-map))
>                       (println "resolving optional " dependency-form))
>                     (dosync (alter optional conj dependency-form))
>                     dependency-form)))
>                (resolve-dependency
>                 ;; walk tree
>                 [d]
>                 (let [d (qualify-dependency d)]
>                   (when (:verbose options) (println "resolving " d))
>                   (when-not (or ((:resolved-fn options) @resolved-set d)
>                                 (let [result ((:exclusion-fn options) 
> @exclusions d)]
>                                   (when (and result
>                                              (:verbose options))
>                                     (println "excluding " d))
>                                   result))
>                     (if (@seen d)
>                       (throw (Exception. "Circular dependency detected"))
>                       (do
>                         (dosync (alter seen conj d))
>                         (doall (map resolve-dependency 
> (get-direct-dependencies! d)))
>                         (dosync
>                          (alter seen disj d)
>                          (alter resolved conj d)
>                          (alter resolved-set conj d)))]
>          (doseq [dependency dependency-list]
>            (resolve-dependency dependency))
>         �...@resolved)))
>   ([dependency-list]
>      (get-all-dependencies! dependency-list nil)))
>
> I've started making it more general with the options map which can
> potentially contain different predicate functions for determining
> whether or not to follow a node, but I'm trying to make it even more
> general. I feel that I can break it down into code that initializing
> data structures, predicates that determine whether to recurse into a
> node, code to execute before recurse into node, code to execute during
> traversal (aka code in get-direct-dependencies!) and code to execute
> after recurse.
>
> I've been thinking about multimethods but they execute one function
> out of many possible. I want to execute many functions over many
> possible.
>
> I've also thought about making hook maps, maps that contain several
> hook functions such as :init, :predicate, :pre, :get, and :post) and
> at each stage in the get-all-dependencies! function, dynamically
> creates a list of hooks  from a list of all the hooks, that fulfill a
> condition (in other words, filters the hooks), based on runtime
> information, and then executes them. I've started this in an
> experimental branch but it doesn't l

New Primitive data types (equal branch) - impact on optimized code.

2010-06-24 Thread Heinz N. Gies
So out of curiosity I did some benchmarking of the new equal branch and wanted 
to see how much I can get out of clojure if I push the limits. Now that said I 
know equal isn't done yet but I figured it won't hurt. Bad news first, despite 
all my attempts clojure was still slower then optimized scala code (of cause 
this is a purely hypothetical benchmark and that scala is way closer to java 
gives it a huge advantage when it coms to that).

The benchmark I did was the fannkuchen-redux benchmark the code I came up with 
was the following:

http://github.com/Licenser/clj-shootout/blob/master/fannkuchen/src/profile/fannkuchen.clj

the scala version I used is from the alioth shootout:

http://github.com/Licenser/clj-shootout/blob/master/fannkuchen/scala/fannkuchen.scala

For the clojure version, I tried to get rid of anything that isn't very close 
to java. All data ist stored in mutable arrays, all in all I use three and no 
extra data is allocated or tossed away for this. I tried to make everything I 
could to a macro (removing overhead for function calls), also I tried to use 
unchecked and primitive math wherever possible. The code is not pretty and 
certainly not idiomatic but it is somewhat fast, I managed to get things to a 
point where my clojure version took only 3.5 times longer then the scala 
version (I say only since the most idiomatic version was beyond compare so it 
was just beautiful!).

After this I did some profiling - eevar will love me for that - and I noticed 
one thing that stood out. intCast is called a gazillion times (in a run of 
about 4 seconds it was called ca. 150 million times) that IS a lot and it took 
some time (more then 10% of the over all execution time).  That stroke me as 
odd, so I did some diging and found an interesting point:

Java arrays use int's as index - which since long is the primitive causes every 
single array access to be typecast via the intCast(long) call which is 
expensive since it does range checking. Now since clojure is open source - yay 
- I changed the aget java code to take a long and do a unckeded typecast as in 
'(int)i' when accessing the array and made my own aget and aset methods that 
did not typecheck (since I knew what it was called with). This bought about 10% 
execution time.

So what I'd suggest is to add some unckecked-aget methods that take a long as 
index and don't typecast, for array intensive code this is a 10% speedup which 
isn't that bad. Other then that I am still looking why clojure is slower by 
such a magnitude.

Also it would be great if there were a way to give functions signatures if 
desired, as in having (aget Object) that runs (int ...) on Object and (aget 
int/long) that does just pass the value w/o casting.

Also the profiles show that despite my best efforts there is still a large 
number of calls made for Number casts, I'm not sure where they are from, likely 
from clojures core interiors.


Here are some of the results I got: http://grab.by/57x0

and some profiling results: http://grab.by/57vO (look at the time taken for 
intCast)

Regards,
Heinz

-- 
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 Primitive data types (equal branch) - impact on optimized code.

2010-06-24 Thread David Nolen
On Thu, Jun 24, 2010 at 5:08 PM, Heinz N. Gies  wrote:

> So out of curiosity I did some benchmarking of the new equal branch and
> wanted to see how much I can get out of clojure if I push the limits. Now
> that said I know equal isn't done yet but I figured it won't hurt. Bad news
> first, despite all my attempts clojure was still slower then optimized scala
> code (of cause this is a purely hypothetical benchmark and that scala is way
> closer to java gives it a huge advantage when it coms to that).
>
> The benchmark I did was the fannkuchen-redux benchmark the code I came up
> with was the following:
>
>
> http://github.com/Licenser/clj-shootout/blob/master/fannkuchen/src/profile/fannkuchen.clj
>
> the scala version I used is from the alioth shootout:
>
>
> http://github.com/Licenser/clj-shootout/blob/master/fannkuchen/scala/fannkuchen.scala
>
> For the clojure version, I tried to get rid of anything that isn't very
> close to java. All data ist stored in mutable arrays, all in all I use three
> and no extra data is allocated or tossed away for this. I tried to make
> everything I could to a macro (removing overhead for function calls), also I
> tried to use unchecked and primitive math wherever possible. The code is not
> pretty and certainly not idiomatic but it is somewhat fast, I managed to get
> things to a point where my clojure version took only 3.5 times longer then
> the scala version (I say only since the most idiomatic version was beyond
> compare so it was just beautiful!).
>
> After this I did some profiling - eevar will love me for that - and I
> noticed one thing that stood out. intCast is called a gazillion times (in a
> run of about 4 seconds it was called ca. 150 million times) that IS a lot
> and it took some time (more then 10% of the over all execution time).  That
> stroke me as odd, so I did some diging and found an interesting point:
>
> Java arrays use int's as index - which since long is the primitive causes
> every single array access to be typecast via the intCast(long) call which is
> expensive since it does range checking. Now since clojure is open source -
> yay - I changed the aget java code to take a long and do a unckeded typecast
> as in '(int)i' when accessing the array and made my own aget and aset
> methods that did not typecheck (since I knew what it was called with). This
> bought about 10% execution time.
>
> So what I'd suggest is to add some unckecked-aget methods that take a long
> as index and don't typecast, for array intensive code this is a 10% speedup
> which isn't that bad. Other then that I am still looking why clojure is
> slower by such a magnitude.
>
> Also it would be great if there were a way to give functions signatures if
> desired, as in having (aget Object) that runs (int ...) on Object and (aget
> int/long) that does just pass the value w/o casting.
>
> Also the profiles show that despite my best efforts there is still a large
> number of calls made for Number casts, I'm not sure where they are from,
> likely from clojures core interiors.
>
>
> Here are some of the results I got: http://grab.by/57x0
>
> and some profiling results: http://grab.by/57vO (look at the time taken
> for intCast)
>
> Regards,
> Heinz
>
> --
> 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


Don't have time to dive into this right now, but all I can say is now you
are starting to have an idea what the "other side" looks like. The kind of
hoop jumping you have to do get within 3x of Scala is absurd.

This style of coding is largely unnecessary with the latest equals branch.
However in order to be competitive you're going to have to be a bit more
clever with your combination of deftype/record, protocols, statics:

* Data locality, solved by fields with deftype/record (also allows to define
a bunch of method/fns that have access to the field type to avoid cast)
* primitive return solved by static
* macro inlining is unnecessary with static

-- 
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: State of Clojure web development

2010-06-24 Thread Meikel Brandmeyer
Hi,

Am 24.06.2010 um 21:12 schrieb Tim Robinson:

> I would like some chaining to less the brackets.
> i.e.
> 
>> (def stuff {:key1 {:item1 {:sub1 val1}})
>> (((stuff :key1) :item1) sub1)  <--- YUCK
> val1
> 
> Instead do this:
>> stuff:key1:item1:sub1
> val1

(-> stuff :key1 :item1 sub1)

> Also, some of the function names don't make sense:
> (def stuff (list 1 2 3 4 5))
>> (rest stuff)
> (2 3 4 5)
>> (next stuff)
> (2 3 4 5) < this can be done with rest.

next and rest are not the same. See http://clojure.org/lazy.

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: New Primitive data types (equal branch) - impact on optimized code.

2010-06-24 Thread David Nolen
On Thu, Jun 24, 2010 at 5:17 PM, David Nolen  wrote:

> On Thu, Jun 24, 2010 at 5:08 PM, Heinz N. Gies  wrote:
>
>> So out of curiosity I did some benchmarking of the new equal branch and
>> wanted to see how much I can get out of clojure if I push the limits. Now
>> that said I know equal isn't done yet but I figured it won't hurt. Bad news
>> first, despite all my attempts clojure was still slower then optimized scala
>> code (of cause this is a purely hypothetical benchmark and that scala is way
>> closer to java gives it a huge advantage when it coms to that).
>>
>> The benchmark I did was the fannkuchen-redux benchmark the code I came up
>> with was the following:
>>
>>
>> http://github.com/Licenser/clj-shootout/blob/master/fannkuchen/src/profile/fannkuchen.clj
>>
>> the scala version I used is from the alioth shootout:
>>
>>
>> http://github.com/Licenser/clj-shootout/blob/master/fannkuchen/scala/fannkuchen.scala
>>
>> For the clojure version, I tried to get rid of anything that isn't very
>> close to java. All data ist stored in mutable arrays, all in all I use three
>> and no extra data is allocated or tossed away for this. I tried to make
>> everything I could to a macro (removing overhead for function calls), also I
>> tried to use unchecked and primitive math wherever possible. The code is not
>> pretty and certainly not idiomatic but it is somewhat fast, I managed to get
>> things to a point where my clojure version took only 3.5 times longer then
>> the scala version (I say only since the most idiomatic version was beyond
>> compare so it was just beautiful!).
>>
>> After this I did some profiling - eevar will love me for that - and I
>> noticed one thing that stood out. intCast is called a gazillion times (in a
>> run of about 4 seconds it was called ca. 150 million times) that IS a lot
>> and it took some time (more then 10% of the over all execution time).  That
>> stroke me as odd, so I did some diging and found an interesting point:
>>
>> Java arrays use int's as index - which since long is the primitive causes
>> every single array access to be typecast via the intCast(long) call which is
>> expensive since it does range checking. Now since clojure is open source -
>> yay - I changed the aget java code to take a long and do a unckeded typecast
>> as in '(int)i' when accessing the array and made my own aget and aset
>> methods that did not typecheck (since I knew what it was called with). This
>> bought about 10% execution time.
>>
>> So what I'd suggest is to add some unckecked-aget methods that take a long
>> as index and don't typecast, for array intensive code this is a 10% speedup
>> which isn't that bad. Other then that I am still looking why clojure is
>> slower by such a magnitude.
>>
>> Also it would be great if there were a way to give functions signatures if
>> desired, as in having (aget Object) that runs (int ...) on Object and (aget
>> int/long) that does just pass the value w/o casting.
>>
>> Also the profiles show that despite my best efforts there is still a large
>> number of calls made for Number casts, I'm not sure where they are from,
>> likely from clojures core interiors.
>>
>>
>> Here are some of the results I got: http://grab.by/57x0
>>
>> and some profiling results: http://grab.by/57vO (look at the time taken
>> for intCast)
>>
>> Regards,
>> Heinz
>>
>> --
>> 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
>
>
> Don't have time to dive into this right now, but all I can say is now you
> are starting to have an idea what the "other side" looks like. The kind of
> hoop jumping you have to do get within 3x of Scala is absurd.
>
> This style of coding is largely unnecessary with the latest equals branch.
> However in order to be competitive you're going to have to be a bit more
> clever with your combination of deftype/record, protocols, statics:
>
> * Data locality, solved by fields with deftype/record (also allows to
> define a bunch of method/fns that have access to the field type to avoid
> cast)
> * primitive return solved by static
> * macro inlining is unnecessary with static
>

Couple other notes:

* You can use definterface to define type-hinted methods for deftype/record,
you can't do that with protocols.
* A good example of how fast protocols can be is
http://github.com/ztellman/cantor.
* Protocols and static cannot interact at the moment

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

Re: State of Clojure web development

2010-06-24 Thread Meikel Brandmeyer
Hi,

Am 24.06.2010 um 22:07 schrieb Tim Robinson:

> Along this vein, I find the documentation is great, but a little hard
> to navigate around.

http://richhickey.github.com/clojure
http://richhickey.github.com/clojure-contrib

Note the branch links on the top left.

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: New Primitive data types (equal branch) - impact on optimized code.

2010-06-24 Thread Michał Marczyk
On 24 June 2010 23:17, David Nolen  wrote:
> Don't have time to dive into this right now, but all I can say is now you
> are starting to have an idea what the "other side" looks like. The kind of
> hoop jumping you have to do get within 3x of Scala is absurd.

I have to admit this is true...

(With the above realisation, I feel like I'm biting off a chunk of a
cake which I really wanted to keep just a short while ago.)

Sincerely,
Michał

-- 
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 Primitive data types (equal branch) - impact on optimized code.

2010-06-24 Thread David Nolen
If you want some ideas: http://gist.github.com/452032

This was posted earlier in the ML in an un-optimized Clojure form as taking
98secs while the Java version took about 16ms on the OP's machine. With
Rich's latest changes this optimized Clojure code runs in about 20-25ms on
my i7 laptop.

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: clojure.xml/parse cannot handle filenames containing #

2010-06-24 Thread Zak Wilson
On Jun 23, 11:37 pm, Stuart Halloway 
wrote:
> I can certainly see why this would be confusing! Is there a way to make it 
> better without violating the expectations of someone who knows the Java API 
> and expects strings to be treated as URIs?

Perhaps throwing an appropriately informative exception when a
filename is provided as an argument would help. It might have helped
if I'd actually read the documentation carefully, but it's easy to be
surprised when the platform's convention is different from what I'm
used to.

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


Having trouble with labrepl jars

2010-06-24 Thread Harrison Maseko
Hi, I am a newbie trying to learn Clojure. I would like to try the
labrepl environment, but due to my circumstances I have to download
all the jars manually one by one and install them manually in
NetBeans. The trouble is, I cannot find most of the jars to download.
So far, I have circumspect-0.0.13.jar and clojure-1.2.0-master-
SNAPSHOT.jar. Could someone give me literal URLs please for the
following jars:

clojure-contrib-1.2.0-master-SNAPSHOT.jar
clojure-http-client-1.0.0-SNAPSHOT.jar
log4j-1.2.14.jar
postgresql-8.4-701.jdbc4.jar
stringtemplate-2.2.jar
swank-clojure-1.1.0-SNAPSHOT.jar

Thanks for understanding and for helping.

Harrison.

-- 
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: slow raw io

2010-06-24 Thread cageface
I put a self-contained test up here:
http://gist.github.com/452095

To run it copy this to slurptest.clj and run these commands
java clojure.main slurptest.clj makewords 100 (100 seems good for
macs, 300 for linux)

java -Xmx3G -Xms3G clojure.main slurptest.clj slurp|
slurp2

Trying either slurp or slurp2. I see big timing differences on both
macs and linux machines but it would be interesting to see if other
people do too.

-- 
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: Having trouble with labrepl jars

2010-06-24 Thread Michał Marczyk
Really no way that you could download the dependency jars through,
say, Maven...? (As documented in labrepl's readme [1].)

If not, you can download the jars from the Maven repositories by hand.
The relevant repos are Hudson [2] (for clojure.jar and
clojure-contrib.jar; use the "releases" section), Clojars [3] (for
Clojure libraries; in this case, clojure-http-client and
swank-clojure) and Maven Central [4] (for Java libraries; in this
case, log4j, postgresql and stringtemplate). Note these links are to
the repos' contents (viewable through a browser as a directory tree);
for Hudson and Clojars, drop the final (directory) part of the URLs
for the useful websites backed by these repositories.

Sincerely,
Michał

[1] http://github.com/relevance/labrepl
[2] http://build.clojure.org/releases/
[3] http://clojars.org/repo/
[4] http://repo1.maven.org/maven2/

-- 
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: State of Clojure web development

2010-06-24 Thread Mike Meyer
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?

roman candle is a web app designed to let me control X10 plc
components from any web-capable device, using the X10 firecracker
controller. It's still in very early development, and hasn't been
given much attention lately. The intent is more to learn about clojure
rather than provide a distributable utility.

> 2. Which libraries or frameworks are you using? Which versions?

I've always been impressed by the Seaside framework, if only it
weren't tied to smalltalk. While there are now some C/C++ frameworks
along this line, there don't appear to be any available for Java, much
less clojure.  So I'm developing a small framework - bitchen' - in
parallel with roman candle. This is also more pedagogical than
production, in that it's not at all clear how to "port" the seaside
model from an OO language to a functional/immutable one like Clojure.
Should I decide that I'm going to get serious about clojure, this
might eventually become a full-fledged framework.

> 3. What made you choose Clojure to develop web applications in? What
> are the strengths of Clojure web development?

Wanting to provide a better answer to that question. Clojure itself is
interesting for it's LISPyness, concurrency facilities, and tight
integration with the JVM.

> 4. What do you think are the current weaknesses of web development in
> Clojure? What could be improved?

The tight integration with the JVM. I believe it's brought more pain
than happiness.

> 5. Anything else you want to comment on?

Not really.

 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: Enhanced Primitive Support

2010-06-24 Thread Mike Meyer
[Not really about enhanced primitive support - more about optimization
 on the jvm.]

On Tue, 22 Jun 2010 01:47:26 -0400
David Nolen  wrote:
> Yet consider this, If I'm writing OpenGL code in Penumbra I will have quite
> a bit of code that amounts to the following:
> 
> ; 630 msecs
> (dotimes [_ 10]
>   (time
>(dotimes [_ 10]
>  (+ 1 2
> 
> Yes. With Rich's primitive work we can get to *1 billion arithmetic
> operations* in < 2/3 of a second on commodity hardware.

Which begs the question - why are you mucking about with SISD
algorithms if you need that kind of thing to be fast? IIUC, recent
versions of the JVM can access the SIMD instructions that have been
available on most commodity hardware for the last couple of years. Why
aren't you trying to get to those to get a serious performance boost?
Better yet, given that you're using OpenGL and presumably have real
graphics hardware available, why aren't you trying to push this stuff
out to the vector processor on the GPU where it will really fly?

 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: State of Clojure web development

2010-06-24 Thread Howard Lewis Ship
On Wed, Jun 23, 2010 at 2:23 PM, James Reeves
 wrote:
> Hello there!
>
> Chas Emerick's recent "State of Clojure" survey [http://bit.ly/dtdAwb]
> indicated that a significant proportion of Clojure users are beginning
> to use Clojure for web development. A recent Hacker News posting
> [http://bit.ly/91Bu5J] seems to corroborate these results, with
> several Clojure-based web applications already out in the wild.
>
> As one of the main developers of Ring and Compojure, I'd be very
> interested to hear more about how people are using Clojure to build
> web apps. To this end, I have a few questions I'd like to quiz Clojure
> web developers about:
>
> 1. Have you written, or are you writing, a web application that uses
> Clojure? What does it do?
>

I'm writing a framework, Cascade.

http://wiki.github.com/hlship/cascade/

> 2. Which libraries or frameworks are you using? Which versions?

So far, no dependencies ... but I may switch out some ad hoc logic for
stuff from Ring. Even I try not to reinvent the wheel every time!

>
> 3. What made you choose Clojure to develop web applications in? What
> are the strengths of Clojure web development?

I eventually hope to have Cascade handle parallel rendering of the
overall content across multiple threads, which makes sense when
rendering a single view requires multiple database queries that can
execute in parallel.

Partly Cascade exists as a way to learn Clojure fully, even if I don't
use Cascade professionally in the meantime.  For most projects, I'll
keep using Tapestry :-)

However, I do really like having the template be Clojure forms.

Unlike Compojure/Hiccup, the Cascade templates are rendered to an
intermediate DOM format that can be manipulated before final streaming
as text. There are advantages to this, learned from Tapestry, in terms
of coordinating individual rendering functions (what might be
components in Tapestry) ... especially w.r.t. the inclusion of
stylesheets and JavaScript libraries.  These are done declaratively in
Cascade.


For the most part, it was easier to get live reloading working in
Cascade than in Tapestry (in Tapestry, change a class, it is reloaded.
 In Cascade, change a namespace, it is reloaded). There are still some
issues, especially when there are errors in the reloaded namespace.

>
> 4. What do you think are the current weaknesses of web development in
> Clojure? What could be improved?

Clojure's native exception reporting is weak!  Cascade improves on
this in a couple of ways (some of which may have been picked up by
Compojure).

>
> 5. Anything else you want to comment on?

For what I've heard, I'm not the first person to implement an
application in Cascade, which floors me. It's really at the research
project level right now, but I do like what I've managed so far.

>
> Please reply to this thread with your answers, and thank you very much
> in advance for your time. I really appreciate any feedback you can
> provide.
>
> - James
>
> --
> 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



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: New Primitive data types (equal branch) - impact on optimized code.

2010-06-24 Thread Mark Engelberg
When exactly did people start expecting Clojure to be as fast as Java
and/or Scala?

I seem to recall in one of the original Clojure videos, Rich talked
about the relationship between Clojure and Java.  There's a long
history of C programmers dropping down to assembly, Python programmers
dropping down to C, and so on.  He explained that Java was Clojure's
"assembly".  You use Clojure to write the logic that is too complex to
code compactly in Java.  You write Java to code the low-level bits you
can't do in Clojure.

I must admit I was surprised by Rich's recent statement that Clojure
is not useful to him if he can't write high performance code in it,
because he "only writes the hard bits".  To me this seemed like a
change of perspective from the days when it was accepted that the most
performance-critical parts would likely be implemented in Java;
perhaps the Clojure-in-Clojure project has gotten him more focused on
replacing Java entirely with Clojure.  He says we wouldn't like a
Clojure that was written in Clojure as it currently stands, because it
would be too slow.  That's probably true, but I never expected it to
be possible.  Up until this recent discussion, I believed that the
main focus for Clojure-in-clojure was to find ways to move more parts
into Clojure without affecting performance, in order to achieve better
portability to other hosts.  I didn't think it would ever be possible
to move all of it over.

I agree that it has been extraordinarily difficult to write
high-performance numerical code in Clojure.  I agree that everyone
benefits if this gets easier.  I want faster code as much as anyone.
But I'm worried that people's goals for static-typed-performance might
be unrealistic.  I'm delighted that Clojure already performs so well
for a dynamically typed language, thanks to Rich's hard work
optimizing the Java code that underlies Clojure so everything can be
as fast as possible, but it seems that a lot of people here will be
disappointed if Clojure can't compete with Java/Scala on the
benchmarks.

I'm glad someone is starting to tackle these benchmarks.  I think it's
especially interesting to see how fast the code can be when written
idiomatically, so I hope we'll see more of these results as well.
Once you start using mutable arrays and type hinting every single
variable, why aren't you just using Java?

With respect to this particular benchmark, I don't think it will be
possible to get idiomatic code in the same ballpark as Java, because
if you use Clojure's vectors to store the permuted values, they will
be boxed.  Unless Clojure starts having primitive vectors, I don't see
how it's possible to get around this.  But I'd love to be proven
wrong.

-- 
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 Primitive data types (equal branch) - impact on optimized code.

2010-06-24 Thread Wilson MacGyver
On Jun 24, 2010, at 10:50 PM, Mark Engelberg  wrote:

> When exactly did people start expecting Clojure to be as fast as Java
> and/or Scala?
> 

One of the earlier talk/video, the claim was clojure is between 1x to 3x of java
performance. 

Fast math performance was touched on here also
http://www.infoq.com/interviews/hickey-clojure

And that's pre 1.0

-- 
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 Primitive data types (equal branch) - impact on optimized code.

2010-06-24 Thread Richard Newman

Mark,

I don't disagree with your message as a whole, but:


Once you start using mutable arrays and type hinting every single
variable, why aren't you just using Java?


The argument I've heard is this: there are two ways to get a fast  
program in a slow-by-default language.


The first is Python's way: write the whole thing in Python (high- 
level), find out the parts that are slow, then rewrite those in a  
different language (C). Now you need a C compiler, you need to build  
separately on each platform, and so on.


The second is Common Lisp's way: write the whole thing in un-annotated  
CL (high-level), find out the parts that are slow, then add  
annotations or make representational changes (lists => vectors, alists  
=> hash-maps) to allow the compiler to make them fast.


The argument is that being able to use *the same language* to write  
anywhere on the spectrum from slow/succinct to fast/verbose is useful:  
no complex combined build system, no bridging between environments,  
iterative development, easier profiling, your code always works, etc.


If I can take one little part of my Clojure program and make it ugly  
like Java to get it as fast as Java, it's better than having to  
actually _use_ Java in a heterogeneous project.


-R

--
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 Primitive data types (equal branch) - impact on optimized code.

2010-06-24 Thread David Nolen
On Thu, Jun 24, 2010 at 10:50 PM, Mark Engelberg
wrote:

> With respect to this particular benchmark, I don't think it will be
> possible to get idiomatic code in the same ballpark as Java, because
> if you use Clojure's vectors to store the permuted values, they will
> be boxed.  Unless Clojure starts having primitive vectors, I don't see
> how it's possible to get around this.  But I'd love to be proven
> wrong.


gvec already holds primitives. What we're missing are fns that can take
advantage of that.

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