Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread Albert Cardona
YES please. If I could upvote this message I would. A half-a-dozen of examples on ns/in-ns and require/use/refer and the differences in using them at the prompt or inside a ns would be fantastic. The ns macro is one of the obscure corners of clojure. It relates to the java class path problem,

Understanding Clojure Closures

2009-11-11 Thread mbrodersen
A quick question about how closures work in Clojure. In this simple recursive expression: (def t (fn [x] (if (zero? x) 0 (+ x (t (dec x)) The fn special form is evaluated within a context where t is not yet bound. t is only bound AFTER fn has captured its environment. In other words, the

Minor inconsistency in 'some docstring

2009-11-11 Thread Daniel Werner
(doc some) says: ... this will return true if :fred is in the sequence, otherwise nil: (some #{:fred} coll) However, some returns the matching value instead: = (some #{:fred} [:foo :fred :ethel]) :fred Attached patch fixes the docstring. (Not that applying the patch would be any easier than

Re: Understanding Clojure Closures

2009-11-11 Thread Alex Osborne
mbrodersen wrote: In this simple recursive expression: (def t (fn [x] (if (zero? x) 0 (+ x (t (dec x)) The fn special form is evaluated within a context where t is not yet bound. t is only bound AFTER fn has captured its environment. In other words, the closure captured by fn

Re: How to print without spaces?

2009-11-11 Thread Alex Osborne
John Ky wrote: How to I print without spaces? (println (str a b 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

Re: How to print without spaces?

2009-11-11 Thread Lauri Oherd
Hi, (println (str a b c)) Regards, Lauri On Wed, Nov 11, 2009 at 9:15 AM, John Ky newho...@gmail.com wrote: Hi all, How to I print without spaces? For example:    (println a b c) Gives:    a b c Rather than    abc Thanks, -John -- You received this message because you are

Re: How to write a macro

2009-11-11 Thread Alex Osborne
John Ky wrote: Hi all, I'm looking for a way to write a defkw macro so that (defkw ABSENT) expands to (def ABSENT (kw ABSENT :ABSENT )). Just use `(...) as a template and use ~ to unescape, like so: (defmacro defkw [sym] `(def ~sym (kw ~(str sym) ~(keyword sym (defkw ANSEMT) =

How to write a macro

2009-11-11 Thread John Ky
Hi all, I'm looking for a way to write a defkw macro so that (defkw ABSENT) expands to (def ABSENT (kw ABSENT :ABSENT )). Thanks, -John -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com

How to print without spaces?

2009-11-11 Thread John Ky
Hi all, How to I print without spaces? For example: (println a b c) Gives: a b c Rather than abc Thanks, -John -- You 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

Re: Consistency of the API

2009-11-11 Thread Kresten Krab Thorup
On Nov 10, 2:28 am, John Harrop jharrop...@gmail.com wrote: (I suppose T and F are static fields holding java.lang.Booleans, and this code was written pre-autoboxing?) It's still much faster to use a pre-boxed Boolean than to create a new boxed value every time around. Kresten -- You

Re: Understanding Clojure Closures

2009-11-11 Thread Meikel Brandmeyer
Hi, On Nov 11, 2:34 pm, Alex Osborne a...@meshy.org wrote: (let [t (fn [x] (if (zero? x) 0 (+ x (t (dec x)] (t 2)) But also note, that you can give an anonymous function a name. %) (let [t (fn t [x] (if (zero? x) 0 (+ x (t (dec x)] (t 2)) Sincerely Meikel -- You received this

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread Miron Brezuleanu
Hello, On Wed, Nov 11, 2009 at 2:57 PM, Albert Cardona sapri...@gmail.com wrote: YES please. If I could upvote this message I would. A half-a-dozen of examples on ns/in-ns and require/use/refer and the differences in using them at the prompt or inside a ns would be fantastic. Some more ns

Re: Understanding Clojure Closures

2009-11-11 Thread Howard Lewis Ship
Symbols are late resolved to functions. (def t (fn ...)) means define a Var bound to symbol t, and store the function in it. In JVM terms, the function becomes a new class that is instantiated. (t (dec x)) means locate the Var bound to symbol t -- at execution time (not compilation time) ---

Re: Communication in a distributed system

2009-11-11 Thread tmountain
Check out this post for some suggestions on working with Clojure in a distributed fashion. http://groups.google.com/group/clojure/msg/4a7a866c45dc2101 -Travis On Nov 9, 2:09 pm, Michael Jaaka michael.ja...@googlemail.com wrote: Hi! Is there any support from Clojure for communication between

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread Stephen C. Gilardi
On Nov 10, 2009, at 9:08 PM, John Harrop wrote: (ns foo.bar.baz (:use [clojure.contrib.core :only (seqable?)])) (and thus violates the usual clojure rule of using vectors rather than lists for groupings that are not invocations -- that is, function calls, macro calls, or special form

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread John Harrop
On Wed, Nov 11, 2009 at 1:12 PM, Stephen C. Gilardi squee...@mac.comwrote: Before: (:refer-clojure :exclude [read]) (:require (clojure.contrib [graph :as graph] [fcase :as fcase]) [clojure.contrib.stream-utils :as su]) (:use [clojure.contrib def except server-socket]

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread Andrew Boekhoff
(:uses [clojure.core :exclude [read]) [clojure.contrib.graph] [clojure.contrib.fcase] [clojure.contrib.stream-utils :as su] [clojure.contrib.def :refer-all true] [clojure.contrib.except :refer-all true] [clojure.contrib.server-socket

Re: Language request: make key and val work on vector pairs too

2009-11-11 Thread ataggart
Just use first and second for both cases. On Nov 11, 9:52 am, samppi rbysam...@gmail.com wrote: Clojure 1.1.0-alpha-SNAPSHOT user= (conj (first {1 2}) 3) [1 2 3] user= (conj {1 2} [2 5]) {2 5, 1 2} user= (key (first {1 2})) 1 user= (key [1 2]) java.lang.ClassCastException:

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread Chouser
On Wed, Nov 11, 2009 at 1:12 PM, Stephen C. Gilardi squee...@mac.com wrote: Here are some of the ideas I've liked best for how to do it. Thanks for pulling this together. I like the whole direction you're going here. - require that each libspec (reference to a lib) be a vector, disallowing

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread Christophe Grand
Hi! On Wed, Nov 11, 2009 at 7:12 PM, Stephen C. Gilardi squee...@mac.com wrote: Here are some of the ideas I've liked best for how to do it. I like where this is heading. - don't refer any names from the target namespace into the current namespace by default YES!  - support :only [],

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread Laurent PETIT
2009/11/11 Andrew Boekhoff boekho...@gmail.com:  (:uses [clojure.core :exclude [read])         [clojure.contrib.graph]         [clojure.contrib.fcase]         [clojure.contrib.stream-utils :as su]         [clojure.contrib.def :refer-all true]         [clojure.contrib.except :refer-all

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread John Harrop
On Wed, Nov 11, 2009 at 3:54 PM, Laurent PETIT laurent.pe...@gmail.comwrote: 2009/11/11 Andrew Boekhoff boekho...@gmail.com: (:uses [clojure.core :exclude [read]) [clojure.contrib.graph] [clojure.contrib.fcase] [clojure.contrib.stream-utils :as su]

Re: Better documentation and error messages are needed for the ns macro

2009-11-11 Thread Jason Wolfe
I like almost all of this a lot. My only disagreement is on prefix lists ... I wouldn't want to lose them, and in fact would prefer to see them extended to recursive prefix lists (trees). -Jason On Nov 11, 10:12 am, Stephen C. Gilardi squee...@mac.com wrote: On Nov 10, 2009, at 9:08 PM, John

Re: Understanding Clojure Closures

2009-11-11 Thread mbrodersen
Thanks Howard. Another great answer. Morten On Nov 12, 2:58 am, Howard Lewis Ship hls...@gmail.com wrote: Symbols are late resolved to functions. (def t (fn ...)) means define a Var bound to symbol t, and store the function in it. In JVM terms, the function becomes a new class that is

Re: Understanding Clojure Closures

2009-11-11 Thread mbrodersen
Great answer Alex. Thanks! Morten On Nov 12, 12:34 am, Alex Osborne a...@meshy.org wrote: mbrodersen wrote: In this simple recursive expression: (def t (fn [x] (if (zero? x) 0 (+ x (t (dec x)) The fn special form is evaluated within a context where t is not yet bound. t is only

clojure vim shebang

2009-11-11 Thread John Ky
Hi all, Does anyone know why if the first character in my *.clj file is '#', then when I open it in VIM, ClojureVIM fails to recognise it as a Clojure file? Thanks -John -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send

Re: How to print without spaces?

2009-11-11 Thread John Ky
Thanks, On Thu, Nov 12, 2009 at 12:34 AM, Alex Osborne a...@meshy.org wrote: John Ky wrote: How to I print without spaces? (println (str a b c)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: How to write a macro

2009-11-11 Thread John Ky
Hi Alex, I had to ~(keyword (str sym)) instead of ~(keyword sym), but now it works well. Cheers, -John On Thu, Nov 12, 2009 at 12:40 AM, Alex Osborne a...@meshy.org wrote: John Ky wrote: Hi all, I'm looking for a way to write a defkw macro so that (defkw ABSENT) expands to (def

Re: How to write a macro

2009-11-11 Thread Alex Osborne
John Ky wrote: I had to ~(keyword (str sym)) instead of ~(keyword sym), but now it works well. Hmm, odd. Must have changed since Clojure 1.0. (keyword 'some-symbol) works for me on the new branch. -- You received this message because you are subscribed to the Google Groups Clojure group.

Re: clojure vim shebang

2009-11-11 Thread MarkSwanson
Does anyone know why if the first character in my *.clj file is '#', then when I open it in VIM, ClojureVIM fails to recognise it as a Clojure file? I don't know why, but I can provide this data point: It does not do that for me. Vim 7.2, vimclojure 2.1.2, java 6.0.14 -- You received this

Re: Mocking (with EasyMock?) java calls

2009-11-11 Thread Howard Lewis Ship
Try looking at this: http://github.com/hlship/cascade/blob/master/src/main/clojure/cascade/mock.clj On Thu, Nov 5, 2009 at 5:00 AM, vanallan vanal...@gmail.com wrote: Hi Im trying to convert a couple of Java methods in a Java project to Clojure. The Java methods have test methods that mocks

Re: newbie question

2009-11-11 Thread jan
Warren Wood warrenthomasw...@yahoo.com writes: Thought of this, which I like better. Again, I'm surprised if conjunction is not already a standard function, but I can't find it. I'm still a bit tempted to call it AND for readabilty of code. (I spent some time studying combinatory logic back

clojure event handling

2009-11-11 Thread nchubrich
I'm curious what the best idiomatic way of handling events is (e.g. receiving a series of messages and dispatching functions on the basis of the messages). One could use the 'experimental' add-watch(er) functions. But it might also be nice to do something stream-oriented, e.g. a doseq on a

Re: clojure vim shebang

2009-11-11 Thread John Ky
Mine is almost the same: Vim 7.2, vimclojure 2.1.2, java 1.6.0_10 On Thu, Nov 12, 2009 at 10:47 AM, MarkSwanson mark.swanson...@gmail.comwrote: Does anyone know why if the first character in my *.clj file is '#', then when I open it in VIM, ClojureVIM fails to recognise it as a Clojure

Re: clojure event handling

2009-11-11 Thread Alex Osborne
nchubrich wrote: I'm curious what the best idiomatic way of handling events is (e.g. receiving a series of messages and dispatching functions on the basis of the messages). One could use the 'experimental' add-watch(er) functions. But it might also be nice to do something stream-oriented,

Topological sort

2009-11-11 Thread Nick Day
Hi, I've been trying to implement a topological sort and have been struggling a bit. I have a map of symbol vs collection of symbols like: {a [b c], b [c], c [nil]} which can be read as 'a' depends on 'b' and 'c', 'b' depends on 'c' and 'c' doesn't depend on anything. I've been trying to write

Clojure CSV Library

2009-11-11 Thread David Santiago
Hi everyone. I wrote a CSV parsing and output library for my own uses when I didn't see another one available. Someone on #clojure suggested it might be of general interest for clojure.contrib. If you guys agree, I'm happy to do whatever is necessary to assist with that. The code is at

Re: Gensym collisions can be engineered.

2009-11-11 Thread Kevin Tucker
Yeah, sorry, missed that. How does making the gensyms unreadable make things worse for macroexpand than they are in CL? If the gensym is used more than once in the expansion (like bound to something in a let then referenced), then reading the expansion back in will read two different symbols and

Unified string/keyword/symbol Library

2009-11-11 Thread Sean Devlin
I often have to manipulate keywords and symbols. A symbol name needs a string appended in a macro, a keyword uses underscores instead of dashes. In order to do this, I usually transform them into a string, do some manipulation, and then turn the result back into a keyword/symbol. This pattern

Re: Topological sort

2009-11-11 Thread jan
Nick Day nicke...@gmail.com writes: I've been trying to implement a topological sort and have been struggling a bit. I have a map of symbol vs collection of symbols like: {a [b c], b [c], c [nil]} which can be read as 'a' depends on 'b' and 'c', 'b' depends on 'c' and 'c' doesn't depend on

Re: Topological sort

2009-11-11 Thread John Harrop
On Wed, Nov 11, 2009 at 2:04 PM, Nick Day nicke...@gmail.com wrote: Hi, I've been trying to implement a topological sort and have been struggling a bit. I have a map of symbol vs collection of symbols like: {a [b c], b [c], c [nil]} which can be read as 'a' depends on 'b' and 'c', 'b'

Re: Gensym collisions can be engineered.

2009-11-11 Thread John Harrop
On Wed, Nov 11, 2009 at 10:46 PM, Kevin Tucker tuckerke...@gmail.comwrote: Yeah, sorry, missed that. How does making the gensyms unreadable make things worse for macroexpand than they are in CL? It doesn't. Just worse than they currently are in Clojure. :) -- You received this message