Re: Why does using a dynamic binding make a function impure?

2010-07-19 Thread Paul Moore
On 19 July 2010 19:41, Laurent PETIT laurent.pe...@gmail.com wrote:
 2010/7/19 Stuart Halloway stuart.hallo...@gmail.com

 use =  rely on

 In your example, func relies on a variable which is (presumably, based on
 its use in other-func) intended for dynamic binding. Therefore, func is
 impure.

 It is idiomatic to name such variables with earmuffs, e.g. *forty-two*.


 Sure.
 But the OP is somehow true: it is by convention that it is declared pure.
 Indeed, even func itself could have been rebound dynamically, thus making
 the content of the result theoretically unpredictable, given only the
 values of its arguments.

I think the point being made here is that, because other-func uses
dynamic binding (and hence is impure) you have to be more careful
about how you code it. For example, in the absence of impure code,
it is perfectly acceptable to name intermediate values freely - so

(defn demo1 []
  (+ (some-fn) 17))

and

(defn demo2 []
  (let [res (some-fn)]
(+ res 17)))

are exactly the same. That doesn't work with the impure other-func:

(defn other-func []
  (binding [forty-two 6] (func)))

vs

(defn other-func-2 []
  (let [res (func)]
(binding [forty-two 6] res)))

Transformations like naming intermediate values only work (at least,
without analysis) in the definition of pure functions.

When coming from an imperative language like Java or C, this seems
glaringly obvious - of course you have to be careful when moving
code round like that. The point is that in functional languages (and
in Clojure when you avoid impure functions) you *don't* have to be
careful - you can do as much of that type of refactoring as you want,
without worrying.

I hope that helps clarify things.
Paul.

-- 
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.sql does not protect table names?

2010-07-14 Thread Paul Moore
On 14 July 2010 16:21, Tim McCormack basalgang...@brainonfire.net wrote:
 Is there some kind of JDBC nonsense that I'm not aware of? Are
 backticks a special feature of MySQL that can't be read by all JDBC-
 compatible RDBMSs? I'm not a database person, but it seems to me that
 either backticks should be placed around all table, database, and
 column names, or a warning should be added to the docs about only
 using non-reserved alphabetic table names.

Certainly backticks aren't understood by Oracle. Unless JDBC does a
translation, I think it's database specific (Oracle uses double quotes
instead).

Paul

-- 
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: ClojureDocs.org

2010-07-13 Thread Paul Moore
On 12 July 2010 23:25, j-g-faustus johannes.fries...@gmail.com wrote:
 The site looks very nice, I especially like the find real world
 examples functionality and the fact that it collects documentation
 for common non-core libraries as well.

 I made my own cheat sheet for private use over the past month or so,
 core functions only. It's at the 80% stage, I don't expect it will
 ever be 100%, but I have found it useful:
 http://faustus.webatu.com/clj-quick-ref.html

Can I suggest omitting the Table of contents sidebar when printing?
I've not tried printing the document to see how it looks, but removing
the sidebar would be an essential starting point...

Paul.

-- 
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: Idiomatic Clojure namespace names

2010-07-10 Thread Paul Moore
On 10 July 2010 09:06, James Reeves jree...@weavejester.com wrote:
 On 9 July 2010 17:46, Paul Moore p.f.mo...@gmail.com wrote:
 Is there any benefit to using a name like foo.core (or foo.api) rather
 than simply foo (beyond sytlistic considerations, that is)?

 Clojure compiles foo to a package-less class called foo.
 foo.ciore is compiled to a class called core in the package foo.

 Package-less classes are a bit problematic if you want to call them
 from another Java package, IIRC. But if your library isn't intended to
 be AOT-compiled and used from Java, I don't think it makes a
 difference.

Ah! I hadn't realised the package/class distinction - a result of my
having no Java background. Thanks for the explanation, I can now
understand the trade-offs better.

Paul

-- 
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: Idiomatic Clojure namespace names

2010-07-09 Thread Paul Moore
On 9 July 2010 17:30, Laurent PETIT laurent.pe...@gmail.com wrote:
 Indeed, foo.api sounds better than foo.core to me, now than I'm exposed to
 that (core sounds more like 'internals'). But still I prefer to have the
 library name at the end of the namespace, it's easier to spot than in the
 middle (e.g. I prefer net.cgrand.parsley to paredit.core)

Is there any benefit to using a name like foo.core (or foo.api) rather
than simply foo (beyond sytlistic considerations, that is)? Leiningen
creates a foo.core source file as part of its new project skeleton,
but I prefer foo. Before I start fighting Leiningen, are there any
pitfalls I'll hit (other than the obvious problems of fighting your
tools...)?

Paul.

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

2010-07-06 Thread Paul Moore
On 6 July 2010 22:02, Greg g...@kinostudios.com wrote:
 Greg you're enthusiasm is appreciated. But this ML is filled with talented
 and smart people who have an equal grasp of logic and reason who have been
 using Clojure for a couple years now and they aren't clamoring to your nice
 snippet of code. That's something to consider.

 It is indeed. I would be surprised though if I was the only person who sees
 -- as useful, and that brings us to your next sentence...

 It is interesting that this is not the first time such a feature has been
 requested. But again, I haven't ever had a need for such a general threading
 macro.

 I'll make a list here of the reasons given for Yay/Nay so far:
 Nay:
 1) I haven't had a need for a general threading macro.
 2) The response so far is negative (and consists of repeating point #1
 above).

Sigh. I just *know* I shouldn't get involved in this...

- It isn't particularly readable. (I know you disagree with this, but
nevertheless, it has been stated as a negative point).
- It is perfectly possible to write the macro yourself and use it in
your own code. The fact that people haven't done this implies that
it's less useful than you claim (you'll say I'm repeating (1) here,
but never mind).
- It is easy to emulate using the existing macros and anonymous
functions like #(fn a % b).
- The named variable can be omitted from a form. The implications of
this are far from intuitive (and in the previous thread, there was
even a suggestion that this should be treated as an error).

 Yay:
 1) This has been requested multiple times. (Which pretty much cancels out
 Nay #1  #2).

I think the statement was that it's been requested twice. Better than
just once, but hardly multiple/

 2) -- is a generalized version of - and -, and therefore useful in
 situations where you can't use - or -. It is the 'nth' to 'first' 
 'last'.

If you use anonymous functions, there are no such situations. It's a
convenience rather than a generalisation.

 3) It makes code more readable by explicitly indicating where the argument
 is passed.

Your view. I find it very *un*readable. The first time I saw the let-
proposal, the named argument completely confused me. First, I misread
the forms as expressions rather than templates, then I didn't follow
the way the variable was (in effect) updated in each step.

 At least if I've outlined the positions correctly, it's pretty sad that this
 is being fought against so hard.

You haven't.

 I'll make the additional points that:
 - There are plenty of macros and functions in the core that I'm sure you've
 never used once, yet they are there for others who find them useful. So
 simply responding to my proposal by saying, I don't think I need it isn't
 a valid reason against its inclusion.

Correct. The argument you are mischaracterising is that there is no
evidence that an existing body of code (such as clojure core or
clojure contrib) would benefit in any significant way from the
proposal.

Paul.

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

2010-07-06 Thread Paul Moore
On 6 July 2010 22:24, Greg g...@kinostudios.com wrote:
 This would be most likely java interop, ie. -.
 There the main arguments are 99% of the times the first or the last ones. So 
 - or - will work

 OK, so what happens when one of the functions takes it in the front, and the 
 other in the back?

 Or what happens when you're using a piece of code that doesn't follow either 
 convention? Are you
 saying such code doesn't exist?

Use an anonymous function.

 In both those cases, - and - become useless.

Not useless, merely less convenient.
Paul.

-- 
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: Documentation and examples (and where is the documentation on reduce)?

2010-07-02 Thread Paul Moore
On 2 July 2010 15:50, Meikel Brandmeyer m...@kotka.de wrote:
 Then there are examples like this one:
 (reduce '* '(1 2 3))

 Someone who is new to Clojure and tries to understand reduce... Does
 he understand why the result is 3? A result which relies on a not very
 well-known fact, that you can actually call symbols like keywords for
 map lookup with up to two arguments. (I bet there quite a few of
 seasoned clojurians who didn't know that) I - if I was a newbie to
 the language - would mainly think: wtf?

Even with your explanation, I'm baffled... I can get to

user= ('* ('* 1 2) 3)
3

Ah. This means look '* up in ('* 1 2) and use 3 as the default if you
don't find it. And you don't (for all sorts of odd reasons - why
doesn't this raise a what are you doing, it's not even a map you're
looking up in exception? :-)), so the result is the default, 3.

Uh, yeah.

That example is actually harmful - as it confused me about what does
and doesn't need quoting - something I would probably have got right
instinctively until I read this :-(

Paul.

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


Managing the classpath

2010-07-01 Thread Paul Moore
First, a disclaimer - I don't have any problem with the idea of the
classpath in Java. In principle, it's pretty similar to Python's
sys.path. And jar files are much like Python having zip files on
sys.path. So I'm familiar with the idea.

Where I struggle is with the practicalities of managing the classpath.
From what I can tell, there is no way of modifying the classpath from
a running Java/Clojure program (barring use of a custom classloader
which sounds like deep magic). So, assuming that is right, I need to
list my dependencies in advance, when I start the JVM (either by
setting the CLASSPATH environment variable, or with the -classpath
argument).

Generally, I avoid using global environment variables like CLASSPATH
(except if they are locally set in a wrapper script), so I guess that
I have the following options for my Clojure applications:

* Use something like lein uberjar to wrap all my dependencies up in one file
* Create an application-specific wrapper, which sets CLASSPATH (or
uses -cp) and runs my application

I have personal reservations about both of these options (I won't
elaborate, to avoid boring people with my prejudices - ask if you
really want to know) so I guess my question would be - is there
another option I have missed?

Python doesn't have these issues because (a) conventionally,
dependencies are installed into the site-packages directory which is
on the standard sys.path - it appears to me that the JVM doesn't have
such an always available install location, and (b) for special cases
sys.path can be manipulated at runtime (as noted above, the JVM
doesn't really have this option).

One further question - does having a lot of entries on CLASSPATH slow
down JVM code (either at startup time, or in terms of slowing down
runtime class loading)? Essentially, is there a cost to including
things like clojure-contrib just in case? (I don't imagine that the
cost would be significant for just one such case, but I could imagine
that if the practice were to become common, it wouldn't be long before
there were many extra entries, not just one).

I appreciate that this question is only tangentially Clojure-related.
If there is a better forum to discuss this type of question, please
feel free to direct me there.

Thanks,
Paul.

-- 
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: Managing the classpath

2010-07-01 Thread Paul Moore
On 1 July 2010 15:29, Laurent PETIT laurent.pe...@gmail.com wrote:
 Hello,

 note that with java 6 you can specify at once to add all the jars
 located in a directory:

 java -cp libs/* clojure.main

 and you can place any jar you want in directory libs.

 and this is composable:

 java -cp clojure.jar:libs/* clojure.main

 My 0.02€, just in case you didn't know this (rather recent) possibility.

Thanks. I had actually just discovered this possibility in the last
few days. In fact, it is what raised in my mind the question of
whether having too many jars on the classpath would hurt performance.
I've not yet fully integrated the idea into my thinking.

I guess it allows the possibility of bundling all application
dependencies into a lib directory, then doing something like java -cp
clojure.jar;lib/* clojure.main myapp.clj

But in practical terms, I guess that's the equivalent of an uberjar.
(My biggest concern about an uberjar is that I end up with each app
having a separate bundled copy of all its dependencies. That makes
version management a huge pain - imagine a bugfix release of
clojure.jar - but is otherwise not an unreasonable option).

Paul.

-- 
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: Managing the classpath

2010-07-01 Thread Paul Moore
On 1 July 2010 16:49, Kevin Livingston kevinlivingston.pub...@gmail.com wrote:
 Some of the build tools like Maven can help a lot.

(Thanks for your other comments, which I've cut. But this one made me think).

I've heard comments like this elsewhere (with regard to both Maven and
Leiningen), but I'm not quite sure I follow. You say

[...]
 put the jar on ProjB's class path

But as I understand it, ProjB doesn't *have* a classpath in its own
right - rather, when you run ProjB, you specify a classpath (and if
you get it wrong, ProjB won't run). But there's no concrete,
discoverable entity that can be considered ProjB's classpath, and
referenced from elsewhere. Otherwise, the often-quoted clj.bat driver
script could be written as

Get %1's classpath into CLASSPATH somehow
java clojure.main %1

and nobody would ever worry about classpaths again :-)

If Maven (and/or Leiningen) actually do maintain, for each project,
metadata including its required classpath, then I'd love to know how
to extract that metadata - because I could certainly use it to write a
generic driver script (at least for my own purposes, even if it wasn't
sufficiently general for every use).

Paul.

-- 
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's n00b attraction problem

2010-06-30 Thread Paul Moore
On 30 June 2010 04:02, Jason Smith ja...@lilypepper.com wrote:
 So I'll say it again, it's just not that simple.  Unless you already
 know Java, and the only learning curve you face is the new features in
 Clojure.  Then it's not bad. But it does give you new ways to cut your
 foot off more quickly. :-)

An interesting alternative not that simple point of view, that it's
not Clojure's Lisp-like features that are the hard bit, but the Java
integration :-)

Based on this comment, maybe I could ask an alternative question - can
you suggest where I should go to read some tutorials which would give
me a fast start on just enough Java infrastructure to get
comfortable in Clojure? Most of the Java tutorials I've seen tend to
assume I want to learn Java - I know enough Java to read code samples,
and that'll do for what I want.

Paul.

-- 
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's n00b attraction problem

2010-06-30 Thread Paul Moore
On 29 June 2010 23:31, Sean Corfield seancorfi...@gmail.com wrote:
 FWIW, I blogged a short step-by-step post on getting up and running
 with Leiningen to show some Clojure at the repl, run as a script and
 compiled to a JAR and run via java:

 http://corfield.org/blog/post.cfm/getting-started-with-clojure

 Bear in mind my blog audience is folks with some familiarity with Java...

That's nice! I never noticed lein repl before...

One thing I've found is that the experience (as described) is a lot
simpler on Unix/Linux/Mac than my experience on Windows. Part of the
reason may be that lein self-install doesn't work on Windows. I may
look into that.

I wonder - would a Windows installer package that installed clojure,
clojure-contrib and leiningen, and set up some basic paths and start
menu shortcuts be of use? I'm not a great fan of installers myself,
but I suspect that once I get a clean working environment set up for
myself, it wouldn't be a big step to package that up in an installer
so that others could use it.

Paul.

PS What are the standards for jar naming conventions? I have seen some
people use clojure.jar and others use clojure-1.1.0.jar. Should I
have version numbers in my jar filenames? Is there a Java best
practice I should be referring to for things like this?

-- 
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: Newb Question

2010-06-29 Thread Paul Moore
On 28 June 2010 20:24, Angel Java Lopez ajlopez2...@gmail.com wrote:
 Hi people!

 Any way to produce a lazy seq of chars, that prints as a string, based on
 two parameters, n (number of repeats), text (text to repeat)?

 Then, something like

 (myrepeat 100 superdupertext)

 could be implemented without a big processing or concatenation.

The built in repeat is lazy:

user= (doc repeat)
-
clojure.core/repeat
([x] [n x])
  Returns a lazy (infinite!, or length n if supplied) sequence of xs.

Paul.

-- 
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's n00b attraction problem

2010-06-29 Thread Paul Moore
On 28 June 2010 19:49, Mike Meyer
mwm-keyword-googlegroups.620...@mired.org wrote:
 Yet another set of choices n00bs are faced with is figuring out how
 to actually compile their source into an executable.

 Executable? We're talking about Java here. It doesn't do executables -
 it does jar files. There's little reason to build those as a newb, as
 it's not noticeably harder to run the source than it is to run a jar
 file - or to import them if you're building libraries.

We're not talking about Java here, we're talking about clojure!

A certain proportion of new clojure users are coming from
non-Java/non-JVM backgrounds. To them, how do I make an executable
is a perfectly valid question. And clojure doesn't do executables
isn't a particularly encouraging answer (not even if you blame Java
for it :-)) Classpaths, server vs client JVMs, ant/maven, all of these
are confusing hurdles to get over if you don't have any Java
experience.

For such people, introductory clojure material needs to (a) assume no
JVM/Java knowledge, and (b) provide some guidance for how to interpret
the inevitable Java terminology that a newcomer will encounter. For
example:

Q: How do I make an executable in clojure?
A: Clojure scripts can be executed in a similar manner to scripting
languages like Python or Perl - clj myscript.clj. [Note: a standard
clj wrapper script should be supplied with clojure!] However, even
when executed like this, clojure code is compiled (for more details
read up on JVM bytecode, and the Java just in time compilers). You
can compile clojure code into a jar file - which is a JVM executable
format which can be run using the java command (insert reference to
more detailed explanation here). More or less self-contained formats
(bundling dependencies, or hiding the invocation of the java
command) are possible, but are generally reserved for more specialised
applications.

Q: What are ant, maven?
A: JVM build systems, commonly used in the Java world. The clojure
community is beginning to standardise on Leiningen (insert reference
here) which uses a more clojure-like language for describing builds,
but which works with the existing ant/maven infrastructure (so all of
the existing libraries available via these tools are available for
free in Leiningen).

If these examples are useful, feel free to add them to a FAQ or newbie
documentation.

Paul.

-- 
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: Life on the bleeding edge

2010-06-29 Thread Paul Moore
On 29 June 2010 06:47, Mark Engelberg mark.engelb...@gmail.com wrote:
 Yes, that is disconcerting that clojure-contrib produces errors on
 Windows (sigh, it often feels like Windows is a second-class citizen
 when it comes to clojure), but that did the trick and allowed the
 build to complete.  Thanks for the tip.

Is there anything a clojure newbie with little JVM development
experience (but a willingness to learn) can do to help with the
Windows situation? From what I understand, Java itself is fine on
Windows, so I assume this is a clojure-specific issue?

Paul.

-- 
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's n00b attraction problem

2010-06-29 Thread Paul Moore
On 28 June 2010 23:13, Lee Spector lspec...@hampshire.edu wrote:
 and more recently I had to figure out about.dotted.names and their meaning 
 with respect to directory structures,
 in order to get require to find a second clj file. It's not complicated, but 
 it's also not obvious to everyone first coming
 to Clojure.

That's actually far more of a stumbling block than the classpath. In
my experience, very few languages/environments tie directory structure
and language identifiers (class name in Java, namespace in Clojure)
together as closely as the Java/JVM environment. As in, if you change
the filename, you have to change the namespace declaration as well -
and vice versa. Or Clojure can't find your code, and you have no idea
why :-(

And yet, there's no reference that I can see to this fact in any of
the Clojure tutorials. Not even in Programming Clojure (which is
generally a great book). I could have missed something, of course - I
wasn't looking for the information - but I've hit the issue a couple
of times, so I suspect if I had seen anything, I would have
remembered.

Paul.

-- 
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's n00b attraction problem

2010-06-29 Thread Paul Moore
On 28 June 2010 22:41, cageface milese...@gmail.com wrote:
 On Jun 28, 12:16 pm, Martin DeMello martindeme...@gmail.com wrote:
 It depends. I found the concepts pretty easy, since I have done a lot
 of functional programming, but when I was new to clojure I had a truly
 horrible time figuring out the various classpath issues needed to get
 things working.

 What is it about the classpath in particular that people find
 difficult? Is it that different from things like PYTHONPATH or
 RUBYLIB? The main differences I can see are:

For me (and to be honest, I don't have any real problem with the
*concept* of the classpath, just with some of the practicalities) it's
the fact that by default, Clojure doesn't work. OK, that's overstating
it - the issue is that clojure.jar isn't on the *default* classpath.
This is hardly surprising, of course, but it does make it harder - you
encounter the classpath right at the start, before you even get
Clojure running. And unless you write your own wrapper, you keep
having to deal with it (hmm, java -cp, now where did I put clojure,
D:\Apps\Clojure\clojure.jar, clojure.main, oops no, this is the PC
it's on the C drive. Or ...). I know you can set the global
CLASSPATH, but that feels a bit too general - what else might it
affect?

The simple fix to that, of course, is to supply a small wrapper script
with clojure. The response it's easy for you to write one yourself
misses the point - we're talking about the out of the box experience.

If clojure.org included a Download Clojure link that pointed at a
zipfile containing clojure.jar, clojure-contrib.jar, and a wrapper
script (well, two, one for Unix, one for Windows) which set classpath
based on the location of the script and ran Clojure, then people could
download that, unzip it anywhere, and go. It doesn't solve all the
world's problems, but it sure simplifies the initial experience!

For what it's worth, here's a trivial clj.bat for Windows:

@echo off
setlocal
set CLASSPATH=%~dp0clojure.jar;%~dp0clojure-contrib.jar;%CLASSPATH%
java clojure.main %*
endlocal

Add as much extra complexity as you like, but that's enough for a starter.

Paul.

-- 
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's n00b attraction problem

2010-06-29 Thread Paul Moore
On 29 June 2010 06:11, cageface milese...@gmail.com wrote:
 On Jun 28, 9:14 pm, Michael Richter ttmrich...@gmail.com wrote:
 Ah.  The Clojure community has already started down the road to Common
 Lisp-style, smugness-generated obscurity and disdain.  Bravo!  Well-played!

 Not at all. Nothing would make me happier than Clojure for Dummies
 and Wrox Professional Clojure books on the shelves of every Barnes 
 Noble programming section. It's pained me to watch Python and Ruby far
 outpace the growth of any functional language in the last ten years.
 I'd love to stop looking for excuses to sneak things like Clojure
 under the radar at work and actually have a management mandate to use
 them.

It is very, very hard to get a decent characterisation of newbies.
It's too wide a range. You've lumped at least three different
possibilities in the paragraph above alone:

- Completely new programmers (Clojure for dummies) who need to learn
things like what is recursion, how do I do the same thing 10
times, etc.
- Experienced programmers in a scripting language (Python/Ruby) who
know how to program and need to know how Clojure differs (and there's
a whole subrange in here).
- People who work in a Java Shop (sneak things like Clojure under
the radar - I'm making assumptions here) and who work with the JVM
regularly, but maybe have little or no experience with
non-traditional languages.

And by my own argument, there are many more possibilities. Each of
these groups will want something different (or more likely, look for
the best fit in what they can find, and ignore the bits they don't
need).

It's important to look at what people are actually asking for in each
case, and not offer a single generic response to everyone (you'd
offend me if you suggested I need Clojure for Dummies, but on the
other hand, you'd look elitist to someone who had never programmed
before if you launched straight into recursion or the advantages of
immutability when a new programmer asked for help getting his Hello,
World program to write its output 10 times...)

 The fact remains though that Clojure trades in heavy concepts. The
 syntax alone will simply be a non-starter for at least half the
 potential audience. Toss in concurrency and non-mutability and
 ubiquitous recursion which are tricky concepts no matter how cleanly
 exposed in the language.

Only for certain audiences. And anyone can learn given a sympathetic
teacher. What I wouldn't do is expect people to have to pick up
multiple things at once. That's why, for people who are new to the
language concepts in Clojure, I'd say you want a fast start
environment which lets them get straight to writing (simple) code.
Writing a hello world program, or your first recursive factorial,
shouldn't be hard.

java -cp clojure.jar clojure.main myprog.clj isn't hard, but a
trivial script that wraps that as clj myprog.clj is a little less
intimidating (and as a bonus, matches the expectations of people who
have seen Python, Ruby, or any one of many others). And a
straightforward if you like IDEs like Visual Studio, grab this
package for now and you're off will help people who prefer an IDE.
(They can make their own choice from the various options later, when
they have more experience).

 As many posters have said in this thread, you
 really do have to have a decent grasp on Java to do real work in
 Clojure so you're already on the hook for two languages, one of which
 is a baroque and provincial monster.

OK, that's a good point. For people who won't have an issue with
Clojure's concepts (e.g. Lisp users, people with a wider range of
programming experience, etc) this means the message is you want to
learn Clojure - presumably because it's a high-level, sophisticated
language - so you also need to learn Java (which, frankly, is pretty
much the antithesis of a sophisticated language in many such
people's minds).

Maybe JVM experience can't be avoided. But it's a bitter pill to
swallow for a certain class of newbies (and this is where I'd place
myself) so why not try to make it easier? As some examples of what
could be done:

- Build a page of JVM concepts for non-Java programmers
- Collect links to tutorial information on the key JVM concepts,
looking particularly for material which is as language-agnostic as
possible. The Jython, JRuby, Groovy, Scala people presumably also have
this problem - why not share any generic links with them?
- Promote clojure-like alternatives to Java tools (Leiningen vs Maven)
for people with non-Java background. Work with such people to pick out
places where the documentation of such tools assumes too much
knowledge, and work to improve it (I'll help here!)
- Give examples of how to use the more obvious benefits of the
JVM-hosted environment:
  * How to find and use some of the huge range of 3rd party Java code
out there (not interop, but finding things on the net, referencing
them in your project, etc etc).
  * How to use the scalability of the JVM (hosting a Clojure app 

Re: Newb Question

2010-06-29 Thread Paul Moore
On 29 June 2010 15:14, Angel Java Lopez ajlopez2...@gmail.com wrote:
 Hi people!

 Paul, yes! but...

 The apply and str evaluations in (apply str (repeat n text))
 are lazy?

 I guess the result could be a big string.  Isn't it?

So you're looking for a result that behaves like a string, but isn't
an actual java.lang.String, rather it's a type that produces
characters lazily, on demand somehow?

I'm afraid I've no idea if Clojure has such a thing, or even if it
could support such a thing. (There's no string abstraction similar
to the seq abstraction, as far as I'm aware). But I'm very new at
Clojure, so I could easily be wrong...

Paul.

-- 
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: Life on the bleeding edge

2010-06-29 Thread Paul Moore
On 29 June 2010 18:36, Mark Engelberg mark.engelb...@gmail.com wrote:
 On Tue, Jun 29, 2010 at 12:30 AM, Paul Moore p.f.mo...@gmail.com wrote:
 Is there anything a clojure newbie with little JVM development
 experience (but a willingness to learn) can do to help with the
 Windows situation? From what I understand, Java itself is fine on
 Windows, so I assume this is a clojure-specific issue?

 Paul.

 Tom mentioned to me a few weeks ago that he'd love to have some help
 getting autodoc to work on Windows, and that he'd be willing to
 supervise someone who had the time to make the changes.  That might be
 a great way to dive in!

OK, I'll take a look.

Thanks.
Paul

-- 
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: Leiningen documentation review?

2010-06-29 Thread Paul Moore
On 29 June 2010 21:03, Phil Hagelberg p...@hagelb.org wrote:
 On Wed, Jun 16, 2010 at 9:24 PM, Phil Hagelberg p...@hagelb.org wrote:
 Mostly I'd like feedback on the tutorial:
 http://github.com/technomancy/leiningen/blob/master/TUTORIAL.md

 But if you've got some time to look over the readme, that would be
 great too: http://github.com/technomancy/leiningen/blob/master/README.md

 With all the newbies that have chimed in recently with strong opinions
 on the newbies thread, I was wondering if I could convince some of
 them to help the out-of-the-box experience by suggesting improvements
 to the recently-revised pieces of documentation above. =)

I'd read the current versions of the docs. The README seems not to
have changed much, but that's OK, it was pretty good before.

The tutorial looks pretty good now - it does an excellent job of
covering what's needed of the Maven infrastructure without expecting
the reader to follow Java-style material or read too many links to
source documentation.

One thing I would have found useful, although it's not strictly
something for Leiningen, is a brief explanation of how namespace
declarations need to match filenames. My experience so far is that all
my initial code has been single-file scripts (where I could get away
with ignoring namespaces and just naming the file whatever I wanted).
When I made the leap to proper projects, I moved to Leiningen and at
the same time, I encountered namespaces - so a note in the Leiningen
documentation on how to define my namespaces to match my project
structure would have saved me a significant amount of grief!

Paul.

-- 
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: Batch file wrappers on Windows

2010-06-22 Thread Paul Moore
On 21 June 2010 22:12, Russ Olsen russol...@gmail.com wrote:
 Paul,

 One way would be to use the cljw.exe that comes with
 dejour. This is a windows executable that runs clojure
 without creating that annoying extra window.

Thanks. That's certainly one option - I could probably without too
much difficulty put together something similar for Leiningen.

It sounds like there isn't a generic answer, so going with a custom
launcher sounds viable. Hmm, I wonder whether a stub executable plus a
suitable Ant task / Leiningen plugin (see how I use these terms like I
know what they mean? :-)) would be an option - add some static data
onto the stub, which the stub reads and sets the appropriate variables
and command line args, then launches Java.

Something to think about...
Paul.

-- 
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: Batch file wrappers on Windows

2010-06-22 Thread Paul Moore
On 22 June 2010 00:11, Rick Moynihan rick.moyni...@gmail.com wrote:
 On 21 June 2010 18:42, Paul Moore p.f.mo...@gmail.com wrote:
 3. Using a bat file to start a GUI application from Explorer causes an
 unnecessary and ugly console window to appear.

 You should use javaw instead of java to start the JVM without the
 console window appearing.  This should ship with both the JRE and JDK
 on Windows.

Sorry for not being clear - I know about javaw, but even with that,
double clicking on a .bat file flashes up a console window (briefly).
I can also set the console to start minimised and it's then a very
minor inconvenience. As I said, there are workarounds (and this is the
least problematic of the three issues I noted) but I still find it an
issue.

Clearly others don't get so up tight about these inconveniences as me,
which is fine. At least that means I haven't missed a solution that
already exists.

Thanks for the feedback,
Paul.

-- 
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: Batch file wrappers on Windows

2010-06-22 Thread Paul Moore
On 22 June 2010 15:15, Lars Nilsson chamael...@gmail.com wrote:

 Maybe Windows Script Host is an option, if you haven't looked at that one yet.

Yes, WSH/VBS is a reasonable option. There are some gotchas which you
need to be careful of though - there's *still* only one filetype
(.vbs) which is executed by cscript or wscript depending on
user-settable defaults (cscript //H:wscript) which makes it
unreliable.

For a really robust solution, I think a custom EXE might be the best
(for the user) answer.

But this is probably far too Windows-specific for the list now. I'll
go off and try to implement something and report back.

Thanks for all the feedback,
Paul.

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


Batch file wrappers on Windows

2010-06-21 Thread Paul Moore
The common way of running Java applications (and hence Clojure code)
on Windows seems to be to use a batch file wrapper (for example,
lein.bat for Leiningen). It seems to me that there are a number of
issues with this:

1. Batch files don't nest well - if I want to call lein.bat from
within another batch file, I have to remember to say call lein arg
arg... rather than simply lein arg arg... as the latter doesn't
return to the calling script.
2. I use JP Software's Take Command, which implements a command
language almost, but not precisely, like that of cmd.exe. As a result,
lein.bat (in particular, possibly others) fails with syntax errors. I
appreciate that this is a Take Command problem (and it's not too hard
to work around, in fact) but nevertheless it does routinely trip me
up. And presumably other Take Command users have the same problem.
3. Using a bat file to start a GUI application from Explorer causes an
unnecessary and ugly console window to appear.

Before I spend time trying to solve a problem that the Java community
turns out to have solved years ago, is there another solution that
people use? Or is it just one of those things that Windows people put
up with (I'm not a typical Windows user, I guess :-))?

Thanks,
Paul

-- 
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: Basic toolset for non-Java programmer

2010-06-19 Thread Paul Moore
Thanks to Ryan, Rob and Alex for the suggestions. I'll have a deeper
look into all of them.
Paul

-- 
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 script in the classpath

2010-06-19 Thread Paul Moore
On 19 June 2010 07:24, rzeze...@gmail.com rzeze...@gmail.com wrote:
 On Jun 18, 6:15 pm, Paul Moore p.f.mo...@gmail.com wrote:
 I've just seen a couple of postings which, if I'm not mistaken, imply
 that it's possible to have a Clojure script in my classspath. Is that
 right?

 Yes, you can have .clj files on your classpath.  In fact, you can
 pretty much have anything on your classpath.  Checkout
 java.lang.ClassLoader 
 http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String)
 .  This is what Clojure uses under the covers.

Thanks! (And thanks for the rest of your comments). I'll look into
this a bit more. I think that my experiments were failing because I
had the namespaces wrong - thanks for the pointer.

Paul.

-- 
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 script in the classpath

2010-06-19 Thread Paul Moore
On 19 June 2010 17:22, Chas Emerick cemer...@snowtide.com wrote:
 If you're just looking to run a script that happens to be on the classpath,
 you can do so by prepending an '@' character to the classpath-relative path
 to the script.

 So, if a directory foo is on your classpath, and a clojure file you'd like
 to run is at foo/bar/script.clj, then you can run it with:

 java -cp your_classpath_here clojure.main @/bar/script.clj

 FWIW, this is noted in the documentation for clojure here:

 http://clojure.org/repl_and_main

Nice! Thanks.
Paul.

-- 
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-18 Thread Paul Moore
On 18 June 2010 15:08, Stuart Halloway stuart.hallo...@gmail.com wrote:
 While I enjoy a theoretical debate as much as the next person, it would be
 nice to see

 (1) examples of real code that fail on reasonable inputs, if this change
 were made. And how difficult it would be to fix them.

 (2) examples of real code that get way faster, and the ease of making those
 changes (if any).

 WRT #1, we have tested a few dozen libs, and found only a single trivial
 breakage in their test suites. But I would say tha is still just plural
 anecdotes. More data welcome!

I'm new to clojure, and while I have an interest in fast number
crunching, and in easily using big numbers, I don't have a valid
opinion on the whole matter.

However, I know that some time back, Python changed in precisely the
opposite direction - from separate small and big numbers to a unified
numeric type. Their situation is completely different (not least
because all Python objects are effectively boxed, so the speed benefit
of primitive arithmetic isn't relevant) but there may be real-world
examples of code that demonstrates (1) in the Python discussions. If
the information might be useful, I'd be happy to do some searching of
the archives.

Paul.

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


Basic toolset for non-Java programmer

2010-06-18 Thread Paul Moore
I'm wondering, what would be a useful basic set of tools for a
newcomer to Clojure with no Java background? I'm not really talking
about IDEs (everyone has their own opinions about IDEs, and I've seen
some discussions elsewhere to give me some pointers on that one). I'm
more interested in things like build tools, testing frameworks,
debuggers, etc. Also, in terms of deployment, what should I be looking
at?

To try to clarify what I mean:

- Build tools: There seem to be things like ant, maven, leiningen. How
do they relate to each other? Is there an obvious best answer or
should I be expecting to check them all out depending on my needs? In
that case, are there any good comparisons around?
- Debuggers: Should I be assuming I use my IDE for debugging? What if
I stick to a basic text editor to develop my code? Is there a good
standalone debugger?
- Profilers: Same sort of question - do IDEs offer this, are there
standalone tools?
- Testing: I've not really got to the documentation on Clojure's own
testing tools, so maybe that's all I need, but are there testing
frameworks I should look at, that sort of thing?
- Deployment: For simple standalone utilities, am I looking at bat
file wrappers (I'm on Windows mainly) to set classpath and the like?
Given that there are some annoying limitations with bat files (nasty
nesting behaviour, ugly console windows for GUI applications), are
there any commonly used better solutions? For web applications, I
gather that a servlet container (all that fancy J2EE stuff :-)) and
something like compojure is a good place to start. For non-web
long-running services, is it still reasonable to use an application
server, or should I be looking at something to wrap a Clojure app up
as a Windows service (something like Java Service Wrapper
(http://wrapper.tanukisoftware.org/doc/english/download.jsp) came up
for me on a Google search)?

That's a lot of stuff, and I certainly don't need to dive into all of
this at once, but any pointers, comments or suggestions would be very
gratefully received.

Thanks in advance,
Paul.

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


java -server

2010-06-03 Thread Paul Moore
More of a Java question than a Clojure one, but it's in the context of
clojure, and I don't know a better place to ask, so forgive me...

I've seen a couple of references in articles about clojure to using
java -server. My java executable has a server option, but when I
try it, I get told:
Error: no `server' JVM at `C:\Program Files\Java\jre6\bin\server\jvm.dll'.

I have
java version 1.6.0_20
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

This is on Windows 7 32 bit. Is there a different download I should be
using to have a server VM available? (Is it just a J2EE thing? I've
never used J2EE except in enterprise setups, and I'd certainly not
expect to use it on my PC).

Paul.

PS I suppose there's a more general question - does java -server
make enough of a difference for me to be bothering about all this?

-- 
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: java -server

2010-06-03 Thread Paul Moore
On 3 June 2010 21:25, Aaron Cohen aa...@assonance.org wrote:
 This error indicates that your java executable is coming from the
 JRE rather than the JDK. On windows, the JRE only includes the
 client virtual machine.

 If you have the JDK already installed on your computer, switch your
 JAVA_HOME and PATH to use it instead, and try it again.

Thanks, that was precisely the issue.

Regards,
Paul.

-- 
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: Multithreading didn't make my program as much faster as I expected...

2010-05-31 Thread Paul Moore
On 31 May 2010 06:12, Zak Wilson zak.wil...@gmail.com wrote:
 The trouble with pmap is that it only works well with a slow function
 and a short sequence. In trivial tests, it seems to be best if the
 sequence has as many elements as you do cores.

 I've been experimenting with things that are like pmap, but work
 better in situations that I care about. I'm having trouble getting
 full performance out of a quad-core machine, but dual-core is working
 pretty well so far. Here's some discussion with a link to sample code:
 http://groups.google.com/group/clojure/browse_thread/thread/963cdb76f0c3c178

 And here's my personal utility file containing mostly re-
 implementations of things I didn't know where to find. The zpmap
 function is an eager parallel map that works well on large vectors and
 maps with a fairly fast function:
 http://github.com/zakwilson/zutil-clj/blob/master/util.clj

Interesting! Reducing the number of parallel threads in my test case
from 10 to 2 improved the speed of the test from 12 seconds to 10,
which is about as good as can be expected. And it immediately steps
back up to 12 seconds when I use 3 threads.

So for CPU intensive tasks, it seems that having precisely the same
number of threads as CPUs gives the best performance. It looks like
Java schedules 1 thread per CPU, until it can't, and at that point
scheduling overhead kicks in (costing something like 30% performance).

How did you arrive at the number of CPUs + 2 approach in zpmap? I'd
have thought that the +2 would hurt performance as it did in my case.

So even when Clojure makes threading as easy as possible, it's still
complicated in subtle ways. Ah, well :-)

Thanks for the help.
Paul.

-- 
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 script with shebangoid on windows

2010-05-31 Thread Paul Moore
On 31 May 2010 07:48, alux alu...@googlemail.com wrote:
 Hello Glen, good hint. Problem and solution reproduced ;-)

Yes, it looks like Clojure's (comment ...) form requires the contents
of the comment to be syntactically correct Clojure forms. As Glen
says, forward slashes seem to work - although personally, I dislike
being forced to use forward slashes on Windows :-(

Is there a multi-line comment form in Clojure that can contain arbitrary text?
Paul.

-- 
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 script with shebangoid on windows

2010-05-30 Thread Paul Moore
On 30 May 2010 12:31, alux alu...@googlemail.com wrote:
 Small addition, you missed to add the : before eof

 replace goto eof by goto :eof

Thanks, good catch. (goto eof without the colon works on TCC, which
I normally use as my command shell).

Paul.

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


Multithreading didn't make my program as much faster as I expected...

2010-05-30 Thread Paul Moore
I've written a small simulation program, in order to help me learn
Clojure. I've reproduced it below. It's quite likely not very
idiomatic - any suggestions on how to improve it would be nice.
However, my main concern is that it doesn't seem to scale as I would
expect when multi-threading.

The simulation is a simple test of rolling 3 6-sided dice 1,000,000
times. It uses Sean Luke's Java implementation of the Mersenne Twister
RNG. I'm using the fast (non-threadsafe) version, which is why I'm
using a separate MT instance in each thread.

The non-threaded version takes about 18 seconds to run, with CPU
showing at about 50% throughout (on my dual-core PC). The threaded
version shows CPU maxed out at 100%, but still takes 12 seconds to
run. That's not a bad speedup, but it still implies there's about a
33% overhead for multithreading.

Are these plausible sorts of figures to see? Or should I be able to
get extra performance by tricks I haven't thought of?

Thanks,
Paul.

(use 'clojure.contrib.accumulators)

(defn D [mt n m]
  (apply +
(take n
  (repeatedly #(+ 1 (.nextInt mt m))

(defn histogram [s] (add-items empty-counter s))

(defn testN [count n m]
  (let [mt (ec.util.MersenneTwisterFast.)]
(histogram (take count (repeatedly #(D mt n m))

(time (pr
  (testN 100 3 6)))
(time (pr
  (apply combine (pmap #(testN % 3 6) (repeat 100 1)
(shutdown-agents)

-- 
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 script with shebangoid on windows

2010-05-28 Thread Paul Moore
On 28 May 2010 09:48, alux alu...@googlemail.com wrote:
 Hello!

 Short: It works, but is not perfect.

 (this may need an windows expert to make it better)

Try this:

--- myscript.bat ---
:x (comment
@echo off
java -cp clojure.jar clojure.main %~f0 %*
goto eof
)

(println Hi! *command-line-args*)

--

The way it works:

The line starting with :x is treated as a label by cmd.exe (and so, in
effect, ignored). In Clojure, it's treated as a keyword :x followed by
the start of a multiline comment - (comment

So everything down to the closing ) is ignored by clojure, but
executed by cmd.exe

The next bits:
@echo off - suppress cmd.exe's annoying habit of displaying everything
java... Run the clojure script. %~f0 is the script name - I quote it
in case it has spaces, and %* is the rest of the command line.
Then, goto eof terminates the batch file (goto end of file), ignoring
the rest of the file, which can therefore be arbitrary clojure.

Paul.

-- 
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 script with shebangoid on windows

2010-05-28 Thread Paul Moore
On 28 May 2010 16:17, alux alu...@googlemail.com wrote:
 Hello Paul,

 thats much better, many thanks!

I've added it to the Wikibooks page,
http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Shebang_Scripting_in_Clojure

Paul.

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


Newbie (with no Java experience) - how best to learn?

2010-05-27 Thread Paul Moore
Hi,
I'm new to Clojure, and looking for the best way to get going. I've
got a pretty broad experience of various programming languages (C,
Python, Lua, Factor, JavaScript, Haskell, Perl, ...) including a bit
of experience with Lisp-like languages, so the language itself isn't
likely to be a huge problem for me. But I've no background with Java
(beyond a few toy programs, and knowing the syntax) so the
environment (classpaths, compiling, where to find libraries,
performance, JVMs, etc) is pretty much a mystery to me.

I've browsed a bit online, read some of the wikibook articles, and
Mark Volkmann's excellent summary, but I'd like to dig a bit deeper
(as I say, particularly around libraries and environment, less on how
to program in a lisp-like language). Ideally, in a form that I can
read offline (printable/PDF documents, or books) as I've got limited
free time I can spend in front of a computer screen. I've got a sample
program I have tried porting from Python - the experience was
interesting, but limited (the core of the relatively complex
multithreaded database monitoring process converted to 47 lines of
Clojure...!!!)

Has anybody got any good suggestions as to where I should go next?
I've considered getting one of the Manning books (The Joy of Clojure
or Clojure in Action) but I'm not sure which would be better for me -
they seem broadly similar, with Clojure in Action looking like a
slightly better fit for my needs, but I'd appreciate any
comments/recommendations). Also, I wonder whether there's some
Java-based documentation that would be worth my while investigating. I
suspect that it'd be very easy to get sucked into a huge amount of
detail which is only tangentially related at best, but I'm sure an
overview would help.

Thanks for any suggestions,
Paul.

-- 
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: Newbie (with no Java experience) - how best to learn?

2010-05-27 Thread Paul Moore
On 27 May 2010 15:16, Sean Devlin francoisdev...@gmail.com wrote:
 Welcome aboard Paul!

Thanks!

 1.  Pick an IDE and stick with it.  I'd recommend ClojureBox if you're
 interested in Clojure only, or NetBeans + Enclojure if you want to
 learn some about Java too.  In fact, NetBeans is probably a better
 place to start.

I don't really like IDEs, I'm a text editor sort of person, I'm
afraid. I'll be using Vim to write my code, unless someone gives me
very strong reasons to do otherwise. And to be honest, if I can't code
in clojure using Vim, I'd be assuming clojure isn't for me, I'm
afraid.

 2.  If you're looking for a dead tree reference, Halloway's book
 Programming Clojure is a great start.  I'd recommend it to anyone not
 named Rich Hickey.  Also, I strongly recommend Core Java Volumes I 
 II from Horstmann  Cornell to get started with Java.

Thanks for the references. I'd been under the impression that
Programming Clojure was more a language tutorial. Looks like I was
wrong - I'll check it out!

While the Java books look good, I'm not sure how useful they will be.
I have (a fairly old copy of) Java in a Nutshell and a couple of
other ones, and I'm really not a fan of Java the language - so I don't
want to invest too heavily in Java books unless they are going to be
useful from a clojure point of view. I'll keep them in mind, though.
(Basically, I'd rather get Java background from something downloadable
for free).

 3.  Once you start to play around with the examples in a REPL, take a
 look at some of the material here:

 http://news.ycombinator.com/item?id=1033503

Nice link, thanks!

 4.  Find a project  start playing.  The best way to learn is by
 doing, after all :)

Absolutely - I'm planning on building up my database monitoring app as
a starter. I also have a couple of other testbed applications I'd like
to try. On that note, are there good (java|clojure) libraries I should
look at for:
- command line argument handling (getopt style option handling)
- simple parsing (suitable for something like a small expression parser)

Thanks again,
Paul.

-- 
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: Newbie (with no Java experience) - how best to learn?

2010-05-27 Thread Paul Moore
On 27 May 2010 15:38, Base basselh...@gmail.com wrote:
 Regarding Clojure I got Stuart Halloway's book Programming Clojure

Another recommendation! Looks like that's definite then :-) Thanks.

 Also, I spend a *lot* of time on this site and ask a lot of really
 dumb questions.  Clojure has the best group support by far of any
 language I have ever seen.  The people on this board are truly
 amazingly helpful and patient - even with us newbies :)

Reassuring to know. As I suspect my dumb questions will be heavily
JVM-biased (What's a classpath?) I'll probably need all the patience
people can muster!

Actually here's a JVM sort of question to start off with. To run my
little database monitor script on Windows, I use a command line

java -cp 
clojure.jar;clojure-contrib.jar;D:\Oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar
clojure.main db.clj

That's a pretty hairy command line, just to run a script with no
parameters! What's the best way to tidy this up (on the Windows
command line)? I'd prefer not to wrap it in a batch file for a couple
of reasons - two files to maintain, and batch files have some
irritating properties on Windows.

For the script, I can associate java -cp clojure.jar clojure.main %*
with the .clj extension and that's OK, But is there a way of adding
the references to the other jars from within the script, so I don't
need to specify the classpath on the command line?

 The hardest part for me was getting things configured.  It is really
 confusing - particularly if you have no background to java.  Most of
 the users here use emacs for their IDE.  If you know emacs you can
 certainly try that.  There is Clojure in a Box that is a self
 contained package If you do not use emacs ( I do not - it is too damn
 confusing for me) then i recommend using and IDE that has clojure
 support.  There is one for Netbeans called Enclojure.  I use Eclipse
 and a plugin called CounterClockwise.  I really like it.

As a non-Java user, I'm strongly averse to the various IDEs.
Personally, I'm a Vim user and I like to do my compiling from the
command line. Hopefully, the bare metal approach won't get me into
too much trouble!

 Stu Halloway has a great starting tutorial with instructions on how to
 get up to speed and has a series of tutorials via a web server
 (integrated into the app). It is located at:

 http://github.com/relevance/labrepl

 This is where I would start.  It has helped me out immensely.

That looks like a great resource! Thanks!

Paul.

-- 
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: Newbie (with no Java experience) - how best to learn?

2010-05-27 Thread Paul Moore
On 27 May 2010 16:39, eyeris drewpvo...@gmail.com wrote:
 The Full Disclojure video series is targeted more toward the lisp
 newbie, but it contains a series of videos touring different
 development environments. http://vimeo.com/channels/fulldisclojure

Ta. Any way of downloading these to watch on my iPod? As I say, I have
limited opportunities to sit in front of a PC to read/watch training
stuff.

Paul.

-- 
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: Newbie (with no Java experience) - how best to learn?

2010-05-27 Thread Paul Moore
On 27 May 2010 18:26, Sean Devlin francoisdev...@gmail.com wrote:
 I make them available CC BY-NC-SA, so download away.  You'll need a
 vimeo account (free) to download them, though.

Ah, I hadn't realised that signing up got a download option. Thanks!
Paul.

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


Mersenne Twister

2010-05-27 Thread Paul Moore
I want to write a reasonably high-performance simulation program in
Clojure. For the random numbers, I'd prefer to use Mersenne Twister
(for a number of reasons - it's a well-known, good RNG, and it's
commonly used in a number of other languages I use, so it's a good
baseline for comparing implementations). The Java RNG, which Clojure
uses, is not MT, but Knuth's linear congruential RNG.

Can someone recommend a good Mersenne Twister implementation I could
use? A web search finds a number of implementations in Java -
presumably I can use these via Java interop - is that a sensible thing
to do?

I'm also looking to parallelise my simulation, so I'd want to have
multiple threads all generating random numbers. I'm not an expert in
this field, if I just naively generate random numbers in multiple
threads is that OK, or could it compromise the randomness? If there is
an issue, has anyone got a pointer to a thread-safe MT implementation
that I could use?

Thanks,
Paul.

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