Re: Looking to fit Clojure into my architecture and am in need of your informed advice!

2010-08-01 Thread Saul Hazledine
Hello Kent,

On Aug 1, 2:00 pm, Kent Larsson  wrote:
>
> I'm planning to reduce my time at my full time job to create a small
> startup. And I am thinking about create a lean and mean architecture
> which will enable me to get things done.
>
Cool!

> I am thinking about creating a layered architecture like this:
>
> 1. Front end
> 2. Business
> 3. Database
>
> I think that the "2. Business Layer" should be Clojure. It would talk
> to the "1. Front End" by a web service REST interface. Exactly how the
> data should be encoded is something I haven't though about yet. But
> JSON seems like an easy format.
>
Building a JSON service in Clojure and Compojure is easy to do.

> My idea is basically to create a good Customer Relationships
> Management (CRM) system and sell it as a service to companies. The
> users will input information about customers and related events and it
> will be easy to search. I'll have quite a lot of business logic which
> makes these tasks easier. The logic will most often be stuff which
> handles graphs (which SQL really has some problems handling nicely).
>
I've not used it but neo4j looks like it might be worth looking at:
http://neo4j.org/

> Some must have goals:
>
> 1. If it becomes a success, it needs to be able to scale over multiple
> machines with load balancing. There will be some data which should be
> replicated between the machines, but a delay is all right.
> 2. As I sell it uptime is important. If I have several machines and
> one of them dies. I'd like the service to be available using the other
> machines.
>
Some people have had success getting Clojure running on google app
engine. You get scaling for little effort but the BIG downside is that
your app can take over 10 seconds to respond when nobody is using it
(when under load the app runs at a decent speed).

> My questions:
>
> 1. Do you think Wicket is a good choice for the front end for me? It
> has session state on the server which I need to replicate in more or
> less real time. If I have the state on the client using JavaScript I
> don't have to deal with that replication. But how would I achieve that
> in the most smooth way? Should I go for Compojure for the front end to
> not have to deal with two languages? And then maybe skip the
> separation of layer "1. Front End" and "2. Business"?
>
I've not used wicket. Compojure/Hiccup are wonderful, will handle
session state no problem, but they aren't a full web framework. You
will have to do extra work compared to say Ruby on Rails, Django or
Grails where you can get a front-end up in a weekend.

> 2. Will it be hard to write a nice web service interface in Clojure?
> Is it a suitable communication strategy with Clojure? Maybe I am
> making it too complicated?
>
Web services are easy in Clojure/Compojure (that's worth saying
twice).

> 3. Clojure has a lot of nice stuff for handling data in transactions.
> But if all my data resides in a database will I get to really enjoy
> this advantage? I have been thinking about actually storing the data
> using Clojure and skip the database, to get more out of Clojure. Is
> that idea too crazy? I will have to deal with data replication myself
> then, or maybe something like memcache will solve it for me?
>
Personally, I'd stick with some sort of database as it will have been
designed to protect your data from accidents. Clojure has lots of
advantages even if you don't use the concurrency features.

>
> 5. Is it hard to debug Clojure? Using Java/C# today you get a real
> treat when it comes to debugging with interactive stepping, expression
> watching and a lot of other cool things. Where is Clojure debugging
> compared to other languages? Is the debugging features as necessary as
> in other languages?
>
Conventional debugging is harder at the moment but having a REPL or
using swank means there is less need for debugging anyway. You can
play with each function as you write it.

> 7. Any other advice or thoughts you have about this?
>
I wouldn't worry too much about scaling. Making an application
scalable is a lot of work (unless you're using something like Google
appengine). Computers are much faster than they used to be. A single
machine running Jetty/Compojure with a database such as H2 will handle
100's/1000's of pages per second. If you exceed this your business
will be very successful, you will know your application better and
then you can concentrate on scaling.

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: setting classpath and using namespace: how to enable example scripts in library?

2010-08-01 Thread Nikita Beloglazov
I don't know how my example fits your needs, but I use something like:

# /bin/sh
java -cp "lib/*":"src" clojure.main -e "(require 'my-project.core)
(my-project.core/print-hello)"

assuming, that in lib all neccesary libs are placed (clojure.jar,
clojure-contrib.jar, etc)
To download needed libs in lib directory I use "lein deps"
If you want to run examples then you can use
# /bin/sh
java -cp "lib/*":"examples" clojure.main -e "(require 'example-1)
(example-1/print-hello)"

Note that if you use namespaces with dashes (e.g. example-1), file should
have name example_1.clj (replace dashes with underscores)

You can also make java class with main method and compile and execute it.
How to do it described here:
http://clojure.org/compilation

Regards,
Nikita Beloglazov



On Mon, Aug 2, 2010 at 12:09 AM, jandot  wrote:

> Hi all,
>
> I'm writing a library which is organized using "lein new", so the
> directory structure contains an "src" and "test". I have added a
> directory "examples" with scripts that should be able to run by just
> typing "./example-1.clj".
>
> So the directory structure is:
> 
>  +- project.clj
>  +- src
>  |+- my-project
>  |+- core.clj
>  |+- io.clj
>  |+- conversions.clj
>  +- test
>  +- examples
>   +- example-1.clj
>   +- example-2.clj
> 
>
> Suppose that src/my-project/core.clj has the following contents:
>  (ns my-project.core)
>  (defn print-hello [] "Hello world")
>
> I can run that code from the repl (in my case: using liebke's "cljr
> repl") with:
>  (load-file "core.clj")
>  (print-hello)
>
> However, I have not been able yet to create the example script that
> should be executable by itself. What should that file look like? There
> are basically 2 issues: the she-bang line and the namespace. I've
> tried using different versions of "/usr/bin/env cljr run" and "/usr/
> bin/env java -cp cljr.jar ..." in the she-bang line, but no luck. Same
> goes for loading the my-project source files.
>
> It'll be obvious to you that I don't know java :-) Should be simple,
> but
>
> Many thanks,
> jan.
>
> --
> 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: Symbol substitution in macro

2010-08-01 Thread Heinz N. Gies

On Aug 2, 2010, at 3:34 , Kyle Schaffrick wrote:

> Hello,
> 
> I'm trying to write a library with two main parts. The first is a
> macro, I'll call it 'with-feature, that walks through forms passed
> inside it, and any time it sees a call to another function in my
> library, 'feature, do some transformations.
> 
> The problem I'm concerned about is as follows: When my macro sees the
> forms that are passed into it, the symbols come in however the consumer
> of the library wrote them. So say I :require my library and alias it to
> 'mylib', then the call 'with-feature is looking for appears as
> 'mylib/feature. Or, I could :use the library, and then it would appear
> as 'feature, or I could alias 'feature to 'banana--you get the idea.
> 
> I don't want to reserve some magic symbol name that defies namespace
> rules, so that if the library consumer code uses the symbol 'feature
> to mean something different, they get bizarre results.
> 
> What is a good pattern for writing the "matching" logic in such a
> selectively-transforming macro so that it can properly find the magic
> call it's looking for in the presence of normal namespacing behavior?
> 
> Thanks,

Hi Kyle,
I face a simular chalange in clj-sandbox, and I ended up matching against the 
variable name only not the namespace so bla not a.b.c/bla. I know it's not 
perfect but at least it only yields false positives in the worst case, not 
false negatives :).

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: Bug: contains? doesn't work on transient maps or sets

2010-08-01 Thread Jason Wolfe
Related: in 1.2 RC1, "find" also fails to work with transient maps
(although it does throw an error, rather than fail silently).



On Aug 1, 12:25 pm, Mark Engelberg  wrote:
> I just tested this in Clojure 1.2, and the bug is still there:
>
> (contains? (transient #{1 2}) 1) -> false          ;should return true
>
> On Mon, Mar 22, 2010 at 5:46 PM, Mark Engelberg 
> wrote:
>
> > Disturbingly, it doesn't error, it just always returns false.
> > This is in version 1.1.  Can someone check and see if this is still a
> > problem on the latest version?
>
> > Thanks,
>
> > Mark

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


Symbol substitution in macro

2010-08-01 Thread Kyle Schaffrick
Hello,

I'm trying to write a library with two main parts. The first is a
macro, I'll call it 'with-feature, that walks through forms passed
inside it, and any time it sees a call to another function in my
library, 'feature, do some transformations.

The problem I'm concerned about is as follows: When my macro sees the
forms that are passed into it, the symbols come in however the consumer
of the library wrote them. So say I :require my library and alias it to
'mylib', then the call 'with-feature is looking for appears as
'mylib/feature. Or, I could :use the library, and then it would appear
as 'feature, or I could alias 'feature to 'banana--you get the idea.

I don't want to reserve some magic symbol name that defies namespace
rules, so that if the library consumer code uses the symbol 'feature
to mean something different, they get bizarre results.

What is a good pattern for writing the "matching" logic in such a
selectively-transforming macro so that it can properly find the magic
call it's looking for in the presence of normal namespacing behavior?

Thanks,

-Kyle

-- 
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: abstract structural binding

2010-08-01 Thread doug
thanks- you are correct. it is -what it is! -doug

On Aug 1, 1:03 pm, Rasmus Svensson  wrote:
> 2010/8/1 doug <395curra...@gmail.com>
>
>
>
>
>
> > Hey all!
>
> > can't seem to get the last element to bind. tia -doug
>
> > user> cj-mpdata
> > ["0010335602       " "" "40.00" "" "1060.51" "6/23/2010" "DISCOVER E-
> > PAYMENT 7796" "" "" ("DISCOVER")]
> > user> (let [[[_ ck db cr _ dt _ _ _][dsc]]
> >           [["Acct" "Chk" "Debt" "Crd" "Bal" "Date" "Desc" "Payee"
> > "Catagory"]
> > ["newDescript"]]]
> >                 [dt ck  db cr  dsc])
> > ["Date" "Chk" "Debt" "Crd" "newDescript"]
> > user> (let [[[_ ck db cr _ dt _ _ _][dsc]] [cj-mpdata]]
> >     [dt ck  db cr  dsc])
>
> > ["6/23/2010" "" "40.00" "" nil]
> > user>
>
> The data you pass to the first let is structured like this:
>     [[:a :b :c :d :e :f :g :h :i] [:j]]
> i.e., a 2-vector with a 9-vector and a 1-vector in it.
>
> But the data in cj-mpdata is structured like this:
>     [:a :b :c :d :e :f :g :h :i [:j]]
> i.e., a 10-vector with a 1-vector as its last element.
>
> In your second let case, doing this should work:
>     (let [[_ ck db cr _ dt _ _ _ [dsc]] cj-data]
>       [dt ck  db cr  dsc])
>
> Also, adding square brackets to both the left hand side and the right and
> side in a let binding is a no-op, and can be removed.
>
> // raek

-- 
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: dtd question

2010-08-01 Thread Randy Hudson
I think we're almost there, sorry for the various mistakes.

If you look in the source for clojure.xml, you can see that the
default "startparse" argument for xml/parse is

(defn startparse-sax [s ch]
  (.. SAXParserFactory (newInstance) (newSAXParser) (parse s ch)))

and we've only gotten as far as the newSAXParser part with the
definition of parser. So:

(defn startparse [s ch] (.parse parser s ch))
(defn parse-xml [source]  (xml/parse source startparse))

should finally do it.

I do apologize, I'd forgotten about the function wrapper part of this
machinery. I hope this has been helpful despite my mistakes.


On Aug 1, 2:50 pm, Manfred Lotz  wrote:
> Hi Randy,
>
> On Sun, 1 Aug 2010 10:04:16 -0700 (PDT)
>
> Randy Hudson  wrote:
> > Right you are Michael; sorry for the missing paren at the end of the
> > def.
>
> Now compiling the code works:
>
> (def parser (.newSAXParser (SAXParserFactory/newInstance)))
>
> (.setEntityResolver (.getXMLReader parser) resolver)
>
> (defn parse-xml [source] (xml/parse source parser))
>
> however when trying to apply it by adding
>
> (parse-xml (java.io.File. "test.xml"))    
>
> it no longer compiles:
> Exception in thread "main" java.lang.ClassCastException:
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl cannot be cast to
> clojure.lang.IFn (xmltest1.clj:0)
>
> --
> Thanks,
> Manfred

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


setting classpath and using namespace: how to enable example scripts in library?

2010-08-01 Thread jandot
Hi all,

I'm writing a library which is organized using "lein new", so the
directory structure contains an "src" and "test". I have added a
directory "examples" with scripts that should be able to run by just
typing "./example-1.clj".

So the directory structure is:

  +- project.clj
  +- src
  |+- my-project
  |+- core.clj
  |+- io.clj
  |+- conversions.clj
  +- test
  +- examples
   +- example-1.clj
   +- example-2.clj


Suppose that src/my-project/core.clj has the following contents:
  (ns my-project.core)
  (defn print-hello [] "Hello world")

I can run that code from the repl (in my case: using liebke's "cljr
repl") with:
  (load-file "core.clj")
  (print-hello)

However, I have not been able yet to create the example script that
should be executable by itself. What should that file look like? There
are basically 2 issues: the she-bang line and the namespace. I've
tried using different versions of "/usr/bin/env cljr run" and "/usr/
bin/env java -cp cljr.jar ..." in the she-bang line, but no luck. Same
goes for loading the my-project source files.

It'll be obvious to you that I don't know java :-) Should be simple,
but

Many thanks,
jan.

-- 
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: Bug: contains? doesn't work on transient maps or sets

2010-08-01 Thread Mark Engelberg
I just tested this in Clojure 1.2, and the bug is still there:

(contains? (transient #{1 2}) 1) -> false  ;should return true

On Mon, Mar 22, 2010 at 5:46 PM, Mark Engelberg wrote:

> Disturbingly, it doesn't error, it just always returns false.
> This is in version 1.1.  Can someone check and see if this is still a
> problem on the latest version?
>
> Thanks,
>
> Mark
>

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

Re: Clojure 1.2 RC1

2010-08-01 Thread Mark Engelberg
Aha, so it is.  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 1.2 RC1

2010-08-01 Thread Btsai
The jar can be located in the target sub-directory.

On Aug 1, 2:37 am, Mark Engelberg  wrote:
> Meant to say, "...zip doesn't have a compiled jar..."
>
> On Sun, Aug 1, 2010 at 1:36 AM, Mark Engelberg 
> wrote:
>
>
>
> > On Fri, Jul 30, 2010 at 8:00 AM, Stuart Halloway <
> > stuart.hallo...@gmail.com> wrote:
>
> >> Clojure 1.2 RC 1 is now available, along with a corresponding Clojure
> >> Contrib, at:
>
> >>http://clojure.org/downloads
>
> > Is there any particular reason the contrib release candidate zip have a
> > compiled jar inside 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: dtd question

2010-08-01 Thread Manfred Lotz
Hi Randy,


On Sun, 1 Aug 2010 10:04:16 -0700 (PDT)
Randy Hudson  wrote:

> Right you are Michael; sorry for the missing paren at the end of the
> def.
> 

Now compiling the code works:

(def parser (.newSAXParser (SAXParserFactory/newInstance)))

(.setEntityResolver (.getXMLReader parser) resolver)

(defn parse-xml [source] (xml/parse source parser)) 



however when trying to apply it by adding 

(parse-xml (java.io.File. "test.xml")) 


it no longer compiles: 
Exception in thread "main" java.lang.ClassCastException:
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl cannot be cast to
clojure.lang.IFn (xmltest1.clj:0)



 

-- 
Thanks,
Manfred


-- 
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: dtd question

2010-08-01 Thread Randy Hudson
Right you are Michael; sorry for the missing paren at the end of the
def.

On Aug 1, 11:59 am, Michael Wood  wrote:
> On 1 August 2010 17:15, Manfred Lotz  wrote:
>
>
>
>
>
> > Hi Randy,
>
> > On Sun, 1 Aug 2010 06:23:58 -0700 (PDT)
> > Randy Hudson  wrote:
>
> >> Hi Manfred,
>
> >> I'm sorry the code wasn't quite correct. The EntityResolver is set on
> >> the parser's XMLReader, not on the parser itself:
>
> >> (def parser (.newSAXParser (SAXParserFactory/newInstance))
> >> (.setEntityResolver (.getXMLReader parser) resolver)
>
> > It doesn't work. Even if I add a ) in the end I get
> > Exception in thread "main" java.lang.Exception: Too many arguments to
> > def (test.clj:21)
>
> > I tried then:
>
> > (def parser (doto (.newSAXParser (SAXParserFactory/newInstance))
> >        (.setEntityResolver (.getXMLReader parser) resolver)))
>
> I think he meant this:
> (def parser (.newSAXParser (SAXParserFactory/newInstance)))
> (.setEntityResolver (.getXMLReader parser) resolver)
>
> --
> Michael Wood 

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


Re: abstract structural binding

2010-08-01 Thread Rasmus Svensson
2010/8/1 doug <395curra...@gmail.com>

> Hey all!
>
> can't seem to get the last element to bind. tia -doug
>
> user> cj-mpdata
> ["0010335602   " "" "40.00" "" "1060.51" "6/23/2010" "DISCOVER E-
> PAYMENT 7796" "" "" ("DISCOVER")]
> user> (let [[[_ ck db cr _ dt _ _ _][dsc]]
>   [["Acct" "Chk" "Debt" "Crd" "Bal" "Date" "Desc" "Payee"
> "Catagory"]
> ["newDescript"]]]
> [dt ck  db cr  dsc])
> ["Date" "Chk" "Debt" "Crd" "newDescript"]
> user> (let [[[_ ck db cr _ dt _ _ _][dsc]] [cj-mpdata]]
> [dt ck  db cr  dsc])
>
> ["6/23/2010" "" "40.00" "" nil]
> user>
>

The data you pass to the first let is structured like this:
[[:a :b :c :d :e :f :g :h :i] [:j]]
i.e., a 2-vector with a 9-vector and a 1-vector in it.

But the data in cj-mpdata is structured like this:
[:a :b :c :d :e :f :g :h :i [:j]]
i.e., a 10-vector with a 1-vector as its last element.

In your second let case, doing this should work:
(let [[_ ck db cr _ dt _ _ _ [dsc]] cj-data]
  [dt ck  db cr  dsc])

Also, adding square brackets to both the left hand side and the right and
side in a let binding is a no-op, and can be removed.

// raek

-- 
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: dtd question

2010-08-01 Thread Michael Wood
On 1 August 2010 17:15, Manfred Lotz  wrote:
> Hi Randy,
>
> On Sun, 1 Aug 2010 06:23:58 -0700 (PDT)
> Randy Hudson  wrote:
>
>> Hi Manfred,
>>
>> I'm sorry the code wasn't quite correct. The EntityResolver is set on
>> the parser's XMLReader, not on the parser itself:
>>
>> (def parser (.newSAXParser (SAXParserFactory/newInstance))
>> (.setEntityResolver (.getXMLReader parser) resolver)
>
> It doesn't work. Even if I add a ) in the end I get
> Exception in thread "main" java.lang.Exception: Too many arguments to
> def (test.clj:21)
>
> I tried then:
>
> (def parser (doto (.newSAXParser (SAXParserFactory/newInstance))
>        (.setEntityResolver (.getXMLReader parser) resolver)))

I think he meant this:
(def parser (.newSAXParser (SAXParserFactory/newInstance)))
(.setEntityResolver (.getXMLReader parser) resolver)

-- 
Michael Wood 

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


Looking to fit Clojure into my architecture and am in need of your informed advice!

2010-08-01 Thread Kent Larsson
Hi!

I'm not any good at Clojure, but it seems like a great language! I
have tried some examples and am reading a book about it. I have
dabbled with Haskell before and I am really fascinated by the
functional paradigm.

I'm planning to reduce my time at my full time job to create a small
startup. And I am thinking about create a lean and mean architecture
which will enable me to get things done.

For me, a big part of getting things done will be having fun. And I
can see myself having lots of fun developing in Clojure. Also the
expressiveness of functional languages attract me and I think it will
be a great part of achieving results too.

I am thinking about creating a layered architecture like this:

1. Front end
2. Business
3. Database

It is a pretty common architecture I think. When it comes to OO
languages like Java it is commonly used. In my own a opinion a bit too
common as the separation between layers turns it more into procedural
programming than OOP. But that isn't what this post is about, and I
suspect this kind of architecture could be suitable when I put Clojure
into the mix.

I think that the "2. Business Layer" should be Clojure. It would talk
to the "1. Front End" by a web service REST interface. Exactly how the
data should be encoded is something I haven't though about yet. But
JSON seems like an easy format.

Ideally the "1. Front End" would support users which have JavaScript
turned off as well as the most common on. I have used a bit of Wicket
for Java and I like it. So I might use Wicket for that and have the
models (Wicket has the data needed for the web user interface in an
abstraction called models) talk to the "2. Business Layer".

When it comes to the "3. Database" I am leaning towards PostgreSQL, or
maybe MySQL. They have been around for a long while and at least I
know MySQL relatively well. The NoSQL solutions seems a bit
interesting too, but I have no experience with them.

My idea is basically to create a good Customer Relationships
Management (CRM) system and sell it as a service to companies. The
users will input information about customers and related events and it
will be easy to search. I'll have quite a lot of business logic which
makes these tasks easier. The logic will most often be stuff which
handles graphs (which SQL really has some problems handling nicely).

Some must have goals:

1. If it becomes a success, it needs to be able to scale over multiple
machines with load balancing. There will be some data which should be
replicated between the machines, but a delay is all right.
2. As I sell it uptime is important. If I have several machines and
one of them dies. I'd like the service to be available using the other
machines.

It would be nice if I supported both clients able to execute
JavaScript and those who do not. But I think most clients will be able
to use JavaScript.

My questions:

1. Do you think Wicket is a good choice for the front end for me? It
has session state on the server which I need to replicate in more or
less real time. If I have the state on the client using JavaScript I
don't have to deal with that replication. But how would I achieve that
in the most smooth way? Should I go for Compojure for the front end to
not have to deal with two languages? And then maybe skip the
separation of layer "1. Front End" and "2. Business"?

2. Will it be hard to write a nice web service interface in Clojure?
Is it a suitable communication strategy with Clojure? Maybe I am
making it too complicated?

3. Clojure has a lot of nice stuff for handling data in transactions.
But if all my data resides in a database will I get to really enjoy
this advantage? I have been thinking about actually storing the data
using Clojure and skip the database, to get more out of Clojure. Is
that idea too crazy? I will have to deal with data replication myself
then, or maybe something like memcache will solve it for me?

4. Clojure has stuff to deal with transactions. But so do databases.
How do they come together in a nice symbiosis? Making most of the
processing on the database is often regarded as a best practice. But
then I will be writing some logic in SQL and others in Clojure. I am
not so thrilled about SQL as I am with Clojure. Where should I draw
the line to get the best system and enjoy the fruits of Clojure?

5. Is it hard to debug Clojure? Using Java/C# today you get a real
treat when it comes to debugging with interactive stepping, expression
watching and a lot of other cool things. Where is Clojure debugging
compared to other languages? Is the debugging features as necessary as
in other languages?

6. And what about profiling? I guess I can use any JVM profiler. But
will it be hard for me to connect a performance problem with the
relevant Clojure code?

7. Any other advice or thoughts you have about this?

Thank you SO MUCH for reading this rather long mail! I appreciate it
and would really love if you have some feedback for me!

Best regards,
Kent Larsson

-- 
You re

Implementing let-over-lambda chapter 7 badger network for sorting

2010-08-01 Thread Christian Schuhegger
Hello,

I am currently trying to implement part of chapter 7 in let-over-
lambda in Clojure. I am used to writing ANSI Common Lisp code and
relatively new to Clojure. In CL it is possible to get a performance
gain over the standard lisp sort function by using compiled sort
networks. I am trying to achieve the same in Clojure.

My measurements are quite disappointing so far. If I use a sample set
of 50 Integers and repeat the sorting action 10 times and compare
the Arrays.sort performance against the sort network I currently get
following results:
"Elapsed time: 16.594209 msecs"
"Elapsed time: 1456.444706 msecs"
Which is a slow down of a factor of 100.

You can find my code here:
http://snippets.dzone.com/posts/show/11961

I am aware of the development of enhanced primitive type support:
http://www.assembla.com/wiki/show/clojure/Enhanced_Primitive_Support
http://clj-me.cgrand.net/2010/06/10/primitive-types-support-for-fns-coming-to-a-clojure-branch-near-you/
Could I expect improvements from those enhancements?

My question is basically:
1) Do I do something fundamentally wrong or
2) Do I have to expect that factor of 100 slow down for what I am
trying to do in general?

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


abstract structural binding

2010-08-01 Thread doug
Hey all!

can't seem to get the last element to bind. tia -doug

user> cj-mpdata
["0010335602   " "" "40.00" "" "1060.51" "6/23/2010" "DISCOVER E-
PAYMENT 7796" "" "" ("DISCOVER")]
user> (let [[[_ ck db cr _ dt _ _ _][dsc]]
   [["Acct" "Chk" "Debt" "Crd" "Bal" "Date" "Desc" "Payee" "Catagory"]
["newDescript"]]]
 [dt ck  db cr  dsc])
["Date" "Chk" "Debt" "Crd" "newDescript"]
user> (let [[[_ ck db cr _ dt _ _ _][dsc]] [cj-mpdata]]
 [dt ck  db cr  dsc])

["6/23/2010" "" "40.00" "" nil]
user>

-- 
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: Today is "Get Your App on Clojure 1.2" Day

2010-08-01 Thread lozh
These should be fixed in technomancy's github. He pushed
http://github.com/downloads/technomancy/leiningen/leiningen-1.3.0-SNAPSHOT-standalone.jar
yesterday, which I'd expect to include the fixes, though I haven't
tested it myself.

On Jul 30, 11:33 pm, Bootvis  wrote:
> There seems to be a problem with the RC on Windows. I was 
> followinghttp://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applica...
> using the RC and doing "lein.bat run script/run.clj" errors with:
>
> Exception in thread "main" clojure.lang.LispReader$ReaderException:
> java.lang.Exception: Invalid token: C:
>
> Is this problem known?
>

-- 
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: Today is "Get Your App on Clojure 1.2" Day

2010-08-01 Thread Dmitry Gutov
That's leiningen bug 62: 
http://github.com/technomancy/leiningen/issues/closed/#issue/62
It should be fixed in trunk.

On Jul 31, 2:33 am, Bootvis  wrote:
> There seems to be a problem with the RC on Windows. I was 
> followinghttp://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applica...
> using the RC and doing "lein.bat run script/run.clj" errors with:
>
> Exception in thread "main" clojure.lang.LispReader$ReaderException:
> java.lang.Exception: Invalid token: C:
>
> Is this problem known?

-- 
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: How to do multiple trys

2010-08-01 Thread abhinav sarkar
Thanks to everyone for their suggestions. This is what I have used finally:

(defn parse-date [date-str]
  (when-not (blank? date-str)
(let [clean-date-str (trim date-str)
  parse-or-nil
(fn [format]
  (try
(.parse format clean-date-str)
(catch java.text.ParseException e nil)))]
  (some parse-or-nil
[full-date-format date-format-wo-tz short-date-format-wo-tz]

Using some is better than using map because it will stop at the first
successful parsing.

Regards,
Abhinav

On Sat, Jul 31, 2010 at 3:05 AM, ataggart  wrote:

> Untested, but maybe this:
>
> (def- parse-date [date-str]
>  (when-not (blank? date-str)
>(let [date-str (trim date-str)]
>  (take 1
>(filter identity
>  (map #(try (.parse % date-str) (catch ParseException e nil))
>[full-date-format date-format-wo-tz short-date-format-wo-
> tz]))
>
> WARNING: SimpleDateFormat is not thread-safe, so it's probably a bad
> idea to stick one in a shared context like def.
>
>
> On Jul 29, 10:35 pm, abhinav sarkar  wrote:
> > Hi,
> > I am just starting to learn Clojure by writing a small library. I came
> > across a situation in which I have to parse a String for getting a Date.
> Now
> > the string can be in one of the three formats. So I wrote this functions
> to
> > parse it:
> >
> > (def #^{:private true :tag SimpleDateFormat} full-date-format
> >   (doto (SimpleDateFormat. "EEE, dd   HH:mm:ss +")
> > (.setTimeZone (TimeZone/getTimeZone "GMT"
> >
> > (def #^{:private true :tag SimpleDateFormat} date-format-wo-tz
> >   (doto (SimpleDateFormat. "EEE, dd   HH:mm:ss")
> > (.setTimeZone (TimeZone/getTimeZone "GMT"
> >
> > (def #^{:private true :tag SimpleDateFormat} short-date-format-wo-tz
> >   (doto (SimpleDateFormat. "dd MMM , HH:mm")
> > (.setTimeZone (TimeZone/getTimeZone "GMT"
> >
> > (defn- parse-date [date-str]
> >   (if (some #(% date-str) [nil? blank?])
> > nil
> > (let [clean-date-str (trim date-str)]
> >   (try
> > (.parse full-date-format clean-date-str)
> > (catch java.text.ParseException e
> >   (try
> > (.parse date-format-wo-tz clean-date-str)
> > (catch java.text.ParseException e
> >   (.parse short-date-format-wo-tz clean-date-str
> >
> > I can't help but think that there must be a better way to do the same
> > without so many nested try catch blocks. If this were Java, I could have
> > looped over all the date formats and used an explicit return in the try
> > block and continue in catch block. I don't understand how to do explicit
> > return in Clojure.
> >
> > Also as the number of formats grows, I'll have to add more nested try
> catch
> > blocks. Please suggest a cleaner way to do this.
> >
> > Regards,
> > Abhinav
>
> --
> 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: dtd question

2010-08-01 Thread Manfred Lotz
Hi Randy,

On Sun, 1 Aug 2010 06:23:58 -0700 (PDT)
Randy Hudson  wrote:

> Hi Manfred,
> 
> I'm sorry the code wasn't quite correct. The EntityResolver is set on
> the parser's XMLReader, not on the parser itself:
> 
> (def parser (.newSAXParser (SAXParserFactory/newInstance))
> (.setEntityResolver (.getXMLReader parser) resolver)
> 

It doesn't work. Even if I add a ) in the end I get
Exception in thread "main" java.lang.Exception: Too many arguments to
def (test.clj:21)

I tried then:

(def parser (doto (.newSAXParser (SAXParserFactory/newInstance))
(.setEntityResolver (.getXMLReader parser) resolver)))

which doesn't work either:
Exception in thread "main" java.lang.IllegalStateException: Var
xmltest/parser is unbound. (xmltest.clj:20)

I understand that parser after .getXMLReader cannot be resolved but I'm
unsure what has to be there.


-- 
Manfred



-- 
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: Today is "Get Your App on Clojure 1.2" Day

2010-08-01 Thread Phil Hagelberg
On Fri, Jul 30, 2010 at 3:33 PM, Bootvis  wrote:
> There seems to be a problem with the RC on Windows. I was following
> http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html
> using the RC and doing "lein.bat run script/run.clj" errors with:
>
> Exception in thread "main" clojure.lang.LispReader$ReaderException:
> java.lang.Exception: Invalid token: C:
>
> Is this problem known?

That's a bug in lein.bat, not in Clojure. It has been fixed in the
latest version, which should see a release next week.

-Phil

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


Re: dtd question

2010-08-01 Thread Randy Hudson
Hi Manfred,

I'm sorry the code wasn't quite correct. The EntityResolver is set on
the parser's XMLReader, not on the parser itself:

(def parser (.newSAXParser (SAXParserFactory/newInstance))
(.setEntityResolver (.getXMLReader parser) resolver)

You don't need any external jars: all the classes and interfaces are
in the JRE.

On Aug 1, 5:31 am, Manfred Lotz  wrote:
> Hi Randy,
> Thanks for your help. A bit late my answer because in the meantime I was
> on vacation and only now found the time to pursue it further.
>
> On Tue, 29 Jun 2010 18:53:30 -0700 (PDT)
>
>
>
>
>
> RandyHudson  wrote:
> > Yes, you can do this by defining an EntityResolver that corrects the
> > bad system id, define a SAXParser that uses that resolver, and pass
> > the parser into the xml/parse call. Something like this:
>
> > (import
> >   '[javax.xml.parsers SAXParserFactory]
> >   '[org.xml.sax EntityResolver InputSource])
>
> > (def resolver
> >   (proxy [EntityResolver] []
> >     (resolveEntity [public-id system-id]
> >       (InputSource.
> >         (if (= system-id the-bad-system-id)
> >           the-good-system-id
> >           system-id)
>
> > (def parser
> >   (doto (.newSAXParser (SAXParserFactory/newInstance))
> >     (.setEntityResolver resolver)))
>
> > (defn parse-xml [source] (xml/parse source parser))
>
> The problem I have with it is that I don't seem to find the right jar.
> I get an exception like this:
>
> Exception in thread "main" java.lang.IllegalArgumentException: No
> matching method found: setEntityResolver for class
> com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl (test.clj:14)
>
> I tried sax2r2.jar fromhttp://www.saxproject.org/.
>
> --  
> Manfred

-- 
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: dtd question

2010-08-01 Thread Manfred Lotz
Hi Randy,
Thanks for your help. A bit late my answer because in the meantime I was
on vacation and only now found the time to pursue it further.


On Tue, 29 Jun 2010 18:53:30 -0700 (PDT)
RandyHudson  wrote:

> Yes, you can do this by defining an EntityResolver that corrects the
> bad system id, define a SAXParser that uses that resolver, and pass
> the parser into the xml/parse call. Something like this:
> 
> (import
>   '[javax.xml.parsers SAXParserFactory]
>   '[org.xml.sax EntityResolver InputSource])
> 
> (def resolver
>   (proxy [EntityResolver] []
> (resolveEntity [public-id system-id]
>   (InputSource.
> (if (= system-id the-bad-system-id)
>   the-good-system-id
>   system-id)
> 
> (def parser
>   (doto (.newSAXParser (SAXParserFactory/newInstance))
> (.setEntityResolver resolver)))
> 
> (defn parse-xml [source] (xml/parse source parser))
> 
> 

The problem I have with it is that I don't seem to find the right jar.
I get an exception like this:

Exception in thread "main" java.lang.IllegalArgumentException: No
matching method found: setEntityResolver for class
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl (test.clj:14)


I tried sax2r2.jar from http://www.saxproject.org/.





--  
Manfred


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

2010-08-01 Thread Mark Engelberg
Meant to say, "...zip doesn't have a compiled jar..."

On Sun, Aug 1, 2010 at 1:36 AM, Mark Engelberg wrote:

> On Fri, Jul 30, 2010 at 8:00 AM, Stuart Halloway <
> stuart.hallo...@gmail.com> wrote:
>
>> Clojure 1.2 RC 1 is now available, along with a corresponding Clojure
>> Contrib, at:
>>
>> http://clojure.org/downloads
>>
>>
> Is there any particular reason the contrib release candidate zip have a
> compiled jar inside 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: Clojure 1.2 RC1

2010-08-01 Thread Mark Engelberg
On Fri, Jul 30, 2010 at 8:00 AM, Stuart Halloway
wrote:

> Clojure 1.2 RC 1 is now available, along with a corresponding Clojure
> Contrib, at:
>
> http://clojure.org/downloads
>
>
Is there any particular reason the contrib release candidate zip have a
compiled jar inside 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: Today is "Get Your App on Clojure 1.2" Day

2010-08-01 Thread Mark Engelberg
On Fri, Jul 30, 2010 at 8:52 AM, Stuart Halloway
wrote:

>
> Also, while
> microbenchmarks are often misleading, if you have some that seem to show 1.2
> issues I would be happy to run them and take a look.
>
> Stu
>
>
Yeah, I'm not talking about microbenchmarks -- my actual projects tend to
run about 10% slower in 1.2.

Just to give you one concrete example that you can try on your machine, to
see if you get the same results as I:
(use 'clojure.contrib.combinatorics)
(time (dorun (permutations (range 10
or
(time (dorun (permutations (range 11

I see a 10% slowdown on this function moving to 1.2 (both running under java
-server -Xmx1500m, sampled several times), just like I see on all the code I
have tested so far.

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