Re: about the repl

2010-12-21 Thread Tom Faulhaber
Hmm, looks like I broke some logic when I hand unrolled the original
cl-format based dispatch to get better performance for lists, vectors, and
maps. (Really I shouldn't have to do this, but I need to make cl-format
itself generate code rather than threaded functions which are slow and tend
to blow your stack. Haven't gotten around to that yet, though so the
hand-coded versions are stop-gaps.)

I'm not digging the patch too much, though, for 3 reasons:

1) It breaks sets and arrays, which work in master.
2) It pushes the logic for *print-length* printing into the dispatch
functions (redundantly since there's still logic in write-out). Since these
are customizable, it places that load on whoever customizes it.
3) It adds redundant logic in write-out which is the called for every object
that the pretty printer deals with.

I'll try to take a stab at a patch that fits a little better with what I'm
trying to do in the next couple of days.

Tom


On Sat, Dec 18, 2010 at 1:18 PM, Stuart Halloway
wrote:

> > The latter is easy to fix: provide a version of println that wraps an
> > implicit (take n ...) around seq arguments (including when it calls
> > itself on seqs nested within other structures). (*print-length*
> > doesn't seem to work, just causes an infinite seq to print the first n
> > items and then a never-ending string of "..."s.)
>
> Hi Ken,
>
> In my tests *print-length* works fine with the regular REPL printer, but
> has the defect you describe when using pprint. Can you confirm that you are
> also seeing the problem with pprint, not print?
>
> Do some REPLs automatically replace print with pprint?
>
> Tom:  I have created a ticket with a partial fix and would appreciate your
> input: http://dev.clojure.org/jira/browse/CLJ-695.
>
> Thanks,
> Stu
>
>

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

Re: Native Clojure

2010-12-21 Thread nicolas.o...@gmail.com
If you want native with enough reflection to compile clojure,
Objective-C might be a better choice than C++.

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


Re: Native Clojure

2010-12-21 Thread Alessio Stalla
On Monday, December 20, 2010 8:54:14 PM UTC+1, kaveh_shahbazian wrote:
>
> I understand hosting on a VM has it's own (huge) advantages: GC, 
> libraries, proved practices and vast amount of research and community 
> effort already available; no doubt on that part. 
>
> It is just having a mature and well designed cross-platform natively 
> compiled language (other than C and C++) has it's own advantages (I do 
> not mean Clojure should go down that path; I was just asking). Some 
> high level languages come to mind like Haskell, OCaml, Gambit-C Scheme 
> (and for sure some others) but they lack in some areas and not fully 
> cross platform. 
>
> Clojure is a fantastic language (Although I have just scratched the 
> surface) and It would be "nice" to have it natively compiled. 
>

It could be written on top of Common Lisp. There are natively compiled, 
multithreaded, cross-platform implementations of it, and building on another 
Lisp should be much easier than on C/C++. Of course, since Clojure programs 
often rely on Java libraries to do some of their work, porting won't be a 
no-brainer.

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

Re: Ah-hah! Clojure is a Lisp

2010-12-21 Thread Marko Koci?
You can use 
http://docs.google.com/viewer?url=http://url_to_pdf_or_doc_or_xls_or_something 
to see those documents converted to html. Works ok in most of the cases, 
even on my phone.

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

Re: Ah-hah! Clojure is a Lisp

2010-12-21 Thread Sandeep


On Dec 20, 7:09 am, Tim Daly  wrote:
> It is the algebra language in the Axiom project called 
> Spad.http://axiom-developer.org
> It is open source

There is also Qi (http://www.lambdassociates.org/qilisp.htm). It is
now morphing into Shen (http://www.lambdassociates.org/Shen/
appeal.htm) with Clojure as a possible VM target - Javascript being
the #1 target VM.

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


Re: clojure -> javascript

2010-12-21 Thread Shane Daniel
Hi everybody,

Just for kicks I took Chouser's good start on the PersistentVector port and 
threw it in a Github gist, and demonstrated using it in jsFiddle. I love the 
cloud these days ;)

Anyway, I hope you don't mind Chouser. I plan to refactor your code to use 
Javascript's prototype system, but really just wanted it online because it's 
an excellent starting point. Now it could be forked and demo'd easily.

-Shane

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

Re: clojure -> javascript

2010-12-21 Thread Shane Daniel
Hello there again.

After reading my above post you were probably frustrated, as was I when I 
realized I had completely forgotten to include links to actual resources. 
D'oh.

The gist is here: https://gist.github.com/749750
The jsFiddle demonstration (outputs to console) is here: 
http://jsfiddle.net/simloovoo/ZmruR/

Sorry for the trouble,

Shane

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

Re: clojure -> javascript

2010-12-21 Thread Chouser
On Tue, Dec 21, 2010 at 6:51 AM, Shane Daniel  wrote:
> Hi everybody,
> Just for kicks I took Chouser's good start on the PersistentVector port and
> threw it in a Github gist, and demonstrated using it in jsFiddle. I love the
> cloud these days ;)
> Anyway, I hope you don't mind Chouser. I plan to refactor your code to use
> Javascript's prototype system, but really just wanted it online because it's
> an excellent starting point. Now it could be forked and demo'd easily.

I'd be happy if someone were to get more use out it.  Eventually
I hope we have JS generated from a pure-Clojure implementations
of all the collection types, but until then I guess this will
have to do.  Thanks for getting it out there.

--Chouser
http://joyofclojure.com/

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


Community attitude

2010-12-21 Thread Jay Fields
I was involved with Ruby and Rails in the early days. The Ruby mailing lists / 
conferences were always kind / helpful and the Rails lists / confs were always 
hit and miss. There were plenty of great Rails people, and enough jerks to 
upset anyone. 

I read this (Clojure) google group pretty frequently awhile ago, but took 
several months off. I returned a week ago and after the first day I emailed Stu 
H. And said: Is  one of the leaders of the community now? He 
seems really abrasive.

Having been through this before I'd recommend a few things. 

- individually, 
-- reword responses from: "why would you do that" to "I prefer my solution 
because...". "that's not functional and it's ugly!" to "I believe my solution 
is more in-line with FP style" etc. The trick is to focus on what you are 
looking for (and the positives of the idea) instead of attacking someone else's 
solution. 
-- in niche communities, once you're labeled as a jerk, you're in trouble. 
People won't work with you. People won't answer your questions. And, people 
(often unfairly) assume you are wrong, simply because they don't like you. You 
can deal with this in a large (mostly anonymous) community. In a small 
community it's career limiting. 

- community
-- it might be worth coming up with a few basic rules and removing people who 
can't follow them. Obviously, this isn't an easy task, but it might be worth 
the effort. 

Also, what happened to Rich? It seems like many wasteful discussions could be 
more easily put to bed by his response instead of the current "here's a video 
of Rich from a year ago" or "here's a link to something Rich wrote in the past"

Or, maybe I'm oversensitive and things are fine. 

Sent from my iPhone

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


Re: Native Clojure

2010-12-21 Thread Santosh Rajan
On Tue, Dec 21, 2010 at 3:26 PM, Alessio Stalla  wrote:

>
> It could be written on top of Common Lisp. There are natively compiled,
> multithreaded, cross-platform implementations of it, and building on another
> Lisp should be much easier than on C/C++. Of course, since Clojure programs
> often rely on Java libraries to do some of their work, porting won't be a
> no-brainer.

I am not a Clojure expert. But if I understood Clojure correctly,
Clojure would not be Clojure if it where natively compiled. Eg. The
whole lazy seq's are required because of lack of tail call
optimization in the JVM. Or am I wrong?

-- 
http://about.me/santosh.rajan

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


Re: Community attitude

2010-12-21 Thread .Bill Smith
I think those are fine points.   And to reciprocate, I think it's important 
when you read someone's comments to give the writer the benefit of a doubt. 
 Sometimes it helps to read between the lines.  If you can tone down your 
emotional reaction to a comment that feels unpleasant, you may find the 
commenter has something useful to say.  

Sincerely,
Bill Smith

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

Re: Native Clojure

2010-12-21 Thread nicolas.o...@gmail.com
>
> I am not a Clojure expert. But if I understood Clojure correctly,
> Clojure would not be Clojure if it where natively compiled. Eg. The
> whole lazy seq's are required because of lack of tail call
> optimization in the JVM. Or am I wrong?
>
>
I don't think the lazy seq are necessary because of TCO. They are
useful for a lot of things.
They allow to write a nice abstract function, and have it executed in
an efficient manner.
(Without blowing memory, and, with chunky sequences, with good cache locality.)

They can help to prevent some stack overflow problems, but I am not
sure a lot of lazy function would be
TCoptimised. For example, the usual map is not tail recursive:
(defn my-map [f l]
  (when l
(cons (f (first l)) (my-map f (next l)))

You can write a tail recursive version, but it would be equivalent to
accumulating with a loop and reversing the result.
Which you can do in Clojure.

Best regards,

Nicolas.

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


Re: Community attitude

2010-12-21 Thread Baishampayan Ghose
Jay,

[snip]

I agree with your observations. The last few days have indeed been
kind of upsetting. I hope everyone follows your suggestions.

> Also, what happened to Rich? It seems like many wasteful discussions could be 
> more easily put to bed by his response
> instead of the current "here's a video of Rich from a year ago" or "here's a 
> link to something Rich wrote in the past"

I don't think Rich should be bothered by these issues because he has
harder problems to solve, and forward the state of the art. There is
enough material online which people can peruse without wasting Rich's
time (especially since his work is very well documented).

I believe it's entirely our prerogative to look up the material online
(in whatever format it has been provided) and try to grok Rich's
wisdom; I think it's wrong to expect Rich to intervene every time
someone refuses to read the material online and argues about
nomenclature that has been widely accepted within (and beyond!) the
community.

Having said that, I completely empathise with your feelings --- you
are not being oversensitive at all.

Unfortunately, that's something that we will have to solve among
ourselves, exactly how though, I am not sure.

Regards,
BG

-- 
Baishampayan Ghose
b.ghose at gmail.com

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


Out of memory

2010-12-21 Thread Miles Trebilco
Why does this cause an out of memory error:

(def out_of_mem
  (reduce + 0 (range 5000)))

while this does not:

(def not_out_of_mem
 (let [result 0]
  (reduce + result (range 5000

and neither does this in the REPL:
  (reduce + 0 (range 5000)))


 - Miles

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


Calling methods with a dollar sign in them

2010-12-21 Thread Seth
I am attempting to interop with scala. In scala, if you have a class
which is a var, a method is defined in the .class file called varname_
$eq  which will set the var. Problem is, clojure apprent converts
dollar signs to the text  _DOLLARSIGN_. Is there any way to prevent
this?

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


Re: Calling methods with a dollar sign in them

2010-12-21 Thread Seth
oh, and the public var is defined as private in the .class file, so i
can't use set!

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


Re: Native Clojure

2010-12-21 Thread Alessio Stalla
On Tuesday, December 21, 2010 2:55:58 PM UTC+1, Santosh Rajan wrote:
>
> On Tue, Dec 21, 2010 at 3:26 PM, Alessio Stalla  
> wrote:
>
> >
> > It could be written on top of Common Lisp. There are natively compiled,
> > multithreaded, cross-platform implementations of it, and building on 
> another
> > Lisp should be much easier than on C/C++. Of course, since Clojure 
> programs
> > often rely on Java libraries to do some of their work, porting won't be a
> > no-brainer.
>
> I am not a Clojure expert. But if I understood Clojure correctly,
> Clojure would not be Clojure if it where natively compiled. Eg. The
> whole lazy seq's are required because of lack of tail call
> optimization in the JVM. Or am I wrong?
>

I'm not an expert either, but as I understand it, some things are required, 
and others are strongly influenced, by the JVM. Lazy seqs are neither; recur 
is directly tied to the lack of TCO, though arguably it could be useful even 
with the availability of TCO; the try-catch-finally exception scheme is 
directly derived from Java and the JVM's constructs. Anyway, the biggest 
problem in porting Clojure-the-language to CL (or to some other high-level, 
managed language) is probably porting the library of datastructures, STM, 
etc., not the base language. Porting Clojure-the-ecosystem is much more 
difficult because, as I said, many libraries and frameworks are strongly 
tied to JVM libraries.

Alessio

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

Re: Native Clojure

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 9:12 AM, nicolas.o...@gmail.com <
nicolas.o...@gmail.com> wrote:

> (defn my-map [f l]
>  (when l
>(cons (f (first l)) (my-map f (next l)))
>
> You can write a tail recursive version, but it would be equivalent to
> accumulating with a loop and reversing the result.
> Which you can do in Clojure.
>
> Best regards,
>
> Nicolas.
>

In my experience lazy-seqs are a reasonable replacement for the lack of TCO,
and from what I've heard that is one of the reasons they exist.

(defn a [x]
   (lazy-seq
 (cons x (b (inc x)

(defn b [x]
   (lazy-seq
 (cons x (a (inc x)

David

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

Re: Community attitude

2010-12-21 Thread atreyu
I would like to think is a symptom of the growth of Clojure. More
Clojure users from different perspectives and attitudes means more
potential for conflict. But some attitudes only causes noise: in
particular people who requires without counterpart and think Clojure
is like Visual Basic and this group is the maintenance staff of
Microsoft.
It's difficult to ignore the attitude and convert negative criticism
in improvements for the community but i think that could be is the
way.
With that spirit i am going to traduce rich's material to spanish to
spread the world in spanish dev community (in html format or plain
text, im in doubt :-P) starting with the slides of "Are we ther yet?"

PD: Of course i'll not publish the traductions if some author
disagree.

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


Re: clojure -> javascript

2010-12-21 Thread nickik
The dream would be to have:

- Everything for clojure in clojure
- A nice compiler in clojure
- java speed clojure
- Collections and multimethodes in clojure
- A js generating backend for the compiler that works with GWT for the
required java stuff

Unfortunately I do not (jet) have the skill to do any of that and this
will takes a very long time (if ever).

In the mean time I think Chouser  "In-between" sound pretty good and I
think it would be the most practical. Write clojure code, use the
clojure core functions, be able to use macros and clojure collections
would already be a great project.

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


Re: Native Clojure

2010-12-21 Thread nicolas.o...@gmail.com
> In my experience lazy-seqs are a reasonable replacement for the lack of TCO,
> and from what I've heard that is one of the reasons they exist.
> (defn a [x]
>    (lazy-seq
>      (cons x (b (inc x)
> (defn b [x]
>    (lazy-seq
>      (cons x (a (inc x)
> David
>
I am not sure I get you. COuld you elaborate a bit more this example, please?
Which tail-call functions are you trying to replace by a and b?


Nicolas.

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


Re: Native Clojure

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 11:28 AM, nicolas.o...@gmail.com <
nicolas.o...@gmail.com> wrote:

> I am not sure I get you. COuld you elaborate a bit more this example,
> please?
> Which tail-call functions are you trying to replace by a and b?
> Nicolas.
>

Those are mutual recursive functions. Trying to define them as regular
functions will quickly result in a stack overflow.

You could use trampoline but in my experience you will take a significant
performance hit.

Lazy sequences are a way to efficiently represent mutually recursive
computations w/o TCO.

David

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

Re: Native Clojure

2010-12-21 Thread nicolas.o...@gmail.com
> Those are mutual recursive functions. Trying to define them as regular
> functions will quickly result in a stack overflow.
> You could use trampoline but in my experience you will take a significant
> performance hit.
> Lazy sequences are a way to efficiently represent mutually recursive
> computations w/o TCO.
> David
>
I am not sure to understand.

Neither functions are tail-recursive. So in this situation enabling
tail-recursion
would not help.

Best,

Nicolas.

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


Re: Native Clojure

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 11:41 AM, nicolas.o...@gmail.com <
nicolas.o...@gmail.com> wrote:

> > Those are mutual recursive functions. Trying to define them as regular
> > functions will quickly result in a stack overflow.
> > You could use trampoline but in my experience you will take a significant
> > performance hit.
> > Lazy sequences are a way to efficiently represent mutually recursive
> > computations w/o TCO.
> > David
> >
> I am not sure to understand.
>
> Neither functions are tail-recursive. So in this situation enabling
> tail-recursion
> would not help.
>
> Best,
>
> Nicolas
>

With TCO mutually recursive functions do not consume the stack. The same is
true for well constructed lazy sequences.

David

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

Re: Native Clojure

2010-12-21 Thread nicolas.o...@gmail.com
> With TCO mutually recursive functions do not consume the stack. The same is
> true for well constructed lazy sequences.
> David

With TCO, mutually *tail* recursive functions do not consume the stack.

non-tail call always consume the stack in non CPS compiled languages.
(In which, it consumes the heap).

Nicolas.

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


Re: Native Clojure

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 11:54 AM, nicolas.o...@gmail.com <
nicolas.o...@gmail.com> wrote:

> > With TCO mutually recursive functions do not consume the stack. The same
> is
> > true for well constructed lazy sequences.
> > David
>
> With TCO, mutually *tail* recursive functions do not consume the stack.
>
> non-tail call always consume the stack in non CPS compiled languages.
> (In which, it consumes the heap).
>
> Nicolas.
>

Yes I know, I thought the way I wrote the code was clear about that :)

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

Re: Native Clojure

2010-12-21 Thread Andrew Boekhoff
> With TCO mutually recursive functions do not consume the stack. The same is
> true for well constructed lazy sequences.

If the functions were: 
(defn f [x] (g x))
(defn g [x] (f x))

They would operate in constant space with tail-call optimization.

(defn f [x] (cons x (g x)))
(defn g [x] (cons x (f x)))

Will run out of memory even in languages that support
tail call optimization. 
(assuming we're evaluating them eagerly)

Lazy-seq's are often handy in Clojure to subvert the stack limit imposed
by the the JVM, but it's not quite the same problem that TCO solves.

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


Re: Native Clojure

2010-12-21 Thread nicolas.o...@gmail.com
> Yes I know, I thought the way I wrote the code was clear about that :)

I am sorry, I did not understand.

So let me try to explicit your transformation (please correct me if I am wrong):
- start with some mutually recursive functions: a and b, for example
- create a "lazy stack" for the recursive calls using a lazy-seq
- reduce the seq until you find the result of the computation?

Am I getting the idea or not at all?

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


Re: Native Clojure

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 12:09 PM, nicolas.o...@gmail.com <
nicolas.o...@gmail.com> wrote:

> > Yes I know, I thought the way I wrote the code was clear about that :)
>
> I am sorry, I did not understand.
>
> So let me try to explicit your transformation (please correct me if I am
> wrong):
> - start with some mutually recursive functions: a and b, for example
> - create a "lazy stack" for the recursive calls using a lazy-seq
> - reduce the seq until you find the result of the computation?
>
> Am I getting the idea or not at all?
>

 You can start with as many mutually recursive functions as you want. But
yes, that is the general idea.

David

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

Re: Native Clojure

2010-12-21 Thread nicolas.o...@gmail.com
I have an example to clarify what I understood of your idea:

(declare odd)

(defn even [x]
(if (zero? x)
  [true]
  (lazy-seq nil (odd (dec x)

(defn odd [ x]
(if (zero? x)
  [false]
  (lazy-seq nil (even (dec x)

(defn get-value [l]
(if (nil? (first l)) (recur (next l)) (first l)))

(get-value (even 1500))

Nicolas.

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


Re: Native Clojure

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 12:20 PM, nicolas.o...@gmail.com <
nicolas.o...@gmail.com> wrote:

> I have an example to clarify what I understood of your idea:
>
> (declare odd)
>
> (defn even [x]
>(if (zero? x)
>  [true]
>  (lazy-seq nil (odd (dec x)
>
> (defn odd [ x]
>(if (zero? x)
>  [false]
>  (lazy-seq nil (even (dec x)
>
> (defn get-value [l]
>(if (nil? (first l)) (recur (next l)) (first l)))
>
> (get-value (even 1500))
>
> Nicolas.


Yup :D

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

Re: Native Clojure

2010-12-21 Thread nicolas.o...@gmail.com
It's a funy and original trick but on this example at least,
it seems slower (and it can use a lot of memory, because it retains a
stack in the heap) than trampoline:

(time (get-value (even 1500)))
"Elapsed time: 1899.881769 msecs"

And a version with trampoline

(defn odd [^long x]
(if (zero? x)
  false
  #(even (dec x

(defn even [^long x]
(if (zero? x)
  true
  #(odd (dec x

(time (trampoline (even 1500)))
"Elapsed time: 366.496137 msecs"

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


Re: Community attitude

2010-12-21 Thread Kevin Downey
great, yet another email on the list so unrelated to clojure that not
only does it contain no code, but no reference to code. if you need to
whinge publicly please do it on your own blog. if you don't feel like
the clojure community is giving you the love and support you need then
I am sure rails will take you back.

Sent from who cares

On Tue, Dec 21, 2010 at 5:36 AM, Jay Fields  wrote:
> I was involved with Ruby and Rails in the early days. The Ruby mailing lists 
> / conferences were always kind / helpful and the Rails lists / confs were 
> always hit and miss. There were plenty of great Rails people, and enough 
> jerks to upset anyone.
>
> I read this (Clojure) google group pretty frequently awhile ago, but took 
> several months off. I returned a week ago and after the first day I emailed 
> Stu H. And said: Is  one of the leaders of the community now? 
> He seems really abrasive.
>
> Having been through this before I'd recommend a few things.
>
> - individually,
> -- reword responses from: "why would you do that" to "I prefer my solution 
> because...". "that's not functional and it's ugly!" to "I believe my solution 
> is more in-line with FP style" etc. The trick is to focus on what you are 
> looking for (and the positives of the idea) instead of attacking someone 
> else's solution.
> -- in niche communities, once you're labeled as a jerk, you're in trouble. 
> People won't work with you. People won't answer your questions. And, people 
> (often unfairly) assume you are wrong, simply because they don't like you. 
> You can deal with this in a large (mostly anonymous) community. In a small 
> community it's career limiting.
>
> - community
> -- it might be worth coming up with a few basic rules and removing people who 
> can't follow them. Obviously, this isn't an easy task, but it might be worth 
> the effort.
>
> Also, what happened to Rich? It seems like many wasteful discussions could be 
> more easily put to bed by his response instead of the current "here's a video 
> of Rich from a year ago" or "here's a link to something Rich wrote in the 
> past"
>
> Or, maybe I'm oversensitive and things are fine.
>
> Sent from my iPhone
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Working with maps and vectors

2010-12-21 Thread Anclj
Hi again,

I still don't know how to use the filter function.

I have a map of "provinces - seats" like: (def provs {"p1" "5", "p2"
"8", "p3" "13", "p4" "11"})
And a sequence of "province - party - votes" like: (def votes [["A"
"p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"] ["B" "p2" "21"]])

In order to get the lazy sequence for every province, I have made a
function like: (defn getseq [prov party] (...))

But I don't know how to get each province ("p1", "p2", "p3", ...).

Doing: (take 1 provs)
I get: (["p1" "5"])

Any idea of how could I get "p1"? So I can make a recursive call to my
getseq function with "p1", "p2", ...


Thanks again.

On Dec 21, 2:21 am, Ken Wesson  wrote:
> On Mon, Dec 20, 2010 at 5:05 PM, Anclj  wrote:
> > Thanks a lot for the fast reply!
> > Now I have the vector as I wanted.
>
> > I have been playing with your code: (map #(/ votes %) (iterate inc 1))
>
> > user=> (take 10 (map #(/ 100 %) (iterate inc 1)))
> > (100 50 100/3 25 20 50/3 100/7 25/2 100/9 10)
>
> > I have managed to put that in a lazy sequence:
> > user=> (def ls (lazy-seq (map #(/ 100 %) (iterate inc 1
> > #'user/ls
>
> Eh. (map #(/ votes %) (iterate inc 1)) itself produces a lazy
> sequence, since map and iterate are lazy.
>
> > I don't know how to filter and work with the vector & map in order to
> > apply that function for each party, in each province.
> > I have been trying to use the filter function but I get the following
> > error:
>
> > user=> (filter #"A" [["A" "p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"]
> > ["B" "p2" "21"]])
> > java.lang.ClassCastException: java.util.regex.Pattern cannot be cast
> > to clojure.lang.IFn
>
> For this, you can just use #(= "A" %) as your predicate; there's no
> need to use regex matching.
>
> If you need a regex, use #(re-matches #"pattern" %) as your predicate,
> instead of the regex itself.
>
> > Thanks again and I will be posting any advances!
>
> You're welcome.

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


Re: Native Clojure

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 12:44 PM, nicolas.o...@gmail.com <
nicolas.o...@gmail.com> wrote:

> It's a funy and original trick but on this example at least,
> it seems slower (and it can use a lot of memory, because it retains a
> stack in the heap) than trampoline:
>
> (time (get-value (even 1500)))
> "Elapsed time: 1899.881769 msecs"
>
> And a version with trampoline
>
> (defn odd [^long x]
>(if (zero? x)
>  false
>  #(even (dec x
>
> (defn even [^long x]
>(if (zero? x)
>  true
>  #(odd (dec x
>
> (time (trampoline (even 1500)))
> "Elapsed time: 366.496137 msecs"


On my machine I don't see this difference at all. And the lazy-seq version
is slightly faster.

I'm on Clojure 1.3.0-alpha3.

David

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

Re: Working with maps and vectors

2010-12-21 Thread Benny Tsai
'filter' is for getting a subset of the elements in a collection.  For
getting the names of the provinces, what you want is to get all the
keys from your 'provs' map, which can be done via the 'keys' function.

user=> (keys provs)
("p1" "p2" "p3" "p4")

Personally, I find ClojureDocs' Quick Reference tremendously helpful
whenever I'm looking for a function to do something:

http://clojuredocs.org/quickref/Clojure%20Core

Hope this helps!

On Dec 21, 11:06 am, Anclj  wrote:
> Hi again,
>
> I still don't know how to use the filter function.
>
> I have a map of "provinces - seats" like: (def provs {"p1" "5", "p2"
> "8", "p3" "13", "p4" "11"})
> And a sequence of "province - party - votes" like: (def votes [["A"
> "p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"] ["B" "p2" "21"]])
>
> In order to get the lazy sequence for every province, I have made a
> function like: (defn getseq [prov party] (...))
>
> But I don't know how to get each province ("p1", "p2", "p3", ...).
>
> Doing: (take 1 provs)
> I get: (["p1" "5"])
>
> Any idea of how could I get "p1"? So I can make a recursive call to my
> getseq function with "p1", "p2", ...
>
> Thanks again.
>
> On Dec 21, 2:21 am, Ken Wesson  wrote:
>
>
>
>
>
>
>
> > On Mon, Dec 20, 2010 at 5:05 PM, Anclj  wrote:
> > > Thanks a lot for the fast reply!
> > > Now I have the vector as I wanted.
>
> > > I have been playing with your code: (map #(/ votes %) (iterate inc 1))
>
> > > user=> (take 10 (map #(/ 100 %) (iterate inc 1)))
> > > (100 50 100/3 25 20 50/3 100/7 25/2 100/9 10)
>
> > > I have managed to put that in a lazy sequence:
> > > user=> (def ls (lazy-seq (map #(/ 100 %) (iterate inc 1
> > > #'user/ls
>
> > Eh. (map #(/ votes %) (iterate inc 1)) itself produces a lazy
> > sequence, since map and iterate are lazy.
>
> > > I don't know how to filter and work with the vector & map in order to
> > > apply that function for each party, in each province.
> > > I have been trying to use the filter function but I get the following
> > > error:
>
> > > user=> (filter #"A" [["A" "p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"]
> > > ["B" "p2" "21"]])
> > > java.lang.ClassCastException: java.util.regex.Pattern cannot be cast
> > > to clojure.lang.IFn
>
> > For this, you can just use #(= "A" %) as your predicate; there's no
> > need to use regex matching.
>
> > If you need a regex, use #(re-matches #"pattern" %) as your predicate,
> > instead of the regex itself.
>
> > > Thanks again and I will be posting any advances!
>
> > You're welcome.

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


Re: Native Clojure

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 12:08 PM, Andrew Boekhoff wrote:

> > With TCO mutually recursive functions do not consume the stack. The same
> is
> > true for well constructed lazy sequences.
>
> If the functions were:
> (defn f [x] (g x))
> (defn g [x] (f x))
>
> They would operate in constant space with tail-call optimization.
>
> (defn f [x] (cons x (g x)))
> (defn g [x] (cons x (f x)))
>
> Will run out of memory even in languages that support
> tail call optimization.
> (assuming we're evaluating them eagerly)
>
> Lazy-seq's are often handy in Clojure to subvert the stack limit imposed
> by the the JVM, but it's not quite the same problem that TCO solves.


Having recently converted some Scheme that leaned heavily on the presence of
TCO, I'm curious as to what situations you think could not be solved with
lazy-seqs?

David

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

Re: name protect & anonymous macros ?

2010-12-21 Thread Nate Young
On 12/17/2010 09:54 AM, Trevor wrote:
> 2. Is there a form for anonymous macros?
> 
> i.e. I know I can do : (fn[x](do x)), but can I not do: (macro[x](let
> [x# x] `(do x)))   ?
> 
> Thanks!
> 

A little tardy, but Konrad Hinsen has written a handful of CL-like
functions for symbol macros and macrolet in clojure.contrib.macro-utils:

http://clojure.github.com/clojure-contrib/macro-utils-api.html

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


Automatically unmapping unit tests from namespaces

2010-12-21 Thread Alyssa Kwan
Hi everyone,

My typical development workflow is to use leiningen to create a
project stub, modify project.clj to add swank-clojure as a dev-
dependency, and run lein-swank and connect from Emacs slime.  As I
create and modify files in the test and src namespaces/directory
structures, I use C-c C-k to call slime-compile-and-load on the buffer
that I'm currently in.  And I use C-c M-p to switch to the test
namespace I'm working on so that in the slime REPL I can call (run-
tests).

So far so good.

What about when I need to delete a unit test?  Reloading the test
buffer doesn't remove it, and I need to either restart swank or
reconnect slime, or manually remove those tests using (unmap-ns).
Surely there's a better way...

Thanks!
Alyssa

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


Re: Out of memory

2010-12-21 Thread Ken Wesson
On Tue, Dec 21, 2010 at 9:09 AM, Miles Trebilco  wrote:
> Why does this cause an out of memory error:
>
> (def out_of_mem
>  (reduce + 0 (range 5000)))
>
> while this does not:
>
> (def not_out_of_mem
>  (let [result 0]
>  (reduce + result (range 5000
>
> and neither does this in the REPL:
>  (reduce + 0 (range 5000)))

The first instance must be holding onto the head of (range 5000)
for some reason.

If I had to hazard a guess I'd say it's something in the
implementation of the def special form that causes it. Further, I'd
hypothesize that the let form somehow shields the range from having
its head held onto. One piece of evidence is this:


user=> (def x (let [y 100] (reduce + 0 (range 5000
#'user/x
user=> x
12497500

Even if the let binding is completely irrelevant to the range and the
reduce, it doesn't OOME.

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


Re: Out of memory

2010-12-21 Thread Tim Robinson
You may want to consider the heap size you have allocated to java. I
believe the default is 128.

For example you can set this yourself:

java -Xms256m -Xmx1024m

This provides 256mb initial heap and permits heap to grow to 1024mb.

I've been using Leiningen, so in my case I just changed the settings
in the source, before install.

There's probably a list of pros/cons to upping the default heap size
that you may want to consider.

Tim

On Dec 21, 7:09 am, Miles Trebilco  wrote:
> Why does this cause an out of memory error:
>
> (def out_of_mem
>   (reduce + 0 (range 5000)))
>
> while this does not:
>
> (def not_out_of_mem
>  (let [result 0]
>   (reduce + result (range 5000
>
> and neither does this in the REPL:
>   (reduce + 0 (range 5000)))
>
>  - Miles

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


Re: Working with maps and vectors

2010-12-21 Thread Stephen Pardue
user=> (first (first provs))
"p1"
user=>

On Tue, Dec 21, 2010 at 1:18 PM, Benny Tsai  wrote:

> 'filter' is for getting a subset of the elements in a collection.  For
> getting the names of the provinces, what you want is to get all the
> keys from your 'provs' map, which can be done via the 'keys' function.
>
> user=> (keys provs)
> ("p1" "p2" "p3" "p4")
>
> Personally, I find ClojureDocs' Quick Reference tremendously helpful
> whenever I'm looking for a function to do something:
>
> http://clojuredocs.org/quickref/Clojure%20Core
>
> Hope this helps!
>
> On Dec 21, 11:06 am, Anclj  wrote:
> > Hi again,
> >
> > I still don't know how to use the filter function.
> >
> > I have a map of "provinces - seats" like: (def provs {"p1" "5", "p2"
> > "8", "p3" "13", "p4" "11"})
> > And a sequence of "province - party - votes" like: (def votes [["A"
> > "p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"] ["B" "p2" "21"]])
> >
> > In order to get the lazy sequence for every province, I have made a
> > function like: (defn getseq [prov party] (...))
> >
> > But I don't know how to get each province ("p1", "p2", "p3", ...).
> >
> > Doing: (take 1 provs)
> > I get: (["p1" "5"])
> >
> > Any idea of how could I get "p1"? So I can make a recursive call to my
> > getseq function with "p1", "p2", ...
> >
> > Thanks again.
> >
> > On Dec 21, 2:21 am, Ken Wesson  wrote:
> >
> >
> >
> >
> >
> >
> >
> > > On Mon, Dec 20, 2010 at 5:05 PM, Anclj  wrote:
> > > > Thanks a lot for the fast reply!
> > > > Now I have the vector as I wanted.
> >
> > > > I have been playing with your code: (map #(/ votes %) (iterate inc
> 1))
> >
> > > > user=> (take 10 (map #(/ 100 %) (iterate inc 1)))
> > > > (100 50 100/3 25 20 50/3 100/7 25/2 100/9 10)
> >
> > > > I have managed to put that in a lazy sequence:
> > > > user=> (def ls (lazy-seq (map #(/ 100 %) (iterate inc 1
> > > > #'user/ls
> >
> > > Eh. (map #(/ votes %) (iterate inc 1)) itself produces a lazy
> > > sequence, since map and iterate are lazy.
> >
> > > > I don't know how to filter and work with the vector & map in order to
> > > > apply that function for each party, in each province.
> > > > I have been trying to use the filter function but I get the following
> > > > error:
> >
> > > > user=> (filter #"A" [["A" "p1" "32"] ["B" "p1" "55"] ["A" "p2" "77"]
> > > > ["B" "p2" "21"]])
> > > > java.lang.ClassCastException: java.util.regex.Pattern cannot be cast
> > > > to clojure.lang.IFn
> >
> > > For this, you can just use #(= "A" %) as your predicate; there's no
> > > need to use regex matching.
> >
> > > If you need a regex, use #(re-matches #"pattern" %) as your predicate,
> > > instead of the regex itself.
> >
> > > > Thanks again and I will be posting any advances!
> >
> > > You're welcome.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

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

Re: Out of memory

2010-12-21 Thread Laurent PETIT
2010/12/21 Tim Robinson 

> You may want to consider the heap size you have allocated to java. I
> believe the default is 128.
>
> For example you can set this yourself:
>
> java -Xms256m -Xmx1024m
>

Indeed, but in this example, there is a problem. As Ken said, it seems that
the "locals clearing" does not apply to def.
Maybe there's a technical reason to this, but this problem is not related to
the heap size, IMHO.




>
> This provides 256mb initial heap and permits heap to grow to 1024mb.
>
> I've been using Leiningen, so in my case I just changed the settings
> in the source, before install.
>
> There's probably a list of pros/cons to upping the default heap size
> that you may want to consider.
>
> Tim
>
> On Dec 21, 7:09 am, Miles Trebilco  wrote:
> > Why does this cause an out of memory error:
> >
> > (def out_of_mem
> >   (reduce + 0 (range 5000)))
> >
> > while this does not:
> >
> > (def not_out_of_mem
> >  (let [result 0]
> >   (reduce + result (range 5000
> >
> > and neither does this in the REPL:
> >   (reduce + 0 (range 5000)))
> >
> >  - Miles
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

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

Re: Calling methods with a dollar sign in them

2010-12-21 Thread Stuart Sierra
Right now, probably not. But you can use the Java Reflection API to work 
around it.

-S

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

Re: Automatically unmapping unit tests from namespaces

2010-12-21 Thread Stuart Sierra
You can delete the entire test namespace with `remove-ns` and then do 
`(require ... :reload)`.

Or try Lazytest. :)

-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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Community attitude

2010-12-21 Thread ninjudd
Well, I'm glad to have you in the Clojure community, Jay. I come from
a Ruby background too, and I've enjoyed your blog over the years. Your
interest in Clojure has helped me get other Rails developers at work
excited about Clojure.

On the topic of community attitude, I agree with you. There are some
people in the community who are supernaturally helpful and welcoming
to newcomers, while there are others who seem to have the opposite
effect. As someone who can be at times oversensitive and at other
times abrasive, I understand both sides. In the end, I think it is up
to the community leaders to set the tone and to publicly call people
out who are being jerks. I certainly hope people would call me out if
I'm being one.


On Dec 21, 9:45 am, Kevin Downey  wrote:
> great, yet another email on the list so unrelated to clojure that not
> only does it contain no code, but no reference to code. if you need to
> whinge publicly please do it on your own blog. if you don't feel like
> the clojure community is giving you the love and support you need then
> I am sure rails will take you back.
>
> Sent from who cares
>
>
>
>
>
> On Tue, Dec 21, 2010 at 5:36 AM, Jay Fields  wrote:
> > I was involved with Ruby and Rails in the early days. The Ruby mailing 
> > lists / conferences were always kind / helpful and the Rails lists / confs 
> > were always hit and miss. There were plenty of great Rails people, and 
> > enough jerks to upset anyone.
>
> > I read this (Clojure) google group pretty frequently awhile ago, but took 
> > several months off. I returned a week ago and after the first day I emailed 
> > Stu H. And said: Is  one of the leaders of the community 
> > now? He seems really abrasive.
>
> > Having been through this before I'd recommend a few things.
>
> > - individually,
> > -- reword responses from: "why would you do that" to "I prefer my solution 
> > because...". "that's not functional and it's ugly!" to "I believe my 
> > solution is more in-line with FP style" etc. The trick is to focus on what 
> > you are looking for (and the positives of the idea) instead of attacking 
> > someone else's solution.
> > -- in niche communities, once you're labeled as a jerk, you're in trouble. 
> > People won't work with you. People won't answer your questions. And, people 
> > (often unfairly) assume you are wrong, simply because they don't like you. 
> > You can deal with this in a large (mostly anonymous) community. In a small 
> > community it's career limiting.
>
> > - community
> > -- it might be worth coming up with a few basic rules and removing people 
> > who can't follow them. Obviously, this isn't an easy task, but it might be 
> > worth the effort.
>
> > Also, what happened to Rich? It seems like many wasteful discussions could 
> > be more easily put to bed by his response instead of the current "here's a 
> > video of Rich from a year ago" or "here's a link to something Rich wrote in 
> > the past"
>
> > Or, maybe I'm oversensitive and things are fine.
>
> > Sent from my iPhone
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
>
> --
> And what is good, Phaedrus,
> And what is not good—
> Need we ask anyone to tell us these 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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


SCA FAQ link at clojure.org/contributing....

2010-12-21 Thread Mike Meyer
The link to the SCA FAQ on the page at clojure.org/contributing now
returns a document not found page. Given that the Clojure CA is based
on the Sun Contributor Agreement and what Oracle has since done with
NotQuiteSoOpenSolaris, this would seem to be an important document to
have available.

  http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

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


Re: SCA FAQ link at clojure.org/contributing....

2010-12-21 Thread Laurent PETIT
Indeed, this has been a problem for me too. I also tried to get it via the
backdoors, e.g. via the Open JDK, Netbeans, etc., websites, but they did
respect the "DRY" principle correctly, and all I found was just links to the
missing page  :-/

2010/12/21 Mike Meyer 

> The link to the SCA FAQ on the page at clojure.org/contributing now
> returns a document not found page. Given that the Clojure CA is based
> on the Sun Contributor Agreement and what Oracle has since done with
> NotQuiteSoOpenSolaris, this would seem to be an important document to
> have available.
>
>  --
> Mike Meyer 
> http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

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

Re: SCA FAQ link at clojure.org/contributing....

2010-12-21 Thread Ken Wesson
On Tue, Dec 21, 2010 at 3:43 PM, Laurent PETIT  wrote:
> Indeed, this has been a problem for me too. I also tried to get it via the
> backdoors, e.g. via the Open JDK, Netbeans, etc., websites, but they did
> respect the "DRY" principle correctly, and all I found was just links to the
> missing page  :-/

Tried web.archive.org?

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


Re: SCA FAQ link at clojure.org/contributing....

2010-12-21 Thread Laurent PETIT
2010/12/21 Ken Wesson 

> On Tue, Dec 21, 2010 at 3:43 PM, Laurent PETIT 
> wrote:
> > Indeed, this has been a problem for me too. I also tried to get it via
> the
> > backdoors, e.g. via the Open JDK, Netbeans, etc., websites, but they did
> > respect the "DRY" principle correctly, and all I found was just links to
> the
> > missing page  :-/
>
> Tried web.archive.org?
>

Now yes, and no, no more chances :-(

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

Re: Community attitude

2010-12-21 Thread kovas boguta
Simpler solution: Don't feed the trolls. We know who they are.

On Tue, Dec 21, 2010 at 5:36 AM, Jay Fields  wrote:
> I was involved with Ruby and Rails in the early days. The Ruby mailing lists 
> / conferences were always kind / helpful and the Rails lists / confs were 
> always hit and miss. There were plenty of great Rails people, and enough 
> jerks to upset anyone.
>
> I read this (Clojure) google group pretty frequently awhile ago, but took 
> several months off. I returned a week ago and after the first day I emailed 
> Stu H. And said: Is  one of the leaders of the community now? 
> He seems really abrasive.
>
> Having been through this before I'd recommend a few things.
>
> - individually,
> -- reword responses from: "why would you do that" to "I prefer my solution 
> because...". "that's not functional and it's ugly!" to "I believe my solution 
> is more in-line with FP style" etc. The trick is to focus on what you are 
> looking for (and the positives of the idea) instead of attacking someone 
> else's solution.
> -- in niche communities, once you're labeled as a jerk, you're in trouble. 
> People won't work with you. People won't answer your questions. And, people 
> (often unfairly) assume you are wrong, simply because they don't like you. 
> You can deal with this in a large (mostly anonymous) community. In a small 
> community it's career limiting.
>
> - community
> -- it might be worth coming up with a few basic rules and removing people who 
> can't follow them. Obviously, this isn't an easy task, but it might be worth 
> the effort.
>
> Also, what happened to Rich? It seems like many wasteful discussions could be 
> more easily put to bed by his response instead of the current "here's a video 
> of Rich from a year ago" or "here's a link to something Rich wrote in the 
> past"
>
> Or, maybe I'm oversensitive and things are fine.
>
> Sent from my iPhone
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

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


Re: Native Clojure

2010-12-21 Thread Andrew Boekhoff
> > Lazy-seq's are often handy in Clojure to subvert the stack limit imposed
> > by the the JVM, but it's not quite the same problem that TCO solves.
> 
> Having recently converted some Scheme that leaned heavily on the presence
> of TCO, I'm curious as to what situations you think could not be solved
> with lazy-seqs?
> 
> David

As I understand it, indirect tail calls are the case where TCO is
most difficult to emulate in languages without goto.
Of course, we have trampolines, and
(as demonstrated in Nicolas's example) there's a correspondence
between lazy-seqs and trampolines.
So, I don't mean to claim that there's anything you *can't* do with lazy-seq.
Although I do wonder how to translate cps-code to use lazy-seqs
(as opposed to trampolines).

(apologies in advance for this silly example)

(defn [f k x]
  (if (time-to-return? x)
(k x)
(g (fn [x*] (k (do-stuff-to x*))) 
   x)))

(defn [g k x]
  (if (time-to-return? x)
(k x)
(f (fn [x*] (k (do-other-stuff-to x*)))
   x)))

so with TCO,
assuming k doesn't exhaust memory,
f and g will operate in constant space,
and the eventual call to k will also unwind in constant space. 

cheers,
Andy



 

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


Re: SCA FAQ link at clojure.org/contributing....

2010-12-21 Thread Alex Miller
Darn.  I actually noticed this and redirected to a better link at the
beginning of November but it seems to have gone broken again.

The best alternative I can seem to find right now is this:
http://oss.oracle.com/oca-faq.pdf

I've updated the page with this for now.

Alex


On Dec 21, 2:39 pm, Mike Meyer  wrote:
> The link to the SCA FAQ on the page at clojure.org/contributing now
> returns a document not found page. Given that the Clojure CA is based
> on the Sun Contributor Agreement and what Oracle has since done with
> NotQuiteSoOpenSolaris, this would seem to be an important document to
> have available.
>
>       --
> Mike Meyer           http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail -www.asciiribbon.org

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


Re: SCA FAQ link at clojure.org/contributing....

2010-12-21 Thread Meikel Brandmeyer
Hi,

Am 21.12.2010 um 22:00 schrieb Laurent PETIT:

> Now yes, and no, no more chances :-(

Seems the link is fixed? http://oss.oracle.com/oca-faq.pdf

Sincerely
Meikel

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


Re: Community attitude

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 8:36 AM, Jay Fields  wrote:

> I was involved with Ruby and Rails in the early days. The Ruby mailing
> lists / conferences were always kind / helpful and the Rails lists / confs
> were always hit and miss. There were plenty of great Rails people, and
> enough jerks to upset anyone.


* Community is important, vital even. Not everything is about code.
* Ignore posts/people you personally find inflammatory. The moment a thread
devolves into strange personal esoteria unrelated to Clojure, it's clearly
time to leave it alone.
* Don't take things personally. People are entitled to their own opinions
about Clojure style. Mailing lists are low bandwidth mediums. Much emotive
context is lost.
* At near 4500 members, I think Rich is not in a position to actively police
the list
* Clojure/core is actively watching the list

I still thoroughly enjoy reading through much of what goes on here. The best
and only sustainable form of policing is self-policing.

David

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

Re: Community attitude

2010-12-21 Thread lance bradley
Some good guidelines to foster communities:
http://freenode.net/channel_guidelines.shtml

On Dec 21, 1:15 pm, David Nolen  wrote:
> On Tue, Dec 21, 2010 at 8:36 AM, Jay Fields  wrote:
> > I was involved with Ruby and Rails in the early days. The Ruby mailing
> > lists / conferences were always kind / helpful and the Rails lists / confs
> > were always hit and miss. There were plenty of great Rails people, and
> > enough jerks to upset anyone.
>
> * Community is important, vital even. Not everything is about code.
> * Ignore posts/people you personally find inflammatory. The moment a thread
> devolves into strange personal esoteria unrelated to Clojure, it's clearly
> time to leave it alone.
> * Don't take things personally. People are entitled to their own opinions
> about Clojure style. Mailing lists are low bandwidth mediums. Much emotive
> context is lost.
> * At near 4500 members, I think Rich is not in a position to actively police
> the list
> * Clojure/core is actively watching the list
>
> I still thoroughly enjoy reading through much of what goes on here. The best
> and only sustainable form of policing is self-policing.
>
> David

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


Re: Community attitude

2010-12-21 Thread lprefontaine
Great Kevin,

you just poured more oil on the fire...

Code is not the only thing about Clojure. Getting newbies on board is 
needed and if they need pointers fine with me. There has to be a place to
jump start people. This mailing is a starting point and has to be somewhat
friendly.

I myself can be very rough, my tolerance with wet ware can be very slim at 
times. But I try to restrain myself from opening fire when it's not necessary.
I'll go have a drink or smash something away from public eyes if the pressure
becomes intolerable, at least most of the time.

Arguing is generally useless even when the issue has some real effects on your
life. The effects might be easier to deal with than the argumentation itself.

Try the above recipes next time or take a deep breath as you wish.
Your post was useless at best and tarnished the community at worse.

Luc P.

Kevin Downey  wrote ..
> great, yet another email on the list so unrelated to clojure that not
> only does it contain no code, but no reference to code. if you need to
> whinge publicly please do it on your own blog. if you don't feel like
> the clojure community is giving you the love and support you need then
> I am sure rails will take you back.
> 
> Sent from who cares
> 
> On Tue, Dec 21, 2010 at 5:36 AM, Jay Fields  wrote:
> > I was involved with Ruby and Rails in the early days. The Ruby mailing lists
> / conferences were always kind / helpful and the Rails lists / confs were 
> always
> hit and miss. There were plenty of great Rails people, and enough jerks to 
> upset
> anyone.
> >
> > I read this (Clojure) google group pretty frequently awhile ago, but took
several
> months off. I returned a week ago and after the first day I emailed Stu H. And
> said: Is  one of the leaders of the community now? He seems 
> really
> abrasive.
> >
> > Having been through this before I'd recommend a few things.
> >
> > - individually,
> > -- reword responses from: "why would you do that" to "I prefer my solution
because...".
> "that's not functional and it's ugly!" to "I believe my solution is more 
> in-line
> with FP style" etc. The trick is to focus on what you are looking for (and the
> positives of the idea) instead of attacking someone else's solution.
> > -- in niche communities, once you're labeled as a jerk, you're in trouble.
People
> won't work with you. People won't answer your questions. And, people (often
unfairly)
> assume you are wrong, simply because they don't like you. You can deal with 
> this
> in a large (mostly anonymous) community. In a small community it's career
limiting.
> >
> > - community
> > -- it might be worth coming up with a few basic rules and removing people 
> > who
> can't follow them. Obviously, this isn't an easy task, but it might be worth 
> the
> effort.
> >
> > Also, what happened to Rich? It seems like many wasteful discussions could 
> > be
> more easily put to bed by his response instead of the current "here's a video 
> of
> Rich from a year ago" or "here's a link to something Rich wrote in the past"
> >
> > Or, maybe I'm oversensitive and things are fine.
> >
> > Sent from my iPhone
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with your
> first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
> 
> 
> 
> -- 
> And what is good, Phaedrus,
> And what is not good—
> Need we ask anyone to tell us these 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
> Note that posts from new members are moderated - please be patient with your 
> first
> post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
Luc P.


The rabid Muppet

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


Re: Native Clojure

2010-12-21 Thread David Nolen
On Tue, Dec 21, 2010 at 4:01 PM, Andrew Boekhoff wrote:

>
> (defn [f k x]
>  (if (time-to-return? x)
>(k x)
>(g (fn [x*] (k (do-stuff-to x*)))
>   x)))
>
> (defn [g k x]
>  (if (time-to-return? x)
>(k x)
>(f (fn [x*] (k (do-other-stuff-to x*)))
>   x)))


No, great example! Good point, I don't see any obvious way to handle that
with just lazy-seqs. But lazy-seqs + trampoline seems like it would fit the
bill just fine?

David

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

Re: ANN: Clojure web application using NHPM for server push

2010-12-21 Thread Anders Rune Jensen
On Mon, Dec 20, 2010 at 6:06 PM, rob levy  wrote:
> I have posted a repository containing the code for a web application I made
> using a server push (AKA Comet, long polling) architecture.  The front end
> is in Javascript, and the back end is in Clojure.  The clojure code is able
> to send notifications to clients' browsers effectively through use of
> nginx's push module, which the clients subscribe to.  With websockets
> presently out of reach this can be a good way of doing this sort of thing,
> and at least on my small-scale testing it is a super responsive way of
> simulating a socket.

Hi Rob

Interesting project. I havn't looked at the machine learning part of
it, although that also sounds interesting, but at first I was more
interested in the long polling aspect of your application. I was
looking at something similar but in the end I decided that given my
use case (mostly a single client polling) it didn't make much sense to
use nginx. I'm guessing that in your architecture, nginx makes more
sense because you have a lot of clients polling the same interface?
That way you know that it is much more likely that there will be at
least one subscriber left for a message when the server actually has
something to send. And I guess the way the back-end knows that there
is still someone that wants to know about a message is that nginx says
that there is still clients waiting when it delivers the message.
Could you maybe elaborate a bit more on this?

> https://github.com/rplevy/sayoperation
>
> The application itself is online (for now) at:
>
> http://www.robertplevy.net/sayoperation/
>
> A little bit of context is necessary here.  This is a game I made as part of
> my final project for a course I am in (I am taking courses part time as part
> of an MA program I will eventually complete) on the topic of Machine
> Learning and Natural Language Processing.  The purpose of the game is to
> collect game move data.  I'm in the process of figuring out how to train a
> classifier to learn to make the same sorts of game moves (though the text
> generation piece is out of scope), to have 1/2 of an AI game player.
>
> If you want to play the game and help me collect training data, here are
> some things to know:
>
>    1.  You will be asked to give an instruction to your team mate, given the
> information on the screen.  The red is the target, and the green is what
> your teammate will move to the target.  Notice that the target is always an
> empty space.   For example "put the crab above the butterfly" would make
> sense if the crab had a green border, and there were a red bordered target
> above the butterfly.
>
>    2.  Use clear and natural language when entering data., try to explain in
> the way you would explain to a person.  Punctuation and capitalization is
> stripped out/lowercased.
>
>    3.  The rounds work like this.  Player 1 instruct -> Player 2 move -->
> Player 2 instruct --> Player 1 move.  The game automatically presents your
> next available move just like in RIAs such as gchat or facebook (no need to
> refresh).
>
>    4.  Multiple concurrent games are encouraged.  The game should be
> responsive and will immediately tell you if you have a move to play in any
> of your games.
>
>    5. Caveat:  The application has been tested thoroughly in Firefox and
> Chrome.  While there is no inherent reason why it shouldn't be possible to
> make it work in Opera or Internet Explorer, I have not tested it in IE (so
> it probably doesn't work in that browser), and I am aware that it doesn't
> work in Opera.  This is just a matter of time and effort, that I need to
> spend on the NLP side of this project at the moment.
>
>    6. The high scoring team as of 2am tonight will win something (I haven't
> decide what, give me ideas please).
>
> Thanks,
> Rob
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
Anders Rune Jensen

http://www.iola.dk

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


Re: Automatically unmapping unit tests from namespaces

2010-12-21 Thread Phil Hagelberg
On Dec 21, 10:35 am, Alyssa Kwan  wrote:
> What about when I need to delete a unit test?  Reloading the test
> buffer doesn't remove it, and I need to either restart swank or
> reconnect slime, or manually remove those tests using (unmap-ns).
> Surely there's a better way...

If you're already using swank then you can try clojure-test-mode; it
clears out all deftests in between test runs.

https://github.com/technomancy/clojure-mode/blob/master/clojure-test-mode.el

It also highlights failures in the test buffer for better feedback.

-Phil

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


Software Transactional Memory video

2010-12-21 Thread Tim Daly

 This is another view of the Clojure STM idea, from the Haskell camp:

http://channel9.msdn.com/Shows/Going+Deep/Programming-in-the-Age-of-Concurrency-Software-Transactional-Memory

Recently, we visited MSR Cambridge(UK) to meet some of the great minds 
working there. In this case, we were fortunate enough to get an hour's 
time with Simon Peyton-Jones 
 and Tim Harris 
, who are researchers working 
on a very hard problem: making it easier (more predictable, more 
reliable, more composable) to write concurrent applications in this the 
age of Concurrency (multi-core is a reality, not a dream).


Specifically, Simon and Tim (and team) are working on a programming 
technology called Software Transactional Memory (STM) which provides an 
elegant, easy to use language-level abstraction for writing concurrent 
applications that is based on widely-understood conceptual constructs 
like Atomic operations (and, well, Transactions...). Simon, Tim and team 
do all the nasty locking work for you. With STM-enabled languages, you 
can just concentrate on the algorithms at hand and leave the 
low-level heavy lifting to the sub-system.


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


Re: Community attitude

2010-12-21 Thread Tim Robinson
I think it's a pretty complex problem to solve. Although one could re-
word a statement to be polite, it's still just window dressing what
are still potentially just thoughtless arrogant statements that still
insult people within the community.
In other words, I'd rather someone say "Why would you do that? From
what I can see it's a sucky idea for reason 1. detailed,  2. detailed
and 3 detailed" as opposed to someone say "I prefer my solution -
Thank you and have a nice day".
I think you're expecting too much thinking that *everyone* is going to
do:  "I prefer my solution for reason 1. detailed,  2. detailed".
It's just not how everyone thinks.

In my humble opinion, I don't think what you're experiencing will get
any better, but here are a few thoughts:

1. You can still enjoy the community by changing your expectations and
adopting 1 single rule (which I constantly try to remind myself with
all the time):

See people in a positive light, abrasive comment or otherwise. You're
more likely to treat people with respect when you see them as
genuinely good people than if you let adhoc comments dictate your
feelings for that person.

2. With intentional over the top flare, adding to a fire. Why on
Gods earth are we using Google groups as a community forum? It's
kinda, really, truly, sucky.
Lol :)

I mean really - voting based forums like hackernews/reddit have been
around for years.
The single most useful tool that moderators/community leaders have at
their disposal is to place value based incentives which will get large
masses following a set of expectations.

Note: I know Google groups has voting, but frankly the implementation
bites (Lol) it does not elevate the good and drown the bad which
would allow us to read the valuable and ignore the crap.
I don't even register votes happen in google groups.

Cheers.












On Dec 21, 6:36 am, Jay Fields  wrote:
> I was involved with Ruby and Rails in the early days. The Ruby mailing lists 
> / conferences were always kind / helpful and the Rails lists / confs were 
> always hit and miss. There were plenty of great Rails people, and enough 
> jerks to upset anyone.
>
> I read this (Clojure) google group pretty frequently awhile ago, but took 
> several months off. I returned a week ago and after the first day I emailed 
> Stu H. And said: Is  one of the leaders of the community now? 
> He seems really abrasive.
>
> Having been through this before I'd recommend a few things.
>
> - individually,
> -- reword responses from: "why would you do that" to "I prefer my solution 
> because...". "that's not functional and it's ugly!" to "I believe my solution 
> is more in-line with FP style" etc. The trick is to focus on what you are 
> looking for (and the positives of the idea) instead of attacking someone 
> else's solution.
> -- in niche communities, once you're labeled as a jerk, you're in trouble. 
> People won't work with you. People won't answer your questions. And, people 
> (often unfairly) assume you are wrong, simply because they don't like you. 
> You can deal with this in a large (mostly anonymous) community. In a small 
> community it's career limiting.
>
> - community
> -- it might be worth coming up with a few basic rules and removing people who 
> can't follow them. Obviously, this isn't an easy task, but it might be worth 
> the effort.
>
> Also, what happened to Rich? It seems like many wasteful discussions could be 
> more easily put to bed by his response instead of the current "here's a video 
> of Rich from a year ago" or "here's a link to something Rich wrote in the 
> past"
>
> Or, maybe I'm oversensitive and things are fine.
>
> Sent from my iPhone

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


Re: Community attitude

2010-12-21 Thread Ken Wesson
On Tue, Dec 21, 2010 at 7:47 PM, Tim Robinson  wrote:
> In my humble opinion, I don't think what you're experiencing will get
> any better, but here are a few thoughts:
>
> 1. You can still enjoy the community by changing your expectations and
> adopting 1 single rule (which I constantly try to remind myself with
> all the time):
>
> See people in a positive light, abrasive comment or otherwise. You're
> more likely to treat people with respect when you see them as
> genuinely good people than if you let adhoc comments dictate your
> feelings for that person.

You might be interested to google "fundamental attribution error".

> 2. With intentional over the top flare, adding to a fire. Why on
> Gods earth are we using Google groups as a community forum? It's
> kinda, really, truly, sucky.
> Lol :)
>
> I mean really - voting based forums like hackernews/reddit have been
> around for years.
> The single most useful tool that moderators/community leaders have at
> their disposal is to place value based incentives which will get large
> masses following a set of expectations.
>
> Note: I know Google groups has voting, but frankly the implementation
> bites (Lol) it does not elevate the good and drown the bad which
> would allow us to read the valuable and ignore the crap.
> I don't even register votes happen in google groups.

Not only that, but the votes are only visible in the sucky Google
Groups interface. I expect most of us go there only to subscribe and
then subsequently set various account options; we do our reading and
replying in our email clients. Even gmail's web interface provides a
superior user experience to Google Groups (including having a handy
draft autosave feature), though it also doesn't show Groups ratings
for Groups emails.

But yes, there are problems with the Groups votes besides that. It's
exposed only as a one-to-five-star rating plus the sample size, rather
than being a digg or reddit style positive or negative number; there's
no filtering option based on it; and it's apparently fairly easy to
game. I've seen Groups showing Usenet posts with larger numbers of
votes (good or bad) than there are active participants in the
newsgroup, for instance. Likely you can vote, disconnect and reconnect
to the net with a different IP, and then vote again, up to 256 times
if you have a typical ISP. (You'd actually hit diminishing returns
around halfway there when more often than not you'd log in with an IP
that had already voted and have to try again. But I can see someone
with patience and a will to pervert the vote manage to get forty, or
fifty, or even sixty votes out of it before deciding it would suffice.
:))

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


My first Clojure program: request for code review

2010-12-21 Thread Marek Kubica
Hi,

I wrote a small log file analyzer for IRC logs. We use nickname++ and
nickname-- to track the "karma", so after trying to write it in
JavaScript (failed due to to the fact that Gjs/Seed are unmature yet),
Factor (failed because I am just too stupid to understand it), Guile
(failed because I ran into encoding/regex-problems), so I gave Clojure
a try.

I really liked the immutable data stuctures, so I tried to avoid
mutation.

So uhm, this is my first Clojure program. I tend to learn a lot from
code reviews and would be happy if someone could take a look at it and
tell me what to improve and how to write more idiomatic code.

Code is here, and reproduced below:


Thanks in advance!

regards,
Marek

(ns net.xivilization.karmawhore
  (:gen-class)
  (:use [clojure.contrib.duck-streams :only (read-lines)]))

(def allowed-nickname "[A-z]{1,16}")
(def nick-plus (re-pattern (format "(%s)\\+\\+" allowed-nickname)))
(def nick-minus (re-pattern (format "(%s)\\-\\-" allowed-nickname)))

(defn extract-nicks [regexp line]
  (map second (re-seq regexp line)))

(defn modify-karma [op h nick]
  (let [current-value (h nick)]
(if (nil? current-value) (assoc h nick (op 1))
  (assoc h nick (op current-value 1)

(def increase-karma (partial modify-karma +))
(def decrease-karma (partial modify-karma -))

(defn process-line [acc line]
  (let [nicks-add (extract-nicks nick-plus line)
nicks-sub (extract-nicks nick-minus line)
after-add (reduce increase-karma acc nicks-add)]
(reduce decrease-karma after-add nicks-sub)))

(defn -main [& args]
  (let [file-name (first (first args))
histogram (reduce process-line (hash-map) (read-lines
file-name)) nonzero? (comp not zero? second)
histogram (filter nonzero? histogram)
sorted-by-karma (sort-by #(- (second %)) histogram)]
(doseq [item sorted-by-karma]
  (printf "%s %d\n" (first item) (second item)

(-main *command-line-args*)

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


Re: Community attitude

2010-12-21 Thread Tim Robinson
> You might be interested to google "fundamental attribution error".

After a briefly read on Wikipedia, I'm glad you pointed that out. I'll
read more.
Any other comment I could make on  that seems to open too many doors
to discussions
not related to Clojure, but thank you for sharing.

As for the voting, I try not to get to close to specific details/
failures of hn/reddit style forums.
All I need to know is that when I look at the top voted posts/comments
vs. the bottom votes (on HN) I generally find they
do a much better job separating the good from the bad than not doing
it at all.

On Dec 21, 6:39 pm, Ken Wesson  wrote:
> On Tue, Dec 21, 2010 at 7:47 PM, Tim Robinson  wrote:
> > In my humble opinion, I don't think what you're experiencing will get
> > any better, but here are a few thoughts:
>
> > 1. You can still enjoy the community by changing your expectations and
> > adopting 1 single rule (which I constantly try to remind myself with
> > all the time):
>
> > See people in a positive light, abrasive comment or otherwise. You're
> > more likely to treat people with respect when you see them as
> > genuinely good people than if you let adhoc comments dictate your
> > feelings for that person.
>
> You might be interested to google "fundamental attribution error".
>
> > 2. With intentional over the top flare, adding to a fire. Why on
> > Gods earth are we using Google groups as a community forum? It's
> > kinda, really, truly, sucky.
> > Lol :)
>
> > I mean really - voting based forums like hackernews/reddit have been
> > around for years.
> > The single most useful tool that moderators/community leaders have at
> > their disposal is to place value based incentives which will get large
> > masses following a set of expectations.
>
> > Note: I know Google groups has voting, but frankly the implementation
> > bites (Lol) it does not elevate the good and drown the bad which
> > would allow us to read the valuable and ignore the crap.
> > I don't even register votes happen in google groups.
>
> Not only that, but the votes are only visible in the sucky Google
> Groups interface. I expect most of us go there only to subscribe and
> then subsequently set various account options; we do our reading and
> replying in our email clients. Even gmail's web interface provides a
> superior user experience to Google Groups (including having a handy
> draft autosave feature), though it also doesn't show Groups ratings
> for Groups emails.
>
> But yes, there are problems with the Groups votes besides that. It's
> exposed only as a one-to-five-star rating plus the sample size, rather
> than being a digg or reddit style positive or negative number; there's
> no filtering option based on it; and it's apparently fairly easy to
> game. I've seen Groups showing Usenet posts with larger numbers of
> votes (good or bad) than there are active participants in the
> newsgroup, for instance. Likely you can vote, disconnect and reconnect
> to the net with a different IP, and then vote again, up to 256 times
> if you have a typical ISP. (You'd actually hit diminishing returns
> around halfway there when more often than not you'd log in with an IP
> that had already voted and have to try again. But I can see someone
> with patience and a will to pervert the vote manage to get forty, or
> fifty, or even sixty votes out of it before deciding it would suffice.
> :))

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


Re: Automatically unmapping unit tests from namespaces

2010-12-21 Thread Alyssa Kwan
Awesome!!!  This absolutely does the trick!

On Dec 21, 7:16 pm, Phil Hagelberg  wrote:
> On Dec 21, 10:35 am, Alyssa Kwan  wrote:
>
> > What about when I need to delete a unit test?  Reloading the test
> > buffer doesn't remove it, and I need to either restart swank or
> > reconnect slime, or manually remove those tests using (unmap-ns).
> > Surely there's a better way...
>
> If you're already using swank then you can try clojure-test-mode; it
> clears out all deftests in between test runs.
>
> https://github.com/technomancy/clojure-mode/blob/master/clojure-test-...
>
> It also highlights failures in the test buffer for better feedback.
>
> -Phil

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


Re: Error Handling for Callback API to Blocking API example in Joy of Clojure

2010-12-21 Thread Chouser
On Sun, Dec 19, 2010 at 3:36 AM, HiHeelHottie  wrote:
>
> In Joy of Clojure, there is a callback API to blocking API example in
> the section on promises.  Chouser outlines it a briefly in a
> discussion on Promise/Deliver use cases here -
> http://groups.google.com/group/clojure/browse_thread/thread/b1548aa40ba8072/210ec81bfe26032e?lnk=gst&q=promise#210ec81bfe26032e:
>
> I've used them to convert a callback-based (continuation-passing
> style, if you will) API into a blocking one.  The lib I was using
> provides something you can call like:
>        (rpc-call destination method-args done)
> Where 'done' is a function that gets called with the results of
> the remote procedure call.  But I want to write a function that
> does rpc but *returns* the result, so...
>        (let [p (promise)]
>          (rpc-call destination method-args #(deliver p %))
>         �...@p)
> This will work just fine whether rpc-call calls 'done'
> synchronously, or if it returns right away and 'done' is called
> by some other thread later.
> --Chouser
>
> This is very neat.  Is this robust as is or would you need to add code
> to handle error cases such as an unavailable rpc server, rpc server
> never returning, an error trying to make the rpc call, etc.

It depends entirely on how rpc-call handles error cases.  If it
promises to always call its call back with something, even on
error cases (perhaps passing in an Error object or something),
then this would sufficient as-is.

However, anything that would cause the call back to be skipped
will of course cause the deliver to also be skipped, and the
deref on the promise will block forever.  The easiest way for
this to happen accidentally is if an exception is thrown, so
catching those and turning them into calls to the callback with
an error object is certainly a good idea.

--Chouser
http://joyofclojure.com/

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


Re: My first Clojure program: request for code review

2010-12-21 Thread Benny Tsai
Hi Marek,

Here's my tweaked version:

(ns karma
  (:use [clojure.contrib.duck-streams :only (read-lines)])
  (:use [clojure.contrib.generic.functor :only (fmap)]))

(def allowed-nickname "[A-z]{1,16}")
(def upvote-regexp (re-pattern (format "(%s)\\+\\+" allowed-
nickname)))
(def downvote-regexp (re-pattern (format "(%s)\\-\\-" allowed-
nickname)))

(defn get-votes [regexp line]
  (let [nicks (map second (re-seq regexp line))]
(frequencies nicks)))

(defn get-histogram [line]
  (let [upvotes (get-votes upvote-regexp line)
downvotes (fmap - (get-votes downvote-regexp line))]
(merge-with + upvotes downvotes)))

(defn -main [& args]
  (let [file-name (ffirst args)
histograms (map get-histogram (read-lines file-name))
histogram (apply merge-with + histograms)
non-zero-histogram (remove (comp zero? second) histogram)
sorted-by-karma (reverse (sort-by second non-zero-histogram))]
(doseq [[nick karma] sorted-by-karma]
  (println nick karma

(-main *command-line-args*)

The only non-trivial change is in the way the histogram is created.
Instead of "updating" an accumulator map while processing each line, I
create a mini-histogram for each line and then merge them together at
the end.

'get-votes' is a lot like 'extract-nicks', but leverages the built-in
'frequencies' fn to build a histogram of the upvotes/downvotes in a
line, depending on the regexp passed in:

karma=> (get-votes upvote-regexp "c++ d++ b++ c--")
{"c" 1, "d" 1, "b" 1}
karma=> (get-votes downvote-regexp "c++ d++ b++ c--")
{"c" 1}

Given a line, 'get-histogram' uses 'get-votes' to get a histogram of
the upvotes and a histogram of the downvotes.  It then uses 'fmap' to
convert the downvotes into negative numbers:

karma=> (fmap - {"c" 1})
{"c" -1}

'get-histogram' then uses 'merge-with' to combine the two histograms
into a histogram for the line:

karma=> (merge-with + {"c" 1, "d" 1, "b" 1} {"c" -1})
{"c" 0, "d" 1, "b" 1}

In '-main', 'merge-with' is used again to combine all the histograms
into a single histogram.  After that, the code is essentially
identical to the original, except for a few small tweaks:

- (first (first ...)) can be shortened into (ffirst ...)
- In cases like removing nicks with 0 karma, instead of (filter (not
pred) ...), I prefer (remove pred ...); I find it a little easier to
follow that way.
- To sort the nicks by karma in descending order, instead of sorting
by the negation of the karma, I used (reverse (sort-by ...)); again,
just a subjective thing, makes the intent more clear to me.
- In the final 'doseq', (first item) and (second item) can be replaced
by destructuring.

Hope you find this useful :)

On Dec 21, 6:38 pm, Marek Kubica  wrote:
> Hi,
>
> I wrote a small log file analyzer for IRC logs. We use nickname++ and
> nickname-- to track the "karma", so after trying to write it in
> JavaScript (failed due to to the fact that Gjs/Seed are unmature yet),
> Factor (failed because I am just too stupid to understand it), Guile
> (failed because I ran into encoding/regex-problems), so I gave Clojure
> a try.
>
> I really liked the immutable data stuctures, so I tried to avoid
> mutation.
>
> So uhm, this is my first Clojure program. I tend to learn a lot from
> code reviews and would be happy if someone could take a look at it and
> tell me what to improve and how to write more idiomatic code.
>
> Code is here, and reproduced below:
> 
>
> Thanks in advance!
>
> regards,
> Marek
>
> (ns net.xivilization.karmawhore
>   (:gen-class)
>   (:use [clojure.contrib.duck-streams :only (read-lines)]))
>
> (def allowed-nickname "[A-z]{1,16}")
> (def nick-plus (re-pattern (format "(%s)\\+\\+" allowed-nickname)))
> (def nick-minus (re-pattern (format "(%s)\\-\\-" allowed-nickname)))
>
> (defn extract-nicks [regexp line]
>   (map second (re-seq regexp line)))
>
> (defn modify-karma [op h nick]
>   (let [current-value (h nick)]
>     (if (nil? current-value) (assoc h nick (op 1))
>       (assoc h nick (op current-value 1)
>
> (def increase-karma (partial modify-karma +))
> (def decrease-karma (partial modify-karma -))
>
> (defn process-line [acc line]
>   (let [nicks-add (extract-nicks nick-plus line)
>         nicks-sub (extract-nicks nick-minus line)
>         after-add (reduce increase-karma acc nicks-add)]
>     (reduce decrease-karma after-add nicks-sub)))
>
> (defn -main [& args]
>   (let [file-name (first (first args))
>         histogram (reduce process-line (hash-map) (read-lines
> file-name)) nonzero? (comp not zero? second)
>         histogram (filter nonzero? histogram)
>         sorted-by-karma (sort-by #(- (second %)) histogram)]
>     (doseq [item sorted-by-karma]
>       (printf "%s %d\n" (first item) (second item)
>
> (-main *command-line-args*)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@

Re: My first Clojure program: request for code review

2010-12-21 Thread Justin Kramer
Here's my version. Main points:

* Use with-open & line-seq for worry-free laziness
* Do everything in one swoop (reduce)
* Perform one regexp match per line
* Leverage ->>

;;

(ns user
  (use [clojure.java.io :only [reader]]))

(def re-vote #"([A-z]{1,16})(\+\+|\-\-)")

(defn extract-votes
  [line]
  (map rest (re-seq re-vote line)))

(defn reckon
  [log]
  (with-open [r (reader log)]
(let [votes (mapcat extract-votes (line-seq r))]
  (reduce
   (fn [tally [nick vote]]
 (let [inc-or-dec (if (= vote "++") inc dec)]
   (assoc tally nick (inc-or-dec (tally nick 0)
   {}
   votes

(defn -main [& [[log]]]
  (let [tally (->> log
   reckon
   (remove (comp zero? val))
   (sort-by (comp - val)))]
(doseq [[nick score] tally]
  (println nick score


Hope that helps,
Justin

On Dec 21, 8:38 pm, Marek Kubica  wrote:
> Hi,
>
> I wrote a small log file analyzer for IRC logs. We use nickname++ and
> nickname-- to track the "karma", so after trying to write it in
> JavaScript (failed due to to the fact that Gjs/Seed are unmature yet),
> Factor (failed because I am just too stupid to understand it), Guile
> (failed because I ran into encoding/regex-problems), so I gave Clojure
> a try.
>
> I really liked the immutable data stuctures, so I tried to avoid
> mutation.
>
> So uhm, this is my first Clojure program. I tend to learn a lot from
> code reviews and would be happy if someone could take a look at it and
> tell me what to improve and how to write more idiomatic code.
>
> Code is here, and reproduced below:
> 
>
> Thanks in advance!
>
> regards,
> Marek
>
> (ns net.xivilization.karmawhore
>   (:gen-class)
>   (:use [clojure.contrib.duck-streams :only (read-lines)]))
>
> (def allowed-nickname "[A-z]{1,16}")
> (def nick-plus (re-pattern (format "(%s)\\+\\+" allowed-nickname)))
> (def nick-minus (re-pattern (format "(%s)\\-\\-" allowed-nickname)))
>
> (defn extract-nicks [regexp line]
>   (map second (re-seq regexp line)))
>
> (defn modify-karma [op h nick]
>   (let [current-value (h nick)]
>     (if (nil? current-value) (assoc h nick (op 1))
>       (assoc h nick (op current-value 1)
>
> (def increase-karma (partial modify-karma +))
> (def decrease-karma (partial modify-karma -))
>
> (defn process-line [acc line]
>   (let [nicks-add (extract-nicks nick-plus line)
>         nicks-sub (extract-nicks nick-minus line)
>         after-add (reduce increase-karma acc nicks-add)]
>     (reduce decrease-karma after-add nicks-sub)))
>
> (defn -main [& args]
>   (let [file-name (first (first args))
>         histogram (reduce process-line (hash-map) (read-lines
> file-name)) nonzero? (comp not zero? second)
>         histogram (filter nonzero? histogram)
>         sorted-by-karma (sort-by #(- (second %)) histogram)]
>     (doseq [item sorted-by-karma]
>       (printf "%s %d\n" (first item) (second item)
>
> (-main *command-line-args*)

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


Mocking multimethods

2010-12-21 Thread Alyssa Kwan
Hi everyone,

Does anyone have any experience in mocking multimethods?  I'm working
on a version control framework modeled after Git:

(def
 ^{:private true}
 patches- (ref [])

(defn patches []
  (seq @patches-))

(defn do-patch! [fn & args]
  (dosync
(apply fn args)
(let [patch {:fn fn
 :args (vec args)}]
  (alter patches- conj patch)
  patch)))

I need to be able to undo recorded patches, which means at undo-time,
translating the recorded do-patch! fn and args into an undo-fn which
can be called.  If an undo-fn cannot be found, it throws an
exception.  This has to be extensible so that as I add operations, I
can add the counterpart undo-fn.  Multimethods to the rescue!

(defmulti undo-fn :fn)

(defn undo-patch [patch]
  (let [fn (undo-fn patch)]
(dosync
  (fn)
  (alter patches- #(remove #(= patch %) %)

So in another package, I add the operation create-table! to the
system, which has a counterpart drop-table!:

(defn create-table!- [name columns]
  (... create table stuff ...))

(defn drop-table!- [name]
  (... drop table stuff ...))

(defn create-table! [name columns]
  (make-patch! create-table!- name columns))

(defmethod undo-fn create-table!- [patch]
  #(drop-table!- (:name patch)))

So calling undo-patch! with a patch that was the result of create-
table! will call undo-fn, which will dispatch on the :fn member of the
patch, which is create-table!-, which will end up returning an
anonymous function that calls drop-table!- with the :name from
the :args member of the patch.

OK, this all works.

But from a unit testing perspective, how do I cleanly test undo-patch!
without any undo-fn methods declared?  When testing, I just want to
know that undo-patch! attempts to resolve undo-fn, will throw an error
if it can't, and will call the anonymous function that undo-fn returns
if it can.  In other words, how do I mock undo-fn?

Thanks,
Alyssa

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


Re: Automatically unmapping unit tests from namespaces

2010-12-21 Thread Michael Ossareh
On Tue, Dec 21, 2010 at 16:16, Phil Hagelberg  wrote:
>
>
> It also highlights failures in the test buffer for better feedback.


when there is a failure where are the details of the failure printed out to?
I love that the highlight shows me which test have errors, but since I've
moved over to the emacs starter kit (thanks!!) I've lost the error output
and have to switch to a terminal to run lein test.

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

Re: Automatically unmapping unit tests from namespaces

2010-12-21 Thread Michael Ossareh
On Tue, Dec 21, 2010 at 21:36, Michael Ossareh  wrote:

> On Tue, Dec 21, 2010 at 16:16, Phil Hagelberg  wrote:
>>
>>
>> It also highlights failures in the test buffer for better feedback.
>
>
> when there is a failure where are the details of the failure printed out
> to? I love that the highlight shows me which test have errors, but since
> I've moved over to the emacs starter kit (thanks!!) I've lost the error
> output and have to switch to a terminal to run lein test.
>

The answer: the repl buffer.

I've no idea why they weren't - but they are now. I'll take it :)

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

Re: Mocking multimethods

2010-12-21 Thread Alex Baranosky
Hi Alyssa,

Using the midje library I was able to do your first test.  I'm pretty tired
so I this might be it for the night.

(fact "throws an error if can't resolve undo function"
  (undo-patch [2]) => (throws IllegalArgumentException "No method in
multimethod 'undo-fn' for dispatch value: null"))

Is this what you were thinking?

Alex

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

Re: Mocking multimethods

2010-12-21 Thread Alex Baranosky
So I lied, I couldn't resist doing just one more:

(defn some-fn [] nil)

(fact "calls the anonymous function that undo-fn returns"
  (undo-patch ...patch...) => @patches-
  (provided
(undo-fn ...patch...) => some-fn
(some-fn) => nil))

The two provided statements are mboth mocking and stubbing.  So if either of
those functions isn't called with the expected arguments they will fail.
 The line
(undo-patch ...patch...) => @patches- is saying when I call undo-patch with
any patch, it should return the value inside of patches-  This is probably
ok, since the different undo-fns are thoroughly unit tested.

There might be some better way to not have to create that some-fn that we
just use for testing.  Maybe put it in a let or something?

Best,
Alex

P.S. Midje can be found on Github and Clojars.
https://github.com/marick/Midje

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

Re: Mocking multimethods

2010-12-21 Thread Alyssa Kwan
Hi Alex,

Unfortunately the some-fn has to be created at the top level; it has
to be a var to be dynamically bindable, and Midje (and AFAIK, all
other mocking frameworks) use dynamic binding.

Here's what I came up with, using clojure.contrib.mock.test-adapter:

(deftest test-undo-patch!-calls-undo-fn
  (def mock-fn +)
  (def mock-undo-fn -)
  (expect [mock-fn (times once (has-args [1 2]))
   mock-undo-fn (times once (has-args []))]
(defmethod undo-fn mock-fn [patch]
  mock-undo-fn)
(let [patch (do-patch! mock-fn 1 2)]
  (undo-patch! patch))
(remove-method undo-fn mock-fn))
  (ns-unmap *ns* 'mock-fn)
  (ns-unmap *ns* 'mock-undo-fn))

Note that the multimethod cannot be mocked, so that we have to use
defmethod/remove-method.  Extending the mock frameworks to support
this shouldn't be difficult.

The var for dynamic binding issue is a bigger deal.  Does anyone know
if all statements in the deftest are guaranteed to be executed, in
case a statement in the middle throws an exception?  Otherwise, the
namespace may not be cleaned properly.

Thanks,
Alyssa

On Dec 22, 1:26 am, Alex Baranosky 
wrote:
> So I lied, I couldn't resist doing just one more:
>
> (defn some-fn [] nil)
>
> (fact "calls the anonymous function that undo-fn returns"
>   (undo-patch ...patch...) => @patches-
>   (provided
>     (undo-fn ...patch...) => some-fn
>     (some-fn) => nil))
>
> The two provided statements are mboth mocking and stubbing.  So if either of
> those functions isn't called with the expected arguments they will fail.
>  The line
> (undo-patch ...patch...) => @patches- is saying when I call undo-patch with
> any patch, it should return the value inside of patches-  This is probably
> ok, since the different undo-fns are thoroughly unit tested.
>
> There might be some better way to not have to create that some-fn that we
> just use for testing.  Maybe put it in a let or something?
>
> Best,
> Alex
>
> P.S. Midje can be found on Github and Clojars.https://github.com/marick/Midje

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