Re: Memory Characteristics of Persistent Datastructures

2009-10-03 Thread hoeck
Hi, to measure memory requirements of java programs, it is better use a tool like jvisualvm. The JVM process aquires memory as it needs according to its max heap and max permgen settings. I ran your little snippet on my machine with java -Xmx5M -jar clojure.jar, and while jvisualvm reported arou

Re: apply for macros?

2009-10-03 Thread b2m
Hi, some piece of code that helps me in this special case. Here the "translated" version: (defmacro apply-macro [m & args] `(list* ~m ~...@args)) (def li '(true false false)) (eval (apply-macro 'and true false li)) ; observe of the quote before the macro Or instead of trying sth. like: (de

Re: server-socket on exit event

2009-10-03 Thread Emeka
ngo, I was about doing this kind of client/server thing some days ago, however now you are into it I would like to learn then. I am not quite clear why you have this: (.start (new Thread (fn [] (create-server 8080 chat-loop My concern is on Thread, create-server function has a Thread inside

Re: Debugging questions

2009-10-03 Thread Timothy Pratley
Hi Jose, > ; trying to get the first element of an unordered set > (nth (clojure.set/select #(= 0 (mod % 2)) #{1 2 5 10}) 0) > Why do I get different messages running from the REPL or loading from a clj > file ? I tried it from REPL and file using the from source Clojure 1.1.0- alpha-SNAPSHOT, a

Adding meta data to string?

2009-10-03 Thread Jung Ko
Is it possible to add meta-data to Strings? (with-meta "Hello" {:key 123}) java.lang.String cannot be cast to clojure.lang.IObj [Thrown class java.lang.ClassCastException] One solution that I found by Googling around is to extend the Java class that I want to add meta data (String in this cas

Re: Adding meta data to string?

2009-10-03 Thread pmf
On Oct 3, 9:17 am, Jung Ko wrote: > Is it possible to add meta-data to Strings? > > (with-meta "Hello" {:key 123}) > > java.lang.String cannot be cast to clojure.lang.IObj >   [Thrown class java.lang.ClassCastException] And String is final, making deriving from it impossible. One way (most prob

Re: apply for macros?

2009-10-03 Thread Rob
On Oct 2, 12:47 pm, b2m wrote: > > But all the arguments are in a list e.g. (def arglist '(true false > true false)) > > Is there a simple way to 'apply' the macro to a list of arguments like > it works for functions: (apply + '(1 2 3)) ? > Yes. You build up the code/data structure and pass i

Re: server-socket on exit event

2009-10-03 Thread ngocdaothanh
Emeka, good catch. It's just my mistake. Another thing is I think there may be exception raised when on-msg sends message to a closed socket. How would you solve this? On Oct 3, 7:35 pm, Emeka wrote: > ngo, > I was about doing this kind of client/server thing some  days ago, however > now you

refs implement IFn, atoms and agents do not?

2009-10-03 Thread Stuart Halloway
Is there a principled reason for this? I have written some code that (unintentionally) limits itself to refs because it assumes that all reference types can sit in function position. Thanks, Stu --~--~-~--~~~---~--~~ You received this message because you are s

Re: apply for macros?

2009-10-03 Thread b2m
Hi > Yes.  You build up the code/data structure and pass it to either > `eval' or `macroexpand', depending on your exact goals... thx > user=> (def args '(true false true false)) > #'user/args > user=> (def code `(and ~...@args)) > #'user/code > user=> code > (clojure.core/and true false true fa

Multimethod or Multiple Arg Lists

2009-10-03 Thread Robert Stehwien
I'm toying around with a file utility library as part of a vow to do all my "scripting" in clojure so I can learn the language - this is actually my first attempt at writing anything "real" with clojure. I considered using memoize to cache file listing but wanted to be able to selectively clear th

Re: Multimethod or Multiple Arg Lists

2009-10-03 Thread Sean Devlin
I would definitely prefer clear-cached-files2. I usually use multimethods when I need to change behavior on type of arguments, not the argument count. Let's take a look at reduce. I would write the shorter form in terms of the longer one. (defn reduce ([f coll] (reduce f (first coll) (rest c

Re: Memory Characteristics of Persistent Datastructures

2009-10-03 Thread Elliott Slaughter
Thanks. JVisualVM shows the initial memory usage is a couple hundred MB, then decreases to levels about what you described. I'm using a 64-bit Java with the -server option to increase the max heap size. But in my actual application, the memory performance is much worse: the heap size keeps growi

Re: Debugging questions

2009-10-03 Thread kyle smith
select returns a set, so you need to call seq/vec before calling nth. user> (nth (seq (clojure.set/select #(zero? (mod % 2)) #{1 2 5 10})) 0) 2 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post

Re: apply for macros?

2009-10-03 Thread John Harrop
In the specific cases of "and" and "or", I made utility functions that do non-short-circuiting "and" and "or" for use with "apply" and a stream of boolean data. (Not sure which implementation is more efficient though: a version that returns its argument with one argument, punts to the appropriate m

Load Bitmap

2009-10-03 Thread prishvin
Dear friends, I have some experience in lisp and now want to write a small program in clojure. The question is, how can I load a gray scale bitmap and how can i access individual pixels in it. Thank you in advance. M.Prishvin. --~--~-~--~~~---~--~~ You received

Re: apply for macros?

2009-10-03 Thread b2m
> What macros do y'all have that you want to "apply" things to? I am using structs and functions for workings with these structs. Just some very general example: (defstruct department :name :head :members-l1 :members-l2 ...) (defn process-department [department-struct] (reduce + (list

Re: Load Bitmap

2009-10-03 Thread John Newman
I don't know much about it, but Yann N. Dauphin's Mona Lisa program might use what you're looking for: Clojure: Genetic Mona Lisa problem in 250 beautiful lines Here's the relevant code: > >1. ; grab-pixe

Re: Load Bitmap

2009-10-03 Thread John Newman
Actually, that code is rather dated. An updated version might look like this. (Warning, not tested) ; grab-pixels :: BufferedImage -> [Integer] (defn grab-pixels "Returns an array containing the pixel values of the image" [image] (let [w (.getWidth image) h (.getHeight image)

Re: Load Bitmap

2009-10-03 Thread Sean Devlin
Take a look at the javax.imageio.ImageIO class. There are some useful static methods there for loading files. Also, if you're going to be doing image editing, I'd suggest reading the AWT sections in Cornell & Horstmann. http://www.horstmann.com/corejava.html Both volumes should be required rea

Re: Load Bitmap

2009-10-03 Thread Josh Daghlian
On Oct 3, 8:27 pm, Sean Devlin wrote: > Take a look at the javax.imageio.ImageIO class.  There are some useful > static methods there for loading files.  Also, if you're going to be > doing image editing, I'd suggest reading the AWT sections in Cornell & > Horstmann. > > http://www.horstmann.com/

Re: apply for macros?

2009-10-03 Thread Meikel Brandmeyer
Hi, Am 04.10.2009 um 00:50 schrieb b2m: What macros do y'all have that you want to "apply" things to? A sure code smell, IMO. It most likely is based on a misunderstanding what macros are capable to do. I am using structs and functions for workings with these structs. Just some very gen