Re: Equivalents from java

2009-10-25 Thread John Harrop
On Mon, Oct 26, 2009 at 1:17 AM, Gorsal wrote: > So i've been trying to find two equivalents to keywords in java. The > first one is synchronized. is there any syncrhonized keyword in > clojure? > (locking obj (do-something-with obj foo bar)) is equivalent to Java synchronized (obj) { obj.

Re: binding and threads

2009-10-25 Thread erturne
I'm a total noob to Clojure, but my understanding is that Vars initially have "root" bindings shared by all threads. I think binding changes a Var so that instead of having a root binding shared by all threads it now has thread-local binding; changes made to the thread- local value bound to Var ar

Re: clojure / ruby yield comparison

2009-10-25 Thread Daniel Bush
On Oct 26, 9:26 am, John Harrop wrote: > On Sun, Oct 25, 2009 at 2:50 PM, Radford Smith wrote: > > > Ruby blocks are anonymous functions with syntax sugar. You could write > > James' with_open method like this: > > > def with_open(stream, &f) > >  f.call(stream) > > end > Yeah, sorry I don't

Re: Measuring code complexity

2009-10-25 Thread John Harrop
On Mon, Oct 26, 2009 at 1:09 AM, Chouser wrote: >(count-nodes "abcde") >; 6 Yikes. Maybe special-casing strings would be best: change (seqable? x) into (and (seqable? x) (not (string? x))). I don't know if Seqable is synonymous with that; might there be other seqable?s that aren't Seq

Re: Measuring code complexity

2009-10-25 Thread John Harrop
On Mon, Oct 26, 2009 at 12:45 AM, Timothy Pratley wrote: > > This sounds like a neat idea to me. Maybe the way to get the > 'complexity' is to calculate it at definition, this macro doesn't work > for obvious reasons: > (defmacro defnc > [n & body] > `(let [f# (defn ~n ~...@body)] > (alter-m

Equivalents from java

2009-10-25 Thread Gorsal
So i've been trying to find two equivalents to keywords in java. The first one is synchronized. is there any syncrhonized keyword in clojure? More importantly, however, ive been trying to do somethign like this (proxy [AbstractHandler] [] (execute [~var] ~...@body)) What is the equival

Re: Measuring code complexity

2009-10-25 Thread Chouser
On Sun, Oct 25, 2009 at 10:08 PM, John Harrop wrote: > Reading http://www.paulgraham.com/power.html and specifically the section > titled "Metrics" near the top, I realized that it would be very easy to > calculate such metrics for Lisp code, and it took me literally only seconds > to hack someth

Re: college courses

2009-10-25 Thread artg
I'm going to start the Clojure unit in the senior class in a few weeks. They have done some F# and I will repeat the F# assignments in Clojure for comparison. They all have some Java and some C++ but the unit here is just some functional programming without Java interop so I don't think it matters

Re: Measuring code complexity

2009-10-25 Thread Timothy Pratley
This sounds like a neat idea to me. Maybe the way to get the 'complexity' is to calculate it at definition, this macro doesn't work for obvious reasons: (defmacro defnc [n & body] `(let [f# (defn ~n ~...@body)] (alter-meta! (var ~n) assoc :complexity (count-nodes ~body)) f#)) But I t

Re: Measuring code complexity

2009-10-25 Thread John Harrop
On Sun, Oct 25, 2009 at 11:56 PM, MarkSwanson wrote: > I'm curious (general Clojure question) about your use of the quoted > form. The Clojure docs state that this results in an unevaluated form, > but I had trouble finding more details on this. F.E. I'd like to run > count-nodes against a compile

Re: Measuring code complexity

2009-10-25 Thread John Harrop
On Sun, Oct 25, 2009 at 10:08 PM, John Harrop wrote: > > 4 public class NodeCounter { > 8 public static int countNodes (Object data) { > 10 if (!(data instanceof Iterable)) return 1; > 5 int result = 1; > 8 for (Object e : (Iterable)data) { > 6 result +

Re: Measuring code complexity

2009-10-25 Thread MarkSwanson
That's interesting. I ran this against a quoted Clojure fn of mine and received 92. I'm curious (general Clojure question) about your use of the quoted form. The Clojure docs state that this results in an unevaluated form, but I had trouble finding more details on this. F.E. I'd like to run count

Re: binding and threads

2009-10-25 Thread Richard Newman
> What do threads have to do with bindings? How would they interact? Bindings do not propagate between threads, even if the new thread is created within a binding form. Threads are created with a fresh environment; the values of vars in a new thread are the root bindings (the thread-global

binding and threads

2009-10-25 Thread samppi
Here's something that I've been confused about for a long time: I've read many, many times that binding allows you to give to vars "thread-specific values", and that vars have a "thread-global value" too. I think that I understand how vars and binding work, but I don't understand how binding is n

Measuring code complexity

2009-10-25 Thread John Harrop
Reading http://www.paulgraham.com/power.html and specifically the section titled "Metrics" near the top, I realized that it would be very easy to calculate such metrics for Lisp code, and it took me literally only seconds to hack something in Clojure: user=> (defn count-nodes [data] (if (clojure.c

Re: STM talk

2009-10-25 Thread Dan
On Sat, Oct 24, 2009 at 1:35 PM, Mark Volkmann wrote: > > I gave a talk on STM at a conference in St. Louis called "Strange > Loop" last Thursday. > That is the most awesome title for a conference, ever. (Said the guy who just finished GEB: an EGB). > 1 up and 2 up PDF versions of the slides ar

Re: with-meta overwrites existing metadata; is there a way to just add

2009-10-25 Thread samppi
Excellent; this is perfect. I wonder why I didn't find it when I searched the docs...thanks a lot, though. On Oct 25, 3:16 pm, Phil Hagelberg wrote: > samppi writes: > > with-meta's behavior is annoying for me. I often have something like > > this: > > >   (defn a [blah] (with-meta blah {:type

Re: News on Mini Kanren / Javascript generator; when is an implementation sufficiently original?

2009-10-25 Thread Rich Hickey
On Sun, Oct 25, 2009 at 12:16 AM, Michel Salim wrote: > > Jim was working on logic programming in Clojure up to a few months > ago, and it seems as if the concern was that the code was too > derivative. > > I have recently made available a Scala-based Kanren implementation; > the differences betw

Re: clojure / ruby yield comparison

2009-10-25 Thread John Harrop
On Sun, Oct 25, 2009 at 2:50 PM, Radford Smith wrote: > > Ruby blocks are anonymous functions with syntax sugar. You could write > James' with_open method like this: > > def with_open(stream, &f) > f.call(stream) > end > > The equivalent in Clojure is effectively the same: > > (defn with-open [s

Re: PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-25 Thread Patrick Steiger
+1. I find Clojure error messages a little bit cryptic, and this is a nice effort to change this. 2009/10/25 MarkSwanson > > Hello, > > Someone recently posed the question: (why doesn't this work) > (into {} (map #([% (* % %)]) [1 2 3 4])) > > (reference: > http://groups.google.com/group/clojure

Re: Help with anonymous functions

2009-10-25 Thread jsrodrigues
Thanks for the help Lauri! John On Oct 25, 10:29 am, Lauri Pesonen wrote: > Hi John, > > 2009/10/25 jsrodrigues : > > > > > When I try the following: > > user=> (into {} (map #([% (* % %)]) [1 2 3 4])) > > The #(...) form assumes that the is a function call and thus it is > implicitly wrapped i

Re: clojure / ruby yield comparison

2009-10-25 Thread Radford Smith
Ruby blocks are anonymous functions with syntax sugar. You could write James' with_open method like this: def with_open(stream, &f) f.call(stream) end The equivalent in Clojure is effectively the same: (defn with-open [stream f] (f stream)) On Oct 25, 9:31 am, James Reeves wrote: > I don'

Re: with-meta overwrites existing metadata; is there a way to just add

2009-10-25 Thread Phil Hagelberg
samppi writes: > with-meta's behavior is annoying for me. I often have something like > this: > > (defn a [blah] (with-meta blah {:type ::incredible})) > (defn b [foo] (with-meta (a foo) {::b 2})) > > I'd like ^(b []) to be {:type ::incredible, ::b 2}. But with-meta > overwrites the metadata

with-meta overwrites existing metadata; is there a way to just add

2009-10-25 Thread samppi
with-meta's behavior is annoying for me. I often have something like this: (defn a [blah] (with-meta blah {:type ::incredible})) (defn b [foo] (with-meta (a foo) {::b 2})) I'd like ^(b []) to be {:type ::incredible, ::b 2}. But with-meta overwrites the metadata from a completely. Is there a

Re: clojure / ruby yield comparison

2009-10-25 Thread Jarkko Oranen
> But whilst this is useful, this doesn't really demonstrate why macros > are so powerful. Macros are useful because they automatically > rearrange your source code into something else. They're most similar > to the Ruby 'eval' function, but operate of data structures rather > than strings. > Nitp

pointfree library

2009-10-25 Thread harrison clarke
so i was using haskell, and the pointfree stuff is fun, so naturally i had to implement some of it in clojure. this is what i have so far. library and examples within: http://github.com/hclarke/pointfree-clojure it has >>>, &&&, ***, +++, |||, and others they take functions as arguments and retu

Re: PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-25 Thread MarkSwanson
Ok, I see now I should not post patches here because it messes up the formatting. I can't seem to find an option to paste text. I've placed the patch here: http://www.scheduleworld.com/sw2/arity.patch.gz --~--~-~--~~~---~--~~ You received this message because yo

Re: PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-25 Thread eyeris
+1, This would have helped me a lot when I first came to Clojure (from a non-lisp background). On Oct 25, 11:57 am, MarkSwanson wrote: > Hello, > > Someone recently posed the question: (why doesn't this work) > (into {} (map #([% (* % %)]) [1 2 3 4])) > > (reference:http://groups.google.com/gro

Re: Help with anonymous functions

2009-10-25 Thread MarkSwanson
Thanks Lauri. I was stuck on this too. FYI this issue prompted me to submit a patch to improve the arity error message: http://groups.google.com/group/clojure/browse_thread/thread/de969a419a535a82 --~--~-~--~~~---~--~~ You received this message because you are s

PATCH: AFn.java, RestFN.java (a better throwArity message)

2009-10-25 Thread MarkSwanson
Hello, Someone recently posed the question: (why doesn't this work) (into {} (map #([% (* % %)]) [1 2 3 4])) (reference: http://groups.google.com/group/clojure/browse_thread/thread/7d3ee57ee8041353) The error message was: Caused by: java.lang.IllegalArgumentException: Wrong number of args pass

Re: Help with anonymous functions

2009-10-25 Thread Lauri Pesonen
Hi John, 2009/10/25 jsrodrigues : > > When I try the following: > user=> (into {} (map #([% (* % %)]) [1 2 3 4])) The #(...) form assumes that the is a function call and thus it is implicitly wrapped in parens. That is, #(+ % %) becomes (fn [x] (+ x x)). So in your code the anonymous function bo

Help with anonymous functions

2009-10-25 Thread jsrodrigues
Hi, I'm trying to find the #(...) equivalent of (fn [] ...) for the following case: user=> (into {} (map (fn [x] [x (* x x)]) [1 2 3 4])) {4 16, 3 9, 2 4, 1 1} When I try the following: user=> (into {} (map #([% (* % %)]) [1 2 3 4])) I get the error: java.lang.RuntimeException: java.lang.Illeg

Re: clojure / ruby yield comparison

2009-10-25 Thread James Reeves
I don't think that's a very good example of what macros can do. As you point out, you can do much the same thing in Ruby with blocks: with_open(MyStream.new) do |stream| stream.write "Hello" end In Clojure, blocks are analogous to anonymous functions. So the equivalent Clojure would be: (with

[newb] clojure / ruby yield comparison

2009-10-25 Thread Daniel Bush
hi, I'm new to lisp/clojure in general. I was reading the free whitepaper from Amit Rathore's 'Clojure in Action' where he gives a simple example on macros. In the example on page 9 he shows how you might do an audited connection in java: public void addExpense(long userId, Date date, BigDecima

Re: STM talk

2009-10-25 Thread Mark Volkmann
On Sat, Oct 24, 2009 at 8:36 PM, MarkSwanson wrote: > > I'm confused about the slide on barging: > > "txnB has a status of RUNNING and can be changed to KILLED". > > Are you implying that simply having a status of RUNNING is all that is > required for the txn to be killed? > Or, are there other r