Re: how would I do this functionally? (internally mutable state)

2009-05-28 Thread Daniel Lyons
For whatever reason I just can't seem to put this problem down. I have rewritten the code substantially. A major bottleneck was using Java's MD5 classes. The "Fast MD5" library really is, and that helped a lot. I did get the -> notation to work and I have a reasonable HOF now for doing the

How to hide functions from being imported?

2009-05-28 Thread kinghajj
In Haskell, it's simple to explicitly state what names should be exported by a module. Is there a way to do this in Clojure? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send

Clojure and VisualVM

2009-05-28 Thread Christopher Wilson
I found an interesting article on Hacker News: http://news.ycombinator.com/item?id=631085 "The Best Kept Secret in the JDK: VisualVM" and the article here: http://java.dzone.com/articles/best-kept-secret-jdk-visualvm I fired it up and in no time at all, was profiling some clojure code. Definitely

Re: New reflection warning in r1381

2009-05-28 Thread Dex Wood
The change that caused this problem between 1376 and 1386 was that count got an inline definition, which allowed it to return a primitive. In this case, count is returning an int in both places, which brought to light the problem that I stated in the previous post. The divide issue has been arou

Re: New reflection warning in r1381

2009-05-28 Thread Dex Wood
After seeing this issue, I brought it up in #clojure. After experimenting with it in both 1376 and earlier, it seems that the same behaviour for stuff like (/ (int 1) (int 2)) exist, where it is about 5 times slower than (/ 1 2), which is kind of a strange result. The solution is to create a met

Re: (gensym) not equivalent to #?

2009-05-28 Thread CuppoJava
Yeah. It really is a subtle point. I don't think I would have understood the difference until I ran into the problems I've been having. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this

Re: Programming Clojure Arrives!

2009-05-28 Thread Andrew Wagner
I ordered mine today and look forward to getting it soon! On Thu, May 28, 2009 at 8:51 PM, Sean Devlin wrote: > > I just got my copy of Programming Clojure in the mail today. This is > the only time I expect to see the book in pristine condition, as I > know it will get bookmarked, highlighted,

Programming Clojure Arrives!

2009-05-28 Thread Sean Devlin
I just got my copy of Programming Clojure in the mail today. This is the only time I expect to see the book in pristine condition, as I know it will get bookmarked, highlighted, and well used in a hurry. Congratulations Stuart! --~--~-~--~~~---~--~~ You received t

Re: how would I do this functionally? (internally mutable state)

2009-05-28 Thread James Reeves
On May 28, 2:52 am, Korny Sietsma wrote: Basically, I have a FileInfo class that wraps a data file, used to > compare lots of files on my system. > It has an "exact_match" method similar to: >   def exact_match(other) >      return false if size != other.size >      return false if quickhash() !

Re: (gensym) not equivalent to #?

2009-05-28 Thread Chouser
On Thu, May 28, 2009 at 5:42 PM, Meikel Brandmeyer wrote: > Am 28.05.2009 um 23:29 schrieb CuppoJava: > >> In my recent macro-writing adventure, I discovered that >> (gensym) is not actually equivalent to using #. Can >> someone explain to me how # actually works in backquoted >> form? > > The f

Re: Using generics

2009-05-28 Thread tsuraan
> user=> (show Class) > === public final java.lang.Class === > [ 0] static forName : Class (String) > [ 1] static forName : Class (String,boolean,ClassLoader) > [ 2] asSubclass : Class (Class) > [...] > nil > user=> (show Class 2) > # java.la

Re: Instructions for Emacs+SLIME

2009-05-28 Thread william douglas
That's awesome Phil! I have been using the starter-kit for awhile since you have a fair ton of goodies in there and this provides a great reference for getting my 3 or 4 different clojure set ups consistently working (instead of a version that has java api help integrated, one that has maven hook

Re: "Currying" / Partial Application macro

2009-05-28 Thread Max Suica
Hey, here's a hacked together curry function that does it somewhat like haskell, in pseudo-code. Can you guys help me correct it? (defn curry [f & args1] (cond (= (arity f ) (count args)) (apply f args1) (fixed? (arity f) (fn [& args2] (curry (apply partial f args1) args2)

Re: (gensym) not equivalent to #?

2009-05-28 Thread CuppoJava
Thanks again Meikel -Patrick --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsub

Re: Using generics

2009-05-28 Thread Stephen C. Gilardi
On May 28, 2009, at 5:23 PM, tsuraan wrote: I have a java class whose constructor expects (among other things) a BlockingQueue. It's easy to create a BlockingQueue in clojure (obviously), but I can't figure out the syntax to specialize it to the Long type. Is this possible, or does it even ma

Re: Using generics

2009-05-28 Thread Meikel Brandmeyer
Hi, Am 28.05.2009 um 23:23 schrieb tsuraan: I have a java class whose constructor expects (among other things) a BlockingQueue. It's easy to create a BlockingQueue in clojure (obviously), but I can't figure out the syntax to specialize it to the Long type. Is this possible, or does it even ma

Re: (gensym) not equivalent to #?

2009-05-28 Thread Meikel Brandmeyer
Hi, Am 28.05.2009 um 23:45 schrieb CuppoJava: Ah I see. So the foo# form does it's replacement at read-time. And gensym does it at runtime? I think so. Where "runtime" means "macro expansion time". Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature

Re: (gensym) not equivalent to #?

2009-05-28 Thread CuppoJava
Ah I see. So the foo# form does it's replacement at read-time. And gensym does it at runtime? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.

Re: (gensym) not equivalent to #?

2009-05-28 Thread Meikel Brandmeyer
Hi, Am 28.05.2009 um 23:29 schrieb CuppoJava: In my recent macro-writing adventure, I discovered that (gensym) is not actually equivalent to using #. Can someone explain to me how # actually works in backquoted form? The foo# form will replace the foo symbol statically in the syntax-quote for

(gensym) not equivalent to #?

2009-05-28 Thread CuppoJava
Hi, In my recent macro-writing adventure, I discovered that (gensym) is not actually equivalent to using #. Can someone explain to me how # actually works in backquoted form? eg. This doesn't work: (defmacro deftemp [name text] `(do (def temp# ~text) (defn ~name [] temp#))) In repl: (de

Re: Macro Writing Helper?

2009-05-28 Thread Sean Devlin
Likewise. Good discussion. On May 28, 4:49 pm, Meikel Brandmeyer wrote: > Hi, > > Am 28.05.2009 um 22:23 schrieb CuppoJava: > > > Thanks to Meikel and Sean for their input and help. > > You are welcome. :) > > Sincerely > Meikel > >  smime.p7s > 5KViewDownload --~--~-~--~~--

Using generics

2009-05-28 Thread tsuraan
I have a java class whose constructor expects (among other things) a BlockingQueue. It's easy to create a BlockingQueue in clojure (obviously), but I can't figure out the syntax to specialize it to the Long type. Is this possible, or does it even make sense? I seem to recall that generics are j

Re: Macro Writing Helper?

2009-05-28 Thread Meikel Brandmeyer
Hi, Am 28.05.2009 um 22:23 schrieb CuppoJava: Thanks to Meikel and Sean for their input and help. You are welcome. :) Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature

Re: Macro Writing Helper?

2009-05-28 Thread CuppoJava
Okay. So I grasped some understanding from going through Meikel's macro with a micron comb. Here's my version: it's a little more general (it can accept any number of arguments), and little cleaner. (defmacro defblockfn [function params & body] (let [butlast_params (butlast par

Re: Macro Writing Helper?

2009-05-28 Thread Daniel Lyons
On May 28, 2009, at 1:13 PM, Sean Devlin wrote: > 1. collect is the ruby version of map, not reduce. An interesting > use of reduce, though. For anyone keeping score, inject is Ruby's reduce. And Ruby has map, it's an alias to collect. > This is exactly why I think creating defblockfn is a

New reflection warning in r1381

2009-05-28 Thread kotor
After updating to r1381, the following code produces a "reflection warning - call to divide can't be resolved" on the last line. This warning did not occur at r1376 or earlier. (defn prime-frequency [x y] "integer integer -> real. frequency of primes in range" (let [xy (range x y)] (/ (coun

Instructions for Emacs+SLIME

2009-05-28 Thread Phil Hagelberg
I just posted some instructions for getting up and running with SLIME. I've seen a lot of folks get confused with some of the more convoluted tutorials out there, so I thought it'd be helpful to document the simplest way to get started that I know: http://technomancy.us/126 I welcome feedback

Re: Macro Writing Helper?

2009-05-28 Thread Sean Devlin
That's true. Good job Meikel, macro master! On May 28, 3:31 pm, CuppoJava wrote: > Correction: By "My macro" I, of course, mean "Meikel's macro" since > you're the one that actually got it working. > > Have to give credit where it's due. =) --~--~-~--~~~---~--~~

Re: Macro Writing Helper?

2009-05-28 Thread CuppoJava
Correction: By "My macro" I, of course, mean "Meikel's macro" since you're the one that actually got it working. Have to give credit where it's due. =) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group.

Re: Macro Writing Helper?

2009-05-28 Thread CuppoJava
Ah I understand now. That's a very useful technique for recursive backquotes. I'm going to be using it constantly now. Until I can reason about recursive backquotes in my head at least. My macro is a little simplified. It only works for functions that take no arguments. With a minimal change, you

Re: Macro Writing Helper?

2009-05-28 Thread Sean Devlin
Okay, good to know. It's interesting to see other approaches. It's how we collectively get better. My $.02: (with_file "myfile.txt" #(write "asdf") (close)) Sean On May 28, 3:23 pm, CuppoJava wrote: > It's useful in all the cases where a blocks are useful in Ruby. It > simply saves

Re: Macro Writing Helper?

2009-05-28 Thread Meikel Brandmeyer
Hi, Am 28.05.2009 um 21:10 schrieb CuppoJava: I find defblockfn very useful for functions that take a single function as one of the parameters. Macros are much harder and more error-prone to write than functions, so almost all of my macros do nothing but wrap a body in a function. Yes. This

Re: Macro Writing Helper?

2009-05-28 Thread CuppoJava
It's useful in all the cases where a blocks are useful in Ruby. It simply saves typing out "(fn [])" and IMO makes the code look a little cleaner. eg. (with_file "myfile.txt" (write "asdf") (close)) compared to. (with_file "myfile.txt" (fn [] (write "asdf") (close))) There's argua

Re: Macro Writing Helper?

2009-05-28 Thread Sean Devlin
On May 28, 3:10 pm, CuppoJava wrote: > Thank you Meikel for going to the trouble of writing out the full > macro. It's going to take me a while to decipher it, and hopefully > grasp some understanding at the end of it. "I find defblockfn very useful for functions that take a single function as

Re: Macro Writing Helper?

2009-05-28 Thread Sean Devlin
On May 28, 3:01 pm, Meikel Brandmeyer wrote: > Hi, > > Am 28.05.2009 um 20:11 schrieb Sean Devlin: > > > Without discussing a specific application, I think what you're looking > > for can be achieved by normal macros and functions in Clojure.  I'll > > try implement the collect method in Clojur

Re: Macro Writing Helper?

2009-05-28 Thread CuppoJava
Thank you Meikel for going to the trouble of writing out the full macro. It's going to take me a while to decipher it, and hopefully grasp some understanding at the end of it. I find defblockfn very useful for functions that take a single function as one of the parameters. Macros are much harder

Re: Macro Writing Helper?

2009-05-28 Thread Meikel Brandmeyer
Hi, Am 28.05.2009 um 20:11 schrieb Sean Devlin: Without discussing a specific application, I think what you're looking for can be achieved by normal macros and functions in Clojure. I'll try implement the collect method in Clojure, and hopefully that will explain things. Let's start by creati

Re: Macro Writing Helper?

2009-05-28 Thread Meikel Brandmeyer
Hi, Am 28.05.2009 um 18:50 schrieb CuppoJava: The macro I'm attempting to write is: (defblockfn my_block_fn [arg1 arg2 func] (op1 arg1) (func) (op2 arg2)) Becomes: (defn -my_block_fn [arg1 arg2 func] (op1 arg1) (func) (op2 arg2)) (defmacro my_block_fn [arg1 arg2 & tail] `(-my_block_fn

Re: Macro Writing Helper?

2009-05-28 Thread Sean Devlin
Okay, great. That's my background too. Without discussing a specific application, I think what you're looking for can be achieved by normal macros and functions in Clojure. I'll try implement the collect method in Clojure, and hopefully that will explain things. Let's start by creating a colle

Re: java -cp clojure.jar clojure.lang.Repl vs java -jar clojure.jar - a difference?

2009-05-28 Thread Jacek Laskowski
On Thu, May 28, 2009 at 12:55 PM, Michael Wood wrote: > If you advertise the "-jar" version, then people will get confused > when trying to use other jars, so it's better just to advertise "java > -cp clojure.jar clojure.lang.Repl". Although it's easier for newcomers (like me) to run the execut

Re: Macro Writing Helper?

2009-05-28 Thread CuppoJava
Haha. You got it. I discovered Lisp after using Ruby. Ruby was actually the language that helped me realize what a good idea functional programming is. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group.

Re: Macro Writing Helper?

2009-05-28 Thread Sean Devlin
Okay, this looks a lot like the ruby yeild statement. Is that what inspired you? On May 28, 12:50 pm, CuppoJava wrote: > That's unfortunate. It would have made matters much easier for me. > > The macro I'm attempting to write is: > > (defblockfn my_block_fn [arg1 arg2 func] >   (op1 arg1) >   (

Re: Macro Writing Helper?

2009-05-28 Thread CuppoJava
That's unfortunate. It would have made matters much easier for me. The macro I'm attempting to write is: (defblockfn my_block_fn [arg1 arg2 func] (op1 arg1) (func) (op2 arg2)) Becomes: (defn -my_block_fn [arg1 arg2 func] (op1 arg1) (func) (op2 arg2)) (defmacro my_block_fn [arg1 arg

Re: Macro Writing Helper?

2009-05-28 Thread Sean Devlin
CuppoJava, Could you give us a little more information what you're trying to do? What type of macro-macros are you writing? On May 28, 4:58 am, Konrad Hinsen wrote: > On 28.05.2009, at 03:11, CuppoJava wrote: > > > I'm using macroexpand-1 right now, but it's not terribly useful as > > backquote

Re: how would I do this functionally? (internally mutable state)

2009-05-28 Thread Korny Sietsma
Cool stuff - I really should go to bed now, but I'll look at this further in the morning. By the way, in response to whoever suggested pre-sorting files; I sort-of do this (in the old ruby version) but actually, mostly the program is looking for duplicate *directories* of files - the goal is to p

Re: a question about the definiton of the variable arity function in "Clojure: A Dynamic Programming Language for the JVM," by Rich Hickey

2009-05-28 Thread Stephen C. Gilardi
On May 28, 2009, at 6:57 AM, Baishampayan Ghose wrote: Or may be thisfn used to be something and doesn't exist anymore. That's right. Here's Rich's message about removing it: http://tinyurl.com/thisfn-removed --Steve smime.p7s Description: S/MIME cryptographic signature

Re: how would I do this functionally? (internally mutable state)

2009-05-28 Thread Korny Sietsma
Ah, sorry, I get it now - very cute! This is just the sort of thing I need to understand better - hard to break out of years of object-oriented thinking. - Korny On Thu, May 28, 2009 at 2:34 PM, Mikio Hokari wrote: > > Hash calculation runs only when necessary, because > Clojure's map function

Re: java -cp clojure.jar clojure.lang.Repl vs java -jar clojure.jar - a difference?

2009-05-28 Thread Stephen C. Gilardi
On May 28, 2009, at 6:55 AM, Michael Wood wrote: If you advertise the "-jar" version, then people will get confused when trying to use other jars, so it's better just to advertise "java -cp clojure.jar clojure.lang.Repl". +1 Also, clojure.lang.Repl is a legacy entry point. The current reco

Re: Concerns About Pushing Clojure 1.0.0 to Maven Central Repo?

2009-05-28 Thread Christian Vest Hansen
On Mon, May 18, 2009 at 8:59 AM, Stefan Hübner wrote: > > I've submitted the Maven bundle for Clojure 1.0.0 to > http://jira.codehaus.org/browse/MAVENUPLOAD-2464. Processing the request > might take a couple of days. The upload guide says four weeks. Repository synchronization is the long term s

Re: a question about the definiton of the variable arity function in "Clojure: A Dynamic Programming Language for the JVM," by Rich Hickey

2009-05-28 Thread Baishampayan Ghose
Benjamin L. Russell wrote: >> java.lang.Exception: Unable to resolve symbol: thisfn in this context >> (NO_SOURCE_FILE:6) >> [Thrown class clojure.lang.Compiler$CompilerException] > > However, no definition is given for "thisfn" in the talk. (defn argcount ([] 0) ([x] 1)

Re: java -cp clojure.jar clojure.lang.Repl vs java -jar clojure.jar - a difference?

2009-05-28 Thread Michael Wood
On Thu, May 28, 2009 at 9:26 AM, Jacek Laskowski wrote: > > Hi, > > Is there a difference between executing "java -cp clojure.jar > clojure.lang.Repl" and "java -jar clojure.jar"? Unless it is, the > later is easier and I think might ease http://clojure.org/dynamic. The difference comes in when

java -cp clojure.jar clojure.lang.Repl vs java -jar clojure.jar - a difference?

2009-05-28 Thread Jacek Laskowski
Hi, Is there a difference between executing "java -cp clojure.jar clojure.lang.Repl" and "java -jar clojure.jar"? Unless it is, the later is easier and I think might ease http://clojure.org/dynamic. Jacek -- Jacek Laskowski Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl --~--~---

a question about the definiton of the variable arity function in "Clojure: A Dynamic Programming Language for the JVM," by Rich Hickey

2009-05-28 Thread Benjamin L . Russell
On slide 20 of the talk "Clojure: A Dynamic Programming Language for the JVM" (see ftp://lispnyc.org/meeting-assets/2007-11-13_clojure/clojuretalk.pdf), by Rich Hickey, the following function and evaluation results are defined: >(defn argcount > ([] 0) > ([x] 1) > ([x y] 2) > ([x y & more] >

Re: how would I do this functionally? (internally mutable state)

2009-05-28 Thread Timothy Pratley
Hahaha - you beat me to it! I expect the memory usage would be dominated by the slurping (if there are large files), perhaps using a DigestInputStream avoids this? (I'm not familiar with it, but sounds... streamy). PS: you defined file- comparator but don't use it, your source could be even short

Re: how would I do this functionally? (internally mutable state)

2009-05-28 Thread Timothy Pratley
Thanks for the tip about lazy = Mikio! Wow Daniel, a very thorough description there - it seems file systems are close to your heart :) I've taken your design and implemented a variant on it: http://groups.google.com/group/clojure/web/find-duplicates.clj For this sort of domain I think memo

Re: how would I do this functionally? (internally mutable state)

2009-05-28 Thread Daniel Lyons
I have uploaded my solution to the Google group. It seems to work well for small directories but runs out of memory pretty quickly on a huge directory. I'd appreciate any help with making it more efficient or prettier. I'm sure I can drum up my own uses for this. Also, I thought I could use

Re: "Currying" / Partial Application macro

2009-05-28 Thread Michael Wood
On Thu, May 28, 2009 at 9:57 AM, kinghajj wrote: > > (defmacro $ [f & args] >  (let [args2 (gensym)] >    `(fn [& ~args2] >       (eval (cons (quote ~f) (concat (quote ~args) ~args2)) > > Example: > (def add5 ($ + 5)) > > (add5 3) This already exists :) user=> (doc partial)

Re: Macro Writing Helper?

2009-05-28 Thread Konrad Hinsen
On 28.05.2009, at 03:11, CuppoJava wrote: > I'm using macroexpand-1 right now, but it's not terribly useful as > backquotes expand to something nasty. > > Given: > (defmacro mymacro [] > `(level1 `(level2))) > > I would like to see it expanded to: > (user/level1 `(level2)) That's not possible,

Re: "Currying" / Partial Application macro

2009-05-28 Thread kinghajj
Here's a reason why a partial application macro is better than a partial application function: user=> ((partial or (prn "Hello")) (prn "World")) java.lang.Exception: Can't take value of a macro: #'clojure.core/or (NO_SOURCE_FILE:2) user=> (($ or (prn "Hello")) (prn "World")) "World" "Hello" nil

Re: "Currying" / Partial Application macro

2009-05-28 Thread Laurent PETIT
Here is a somewhat simpler definition :-) : user=> (def $ clojure.core/partial) #'user/$ user=> (def add5 ($ + 5)) #'user/add5 user=> (add5 3) 8 user=> But maybe you want the delayed evaluation of the already included arguments, but it is not clear to me from your e-mail (and your example that u

"Currying" / Partial Application macro

2009-05-28 Thread kinghajj
(defmacro $ [f & args] (let [args2 (gensym)] `(fn [& ~args2] (eval (cons (quote ~f) (concat (quote ~args) ~args2)) Example: (def add5 ($ + 5)) (add5 3) Beware! For this macro evaluates the later parameters before the partially-applied ones, so side-effectful parameters may occu

Re: how would I do this functionally? (internally mutable state)

2009-05-28 Thread Daniel Lyons
On May 28, 2009, at 12:35 AM, Mikio Hokari wrote: > >>> I wonder if there is a more idiomatic way to compare two lazy >>> sequences... lazily? > > You can just use =. I guess I'm imagining a group-by like Haskell's, which takes an equality comparison function and just returns a list of lists.

Re: how would I do this functionally? (internally mutable state)

2009-05-28 Thread Daniel Lyons
On May 28, 2009, at 12:35 AM, Mikio Hokari wrote: > >>> I wonder if there is a more idiomatic way to compare two lazy >>> sequences... lazily? > > You can just use =. > > (= seq1 seq2) > > It works lazily. > > user> (= (iterate inc 0) (map #(do (println %) %) [0 1 2 -3 4 5 6]) ) > 0 > 1 > 2 > -