Return value of load

2009-07-04 Thread Meikel Brandmeyer
Hi, load-reader and load-string currently return the last value from the code loaded. This is actually nice. As waterfront I'd like to use this to load plugins, which then simply return a structure with information about the plugin as last value. I'd like to distribute some standard plugins in t

Re: loneclojurian at ICFP programming contest

2009-07-04 Thread fft1976
On Jul 3, 5:52 pm, Jon Harrop wrote: > On Thursday 02 July 2009 07:58:11 you wrote: > > > I wonder if Jon Harrop is still planning to write Clojure for > > Scientists or Scala for Scientists or both? > > I am certainly interested in writing both books. I reviewed Scala back in 2007 > and decide

Re: loneclojurian at ICFP programming contest

2009-07-04 Thread Nicolas Oury
Hello, after experimenting a bit, it seems that you can get a small gain by putting things in local variables (25% or so) but not much. I looked at the implementation and I was assuming something that is not true: aset-double does not compile to JVM instructions for setting the array directly. It

aset-* family of functions

2009-07-04 Thread Nicolas Oury
Dear all, In another thread, we realized that setting an array of primitive type (it was double in our example) is far quicker in Java than in Clojure. After looking to the implementation of aset-* in Clojure 1.0, I realize that it calls the set* method of java.reflect.Array. Is there a way of av

nth yields "java.lang.OutOfMemoryError: Java heap space"

2009-07-04 Thread arasoft
Using a fairly recent 1.1 snapshot, I get an OutOfMemoryError for this: (defn fib-seq [] ((fn more [a b] (lazy-seq (cons a (more b (+ a b) 0 1) ) (nth (fib-seq) 20) However, this works fine: (defn xth [coll i] (if (zero? i) (first coll) (recur (rest coll) (dec i

Jazz - a wrapper DSL for JGoodies Forms

2009-07-04 Thread Meikel Brandmeyer
Dear Clojurians, I worked a little on the feedback of Laurent and Nicolas. This led to several changes: * clj-forms is now called "Jazz" * Jazz now provides so-called editors for different types, currently: String, Boolean, Integer, :Enum more to come... I'm still not totally rid of the col

Re: Return value of load

2009-07-04 Thread Stephen C. Gilardi
On Jul 4, 2009, at 4:02 AM, Meikel Brandmeyer wrote: Is there some specific reason for that or could load be adapted to also return the last value evaluated? I experimented with this, got it to work for a simple case, and prepared my initial reply below. In working with the idea some more

Re: nth yields "java.lang.OutOfMemoryError: Java heap space"

2009-07-04 Thread Daniel Lyons
On Jul 4, 2009, at 6:04 AM, arasoft wrote: > > Using a fairly recent 1.1 snapshot, I get an OutOfMemoryError for > this: > > (defn fib-seq [] >((fn more [a b] >(lazy-seq (cons a (more b (+ a b) > 0 1) > ) > > (nth (fib-seq) 20) > > However, this works fine: > > (defn xth

Re: nth yields "java.lang.OutOfMemoryError: Java heap space"

2009-07-04 Thread Lennart Staflin
On Jul 4, 4:37 pm, Daniel Lyons wrote: > On Jul 4, 2009, at 6:04 AM, arasoft wrote: > > Using a fairly recent 1.1 snapshot, I get an OutOfMemoryError for > > this: > > > (defn fib-seq [] > >    ((fn more [a b] > >        (lazy-seq (cons a (more b (+ a b) > >     0 1) > > ) > > > (nth (fib-s

Re: loneclojurian at ICFP programming contest

2009-07-04 Thread Rich Hickey
On Sat, Jul 4, 2009 at 4:50 AM, Nicolas Oury wrote: > Hello, > > after experimenting a bit, it seems that you can get a small gain by putting > things in local variables (25% or so) but not much. > > I looked at the implementation and I was assuming something that is not > true: > aset-double does

Re: aset-* family of functions

2009-07-04 Thread Rich Hickey
On Sat, Jul 4, 2009 at 5:00 AM, Nicolas Oury wrote: > Dear all, > > In another thread, we realized that setting an array of primitive type (it > was double in our example) is far quicker in > Java than in Clojure. > > After looking to the implementation of aset-* in Clojure 1.0, I realize that > i

Re: aset-* family of functions

2009-07-04 Thread Nicolas Oury
Thanks for the reply. It seems to speed up quite a bit the array of double. I cannot manage to make it work for the array of booleans. Is there someting different? If aset and aget are faster, what is the goal of the aset-xxx? Best, Nicolas. --~--~-~--~~~---~--~~

Re: parsing program for nested parens and square brackets

2009-07-04 Thread Russell Christopher
(def matches {\( \) \[ \]}) (defn balanced? [s] (empty? (reduce #(if (= (matches (peek %1)) %2) (pop %1) (conj %1 %2)) [] s))) Learning Clojure. So far I'm really liking it. This is the first time I've tried anything outside of some REPL incantations from books, blogs, this list, etc thus it wo

Re: nth yields "java.lang.OutOfMemoryError: Java heap space"

2009-07-04 Thread Meikel Brandmeyer
Hi, Am 04.07.2009 um 17:11 schrieb Lennart Staflin: I don't think this explains it. It is a OutOfMemoryError not a stack overflow. It is not a recursion problem. I think it is that nth hangs on to the head of the lazy fib sequence, and therefor all the elements including the big integers can no

Re: nth yields "java.lang.OutOfMemoryError: Java heap space"

2009-07-04 Thread Rich Hickey
On Jul 4, 8:04 am, arasoft wrote: > Using a fairly recent 1.1 snapshot, I get an OutOfMemoryError for > this: > > (defn fib-seq [] >     ((fn more [a b] >         (lazy-seq (cons a (more b (+ a b) >      0 1) > ) > > (nth (fib-seq) 20) > > However, this works fine: > > (defn xth [coll i

Type annotations in libraries

2009-07-04 Thread Richard Newman
I thought I'd share an observation with the group. I'm walking through my fork of Dan Larkin and Phil Hagelberg's HTTP client library, fixing reflection warnings and generally seeing if I can add some features (to bring it up to parity with some code I've written that uses the Apache HTTP l

ANN: FnParse, a functional parsing library

2009-07-04 Thread samppi
I'm pleased to announce FnParse, a monadic functional parsing library for Clojure, half a year in the making. I started on FnParse in December as my first Clojure project, and now it has matured to something that I believe is very and immediately useful. Currently, I'm writing a YAML parser using

Re: Return value of load

2009-07-04 Thread Meikel Brandmeyer
Hi Stephen, thanks for your thoughts. Am 04.07.2009 um 16:19 schrieb Stephen C. Gilardi: Is there some specific reason for that or could load be adapted to also return the last value evaluated? I experimented with this, got it to work for a simple case, and prepared my initial reply below

Re: ANN: FnParse, a functional parsing library

2009-07-04 Thread Wilson MacGyver
Very timely, I need to parse a bunch on JSON files on Monday :) good work Sent from my iPhone On Jul 4, 2009, at 3:16 PM, samppi wrote: > > I'm pleased to announce FnParse, a monadic functional parsing library > for Clojure, half a year in the making. I started on FnParse in > December as my

particle demo

2009-07-04 Thread Raoul Duke
hi, 1) little particle demo, attached. me trying to learn Clojure by ripping off Rich's ants code. 2) in the repl you can do hot-code-swap (in the vein of Erlang, JavaRebel, etc.) care of agents; see the bottom of the file for examples. 3) i have not run it under a profiler yet. 4) please suggest

adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
Say I have a data structure like this (def ref-map-map-map-set (ref {:key1 {:key2 {:key3 #{)) If I want to add a new member to the set which is the value of :key3, I currently do this: (dosync (let [key1 (:key1 @ref-map-map-map-set) key2 (:key2 key1) key3 (:key3 key2)] (re

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Adrian Cuthbertson
You could use assoc-in... (def rms (ref {:key1 {:key2 {:key3 #{)) (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) {:key1 {:key2 {:key3 "foo"}}} Rgds, Adrian. On Sun, Jul 5, 2009 at 6:07 AM, Rowdy Rednose wrote: > > Say I have a data structure like this > > (def ref-map-map-map-set

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Richard Newman
Rowdy, > Do I really have to assoc all the way through to the inner map? Isn't > there a more succinct way to write this? In Common Lisp there's (setf > (getf ...)) Remember, Clojure's data structures are immutable. You're not adding a value to a set -- what you're describing is (in Clojure) a

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
Much better! Thanks. On Jul 5, 1:20 pm, Adrian Cuthbertson wrote: > You could use assoc-in... > > (def rms (ref {:key1 {:key2 {:key3 #{)) > > (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) > {:key1 {:key2 {:key3 "foo"}}} > > Rgds, Adrian. > > On Sun, Jul 5, 2009 at 6:07 AM, Rowdy Re

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
On Jul 5, 1:23 pm, Richard Newman wrote: > However, I'd point out that: > > * This might be a sign that you're doing things 'wrong'. Could be. I'm still figuring out how to do things the functional way. The reason I have these nested maps is to give my data structure. I don't want to have a loos

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
On Jul 5, 1:20 pm, Adrian Cuthbertson wrote: > (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) > {:key1 {:key2 {:key3 "foo"}}} I just found update-in, which is even better, as I want to update a set: user=> (def gnu-rms (ref {:key1 {:key2 {:key3 #{)) #'user/gnu-rms user=> (dosync