Re: No complex numbers?

2008-11-24 Thread Konrad Hinsen

On 23.11.2008, at 16:28, Rock wrote:

> Furthermore, the implementation should, I think, be generic, that  
> is, we should be capable of creating complex numbers, the real and  
> imaginary parts of which can be integers, rationals, or reals. For  
> instance, it sould be possible to
> do this:
>
> (1/3 + 2/5i) + (1/2 + 1/10i) = (5/6 + 1/2i)
>
> without any loss of precision due to type conversion (ex. towards
> float).

There are good reasons for such a choice, but there are good reasons  
as well to have an implementation that represents a complex number as  
two floats with all operations optimized for speed. Ideallly, there  
would be both, with different constructor names, just like Clojure  
has two map implementations with different performance  
characteristics. Even more ideally, there would be a way (through  
type annotations for example) to tell the compiler to inline complex  
arithmetic operations and generate code that uses primitive Java  
types only, in order to avoid the boxing overhead associated with  
objects.


On 23.11.2008, at 15:42, Rich Hickey wrote:

> I have nothing against complex numbers, and interested parties should
> contribute to this discussion on how best to incorporate them in
> Clojure. The issues are:
>
> What support is required?
> How hard to do with no other libs, a la Ratio?

I don't know if there are any Java libs that do it well enough. As  
with many other things, complex numbers are not hard to implement in  
principle, but hard to implement really well.

Konrad.


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: one way to write a factorial function

2008-11-24 Thread prhlava

> Help me understand why this isn't written
>
> (defn factorial [n]
>   (apply * (range 1 (+ n 1)))
>
> instead. That is, I don't get the purpose of the for statement.

Neither do I now ;-),

nice,

Vlad

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: one way to write a factorial function

2008-11-24 Thread prhlava


user=> (= (range 10) (for [x (range 10)] x))
true

:-)

Vlad
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-11-24 Thread Ed Bowler

Sheffield, UK

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



learning clojure

2008-11-24 Thread syamajala

How easy is it to pick up clojure without having any previous java
experience? I have plenty of common lisp experience, but have just
never bothered learning java. I recently got a chance to watch the
boston lisp talk on clojure, and it looks fairly straightforward, but
I feel that not having any knowledge of java might make it a little
hard to do more advanced things.

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: File Copy

2008-11-24 Thread James G. Sack (jim)

Parth Malwankar wrote:
> 
> 
> On Nov 24, 12:34 am, Stuart Sierra <[EMAIL PROTECTED]>
> wrote:
>> Honestly, for this kind of low-level stuff I always use the Apache
>> Commons libraries, , esp. the Lang and IO
>> components.  They've got every imaginable stream function, all
>> carefully and efficiently implemented.  But if you're determined to do
>> it in Clojure, loop/recur is the way, as James demonstrated.
>> -Stuart Sierra
> 
> Yes. commons.io.FileUtils.copyFile is definitely a nicer way :)
> I am still learning Java (as an when I need it for Clojure). Thanks
> for the pointer.
> 

>From another learner --really a java-ignoramus-extremus:
Would someone take pity and give a clojure recipe for using
commons.io.FileUtils.copyFile to copy "fileA" to "fileB" (say).

I have found and installed commons.io via package manager and it ended
up in /usr/share/java/commons-io.jar. Was that the right thing to do?

The rest of java seems to live under /usr/java/jdk1.6.0_10/

I am starting REPL via the rlwrap script posted on the wiki.

My first stumbling block seems to be how to do the import! :-(

TIA,
..jim

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Typo on http://clojure.org/jvm_hosted

2008-11-24 Thread JonathanMeeks

If this is the incorrect forum to post this please point me in the
correct direction...

On http://clojure.org/jvm_hosted

The celsius defn has a doto with incorrect syntax.  Shouldn't

(doto frame
   (setLayout (new GridLayout 2 2 3 3))
   ...)
be

(doto frame
   (.setLayout (new GridLayout 2 2 3 3))
   ...)

Note the missing dot in the former setLayout. I'm new to clojure, so I
may well not understand something.

--Jonathan

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: learning clojure

2008-11-24 Thread Vincent Foley

As somebody who did only a few hours of Java, but knows object
oriented programming well and had its fair share of fun with Common
Lisp, Scheme and Haskell, Clojure was quite easy to pick up.  For all
pure Clojure stuff, I don't think that you need to know anything about
Java.  When you work with Java libs, it's useful to know about static
vs instance methods, static members, reading Javadoc, etc.

I am currently writing a small tutorial (nothing of the scope of
Stuart's book) on how to fetch web comics online.  I have two parts so
far, and both show a little of the Java interop functionality.  Let me
know if it's useful

http://gnuvince.wordpress.com/2008/10/31/fetching-web-comics-with-clojure-part-1/
http://gnuvince.wordpress.com/2008/11/18/fetching-web-comics-with-clojure-part-2/

Good luck,

Vincent.

On Nov 23, 11:34 pm, syamajala <[EMAIL PROTECTED]> wrote:
> How easy is it to pick up clojure without having any previous java
> experience? I have plenty of common lisp experience, but have just
> never bothered learning java. I recently got a chance to watch the
> boston lisp talk on clojure, and it looks fairly straightforward, but
> I feel that not having any knowledge of java might make it a little
> hard to do more advanced things.
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: French translation of the Clojure rationale

2008-11-24 Thread budu

Wow, jamais je n'aurais pensé lire des commentaires à propos des
problèmes de prononciation de madame Marois ce matin. Comme on dit au
Québec: "Osti qu'j'ai hâte qu'les élections finisse!"

Sorry about being offtopic ;-)

On Nov 22, 11:35 am, Luc Prefontaine <[EMAIL PROTECTED]>
wrote:
> Salutations aux cousins outre-Atlantique,
>
> Je ne veux pas vous décourager mais effectivement la maîtrise de
> l'anglais au moins au niveau de la lecture est
> plutôt incontournable en informatique. J'ai un associé du coin
> d'Aix-en-Provence et un autre d'Algérie qui n'ont pas eu le
> choix à leur arrivée ici. Pourtant ici il y a une majorité qui ne
> maîtrise pas l'anglais (et souvent le français d'ailleurs).
>
> Il y a 25 ans je me suis tapé la lecture d'une partie de la doc d'IBM
> sur mainframe en français (traduction faite en France).
> Les ventes d'IBM à l'époque ne vendaient pas de la camelote pour leurs
> clients vu les prix auxquels ils vendaient leurs gros monstres
> donc c'était un travail de traduction fidèle.
>
> J'en suis vite arrivé à une indigestion. Le volume du texte était
> supérieur d'au moins 30% à son équivalent anglais
> et de plus la référence à des acronymes à toutes les 2 phrases,
> acronymes évidemment tous en anglais, rendait la
> lecture des plus ardue. Passer d'une langue à l'autre pas de problèmes
> mais 20 ou 30 fois dans la même page de texte ?
>
> En ce qui a trait à Clojure, l'intro en français ça peut aller pour
> accrocher l'oeil et susciter de l'intérêt
> mais pour le reste juste à penser au travail d'entretien que ça va
> demander à chaque fois que la doc originale en anglais est modifiée...
> disons que je pense que l'énergie devrait être mise ailleurs.
>
> De toute façon un autre problème qui va se poser c'est que toute
> référence externe à cette documentation a 99% de chance d'être... en
> anglais !
>
> Non je ne suis pas un fan du Parti Québécois dont la chef qui aspire à
> la gouvernance de la province maîtrise l'anglais moins bien qu'une vache
> espagnole.
> Ça vous pouvez vous en douter à la lecture de ce qui précède mais je
> pense qu'il y a des réalités qu'il faut savoir reconnaître...
>
> Bonne chance tout de même, cousins :)))
>
> A+
>
> Luc
> Montréal, Québec
>
> On Sat, 2008-11-22 at 04:43 -0800, peg wrote:
> > j'ai  oublié ... peut être la traduction d'un article comme celui-ci
> > serait-elle plus démonstrative / pédagogique :
>
> >http://www.defmacro.org/ramblings/fp.html
>
> > article référencé ici-même il y a quelques temps
>
> > On Nov 22, 1:40 pm, peg <[EMAIL PROTECTED]> wrote:
> > > Bonjour,
> > > Je peux aussi aider à la traduction mais je pense aussi qu'un
> > > didacticiel serait bienvenue plutot qu'un introduction générale.
> > > Démonstration de l'efficacité par l'exemple.
> > > Phil (from Paris)
>
>
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Typo on http://clojure.org/jvm_hosted

2008-11-24 Thread Michael Wood

On Mon, Nov 24, 2008 at 7:24 AM, JonathanMeeks <[EMAIL PROTECTED]> wrote:
>
> If this is the incorrect forum to post this please point me in the
> correct direction...
>
> On http://clojure.org/jvm_hosted
>
> The celsius defn has a doto with incorrect syntax.  Shouldn't
>
> (doto frame
>   (setLayout (new GridLayout 2 2 3 3))
>   ...)
> be
>
> (doto frame
>   (.setLayout (new GridLayout 2 2 3 3))
>   ...)
>
> Note the missing dot in the former setLayout. I'm new to clojure, so I
> may well not understand something.

The syntax for doto has recently (in the last week or so) changed to
require the dot.  The Clojure release from September will work without
the dot (and will not work with the dot.)

i.e. the documentation needs to be updated.

-- 
Michael Wood <[EMAIL PROTECTED]>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: seq and vector

2008-11-24 Thread Rich Hickey



On Nov 24, 2:41 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Nov 24, 12:41 am, "Kevin Downey" <[EMAIL PROTECTED]> wrote:
>
> > I don't think you understand. clojure data structures are IMMUTABLE.
> > every call to conj, or anyother function returns a "new" object. To
> > optimize there is sharing of structure.
>
> In the particular case at hand, i.e. calling vec on a seq, there is no
> structural sharing involved. On the contrary a new Object array of the
> same length as the seq is created. See RT.seqToArray for details.

This is going around in circles.

If you are going to replace every element in a vector, there can be no
sharing with any prior vector, under any method. If you will only
replace a few elements, use reduce. If you are going to replace most
elements, creating a new vector will be more efficient than sharing.
All of these would be true whether or not you had vmap or vfilter.

The seq functions don't change any types etc. They are functions of
collections/seqs to seqs.

Were filter/map etc to return vectors for vectors, then chained
operations would have to return fully-realized intermediate results.
That's wasteful in comparison to the behavior of the seq-based
functions.

Try this:

(def v (vec (range 100)))

(defn vmap [f v]
  (into [] (map f v)))

(time (count (vmap inc (vmap inc v
user=> "Elapsed time: 1171.923 msecs"

(time (count (into [] (map inc (map inc v)
user=> "Elapsed time: 613.164 msecs"

Speculating about inefficiency without a concrete counter-proposal is
not productive. While there could no doubt be some higher-performance
vector constructor/reducers, producing vector-returning versions of
the sequence ops is not generally a good idea.

Rich

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Keyword constraints not enforced

2008-11-24 Thread Rich Hickey



On Nov 23, 9:09 am, James Reeves <[EMAIL PROTECTED]> wrote:
> On Nov 23, 11:38 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > Hi,
>
> > According tohttp://clojure.org/reader:
>
> > > Keywords are like symbols, except:
>
> > >  o They can and must begin with a colon, e.g. :fred.
> > >  o They cannot contain '.' or name classes.
>
> > Shouldn't this throw an exception? It seems that keywords aren't
> > checked for correctness at all right now.
>
> I'd like to request that keywords continue to allow the '.' character,
> as it's useful for certain edge cases (Compojure and clj-html use it
> to specify class attributes, for instance). Does the inclusion of a
> '.' in a keyword introduce any syntax ambiguity I'm unaware of?
>
> Disallowing class names in keywords seems a little odd too, especially
> with AOT. If you compiled a Clojure file like clojure.contrib.def,
> would that mean you'd lose the ability to use the keyword :def?
>

I think you've both misread "they cannot name classes" to be - "They
cannot contain class names".

The symbol String can name a class but the keyword :String can't,
that's all I meant there.

As far as '.', that restriction has been relaxed. I'll try to touch up
the docs for the next release.

Rich


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: File Copy

2008-11-24 Thread Stuart Sierra

Ok, first you need to add the commons-io.jar to the Java classpath.
You can do this by editing the Clojure startup script.  The argument
to "-cp" is a colon-separated list of directories and/or JAR files to
go on the classpath.  So if the command line was this:

java -cp /path/to/clojure.jar clojure.lang.Repl

Now it will be:

java -cp  /usr/share/java/commons-io.jar:/path/to/clojure.jar
clojure.lang.Repl

(Note: this may also be possible with the add-classpath function in
Clojure, but I'm not sure if that still exists/works.)

Once you've done this, restart Clojure and you should be able to
(import '(org.apache.commons.io FileUtils))

Then call (FileUtils/copyFile fileA fileB)
fileA and fileB should be instances of java.io.File.

Hope this gets you where you need to be. :)

-Stuart Sierra


On Nov 24, 2:26 am, "James G. Sack (jim)" <[EMAIL PROTECTED]> wrote:
> Parth Malwankar wrote:
>
> > On Nov 24, 12:34 am, Stuart Sierra <[EMAIL PROTECTED]>
> > wrote:
> >> Honestly, for this kind of low-level stuff I always use the Apache
> >> Commons libraries, , esp. the Lang and IO
> >> components.  They've got every imaginable stream function, all
> >> carefully and efficiently implemented.  But if you're determined to do
> >> it in Clojure, loop/recur is the way, as James demonstrated.
> >> -Stuart Sierra
>
> > Yes. commons.io.FileUtils.copyFile is definitely a nicer way :)
> > I am still learning Java (as an when I need it for Clojure). Thanks
> > for the pointer.
>
> From another learner --really a java-ignoramus-extremus:
> Would someone take pity and give a clojure recipe for using
> commons.io.FileUtils.copyFile to copy "fileA" to "fileB" (say).
>
> I have found and installed commons.io via package manager and it ended
> up in /usr/share/java/commons-io.jar. Was that the right thing to do?
>
> The rest of java seems to live under /usr/java/jdk1.6.0_10/
>
> I am starting REPL via the rlwrap script posted on the wiki.
>
> My first stumbling block seems to be how to do the import! :-(
>
> TIA,
> ..jim
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Exception reporting

2008-11-24 Thread Stuart Sierra

If you're running this at the REPL, in recent versions only the name
of the exception is printed.  If you want the full backtrace, do:
(.printStackTrace *e)

-Stuart Sierra


On Nov 24, 2:39 am, Timothy Pratley <[EMAIL PROTECTED]> wrote:
> If you put the following into a file and run it:
>
> (defn new-listener [port]
>   (try (java.net.ServerSocket. port)
>        (println "Listening on " port)
>        (catch Exception e
>               (println "Failed to listen on port " port ":
> " (.getMessage e)
>
> (println "Server started")
> (let [listener (new-listener )]
>   (.accept listener))
>
> Exception in thread "main" java.lang.NullPointerException (test.clj:0)
>
> The problem is obviously my user code: new-listener should have
> returned the socket it created. I'm just bringing it up because the
> resulting exception doesn't have enough info to diagnose the problem.
> Usually when there is an error the it displays the line number where
> the problem occurred in the source. Is this a special case? I only
> report it in the hope that such reports can help identify improvements
> to error reporting.
>
> Regards,
> Tim.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: learning clojure

2008-11-24 Thread Stuart Sierra

It's useful to know the standard Java libraries, especially for File/
IO stuff.  You can pick up nearly all of it from the Sun Java
tutorials:
http://java.sun.com/docs/books/tutorial/

-Stuart Sierra


On Nov 23, 11:34 pm, syamajala <[EMAIL PROTECTED]> wrote:
> How easy is it to pick up clojure without having any previous java
> experience? I have plenty of common lisp experience, but have just
> never bothered learning java. I recently got a chance to watch the
> boston lisp talk on clojure, and it looks fairly straightforward, but
> I feel that not having any knowledge of java might make it a little
> hard to do more advanced things.
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Poll: Which clojure.contrib libs should be bundled with Clojure?

2008-11-24 Thread Chouser

This just a quick reminder about the poll.  We've got 22 responses,
but I'm sure there are more than 22 opinionated Clojuristas on this
list.  I'll summarize the results in a couple days, so vote now if you
care.

Vote here:
https://spreadsheets.google.com/viewform?key=p1hkQs__fVyaQGEP_bOFRVQ

--Chouser

On Sat, Nov 15, 2008 at 5:22 PM, Chouser <[EMAIL PROTECTED]> wrote:
> I've put up a poll form to allow everyone to vote on which
> clojure.contrib libs they think should be in clojure.core or otherwise
> bundled with Clojure:
>
> https://spreadsheets.google.com/viewform?key=p1hkQs__fVyaQGEP_bOFRVQ
>
> A summary of the results is available, but I can't figure out how to
> make it visible to anyone who doesn't log in using a Google account:
>
> I'll make the results available to everyone in some other format once
> sufficient time has been passed for everyone to vote.
>
> https://spreadsheets.google.com/gform?key=p1hkQs__fVyaQGEP_bOFRVQ&hl=en&gridId=0#chart
>
> --Chouser
>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Exception reporting

2008-11-24 Thread Michael Wood

On Mon, Nov 24, 2008 at 4:45 PM, Stuart Sierra
<[EMAIL PROTECTED]> wrote:
>
> If you're running this at the REPL, in recent versions only the name
> of the exception is printed.  If you want the full backtrace, do:
> (.printStackTrace *e)

That doesn't explain why the line number is listed as 0.

Is that expected?

The stack trace does not appear to be any more helpful anyway:

user=> (let [listener (new-listener )]
 (.accept listener))
java.lang.NullPointerException (NO_SOURCE_FILE:0)
user=> (.printStackTrace *e)
java.lang.NullPointerException (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4118)
at clojure.lang.Repl.main(Repl.java:93)
Caused by: java.lang.NullPointerException
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:253)
at user$eval__40.invoke(Unknown Source)
at clojure.lang.Compiler.eval(Compiler.java:4107)
... 1 more
nil

-- 
Michael Wood <[EMAIL PROTECTED]>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Box, alpha

2008-11-24 Thread mosi

Hi,
thank you in the name of all noobz who, like me, just want to have a
quick ride with closure.
The installation worked almost perfectly.
The dialog window: outside Emacs, waiting for connection to server ...
(swank) didn`t finish.
The result: no response from server. What is the purpose of the
dialog?

Your clojurebox Emacs runs great with swank, slime and closure.

Thanx a lot!
Best regards,
mosi

On Nov 24, 1:39 am, "Shawn Hoover" <[EMAIL PROTECTED]> wrote:
> Here's a first pass at a Windows installer for a Clojure environment in
> Emacs:http://clojure.bighugh.com/clojure-box-r1109-setup.exe.
>
> The general idea is that of the Lispbox: you simply install and run this one
> thing, and you get a REPL and all the syntax and editing goodies from
> clojure-mode and Slime.
>
> Specifically this version of the installer packages the following
> components:
> - Clojure source and jar from svn r1110
> - Clojure Contrib source and jar from svn r253
> - Compatible clojure-mode and swank-clojure from github.com/jochu
> - Latest patched EmacsW32 from ourcomments.org
> - A tiny bit of Emacs startup to set up clojure-mode and start a Slime REPL
>
> It associates .clj files with Emacs. There are options for adding shortcuts
> in the standard locations.
>
> The best I could do for now was 29MB in size.
>
> I still would like to add icons, the javadoc elisp functions that have been
> floating around on the group lately, and other handy tools like a shortcut
> to launch a REPL or script in a shell. When Clojure is released, I will make
> a version based on that release.
>
> Give it a whirl!
>
> Shawn

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Running Clojure on Pocket PC

2008-11-24 Thread dokondr

Any ideas if resources of Pocket PC (Windows Mobile 2.0) will suffice
to run single-threaded Clojure app?
What JVM for Pocket PC will do the job?
What porting efforts will be required, if any?

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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Running Clojure on Pocket PC

2008-11-24 Thread dokondr

Any ideas if resources of Pocket PC (Windows Mobile 2.0) will suffice
to run single-threaded Clojure app?
What JVM for Pocket PC will do the job?
What porting efforts will be required, if any?

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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-11-24 Thread Adrian Cuthbertson
Johannesburg, South Africa.

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-11-24 Thread Peter Wolf

Boston MA


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Clojure Box, alpha

2008-11-24 Thread Shawn Hoover
On Mon, Nov 24, 2008 at 9:50 AM, mosi <[EMAIL PROTECTED]> wrote:

>
> Hi,
> thank you in the name of all noobz who, like me, just want to have a
> quick ride with closure.
> The installation worked almost perfectly.
> The dialog window: outside Emacs, waiting for connection to server ...
> (swank) didn`t finish.
> The result: no response from server. What is the purpose of the
> dialog?
>
> Your clojurebox Emacs runs great with swank, slime and closure.
>
> Thanx a lot!
> Best regards,
> mosi
>

Mosi, I'm not sure exactly what dialog you're seeing, but perhaps there is a
problem launching Clojure Box at the end of the installer. I'll try a tweak
in the next version. Either way, I'm glad to hear it works for you.

Shawn

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Stephen C. Gilardi


On Nov 23, 2008, at 2:30 PM, Stuart Sierra wrote:

> Hmm, you mean write the REPL in Clojure?  I hadn't though of that.
> Intriguing idea.  It would be neat if the REPL were just a function,
> so you could start it from within a program using arbitrary input/
> output streams.  Something to think about...

I've uploaded a patch along those lines: ant-compile-main.patch, 
http://tinyurl.com/5azp3u 
  based on our recent work on this. This includes Compile.java,  
main.clj, and modifies build.xml.

I'd appreciate interested folks giving it a try and giving feedback.  
(I've included instructions at the end of this message if you're  
unfamiliar with doing that.) The patch changes clojure.jar to point to  
the new class "clojure.main" for its main entry point. In the patched  
Clojure, a new, flexible Clojure main is defined in src/clj/clojure/ 
main.clj .

I decided not to include compile as one of the options in main.clj for  
now because it shares little with the other options and made the help  
text longer. I'd be comfortable with a "clj" script that does eval,  
scripting, and repl and a separate "cljc" script that does compiling  
(analogous to java and javac). Opinions welcome.

Here are some examples of using the proposed clojure.main via "java - 
jar clojure.jar":

Display usage info:

% java -jar clojure.jar --help
Usage: java -jar clojure.jar [option*] [file-arg*] [--] [arg*]

options:
   -h, --help   Print this help message and exit
   -e, --eval expr  Evaluate an expression and print its value
   -r, --repl   Run an interactive Read-Eval-Print Loop
   file Run code from from file
   -Run code from standard input

   With no options, Clojure runs a repl.

   The eval options may be repeated but must not appear after other  
options.

   The remaining options stop options processing and consider the rest  
of
   the command line arguments as file-args and args, separated by "--",
   all of which are optional. Clojure binds the list of args to
   *command-line-args*, loads any files named by file-args, then  
starts the
   repl or loads from the file or standard in.

With no options, run a repl:

% java -jar clojure.jar
Clojure
user=> (+ 3 4)
7
user=>

Evaluate Clojure code from the command line:

% java -jar clojure.jar -e 3 -e "(+ 3 4)" -e "*ns*" -e "\"this is fun 
\""
3
7
#
this is fun

Here are some Clojure source code files to illustrate the order of  
things:

% cat init.clj
(print "hi from init.clj, arguments are ")
(prn *command-line-args*)
% cat init2.clj
(print "hi from init2.clj, arguments are ")
(prn *command-line-args*)
% cat script.clj
(print "hi from script.clj, arguments are ")
(prn *command-line-args*)

Combining eval and repl, demonstrating that the repl can load files  
and see arguments:

% java -jar clojure.jar -e "\"welcome to the repl\"" --repl init.clj  
-- 1 2 :a :b
welcome to the repl
hi from init.clj, arguments are ("1" "2" ":a" ":b")
Clojure
user=> *command-line-args*
(1 2 :a :b)
user=>

Run a script from a file by just giving the filename:

% java -jar clojure.jar script.clj
hi from script.clj, arguments are nil

Now using a filename, no files to load, and arguments:

% java -jar clojure.jar script.clj -- 1 2 3
hi from script.clj, arguments are ("1" "2" "3")

Now using a filename, files to load before it, and arguments

% java -jar clojure.jar script.clj init.clj init2.clj -- a b c
hi from init.clj, arguments are ("a" "b" "c")
hi from init2.clj, arguments are ("a" "b" "c")
hi from script.clj, arguments are ("a" "b" "c")

Executing Clojure code piped into standard in:

% echo "(prn (sort '(:a :z :m :q)))" | java -jar clojure.jar -
(:a :m :q :z)

The patch also includes a repl written in Clojure in src/clj/clojure/ 
main.clj. It supports optional keyword arguments that let you  
customize it quite a bit while defaulting to the familiar behavior of  
java version:

-
clojure.main/repl
([& options])
   Read-eval-print loop. Options are sequential keyword-value
   pairs. Available options and their defaults:

  - :ns, symbol naming the initial namespace for the repl
default: 'user

  - :prompt, function of no arguments, prompts for more input
default: #(printf "%s=> " (ns-name *ns*))

  - :flush, function of no arguments, flushes output
default: flush

  - :read, function of one argument, returns the next object read  
from
the input, or its argument iff the input is exhausted
default: #(read *in* false %)

  - :eval, funtion of one argument, returns the evaluation of its
argument
default: eval

  - :print, function of one argument, prints its argument 

Re: seq and vector

2008-11-24 Thread [EMAIL PROTECTED]

On Nov 24, 3:03 pm, Rich Hickey <[EMAIL PROTECTED]> wrote:>
> Speculating about inefficiency without a concrete counter-proposal is
> not productive. While there could no doubt be some higher-performance
> vector constructor/reducers, producing vector-returning versions of
> the sequence ops is not generally a good idea.

You are right. I give in.
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Observations and questions regarding long-running, adaptable, transparent software

2008-11-24 Thread Randall R Schulz

On Thursday 18 September 2008 15:28, falcon wrote:
> Looks like the FrTime dissertation was published this year:
>
> Integrating Dataflow Evaluation into a Practical Higher-Order
> Call-by- Value Language
> By Gregory Cooper
>
> http://dl.lib.brown.edu/pdfs/etd67.20080429180432.pdf

This document appears to have been removed from its server. Google 
Scholar still indexes it (with only a single hit on the full, quoted 
title) and (for now) has a HTML conversion of it, which I snatched, 
just in case no other copy becomes available and that entry ages out of 
Google's cache.

A little more poking around (using regular Google instead of Google 
Scholar) turned up this:




Randall Schulz

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Stubbing macro for isolated unit tests

2008-11-24 Thread Justin Giancola

On Nov 23, 9:56 pm, James Reeves <[EMAIL PROTECTED]> wrote:
> On Nov 23, 11:58 pm, Justin Giancola <[EMAIL PROTECTED]>
> wrote:
>
> > Neat. I noticed that you're forcing the arg lists into vectors in both
> > make-maps and in stubfn. Since they're not being manipulated at all,
> > you could just as easily leave them as seqs and everything will still
> > work.
>
> The reduce is a good idea, but your method of quoting the hash doesn't
> evaluate the return value:
>
> user=> (stub [(f 1 2) (+ 1 2)] (f 1 2))
> (+ 1 2)
>
> Whilst with the original:
>
> user=> (stub [(f 1 2) (+ 1 2)] (f 1 2))
> 3

Oops--when I realized the arg list hash keys were being evaluated
during stub function creation I should have addressed that directly
instead of just quoting the entire hash!

> This was why I turned it into a vector. It seemed the easiest way of
> getting a hash that I didn't have to quote, but whose values would be
> correctly evaluated.

Using vectors will work since they're self-evaluating, but you can
also prevent the unwanted evaluation by wrapping them in quote forms
as the hash is being assembled:

(defmacro stub [stubs & body]
  (let [stub-maps
(reduce (fn [acc [[f & args] res]]
  (assoc-in acc [f `'~args] res))
{}
(partition 2 stubs))]
`(binding
 [~@(mapcat (fn [[fname fhash]]
  `(~fname (fn [& args#] (~fhash args#
stub-maps)]
   [EMAIL PROTECTED])))

This way when the stub functions are created you end up with list
literals for keys and correctly evaluated values.

However, quoting the arg lists this way necessitates that calls to the
stub functions have arg lists identical to those used to generate the
stubs.

i.e.
user=> (stub [(f 1 2) (+ 1 2)] (f 1 2))
3

but

user=> (stub [(f 1 (+ 1 1)) (+ 1 2)] (f 1 2))
nil

So, you need to evaluate all of the args independently when building
the list literals, possibly with:
(defmacro stub [stubs & body]
  (let [stub-maps
(reduce (fn [acc [[f & args] res]]
  (assoc-in acc [f `(list [EMAIL PROTECTED])] res))
{}
(partition 2 stubs))]
`(binding
 [~@(mapcat (fn [[fname fhash]]
  `(~fname (fn [& args#] (~fhash args#
stub-maps)]
   [EMAIL PROTECTED])))

I'm not sure this is quite as easy to follow, but I'd prefer to avoid
proxying all of the arg lists through vectors just because they're
self-evaluating.


Justin

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Help needed: Clojure wikibook is desperately in need of cleanup!

2008-11-24 Thread Jarkko Oranen

The Clojure wikibook has accumulated a lot of useful information over
time, but it's really getting too big to be just one page. It has no
organisation to speak of and it's even unclear what version of Clojure
is required for each example!

For starters, I created some subpages for the larger topics:

http://en.wikibooks.org/wiki/Clojure_Programming/Getting_Started
http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips
http://en.wikibooks.org/wiki/Clojure_Programming/Concepts
http://en.wikibooks.org/wiki/Clojure_Programming/Examples

(I wiped the old examples subpage as it was just an unorganised
collection showing usage of standard library functions. If someone is
feeling up to it, you can salvage it from the page history and
incorporate it into the book)

For now, the subpages are just verbatim copies of sections on the main
page, which I didn't modify yet to include links to them. With the
material split up somewhat, it should be easier to edit and
reorganise.

Who is responsible for approving changes to the main page by the way?
I personally would like to keep the book open for everyone to edit, at
least until we get things reasonably into shape.

--
Jarkko
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Michael Wood

This looks great :)

A couple of comments below:

On Mon, Nov 24, 2008 at 6:57 PM, Stephen C. Gilardi <[EMAIL PROTECTED]> wrote:
[...]
> Here are some examples of using the proposed clojure.main via "java -
> jar clojure.jar":
>
> Display usage info:
>
> % java -jar clojure.jar --help
> Usage: java -jar clojure.jar [option*] [file-arg*] [--] [arg*]

Perhaps this should be:

Usage: java -jar clojure.jar [option*] [file-arg* [-- [arg*]]]

or does it make sense to allow args without file-args?

> options:
>   -h, --help   Print this help message and exit
>   -e, --eval expr  Evaluate an expression and print its value
>   -r, --repl   Run an interactive Read-Eval-Print Loop
>   file Run code from from file
>   -Run code from standard input
>
>   With no options, Clojure runs a repl.
[...]

Excellent :)

> Combining eval and repl, demonstrating that the repl can load files
> and see arguments:
>
>% java -jar clojure.jar -e "\"welcome to the repl\"" --repl init.clj
> -- 1 2 :a :b
>welcome to the repl
>hi from init.clj, arguments are ("1" "2" ":a" ":b")
>Clojure

This "Clojure" seems out of place.  I wonder if it would make sense to
suppress it if the repl is loading stuff, or if "-e" is used?

>user=> *command-line-args*
>(1 2 :a :b)
>user=>
[...]
> Now using a filename, files to load before it, and arguments
>
>% java -jar clojure.jar script.clj init.clj init2.clj -- a b c
>hi from init.clj, arguments are ("a" "b" "c")
>hi from init2.clj, arguments are ("a" "b" "c")
>hi from script.clj, arguments are ("a" "b" "c")

I think this could just as well load all the files in the order they
appear on the command line.  It seems easier to me to explain "the
files are loaded in order" rather than "the files listed after the
first file are loaded in order, followed by the first file."

> Executing Clojure code piped into standard in:
>
>% echo "(prn (sort '(:a :z :m :q)))" | java -jar clojure.jar -
>(:a :m :q :z)

Could you supply command line args here?  If so, I suppose you can
ignore my comment about the Usage.

> The patch also includes a repl written in Clojure in src/clj/clojure/
> main.clj. It supports optional keyword arguments that let you
> customize it quite a bit while defaulting to the familiar behavior of
> java version:

I like it.

-- 
Michael Wood <[EMAIL PROTECTED]>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Slightly off-topic: building DSLs incrementally in Java

2008-11-24 Thread Stuart Sierra

An interesting idea: hacking the Java compiler to perform source-code
transformations:
http://www.iam.unibe.ch/~akuhn/blog/2008/11/roman-numerals-in-your-java/

Based on ideas in Smalltalk:
http://smallwiki.unibe.ch/diesel/

-Stuart Sierra
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread J. McConnell

On Mon, Nov 24, 2008 at 1:49 PM, Michael Wood <[EMAIL PROTECTED]> wrote:
>
> This looks great :)

Yes, it does!

> On Mon, Nov 24, 2008 at 6:57 PM, Stephen C. Gilardi <[EMAIL PROTECTED]> wrote:
> [...]
> > Here are some examples of using the proposed clojure.main via "java -
> > jar clojure.jar":
> >
> > Display usage info:
> >
> > % java -jar clojure.jar --help
> > Usage: java -jar clojure.jar [option*] [file-arg*] [--] [arg*]
>
> Perhaps this should be:
>
> Usage: java -jar clojure.jar [option*] [file-arg* [-- [arg*]]]
>
> or does it make sense to allow args without file-args?

I was going to suggest something similar:

Usage: java -jar clojure.jar [option*] [file-arg*] [-- [arg*]]

Since you can't pass args without the --. I think it does make sense,
sometimes, to pass args without file-args. I know I've done that for
the REPL to test playing around with *command-line-args*.

- J.

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Stephen C. Gilardi

On Nov 24, 2008, at 1:49 PM, Michael Wood wrote:

> This looks great :)

Thanks!

> A couple of comments below:
>
> On Mon, Nov 24, 2008 at 6:57 PM, Stephen C. Gilardi  
> <[EMAIL PROTECTED]> wrote:
> [...]
>> Here are some examples of using the proposed clojure.main via "java -
>> jar clojure.jar":
>>
>> Display usage info:
>>
>> % java -jar clojure.jar --help
>> Usage: java -jar clojure.jar [option*] [file-arg*] [--] [arg*]
>
> Perhaps this should be:
>
> Usage: java -jar clojure.jar [option*] [file-arg* [-- [arg*]]]
>
> or does it make sense to allow args without file-args?

It does make sense to allow args without file-args. However, -- is  
necessary if and only if you're including args, so I think this is  
correct (please check me on that):

Usage: java -jar clojure.jar [option*] [file-arg*] [-- arg*]

>> Combining eval and repl, demonstrating that the repl can load files
>> and see arguments:
>>
>>   % java -jar clojure.jar -e "\"welcome to the repl\"" --repl  
>> init.clj
>> -- 1 2 :a :b
>>   welcome to the repl
>>   hi from init.clj, arguments are ("1" "2" ":a" ":b")
>>   Clojure
>
> This "Clojure" seems out of place.  I wonder if it would make sense to
> suppress it if the repl is loading stuff, or if "-e" is used?

It's there due to "--repl". I use an init.clj all the time to set up  
things like *print-length* that can't be set up in user.clj. I suppose  
I could put whatever greeting I wanted there if a "repl that loads  
files" didn't print Clojure. I'm inclined to leave it in for now  
pending more feedback.

>> Now using a filename, files to load before it, and arguments
>>
>>   % java -jar clojure.jar script.clj init.clj init2.clj -- a b c
>>   hi from init.clj, arguments are ("a" "b" "c")
>>   hi from init2.clj, arguments are ("a" "b" "c")
>>   hi from script.clj, arguments are ("a" "b" "c")

> I think this could just as well load all the files in the order they
> appear on the command line.  It seems easier to me to explain "the
> files are loaded in order" rather than "the files listed after the
> first file are loaded in order, followed by the first file."
>

I'm thinking of it as being nice to specify a main script first and  
the rest satisfying dependencies or setting up an environment. The  
current way treats file-args as a kind of args to the script, ones  
that cause loading files rather than binding for use.

>> Executing Clojure code piped into standard in:
>>
>>   % echo "(prn (sort '(:a :z :m :q)))" | java -jar clojure.jar -
>>   (:a :m :q :z)
>
> Could you supply command line args here?  If so, I suppose you can
> ignore my comment about the Usage.

You can, and I think the new usage works. Thanks for the feedback,  
I'll make that change!

--Steve


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Stephen C. Gilardi

On Nov 24, 2008, at 2:17 PM, J. McConnell wrote:

>
> On Mon, Nov 24, 2008 at 1:49 PM, Michael Wood <[EMAIL PROTECTED]>  
> wrote:
>>
>> This looks great :)
>
> Yes, it does!

:-)

>
> I was going to suggest something similar:
>
> Usage: java -jar clojure.jar [option*] [file-arg*] [-- [arg*]]

That looks exactly right to me. I'll be adopting that.

> Since you can't pass args without the --. I think it does make sense,
> sometimes, to pass args without file-args. I know I've done that for
> the REPL to test playing around with *command-line-args*.

Thanks!

--Steve



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Stephen C. Gilardi

On Nov 24, 2008, at 2:28 PM, Stephen C. Gilardi wrote:

>> Usage: java -jar clojure.jar [option*] [file-arg*] [-- [arg*]]
>
> That looks exactly right to me. I'll be adopting that.


On further review, I think this is better:

Usage: java -jar clojure.jar [option*] [file-arg*] [-- arg*]

Maybe all those *s should be + instead:

Usage: java -jar clojure.jar [option+] [file-arg+] [-- arg+]

The square brackets already say "optional" which is the difference  
between + and *.

I do think the *s look better though.

--Steve


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Slightly off-topic: building DSLs incrementally in Java

2008-11-24 Thread Dave Newton

--- On Mon, 11/24/08, Stuart Sierra wrote:
> An interesting idea: hacking the Java compiler to perform
> source-code transformations:
> http://www.iam.unibe.ch/~akuhn/blog/2008/11/roman-numerals-in-your-java/

That's pretty cool, but not really a new idea--the JastAdd [1] and Polyglot [2] 
compilers have been used to produce some pretty fun Java extensions, although 
none so fun as Roman numerals. 269 just provides an official way to abuse the 
compiler ;)

Dave

[1] http://jastadd.cs.lth.se/web/extjava/index.shtml
[2] http://www.cs.cornell.edu/projects/polyglot/


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Perry Trolard

Very cool. The two main use cases work well (REPL, script), & the
others -- loaded files, evaluation -- are real bonuses. (It's also
really nice to have an extensible REPL implemented in Clojure).

I think a flag for file loading (-l, --load) to make clear the
distinction b/w the file that's a script & the files which are loaded
beforehand woud be nice; but not nice enough to justify what seems to
be the added complication to the argument-processing code (it'd
require processing all args at once, not serially, it seems; or would
require stipulating an order to arguments...).

Regarding clojure.lang.Compile: this is incredibly handy! Thanks. What
do think about adding a default value to the clojure.compile.path
system property (./classes)?

Perry


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: offtopic - where are you come from? (poll)

2008-11-24 Thread James G. Sack (jim)

San Diego, CA USA

..jim

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Norvig's Spelling Corrector in Clojure

2008-11-24 Thread Brian Adkins

I emailed Peter Norvig about Rich's Clojure version of his spelling
corrector. He graciously added an entry to the web page. Clojure does
quite well for this program. It's very nice aesthetically, and it's
the shortest so far. In fact, I noticed the sort order of the entries
has changed from LOC (with the Python version being the shortest
originally), to alphabetical on language name :)

I'm coming from (most recently) a Ruby background, and I typically
find Ruby to be more concise than various Lisps, but Clojure at 18 LOC
vs. Ruby at 34 LOC is impressive. Beating Haskell, wrt conciseness, on
this exercise is impressive as well.

This is a small program, but there's enough meat in it to exhibit
differences in languages.

http://norvig.com/spell-correct.html

Brian Adkins
http://www.lojic.com
http://lojic.com/blog

P.S. I tried replying to the original thread, but there was no reply
link - I expect due to the age of the post
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: File Copy

2008-11-24 Thread James G. Sack (jim)

Stuart Sierra wrote:
> Ok, first you need to add the commons-io.jar to the Java classpath.
> You can do this by editing the Clojure startup script.  The argument
> to "-cp" is a colon-separated list of directories and/or JAR files to
> go on the classpath.  So if the command line was this:
> 
> java -cp /path/to/clojure.jar clojure.lang.Repl
> 
> Now it will be:
> 
> java -cp  /usr/share/java/commons-io.jar:/path/to/clojure.jar
> clojure.lang.Repl
> 
> (Note: this may also be possible with the add-classpath function in
> Clojure, but I'm not sure if that still exists/works.)
> 
> Once you've done this, restart Clojure and you should be able to
> (import '(org.apache.commons.io FileUtils))
> 
> Then call (FileUtils/copyFile fileA fileB)
> fileA and fileB should be instances of java.io.File.
> 
> Hope this gets you where you need to be. :)

Yes, thanks very much Stuart. I had tried just about everything you said
except I wasn't prepending the "org.apache." in the import. 

==> FYI add_classpath works fine.
As a curiosity, I notice that (System/getProperty "java.class.path")
does not reflect any change after add-classpath.
==> I wonder if this is as it should be? And if so, I am left wondering
how to determine the "real" value of the current classpath.


For possible benefit to other newbies, this is what I came up with for
inclusion in (say) user.clj. (criticism welcome)

- - -
;;Copy file (using pathnames) using the Apache.org commons library
(add-classpath "file:///usr/share/java/commons-io.jar")
(import '(org.apache.commons.io FileUtils))
(defn copyfile-byname [src cpy]
(FileUtils/copyFile (java.io.File. src) (java.io.File. cpy)))
- - -

Regards,
..jim

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



new version of the book: Beta 3

2008-11-24 Thread Stuart Halloway

http://blog.thinkrelevance.com/2008/11/24/programming-clojure-beta-3-is-out

Thanks again to everybody on this list for all your encouragement and  
technical help!

Cheers,
Stuart


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Michael Wood
On Mon, Nov 24, 2008 at 9:27 PM, Stephen C. Gilardi <[EMAIL PROTECTED]>wrote:

>
> On Nov 24, 2008, at 1:49 PM, Michael Wood wrote:
>
> This looks great :)
>
>
> Thanks!
>
> A couple of comments below:
>
> On Mon, Nov 24, 2008 at 6:57 PM, Stephen C. Gilardi <[EMAIL PROTECTED]>
> wrote:
> [...]
>
> Here are some examples of using the proposed clojure.main via "java -
>
> jar clojure.jar":
>
>
> Display usage info:
>
>
> % java -jar clojure.jar --help
>
> Usage: java -jar clojure.jar [option*] [file-arg*] [--] [arg*]
>
>
> Perhaps this should be:
>
> Usage: java -jar clojure.jar [option*] [file-arg* [-- [arg*]]]
>
> or does it make sense to allow args without file-args?
>
>
> It does make sense to allow args without file-args. However, -- is
> necessary if and only if you're including args, so I think this is correct
> (please check me on that):
>
> Usage: java -jar clojure.jar [option*] [file-arg*] [-- arg*]
>

That's fine by me.

Combining eval and repl, demonstrating that the repl can load files
>
> and see arguments:
>
>
>   % java -jar clojure.jar -e "\"welcome to the repl\"" --repl init.clj
>
> -- 1 2 :a :b
>
>   welcome to the repl
>
>   hi from init.clj, arguments are ("1" "2" ":a" ":b")
>
>   Clojure
>
>
> This "Clojure" seems out of place.  I wonder if it would make sense to
> suppress it if the repl is loading stuff, or if "-e" is used?
>
>
> It's there due to "--repl". I use an init.clj all the time to set up things
> like *print-length* that can't be set up in user.clj. I suppose I could put
> whatever greeting I wanted there if a "repl that loads files" didn't print
> Clojure. I'm inclined to leave it in for now pending more feedback.
>

Yes, I understand it's because of the --repl.

This is what Python does:

$ python
Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

$ python -i -c 'print "welcome to the repl"'
welcome to the repl
>>>

$ echo 'print "Hello from test.py"' >test.py
$ python -i test.py
Hello from test.py
>>>

That's not to say you should copy Python for the sake of it, but I think it
makes sense :)

I forgot to say that I think having a separate cljc makes sense.

-- 
Michael Wood <[EMAIL PROTECTED]>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Stephen C. Gilardi

On Nov 24, 2008, at 3:31 PM, Perry Trolard wrote:

> Regarding clojure.lang.Compile: this is incredibly handy! Thanks. What
> do think about adding a default value to the clojure.compile.path
> system property (./classes)?

I like it. I'll make that change. There is an underlying default of  
"classes" and that implies "./classes". I'll stick with that and  
remove the error message about it being missing.

Thanks for your other thoughts as well!

--Steve


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: File Copy

2008-11-24 Thread Michael Wood

On Mon, Nov 24, 2008 at 10:34 PM, James G. Sack (jim) <[EMAIL PROTECTED]> wrote:
[...]
> ==> FYI add_classpath works fine.
> As a curiosity, I notice that (System/getProperty "java.class.path")
> does not reflect any change after add-classpath.
> ==> I wonder if this is as it should be? And if so, I am left wondering
> how to determine the "real" value of the current classpath.
>
>
> For possible benefit to other newbies, this is what I came up with for
> inclusion in (say) user.clj. (criticism welcome)

Apparently "such use of add-classpath is discouraged":

http://groups.google.com/group/clojure/browse_thread/thread/87f40ee8788d54dd/11d4e82c3da1beb7?lnk=gst&q=%22Such+use+of+add-classpath+is+discouraged%22#11d4e82c3da1beb7

-- 
Michael Wood <[EMAIL PROTECTED]>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Stuart Sierra

> On Nov 24, 2008, at 3:31 PM, Perry Trolard wrote:
> > Regarding clojure.lang.Compile: this is incredibly handy! Thanks. What
> > do think about adding a default value to the clojure.compile.path
> > system property (./classes)?

On Nov 24, 3:57 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> I like it. I'll make that change. There is an underlying default of  
> "classes" and that implies "./classes". I'll stick with that and  
> remove the error message about it being missing.

Hi Perry, Stephen,
I like the "convention over configuration"-ness of defaulting to ./
classes.  One thought: Weird errors might result if ./classes is not
on classpath.  Is there an easy way to check that, and display a
helpful error message?

-Stuart Sierra
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



update a ref struct

2008-11-24 Thread Brian Doyle
I am parsing a file and to compare the current line
with the previous line of the file.  I am using line-seq
to go thru the file and I thought I would create a
ref to store the previous line.   When I want to update
the previous line value I can't seem to do it.  I've
never used refs before so I'm sure I'm doing something
very stupid.

(defstruct line :lat :lon :name)

(defn convert [file]
  (let [prev-line (ref (struct line))]
(with-open [r (reader file)]
   (doseq [l (line-seq r)]
 (let [ps (split #"," l)
c-line (struct line (ps 0) (ps 1) (ps 2))]
   (if (not= c-line @pre-line)
 (do ; do stuff here then update pre-line
(dosync ref-set pre-line (apply struct line (vals c-line)))
(println @pre-line  ; this prints out all nils
doesn't seem to work



Sorry if this email is not formatted correctly.  Something is wrong with my
browser
currently typing in a textarea.  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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: File Copy

2008-11-24 Thread James G. Sack (jim)

Michael Wood wrote:
> On Mon, Nov 24, 2008 at 10:34 PM, James G. Sack (jim) <[EMAIL PROTECTED]> 
> wrote:
> [...]
>> ==> FYI add_classpath works fine.
>> As a curiosity, I notice that (System/getProperty "java.class.path")
>> does not reflect any change after add-classpath.
>> ==> I wonder if this is as it should be? And if so, I am left wondering
>> how to determine the "real" value of the current classpath.
>>
>>
>> For possible benefit to other newbies, this is what I came up with for
>> inclusion in (say) user.clj. (criticism welcome)
> 
> Apparently "such use of add-classpath is discouraged":
> 
> http://groups.google.com/group/clojure/browse_thread/thread/87f40ee8788d54dd/11d4e82c3da1beb7?lnk=gst&q=%22Such+use+of+add-classpath+is+discouraged%22#11d4e82c3da1beb7
> 

ok... thanks.

I /am/ left believing I'll remain confused about this part of java for a
while longer. :-(

I was hoping that I could somehow tell java to look in (eg) the
/usr/share/java tree when trying to resolve imports.

If someone can direct me where I can educate myself about this aspect of
java, libs, and jar-files a bit more, that would be appreciated.
Otherwise I don't mean to hijack this list for general java questions.

Regards,
..jim

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Kevin Downey

I know you are asking about refs, but you might want to think about
using reduce to walk the line-seq. the nature of reduce lets you have
access to the line-seq, two lines at a time no need for a ref.

On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle <[EMAIL PROTECTED]> wrote:
> I am parsing a file and to compare the current line
> with the previous line of the file.  I am using line-seq
> to go thru the file and I thought I would create a
> ref to store the previous line.   When I want to update
> the previous line value I can't seem to do it.  I've
> never used refs before so I'm sure I'm doing something
> very stupid.
>
> (defstruct line :lat :lon :name)
>
> (defn convert [file]
>   (let [prev-line (ref (struct line))]
> (with-open [r (reader file)]
>(doseq [l (line-seq r)]
>  (let [ps (split #"," l)
> c-line (struct line (ps 0) (ps 1) (ps 2))]
>(if (not= c-line @pre-line)
>  (do ; do stuff here then update pre-line
> (dosync ref-set pre-line (apply struct line (vals c-line)))
> (println @pre-line  ; this prints out all nils
> doesn't seem to work
>
>
>
> Sorry if this email is not formatted correctly.  Something is wrong with my
> browser
> currently typing in a textarea.  Thanks.
>
>
>
> >
>



-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread [EMAIL PROTECTED]

I believe I have fixed all of my stack-space issues except for this
one annoying function (rewritten from the original since the
multimethod wasn't buying me much):

(defn flatten [x]
  (let [type (:type x)]
(cond (or (= type :NIL) (= type :TEXT))
  x
  (= type :CONCAT)
  (doc-concat (flatten (:doc1 x))
  (flatten (:doc2 x)))
  (= type :NEST)
  (doc-nest (:level x)
(flatten (:doc x)))
  (= type :LINE)
  (doc-text " ")
  (= type :UNION)
  (recur (:doc1 x)

Any ideas?
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Brian Doyle
Thanks Kevin, I will try using reduce instead.  I would like to know what
I'm doing wrong with updating the ref for future reference.  Thanks.

On Mon, Nov 24, 2008 at 3:23 PM, Kevin Downey <[EMAIL PROTECTED]> wrote:

>
> I know you are asking about refs, but you might want to think about
> using reduce to walk the line-seq. the nature of reduce lets you have
> access to the line-seq, two lines at a time no need for a ref.
>
> On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle <[EMAIL PROTECTED]>
> wrote:
> > I am parsing a file and to compare the current line
> > with the previous line of the file.  I am using line-seq
> > to go thru the file and I thought I would create a
> > ref to store the previous line.   When I want to update
> > the previous line value I can't seem to do it.  I've
> > never used refs before so I'm sure I'm doing something
> > very stupid.
> >
> > (defstruct line :lat :lon :name)
> >
> > (defn convert [file]
> >   (let [prev-line (ref (struct line))]
> > (with-open [r (reader file)]
> >(doseq [l (line-seq r)]
> >  (let [ps (split #"," l)
> > c-line (struct line (ps 0) (ps 1) (ps 2))]
> >(if (not= c-line @pre-line)
> >  (do ; do stuff here then update pre-line
> > (dosync ref-set pre-line (apply struct line (vals
> c-line)))
> > (println @pre-line  ; this prints out all nils
> > doesn't seem to work
> >
> >
> >
> > Sorry if this email is not formatted correctly.  Something is wrong with
> my
> > browser
> > currently typing in a textarea.  Thanks.
> >
> >
> >
> > >
> >
>
>
>
> --
> The Mafia way is that we pursue larger goals under the guise of
> personal relationships.
>Fisheye
>
> >
>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Shawn Hoover
On Mon, Nov 24, 2008 at 5:17 PM, Brian Doyle <[EMAIL PROTECTED]> wrote:

> I am parsing a file and to compare the current line
> with the previous line of the file.  I am using line-seq
> to go thru the file and I thought I would create a
> ref to store the previous line.   When I want to update
> the previous line value I can't seem to do it.  I've
> never used refs before so I'm sure I'm doing something
> very stupid.
>
> (defstruct line :lat :lon :name)
>
> (defn convert [file]
>   (let [prev-line (ref (struct line))]
> (with-open [r (reader file)]
>(doseq [l (line-seq r)]
>  (let [ps (split #"," l)
> c-line (struct line (ps 0) (ps 1) (ps 2))]
>(if (not= c-line @pre-line)
>  (do ; do stuff here then update pre-line
> (dosync ref-set pre-line (apply struct line (vals c-line)))
> (println @pre-line  ; this prints out all nils
> doesn't seem to work
>
>
Your let binds prev-line, while the code inside uses pre-line. Is that just
a typo in your email, or is that the code you're running, too?

Shawn

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Kevin Downey

ref-set needs its one set of parens, and the last thing in the ref-set
call needs to be a function either (fn [x] ...) or a symbol for a var
that holds a function

On Mon, Nov 24, 2008 at 2:30 PM, Brian Doyle <[EMAIL PROTECTED]> wrote:
> Thanks Kevin, I will try using reduce instead.  I would like to know what
> I'm doing wrong with updating the ref for future reference.  Thanks.
>
> On Mon, Nov 24, 2008 at 3:23 PM, Kevin Downey <[EMAIL PROTECTED]> wrote:
>>
>> I know you are asking about refs, but you might want to think about
>> using reduce to walk the line-seq. the nature of reduce lets you have
>> access to the line-seq, two lines at a time no need for a ref.
>>
>> On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle <[EMAIL PROTECTED]>
>> wrote:
>> > I am parsing a file and to compare the current line
>> > with the previous line of the file.  I am using line-seq
>> > to go thru the file and I thought I would create a
>> > ref to store the previous line.   When I want to update
>> > the previous line value I can't seem to do it.  I've
>> > never used refs before so I'm sure I'm doing something
>> > very stupid.
>> >
>> > (defstruct line :lat :lon :name)
>> >
>> > (defn convert [file]
>> >   (let [prev-line (ref (struct line))]
>> > (with-open [r (reader file)]
>> >(doseq [l (line-seq r)]
>> >  (let [ps (split #"," l)
>> > c-line (struct line (ps 0) (ps 1) (ps 2))]
>> >(if (not= c-line @pre-line)
>> >  (do ; do stuff here then update pre-line
>> > (dosync ref-set pre-line (apply struct line (vals
>> > c-line)))
>> > (println @pre-line  ; this prints out all nils
>> > doesn't seem to work
>> >
>> >
>> >
>> > Sorry if this email is not formatted correctly.  Something is wrong with
>> > my
>> > browser
>> > currently typing in a textarea.  Thanks.
>> >
>> >
>> >
>> > >
>> >
>>
>>
>>
>> --
>> The Mafia way is that we pursue larger goals under the guise of
>> personal relationships.
>>Fisheye
>>
>>
>
>
> >
>



-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Can Clojure functions be anonymous, curried and allow composition?

2008-11-24 Thread dokondr

How can I write the following examples in Clojure that in Haskell will
be:

--  1) Curried function:
Prelude> let f = (+) 1
Prelude> f 1
2

-- 2) Anonymous function:
Prelude> let f2 = \x -> x * 2
Prelude> f2 2
4

-- 3) Function composition:
Prelude> (f2 . f) 3
8
Prelude>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Jeff Rose

For using references in general, here is a little example:

[EMAIL PROTECTED]:~$ clj
Clojure
user=> (def foo (ref 0))
#'user/foo
user=> foo
#
user=> @foo
0
user=> (ref-set foo 1)
java.lang.IllegalStateException: No transaction running (NO_SOURCE_FILE:0)
user=> (dosync (ref-set foo 1))
1
user=> @foo
1
user=>


Notice that you have to wrap ref-set in a transaction using dosync, and 
reading the reference requires the @ macro.

-Jeff

Brian Doyle wrote:
> I am parsing a file and to compare the current line
> with the previous line of the file.  I am using line-seq
> to go thru the file and I thought I would create a
> ref to store the previous line.   When I want to update
> the previous line value I can't seem to do it.  I've
> never used refs before so I'm sure I'm doing something
> very stupid.  
> 
> (defstruct line :lat :lon :name)
> 
> (defn convert [file]
>   (let [prev-line (ref (struct line))]
> (with-open [r (reader file)]
>(doseq [l (line-seq r)]
>  (let [ps (split #"," l)
> c-line (struct line (ps 0) (ps 1) (ps 2))]
>(if (not= c-line @pre-line)
>  (do ; do stuff here then update pre-line
> (dosync ref-set pre-line (apply struct line (vals c-line)))
> (println @pre-line  ; this prints out all nils 
> doesn't seem to work
> 
> 
> 
> Sorry if this email is not formatted correctly.  Something is wrong with 
> my browser
> currently typing in a textarea.  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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Can Clojure functions be anonymous, curried and allow composition?

2008-11-24 Thread Jeff Rose

dokondr wrote:
> How can I write the following examples in Clojure that in Haskell will
> be:
> 
> --  1) Curried function:
> Prelude> let f = (+) 1
> Prelude> f 1
> 2

(def f (partial + 1)) ; => #'user/f
(f 1) ; => 2

> 
> -- 2) Anonymous function:
> Prelude> let f2 = \x -> x * 2
> Prelude> f2 2
> 4

(def f2 (fn [x] (* x 2))) ; => #'user/f2
(f2 2); => 4

> 
> -- 3) Function composition:
> Prelude> (f2 . f) 3
> 8
> Prelude>

((comp f2 f) 3)   ; => 8


voila.

Jeff

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Can Clojure functions be anonymous, curried and allow composition?

2008-11-24 Thread Jarkko Oranen



On Nov 25, 12:54 am, dokondr <[EMAIL PROTECTED]> wrote:
> How can I write the following examples in Clojure that in Haskell will
> be:
>
> --  1) Curried function:
> Prelude> let f = (+) 1
> Prelude> f 1
> 2
>
> -- 2) Anonymous function:
> Prelude> let f2 = \x -> x * 2
> Prelude> f2 2
> 4
>
> -- 3) Function composition:
> Prelude> (f2 . f) 3
> 8
> Prelude>

1) (def fn1 (partial + 1))
2) (def fn2 #(* % 2)) or (fn [x] (* x 2)))
3) ((comp fn2 fn1) 3)

--
Jarkko


--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Can Clojure functions be anonymous, curried and allow composition?

2008-11-24 Thread Stuart Halloway

>>
>> -- 2) Anonymous function:
>> Prelude> let f2 = \x -> x * 2
>> Prelude> f2 2
>> 4
>
> (def f2 (fn [x] (* x 2))) ; => #'user/f2
> (f2 2); => 4

Or even

(def f2 #(* % 2))

Stuart

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Kevin Downey

On Mon, Nov 24, 2008 at 2:34 PM, Kevin Downey <[EMAIL PROTECTED]> wrote:
> ref-set needs its one set of parens, and the last thing in the ref-set
> call needs to be a function either (fn [x] ...) or a symbol for a var
> that holds a function

I made a mistake here. I was thinking of alter, not ref-set.


> On Mon, Nov 24, 2008 at 2:30 PM, Brian Doyle <[EMAIL PROTECTED]> wrote:
>> Thanks Kevin, I will try using reduce instead.  I would like to know what
>> I'm doing wrong with updating the ref for future reference.  Thanks.
>>
>> On Mon, Nov 24, 2008 at 3:23 PM, Kevin Downey <[EMAIL PROTECTED]> wrote:
>>>
>>> I know you are asking about refs, but you might want to think about
>>> using reduce to walk the line-seq. the nature of reduce lets you have
>>> access to the line-seq, two lines at a time no need for a ref.
>>>
>>> On Mon, Nov 24, 2008 at 2:17 PM, Brian Doyle <[EMAIL PROTECTED]>
>>> wrote:
>>> > I am parsing a file and to compare the current line
>>> > with the previous line of the file.  I am using line-seq
>>> > to go thru the file and I thought I would create a
>>> > ref to store the previous line.   When I want to update
>>> > the previous line value I can't seem to do it.  I've
>>> > never used refs before so I'm sure I'm doing something
>>> > very stupid.
>>> >
>>> > (defstruct line :lat :lon :name)
>>> >
>>> > (defn convert [file]
>>> >   (let [prev-line (ref (struct line))]
>>> > (with-open [r (reader file)]
>>> >(doseq [l (line-seq r)]
>>> >  (let [ps (split #"," l)
>>> > c-line (struct line (ps 0) (ps 1) (ps 2))]
>>> >(if (not= c-line @pre-line)
>>> >  (do ; do stuff here then update pre-line
>>> > (dosync ref-set pre-line (apply struct line (vals
>>> > c-line)))
>>> > (println @pre-line  ; this prints out all nils
>>> > doesn't seem to work
>>> >
>>> >
>>> >
>>> > Sorry if this email is not formatted correctly.  Something is wrong with
>>> > my
>>> > browser
>>> > currently typing in a textarea.  Thanks.
>>> >
>>> >
>>> >
>>> > >
>>> >
>>>
>>>
>>>
>>> --
>>> The Mafia way is that we pursue larger goals under the guise of
>>> personal relationships.
>>>Fisheye
>>>
>>>
>>
>>
>> >>
>>
>
>
>
> --
> The Mafia way is that we pursue larger goals under the guise of
> personal relationships.
>Fisheye
>



-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Can Clojure functions be anonymous, curried and allow composition?

2008-11-24 Thread Matt Moriarity

1 is actually an example of partial application of functions more than
it is currying. Haskell's currying makes partial application far more
natural though. In Clojure you can use the (partial ...) macro to do
this:

user=> (def f (partial + 1))
user=> (f 1)
2

2 is done using the (fn ...) special form. It should be noted that
(defn ...) to define named functions is actually just a macro that
translates basically to (def name (fn ...))

user=> (def f2 (fn [x] (* x 2)))
user=> (f2 2)
4

3 is done with the (comp ...) macro:

user=> ((comp f2 f) 3)
8

Hope this helped!

Matt

On Nov 24, 5:54 pm, dokondr <[EMAIL PROTECTED]> wrote:
> How can I write the following examples in Clojure that in Haskell will
> be:
>
> --  1) Curried function:
> Prelude> let f = (+) 1
> Prelude> f 1
> 2
>
> -- 2) Anonymous function:
> Prelude> let f2 = \x -> x * 2
> Prelude> f2 2
> 4
>
> -- 3) Function composition:
> Prelude> (f2 . f) 3
> 8
> Prelude>
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Can Clojure functions be anonymous, curried and allow composition?

2008-11-24 Thread dokondr


On Nov 25, 2:06 am, Jarkko Oranen <[EMAIL PROTECTED]> wrote:
...
> > -- 3) Function composition:
> > Prelude> (f2 . f) 3
> > 8
> > Prelude>
>
> 1) (def fn1 (partial + 1))
> 2) (def fn2 #(* % 2)) or (fn [x] (* x 2)))
> 3) ((comp fn2 fn1) 3)
>
> --
> Jarkko

And what is 'comp'?
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Can Clojure functions be anonymous, curried and allow composition?

2008-11-24 Thread Matt Moriarity

comp composes functions just like the dot operator

On Nov 24, 6:14 pm, dokondr <[EMAIL PROTECTED]> wrote:
> On Nov 25, 2:06 am, Jarkko Oranen <[EMAIL PROTECTED]> wrote:
> ...
>
> > > -- 3) Function composition:
> > > Prelude> (f2 . f) 3
> > > 8
> > > Prelude>
>
> > 1) (def fn1 (partial + 1))
> > 2) (def fn2 #(* % 2)) or (fn [x] (* x 2)))
> > 3) ((comp fn2 fn1) 3)
>
> > --
> > Jarkko
>
> And what is 'comp'?
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Stuart Halloway

Another possible approach. Key idea here is to use partition to create  
a sliding window over the lines, plus a sentinel value (I picked "")  
before the first line. Pretty sure I like partition over reduce for  
this particular example.

(ns examples.convert
 (:use [clojure.contrib.duck-streams :only (reader)])
 (:use [clojure.contrib.str-utils :only (re-split)]))

(defstruct line :lat :lon :name)

(defn convert [file]
   (with-open [r (reader file)]
 (doseq [[l1 l2] (partition 2 1 (cons "" (line-seq r)))]
   (if (not= l1 l2)
(println (apply struct line (re-split #"," l2)))

> I am parsing a file and to compare the current line
> with the previous line of the file.  I am using line-seq
> to go thru the file and I thought I would create a
> ref to store the previous line.   When I want to update
> the previous line value I can't seem to do it.  I've
> never used refs before so I'm sure I'm doing something
> very stupid.
>
> (defstruct line :lat :lon :name)
>
> (defn convert [file]
>   (let [prev-line (ref (struct line))]
> (with-open [r (reader file)]
>(doseq [l (line-seq r)]
>  (let [ps (split #"," l)
> c-line (struct line (ps 0) (ps 1) (ps 2))]
>(if (not= c-line @pre-line)
>  (do ; do stuff here then update pre-line
> (dosync ref-set pre-line (apply struct line (vals c- 
> line)))
> (println @pre-line  ; this prints out all  
> nils doesn't seem to work
>
>
>
> Sorry if this email is not formatted correctly.  Something is wrong  
> with my browser
> currently typing in a textarea.  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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Distributed concurrent applications in Clojure?

2008-11-24 Thread dokondr

Any ideas how Clojure can be used for distributed concurrent
applications ?
To my mind it should be possible to implement in Clojure  mechanism
similar to Erlang light-weight processes running on distributed
'nodes' that can be addressed by 'ports' to send them 'commands'.
How this can be done with Clojure 'agents'?
An obvious solution would be to create an 'agent proxy' on every node
that will maintain a list of its  agents and will forward (send ...)
messages to other nodes, as well as receive messages addressed to its
own agents from remote nodes and then deliver these messages to
correct agents.
Addressing scheme and message protocols should be developed as well.
Other ways to provide for communication between nodes?

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Can Clojure functions be anonymous, curried and allow composition?

2008-11-24 Thread Randall R Schulz

On Monday 24 November 2008 15:14, dokondr wrote:
> On Nov 25, 2:06 am, Jarkko Oranen <[EMAIL PROTECTED]> wrote:
> ...
>
> > > -- 3) Function composition:
> > > Prelude> (f2 . f) 3
> > > 8
> > > Prelude>
> >
> > 1) (def fn1 (partial + 1))
> > 2) (def fn2 #(* % 2)) or (fn [x] (* x 2)))
> > 3) ((comp fn2 fn1) 3)
> >
> > --
> > Jarkko
>
> And what is 'comp'?

When in doubt:

- Clojure native API
  

- comp
  


Randall Schulz

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Isolating I/O and other side-effects?

2008-11-24 Thread dokondr

Providing that Clojure is NOT a pure functional language like Haskell,
yet how can I isolate imperative-style computational structures  from
the main body of the functional program?
How can I ensure  referential transparency in Clojure?
What I/O primitives Clojure provides?

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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Reactive Programming in F# and CELLs

2008-11-24 Thread falcon

I hope folks here don't mind this post.  The following article
explains how to do reactive programming in F#:
http://tomasp.net/blog/reactive-i-fsevents.aspx (the bottom of the
article has links to rest of the articles in the series)

There has been some recent discussion on CELLs in Clojure.  There was
some question of motivation behind 'reactive' programming...I believe
this article makes the ideas a bit more concrete. Since Clojure
already has some features for concurrent programming, I believe the
reactive model should also be easy to accommodate.

In F#, one can filter/map/reduce events (and much more) just as if
they were operations on a list.  How would this be done in cells?  How
would one combine or split several cells?

This type of data-flow programming also brings clojure one step closer
my dream of a super-spreadsheet: Instead of typing out expressions on
an REPL, why not make the REPL non-linear and allow users to enter
expressions in 2-d space (similar to a grid...but without the grid).
Unlike Excel, clojure could also very easily let end-users define
their own functions and use them in expressions (thereby vastly
improving the lack of abstractions in current spread sheets)
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



JMS and Clojure?

2008-11-24 Thread falcon

What is the best way of accessing Java Messaging Service though
Clojure?

Sounds like Rich has already experimented, with good results:
>>rhickey: I did some playing (in Clojure) with JMS and OpenMQ and it was 
>>awesome, easy, fun and vert fast, with pro level docs from Sun
(http://clojure-log.n01se.net/date/2008-09-08.html)

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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Isolating I/O and other side-effects?

2008-11-24 Thread Rich Hickey



On Nov 24, 7:22 pm, dokondr <[EMAIL PROTECTED]> wrote:
> Providing that Clojure is NOT a pure functional language like Haskell,
> yet how can I isolate imperative-style computational structures  from
> the main body of the functional program?

You can't, other than manually.

> How can I ensure referential transparency in Clojure?

You can't, other than manually.

> What I/O primitives Clojure provides?
>

All of Java's.

Rich

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Perry Trolard


On Nov 24, 4:03 pm, Stuart Sierra <[EMAIL PROTECTED]> wrote:
> Hi Perry, Stephen,
> I like the "convention over configuration"-ness of defaulting to ./
> classes.  One thought: Weird errors might result if ./classes is not
> on classpath.  Is there an easy way to check that, and display a
> helpful error message?
>

Right, good idea. It would just take checking to see if the "path"
variable is in System.getProperty("java.class.path"), right?

--

Answer: no. I tried the approach below against Stephen's
clojure.lang.Compile, & the ant build process failed. All of the
classes currently on the classpath are evidently not reflected in the
system property -- at least when running in Ant. (I believe they would
be when invoking java w/ the -cp option.)

 FAILED APPROACH -

Boolean found = false;
for ( String cp : System.getProperty("java.class.path").split(":") ) {
if (cp == path) {
  found = true;
}
}
if (!found) {
 err.println("System property " + PATH_PROP + " (the current value
of "+
"which is" + path +") must be in your
CLASSPATH.");
System.exit(1);
}

-
Another approach would be to just catch the
java.lang.ClassNotFoundException that would be triggered if the
clojure.compile.path isn't on the classpath. Better ideas, Stephen?

Perry
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread Chouser

On Mon, Nov 24, 2008 at 5:27 PM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
>
> I believe I have fixed all of my stack-space issues except for this
> one annoying function (rewritten from the original since the
> multimethod wasn't buying me much):
>
> (defn flatten [x]
>  (let [type (:type x)]
>(cond (or (= type :NIL) (= type :TEXT))
>  x
>  (= type :CONCAT)
>  (doc-concat (flatten (:doc1 x))
>  (flatten (:doc2 x)))
>  (= type :NEST)
>  (doc-nest (:level x)
>(flatten (:doc x)))
>  (= type :LINE)
>  (doc-text " ")
>  (= type :UNION)
>  (recur (:doc1 x)
>
> Any ideas?

One option: You could use a seq instead of all the various structs.
This would allow you to remove all the doc-foo helper functions.
Instead of calling those helpers, in most cases you could simply build
a vector [:NIL] instead of (doc-nil), [:TEXT " "] instead of (doc-text
" ").  That way, when you need to recurse, you could use a lazy
expression like (lazy-cat [:concat] [(flatten (:doc1 x))] [(flatten
(:doc2 x))])
This would of course require you to change everywhere that currently
expects a struct with a :type to instead use (first x) for the type
and the rest of the seq as args.

Is your current version visible anywhere?  Perhaps a more holistic
look would reveal some other options.

--Chouser

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: update a ref struct

2008-11-24 Thread Brian Doyle
Yep, that's just a typo in the email.  Something was wrong with my browser
and I
couldn't just paste the code in :(

On Mon, Nov 24, 2008 at 3:33 PM, Shawn Hoover <[EMAIL PROTECTED]>wrote:

> On Mon, Nov 24, 2008 at 5:17 PM, Brian Doyle <[EMAIL PROTECTED]>wrote:
>
>> I am parsing a file and to compare the current line
>> with the previous line of the file.  I am using line-seq
>> to go thru the file and I thought I would create a
>> ref to store the previous line.   When I want to update
>> the previous line value I can't seem to do it.  I've
>> never used refs before so I'm sure I'm doing something
>> very stupid.
>>
>> (defstruct line :lat :lon :name)
>>
>> (defn convert [file]
>>   (let [prev-line (ref (struct line))]
>> (with-open [r (reader file)]
>>(doseq [l (line-seq r)]
>>  (let [ps (split #"," l)
>> c-line (struct line (ps 0) (ps 1) (ps 2))]
>>(if (not= c-line @pre-line)
>>  (do ; do stuff here then update pre-line
>> (dosync ref-set pre-line (apply struct line (vals
>> c-line)))
>> (println @pre-line  ; this prints out all nils
>> doesn't seem to work
>>
>>
> Your let binds prev-line, while the code inside uses pre-line. Is that just
> a typo in your email, or is that the code you're running, too?
>
> Shawn
>
>
> >
>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Patch: universal main() with repl/script/compile

2008-11-24 Thread Perry Trolard

I've written a preliminary cljc script -- a shell script for compiling
Clojure libs -- against Stephen's patched Clojure (specifically using
the clojure.lang.Compile class).

Configure the script with the locations of the clojure.jar & clojure-
contrib.jar & running cljc w/o options calls clojure.lang.Compile on
command-line args representing libs or namespaces. With options, it
can (1) wrap the contents of the build directory (hard-coded to be
"classes") into a jar file (with the first lib set to Main-Class) or
(2) wrap the contents of the build directory, the contents of
clojure.jar, & the contents of the clojure-contrib.jar into a jar file
(with the first lib set to Main-Class).

For example, if I have a Clojure lib in hello.clj

- hello.clj 
(ns hello)

(defn reverse-string
   [s]
   (apply str (reverse s)))
(defn -main
   [& args]
   (println (apply str (mapcat reverse-string (interpose " " (reverse
args))

-

& I call cljc in the same directory like this:

   cljc -a hello

I'll get a jar file I can call like

  java -jar hello.jar dlroW olleH

with these results

  Hello World

That is, it's standalone (albeit at 1.4 Megs!).

Anyone who's built Stephen's patch can try it out; others please feel
free to offer suggestions.

Thanks,
Perry

--
#!/usr/bin/env bash
# cljc: Clojure lib compiler

cjar=PATH/TO/clojure.jar
ccjar=PATH/TO/clojure-contrib.jar
build=classes

usage()
{
   echo "Usage: $0 [options*] lib+"
   echo "Options:"
   echo "   (-cp|--classpath) list: colon-separated list of
directories or jar files to add to classpath"
   echo "   (-j|--jar): turn on creation of jar file"
   echo "   (-n|--name) name: specify the name of created jar file"
   echo "   (-a|--all): turn on inclusion of all jars in jar file
(clojure.jar and clojure-contrib.jar) -- will turn on --jar option as
well"
#   echo "   (-e|--extra-jars) list: colon-separated list of jars to
include in created jar file"
   echo "   (-h|--help): display this usage information"
   echo
   echo "If creating a jar file, the first lib listed will be the Main-
Class in the jar's MANIFEST."
}

while [ $# -gt 0 ]; do
   case $1 in
  -cp | --classpath ) shift; cp=$cp:$1; shift;;
  -a  | --all   ) shift; all=true; jar=true;;
  -j  | --jar   ) shift; jar=true;;
#  -e  | --extra-jars) shift; extra=$1; shift;;
  -h  | --help  ) usage; exit 1;;
  -n  | --name  ) shift; name=$1; shift;;
  * ) break;;
   esac
done


if [ -z "$1" ]; then
   usage
   exit 1
fi

mkdir -p $build
java -cp $cp:$cjar:$ccjar:$build clojure.lang.Compile "$@"

if test $jar; then
   name=`! test -z $name && echo $name || echo $1`
   jar cfe $name.jar $1 -C $build .

   if test $all; then
  tmp=scratch-temp-dir
  mkdir $tmp && cd $tmp
  for jar in $cjar $ccjar; do
 jar xf $jar
  done
  cd -
  jar uf $name.jar -C $tmp clojure
  rm -r $tmp
   fi
fi

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: JMS and Clojure?

2008-11-24 Thread Luc Prefontaine
We use a synchronous layer to JMS queues implemented in Java to hook our
Clojure code to the messaging world.

Two Java classes to implement a consumer and a producer with some common
inheritance are used.
We had already some Java implementation so we just beefed it up a bit to
make more robust.

We use Spring to load beans so loading a consumer look like this:

(defn create-producer-consumer [name]
 (get-bean name)
)

The Spring bean being something similar to this:













Now we have small wrappers in Clojure like these:

(defn read-message
"Consume messages"
[consumer]
(. consumer receive)
)

(deftrace send-message
;;"Send messages"
[producer msg]
(. producer send msg)
)

(defn peek-text-message
"Peek at messages"
[consumer]
(let [message (. consumer browse)]
 (if (not (nil? message)) (. message getText))
)
)

and so on for commits, rollbacks, . The Java classes handle
connection/release of resources, cleanup when the JVM exits, 
We use the wrappers to protect ourselves from later changes in the
implementation.

We use ActiveMq 5.1 with master slave redundancy.

Eventually we want to create a wrapper to allow Clojure functions to be
called asynchronously but we are not there yet,
mainly because we have other priorities.

Using the Spring framework is certainly is a viable option,  we look at
to reuse existing code and getting Clojure code called directly
in an asynchronous fashion.

We start the consumers in separate thread. polling for messages through
read-message and consort. This at least gives us some 
asynchronous processing illusion for the moment.

We expect to shrink the Java code down to a certain size in the next
months and shift more stuff to Clojure
but meanwhile we had to take the shortest path and that implied reusing
existing stuff from the first stage prototype.
We are scheduled to be in production in the next 8 weeks.
Clojure was targeted for the routing layer in our message bus, that's
were the immediate benefits are (dispatch logic, message cloning, ...)

For now we have a resilient implementation ready for production so it's
satisfactory considering I heard about Clojure in September...
Since the beta book is in progress, i am also catching up rapidly about
the language and expect to spit out more elegant code in the
near future :)))

Luc


On Mon, 2008-11-24 at 16:36 -0800, falcon wrote:

> What is the best way of accessing Java Messaging Service though
> Clojure?
> 
> Sounds like Rich has already experimented, with good results:
> >>rhickey: I did some playing (in Clojure) with JMS and OpenMQ and it was 
> >>awesome, easy, fun and vert fast, with pro level docs from Sun
> (http://clojure-log.n01se.net/date/2008-09-08.html)
> 
> 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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Isolating I/O and other side-effects?

2008-11-24 Thread Bradbev

On Nov 24, 4:44 pm, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Nov 24, 7:22 pm, dokondr <[EMAIL PROTECTED]> wrote:
>
> > Providing that Clojure is NOT a pure functional language like Haskell,
> > yet how can I isolate imperative-style computational structures  from
> > the main body of the functional program?
>
> You can't, other than manually.
>
> > How can I ensure referential transparency in Clojure?
>
> You can't, other than manually.
>
> > What I/O primitives Clojure provides?
>
> All of Java's.

Is there anyway to assert that code does have side effects & should
never be called in a transaction?

(dosync
 (assert (not (in-transaction -> "Assert: Can't call this code in
a transaction"

That could be useful for debug builds of IO libraries.

Cheers,
Brad
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Isolating I/O and other side-effects?

2008-11-24 Thread Michael Reid

> Is there anyway to assert that code does have side effects & should
> never be called in a transaction?
>
> (dosync
>  (assert (not (in-transaction -> "Assert: Can't call this code in
> a transaction"
>
> That could be useful for debug builds of IO libraries.

I don't know that there's anything provided already in Clojure, but
you could use the clojure.lang.LockingTransaction#getRunning() method
to check if there is a running transaction on the current thread.

>From there it's pretty easy to write some sort of assert expression
that can be placed into your I/O routines.

/mike.

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: learning clojure

2008-11-24 Thread Ethan Herdrick

For the File / IO things, skip the Java libs - they are pretty low
level.  Go with the Jakarta Commons libs:
http://commons.apache.org/io/description.html , as Stuart has
recommended elsewhere.

On Mon, Nov 24, 2008 at 6:48 AM, Stuart Sierra
<[EMAIL PROTECTED]> wrote:
>
> It's useful to know the standard Java libraries, especially for File/
> IO stuff.  You can pick up nearly all of it from the Sun Java
> tutorials:
> http://java.sun.com/docs/books/tutorial/
>
> -Stuart Sierra
>
>
> On Nov 23, 11:34 pm, syamajala <[EMAIL PROTECTED]> wrote:
>> How easy is it to pick up clojure without having any previous java
>> experience? I have plenty of common lisp experience, but have just
>> never bothered learning java. I recently got a chance to watch the
>> boston lisp talk on clojure, and it looks fairly straightforward, but
>> I feel that not having any knowledge of java might make it a little
>> hard to do more advanced things.
> >
>

--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread [EMAIL PROTECTED]

On Nov 24, 8:17 pm, Chouser <[EMAIL PROTECTED]> wrote:
> One option: You could use a seq instead of all the various structs.

I took your advice and uploaded the rewrite to the files section in
Google Groups, filename is pretty-printer.clj.  It doesn't get a stack
overflow anymore, but it runs out of heap space on my machine trying
to print (pp (range 10)). (pp (range 75000)) works fine.

This approach might just be too inefficient -- perhaps it would be
best to implement the pretty-printer in an imperative style after all.

One reason I don't like this rewrite is that the doc-nil, doc-concat,
doc-union, doc-line, and doc-text operators are missing. They form an
API for custom pretty-printing layouts. For example, with lazy-cats
the make-show-bracket function looks like this:

(defn make-show-brackets [lbrack rbrack]
  (fn [x]
(lazy-cat [:CONCAT] [(lazy-cat [:TEXT] [lbrack])]
  [(lazy-cat [:CONCAT] [(lazy-cat [:NEST] [1] [(show-
children x)])]
 [(lazy-cat [:TEXT] [rbrack])])])))

but with an API from the Wadler paper this would look like:

(defn make-show-brackets [lbrack rbrack]
  (fn [x]
(doc-concat (doc-text lbrack)
(doc-concat (doc-nest 1 (show-children x))
(doc-text rbrack)

or slightly more readably:

(defn make-show-brackets [lbrack rbrack]
  (fn [x]
(reduce doc-concat (list (doc-text lbrack)
 (doc-nest 1 (show-children x))
 (doc-text rbrack)

Either way, there's a lot less noise than with the lazy-cat stuff...
the trouble is that the arguments need to be lazy. Macros might help,
though then the "reduce" trick above won't work.

-- Steve
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread [EMAIL PROTECTED]



On Nov 25, 12:22 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:

> This approach might just be too inefficient -- perhaps it would be
> best to implement the pretty-printer in an imperative style after all.

OTOH it is pretty darn nifty...

user> (pp (clojure.xml/parse "http://catless.ncl.ac.uk/rdigest.rdf";))
{:tag :rdf:RDF,
 :attrs {:xmlns "http://my.netscape.com/rdf/simple/0.9/";,
 :xmlns:rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#";,
 :xmlns:sy "http://purl.org/rss/1.0/modules/syndication/"},
 :content [{:tag :channel,
:attrs nil,
:content [{:tag :title, :attrs nil, :content ["RISKS
Digest"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks"]}
  {:tag :description,
   :attrs nil,
   :content ["The website of the RISKS Digest
mailing list"]}
  {:tag :sy:updatePeriod, :attrs nil, :content
["daily"]}
  {:tag :sy:updateFrequency, :attrs nil, :content
["1"]}
  {:tag :sy:updateBase,
   :attrs nil,
   :content ["1970-01-01T03:13+00:00"]}]}
   {:tag :image,
:attrs nil,
:content [{:tag :title, :attrs nil, :content ["RISKS"]}
  {:tag :url,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Images/Misc/
rdigest.gif"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks"]}]}
   {:tag :item,
:attrs nil,
:content [{:tag :title,
   :attrs nil,
   :content ["Chinese hackers breach white house
computer systems"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks/
25.45.html#subj1"]}]}
   {:tag :item,
:attrs nil,
:content [{:tag :title,
   :attrs nil,
   :content ["Hacker Tool Targeting MS08-067
Vulnerability"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks/
25.45.html#subj2"]}]}
   {:tag :item,
:attrs nil,
:content [{:tag :title,
   :attrs nil,
   :content ["Lose the BlackBerry? Yes He Can,
Maybe: President-Elect Obama"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks/
25.45.html#subj3"]}]}
   {:tag :item,
:attrs nil,
:content [{:tag :title,
   :attrs nil,
   :content ["Texas Suspends Massive Outsourcing
Contract"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks/
25.45.html#subj4"]}]}
   {:tag :item,
:attrs nil,
:content [{:tag :title,
   :attrs nil,
   :content ["Driver Blames GPS System For Car-
Train Collision"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks/
25.45.html#subj5"]}]}
   {:tag :item,
:attrs nil,
:content [{:tag :title,
   :attrs nil,
   :content ["Stop! Buses only! --What do you
mean, you ARE a bus?"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks/
25.45.html#subj6"]}]}
   {:tag :item,
:attrs nil,
:content [{:tag :title,
   :attrs nil,
   :content ["Martian deep freeze: NASA's Mars
Lander dies in the dark"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks/
25.45.html#subj7"]}]}
   {:tag :item,
:attrs nil,
:content [{:tag :title,
   :attrs nil,
   :content ["The \"Two Focaccia Buttons Defense
\""]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks/
25.45.html#subj8"]}]}
   {:tag :item,
:attrs nil,
:content [{:tag :title,
   :attrs nil,
   :content ["Risks of assuming constant hours in
a day"]}
  {:tag :link,
   :attrs nil,
   :content ["http://catless.ncl.ac.uk/Risks/
25.45.html#subj9"]}]}
   {:tag :item,
:attrs nil,
:content

Re: Adapting a functional pretty-printer to Clojure

2008-11-24 Thread [EMAIL PROTECTED]



On Nov 25, 12:50 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On Nov 25, 12:22 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > This approach might just be too inefficient -- perhaps it would be
> > best to implement the pretty-printer in an imperative style after all.
>
> OTOH it is pretty darn nifty...

...or would be if Google Groups didn't wrap so well...
--~--~-~--~~~---~--~~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Help needed: Clojure wikibook is desperately in need of cleanup!

2008-11-24 Thread Timothy Pratley

Hi Jarkko,

Good changes, the main page was getting hellishly long.

> (I wiped the old examples subpage as it was just an unorganised
> collection showing usage of standard library functions. If someone is
> feeling up to it, you can salvage it from the page history and
> incorporate it into the book)

One man's trash is another man's treasure... I'm trying to build a 1:1
mapping of short examples to the API doc, because for me these usually
communicate the function definition faster than the formal definition.
I've got no problem with (my) Examples being replaced, and agree
that's the right thing to do. I tried to salvage my examples by moving
an old revision to API_Examples... but that moved Examples over as
well and created a link. So I moved it back again and that's fine...
but now API_Examples redirects to Examples... so I can't use
API_Examples. If you know how to remove the API_Examples redirect
without removing Examples, that would be great. For now I'm using
TJP_Examples instead, with the hope one day this will be able to
become API_Examples.


> For now, the subpages are just verbatim copies of sections on the main
> page, which I didn't modify yet to include links to them. With the
> material split up somewhat, it should be easier to edit and
> reorganise.

Good idea, I suggest just going ahead and modifying the links...
otherwise someone will edit the old page and either their changes will
be lost or yours will be.

> Who is responsible for approving changes to the main page by the way?
> I personally would like to keep the book open for everyone to edit, at
> least until we get things reasonably into shape.

Recently wikibooks instigated some sort of review system, but from
what I can tell this can safely be ignored. It has the annoying side
effect of making changes to the main page not default for anonymous
users until an 'editor' 'sights' them, however you can still choose to
see the latest version regardless (or login to avoid it altogether).

I'm pretty new here so am by no means a definitive source, but my
understanding is that it is encouraged to contribute at will.


Regards,
Tim.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---