Re: Inheriting from IDeref - good idea or bad practise?

2010-02-08 Thread Jarkko Oranen
On Feb 8, 3:22 am, Stuart Halloway wrote: > IMO Anything that implements IDeref should adhere to Clojure's vision   > for identity, e.g. reads need to be thread safe, cheap, require no   > coordination, and block no one. Dereferencing futures or undelivered promises block the dereferencing thread

Re: Clojure for system administration

2010-02-08 Thread Asbjørn Bjørnstad
On Feb 5, 12:33 am, Stuart Sierra wrote: > Clojure can certainly do these things; clojure-contrib contains many > file and io-related utilities.  But remember that Clojure, like any > Java program, takes more time to start up than "scripting" languages > like Perl/Bash/Ruby/Python, so it may be le

groovy builders equivalent

2010-02-08 Thread Laurent PETIT
Hello, Did anybody create a functionally equivalent clojure version of so-called Groovy Builders ? ( http://groovy.codehaus.org/Builders ) Not that it should be too difficult to come up with an equivalent, and also not that it would seem to you that it is interesting to do so given the power of c

Re: groovy builders equivalent

2010-02-08 Thread Laurent PETIT
And I've found groovy builders not so well documented, very "magical" (as in "dark magic") where I think this should not be that way. So there is even room to make this simpler for the users, I guess, by correctly implementing a somewhat "verbose" purely functional (and macros-free) DSL, from whom

Removing (gensym) in macro

2010-02-08 Thread Roman Roelofsen
Hi, just for practicing Clojure's macros I wrote the following create-java-list macro. (defmacro create-java-list [& forms] (let [prefixfn (fn [obj form] (cons (symbol ".") (cons obj form))) lname (gensym)] `(let [~lname (java.util.ArrayList.)] ~@(map (partial prefixfn lnam

Re: Removing (gensym) in macro

2010-02-08 Thread Meikel Brandmeyer
Hi, On Feb 8, 11:45 am, Roman Roelofsen wrote: > just for practicing Clojure's macros I wrote the following > create-java-list macro. > > (defmacro create-java-list >   [& forms] >   (let [prefixfn (fn [obj form] (cons (symbol ".") (cons obj form))) >         lname (gensym)] >     `(let [~lname

Re: Removing (gensym) in macro

2010-02-08 Thread Michael Wood
On 8 February 2010 12:45, Roman Roelofsen wrote: > Hi, > > just for practicing Clojure's macros I wrote the following > create-java-list macro. > > (defmacro create-java-list >  [& forms] >  (let [prefixfn (fn [obj form] (cons (symbol ".") (cons obj form))) >        lname (gensym)] >    `(let [~ln

Re: Removing (gensym) in macro

2010-02-08 Thread Meikel Brandmeyer
Hi, On Feb 8, 12:14 pm, Michael Wood wrote: > user=> (doto (java.util.ArrayList.) > (.add "1") > (.add "2")) > # Oops. Yes. You need doto instead of ->. Sorry, my mistake. > > Is it possible to create the macro without the (gensym) call? I wasn't > > able to use something like lname#. > > Sorr

Re: Removing (gensym) in macro

2010-02-08 Thread Roman Roelofsen
> I don't see a compelling reason for such a macro. At least not in this > simple case. I agree. As I said, the purpose of this macro was purely for learning and understanding macros ;-) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this

Re: Removing (gensym) in macro

2010-02-08 Thread Roman Roelofsen
> It doesn't work because the scope of lname# is limited to the `(). > However lname is used in a ~@() which leaves the `() and enters the > enclosing environment (in this case the macros). There the lname# is > not valid. Ah, that makes sense, thanks! Is using (gensym) the common solution here? S

Re: Parallel version of list comprehension

2010-02-08 Thread Sean Devlin
Do you have a specific example, some code you could paste? On Feb 7, 11:53 pm, Tim Snyder wrote: > Is there a straight-forward way to get parallelization when using list > comprehension? > The form of "for" syntax is much preferable to the closest I could > come up with using pmap.  I also was ha

Re: groovy builders equivalent

2010-02-08 Thread Chouser
On Mon, Feb 8, 2010 at 5:29 AM, Laurent PETIT wrote: > Hello, > > Did anybody create a functionally equivalent clojure version of > so-called Groovy Builders ? > ( http://groovy.codehaus.org/Builders ) > > Not that it should be too difficult to come up with an equivalent, and > also not that it wo

Re: Removing (gensym) in macro

2010-02-08 Thread Meikel Brandmeyer
Hi, On Feb 8, 2:06 pm, Roman Roelofsen wrote: > Ah, that makes sense, thanks! Is using (gensym) the common solution > here? So far I thought that (gensym) is more a internal function that > I normally never need to call directly. In such a case using gensym is the normal solution. When you don'

Re: Removing (gensym) in macro

2010-02-08 Thread Laurent PETIT
2010/2/8 Meikel Brandmeyer : > Hi, > > On Feb 8, 2:06 pm, Roman Roelofsen > wrote: > >> Ah, that makes sense, thanks! Is using (gensym) the common solution >> here? So far I thought that (gensym) is more a internal function that >> I normally never need to call directly. > > In such a case using g

Clojure talk TODAY (Feb 8) Paris, France 19:00

2010-02-08 Thread Howard Lewis Ship
Just a last minute reminder ... I'll be presenting "Clojure: Towards the Essence of Programming" on Monday Feb 8th at 19:00, in Paris. The event will be held at Zenika, SkillsMatter's partner in France. You must register for the talk ahead of time. http://skillsmatter.com/event/java-jee/clojure-t

Re: groovy builders equivalent

2010-02-08 Thread Laurent PETIT
2010/2/8 Chouser : > On Mon, Feb 8, 2010 at 5:29 AM, Laurent PETIT wrote: >> Hello, >> >> Did anybody create a functionally equivalent clojure version of >> so-called Groovy Builders ? >> ( http://groovy.codehaus.org/Builders ) >> >> Not that it should be too difficult to come up with an equivalen

Re: Clojure talk TODAY (Feb 8) Paris, France 19:00

2010-02-08 Thread Laurent PETIT
I wish I could be present ! I wish you the best, regards, -- Laurent 2010/2/8 Howard Lewis Ship : > Just a last minute reminder ... > > I'll be presenting "Clojure: Towards the Essence of Programming" on > Monday Feb 8th at 19:00, in Paris. The event will be held at Zenika, > SkillsMatter's pa

Re: groovy builders equivalent

2010-02-08 Thread Sean Devlin
Perhaps I have an incomplete grasp of the problem domain, but wouldn't a map stored in a ref let you do this? On Feb 8, 9:12 am, Laurent PETIT wrote: > 2010/2/8 Chouser : > > > > > On Mon, Feb 8, 2010 at 5:29 AM, Laurent PETIT > > wrote: > >> Hello, > > >> Did anybody create a functionally equi

Re: groovy builders equivalent

2010-02-08 Thread Laurent PETIT
2010/2/8 Sean Devlin : > Perhaps I have an incomplete grasp of the problem domain, but wouldn't > a map stored in a ref let you do this? I don't understand. > > On Feb 8, 9:12 am, Laurent PETIT wrote: >> 2010/2/8 Chouser : >> >> >> >> > On Mon, Feb 8, 2010 at 5:29 AM, Laurent PETIT >> > wrote:

Re: Parallel version of list comprehension

2010-02-08 Thread Tim Snyder
Sure, I was going to add it last night, but brain had shut down for the night. The program I'm working on is a Communicating Sequential Processes toolbox, so you can write a process and collect the traces (along with other tools that simplify expressions and such). I've written a traces function

scope of binding

2010-02-08 Thread Alex
Hi, I have a question about the scope of "binding" of a var. Let's say I have the following var: (def *v* 1) And I define a function that uses it: (defn f [n] (+ *v* n)) "binding" behaves as expected, establishing a thread-local binding to a new value in its scope: user=> (bindin

Re: Clojure talk TODAY (Feb 8) Paris, France 19:00

2010-02-08 Thread Christian Guimaraes
The talk will be in English or French? On Mon, Feb 8, 2010 at 2:13 PM, Laurent PETIT wrote: > I wish I could be present ! > > I wish you the best, > > regards, > > -- > Laurent > > 2010/2/8 Howard Lewis Ship : > > Just a last minute reminder ... > > > > I'll be presenting "Clojure: Towards the Es

Re: scope of binding

2010-02-08 Thread Sean Devlin
The problem is that map returns a lazy seq, and the lazy seq is evaluated outside of the binding by the REPL. If you add a doall inside the binding, it behaves as you expect. user=> (binding [*v* 2] (doall (map f [1 1 1]))) (3 3 3) Sean On Feb 8, 5:47 am, Alex wrote: > Hi, > > I have a questio

Re: Inheriting from IDeref - good idea or bad practise?

2010-02-08 Thread Steven E. Harris
James Reeves writes: > Would those more knowledgable about Clojure care to weigh in on > whether it be a good idea to create a custom class inheriting from > IDeref? That's how promise is implemented, but that's supposed to be an internal detail. -- Steven E. Harris -- You received this mess

Re: Inheriting from IDeref - good idea or bad practise?

2010-02-08 Thread Sean Devlin
I've got no clue, so I would just do the experiment. If it works out well, tell us why. If it's a disaster, tell us what didn't work. Sean On Feb 7, 3:57 pm, James Reeves wrote: > Hi folks, > > Would those more knowledgable about Clojure care to weigh in on > whether it be a good idea to creat

Please share your thoughts on dependency injection

2010-02-08 Thread Boris Mizhen - 迷阵
Hello all, I am playing with the idea of a little library for dependency injection. The idea is to declare injectable values as metadata-to-function map. I started with a sketch of what the client code may look like. Please let me know what you think. Thank you, Boris Dependency declaration cod

Re: Prepping clojure for packaging (was: Re: Clojure for system administration)

2010-02-08 Thread Konrad Hinsen
On 07.02.2010, at 03:25, Constantine Vetoshev wrote: > I stopped using Python and Ruby and Perl partly because the packaging > situation for all those languages is a horrible mess. For example, if I agree. It's not just packaging, even providing sufficiently general installation scripts is a dif

Re: Clojure talk TODAY (Feb 8) Paris, France 19:00

2010-02-08 Thread Konrad Hinsen
On 08.02.2010, at 15:10, Howard Lewis Ship wrote: > Just a last minute reminder ... > > I'll be presenting "Clojure: Towards the Essence of Programming" on > Monday Feb 8th at 19:00, in Paris. The event will be held at Zenika, If I had known this earlier, I might have been able to come :-( Konr

Re: Prepping clojure for packaging (was: Re: Clojure for system administration)

2010-02-08 Thread Greg
>> In short, I think that the Java and Clojure way of packaging software >> make life much easier for programmers, package maintainers, and >> administrators, not harder. Making applications self-contained helps > > I have no experience with this yet, but one reason for looking into the JVM > has

Re: return value of use, requires?

2010-02-08 Thread Raoul Duke
On Sat, Feb 6, 2010 at 2:08 AM, Timothy Pratley wrote: > Good point, I've updated the ticket patch to check options are valid > also, so the behavior is now: that is very cool, thank you! -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to th

Re: scope of binding

2010-02-08 Thread Richard Newman
You can also capture the binding. This looks a little ugly, but it works: it grabs the binding eagerly, and returns a closure that dynamically binds it when the function is invoked. (binding [*v* 2] (map (let [v *v*] (fn [n] (binding [*v* v] (f n

error reporting for macro expansion

2010-02-08 Thread John R. Williams
The Clojure compiler is not very helpful when it comes to debugging exceptions that occur while macros are being expanded. As an example, consider this code: ;; macro-fail.clj (defmacro broken [] (/ 0 0)) (broken) Here's the stack trace I get when I compile this file: Exception in thread "main"

Re: error reporting for macro expansion

2010-02-08 Thread Michał Marczyk
On 8 February 2010 20:11, John R. Williams wrote: > ;; macro-fail.clj > (defmacro broken [] (/ 0 0)) > (broken) > [ ... ] > As you can see, line 3, where the macro is used, appears nowhere in > the stack trace. That's because execution never reaches this point, because the (/ 0 0) bit gets execut

Implicit style streams in Clojure

2010-02-08 Thread Brenton
What is the Clojure best practice, if there is one, for writing a function like this: (defn integral [integrand initial-value dt] (def --integral (cons initial-value (lazy-seq (add-streams (scale- streams integrand dt) --integral --integral) integrand

Re: Implicit style streams in Clojure

2010-02-08 Thread Michał Marczyk
Use let: (defn foo [...] (let [helper (fn [...] ...)] (helper ...))) or letfn: (defn foo [...] (letfn [(helper [...] ...)] (helper ...))) The latter allows you to introduce mutually recursive functions. Sincerely, Michał -- You received this message because you are subscribed to

Re: Implicit style streams in Clojure

2010-02-08 Thread Kevin Downey
don't use def inside functions, ever. in scheme define is lexically scoped, so you do that sort of thing. clojure is not scheme. if you want a lexically scoped function use a lexical scoping construct like let or letfn. On Mon, Feb 8, 2010 at 12:12 PM, Brenton wrote: > What is the Clojure best p

Re: Implicit style streams in Clojure

2010-02-08 Thread Brenton
letfn is exactly what I was looking for. Thank you. On Feb 8, 12:15 pm, Michał Marczyk wrote: > Use let: > > (defn foo [...] >   (let [helper (fn [...] ...)] >     (helper ...))) > > or letfn: > > (defn foo [...] >   (letfn [(helper [...] ...)] >     (helper ...))) > > The latter allows you to i

Re: Clojure talk TODAY (Feb 8) Paris, France 19:00

2010-02-08 Thread Howard Lewis Ship
I've posted it at least once on this list! On Mon, Feb 8, 2010 at 9:35 AM, Konrad Hinsen wrote: > On 08.02.2010, at 15:10, Howard Lewis Ship wrote: > >> Just a last minute reminder ... >> >> I'll be presenting "Clojure: Towards the Essence of Programming" on >> Monday Feb 8th at 19:00, in Paris.

clojure pathnames library

2010-02-08 Thread Vadim Shender
Hi. Is there any clojure third-party library functionally similar to python's os.path? Using java.io.File is not so convenient as os.path. Regards Vadim Shender -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to cl

Trait-like behavior with Protocols

2010-02-08 Thread aria42
Is it possible to have default implementations associated with functions in a protocol? This is most useful when some protocol functions are defined in terms of other. For instance, (defprotocol Span (start [self]) (stop [self]) (span-length [self])) Now I know I can just make span-length a

Re: Prepping clojure for packaging (was: Re: Clojure for system administration)

2010-02-08 Thread Rick Moynihan
On 5 February 2010 18:47, Peter Schuller wrote: >> I've been wondering about this.  The classpath issue seems like a >> major thorn in the side of the JVM, especially for Clojure and other > > It seems to be that there are two problems here. > > One problem is that there needs to be a convention f

Re: Trait-like behavior with Protocols

2010-02-08 Thread Stuart Sierra
On Feb 8, 6:13 pm, aria42 wrote: > (defprotocol Span >   (start [self]) >   (stop [self]) >   (span-length [self])) > > Now I know I can just make span-length a function on Span as opposed > to part of the protocol. Is that what one should do? Yes. -SS -- You received this message because you

Re: clojure pathnames library

2010-02-08 Thread Stuart Sierra
Look at clojure-contrib. In the 1.1 release, use duck-streams and java-utils. In the latest github sources, it's all in clojure.contrib.io. -SS On Feb 8, 5:43 pm, Vadim Shender wrote: > Hi. > > Is there any clojure third-party library functionally similar to python's > os.path? Using java.io.F

Detecting Number of Available CPU Threads

2010-02-08 Thread Wardrop
I'm wondering if there's anyway in Clojure, that one can detect the number of available processoring threads (ie. 4 core cpu with hyperthreading would equal 8 available threads). This will allow me to have a scalable processing app which can run on a single core CPU, or 250 core processor, without

Re: Detecting Number of Available CPU Threads

2010-02-08 Thread Timothy Pratley
On 9 February 2010 11:29, Wardrop wrote: > I'm wondering if there's anyway in Clojure, that one can detect the > number of available processoring threads (.availableProcessors (Runtime/getRuntime)) might be what you are after? -- You received this message because you are subscribed to the Googl

Re: Detecting Number of Available CPU Threads

2010-02-08 Thread Wardrop
That seems like what I'm after, thanks. I assume this would be pretty reliable across all platforms running the JVM. By the way, I did google the Java API with various keywords but never cam across this object property. Thanks On Feb 9, 11:33 am, Timothy Pratley wrote: > On 9 February 2010 11:2

Re: Trait-like behavior with Protocols

2010-02-08 Thread Dan Larkin
On Feb 8, 2010, at 6:13 PM, aria42 wrote: > Is it possible to have default implementations associated with > functions in a protocol? This is most useful when some protocol > functions are defined in terms of other. For instance, > > (defprotocol Span > (start [self]) > (stop [self]) > (span-l

Re: Prepping clojure for packaging (was: Re: Clojure for system administration)

2010-02-08 Thread Brian Schlining
> > IMHO Ruby (and probably python) do this better than Clojure, though > I'm not sure if we'll ever be able to find a solution we can all agree > on. > Groovy has a very decent solution to the classpath issue for scripts. Details can be found at http://groovy.codehaus.org/Grape . It might be wort

Re: Prepping clojure for packaging (was: Re: Clojure for system administration)

2010-02-08 Thread Meikel Brandmeyer
Hi, maybe I don't understand the problem. Why can't the system provide some kind of local repository? The package system (deb, rpm, ports, whatever) just installs the dependencies there. A wrapper script reads in the dependencies and adds them to the classpath on program start. Nothing is download

Re: Trait-like behavior with Protocols

2010-02-08 Thread Meikel Brandmeyer
Hi, On Feb 9, 12:13 am, aria42 wrote: > Is it possible to have default implementations associated with > functions in a protocol? This is most useful when some protocol > functions are defined in terms of other. For instance, > > (defprotocol Span >   (start [self]) >   (stop [self]) >   (span-