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 winnowing, which might even be applicable to another  
program someday, maybe.

Anyway I uploaded it here:  and again I'd love any feedback anyone cares to give.

Just to add insult to injury, I went ahead and programmed it again in  
Ruby. The good news is that I can't seem to get Ruby to find all the  
files the Clojure one finds, but the bad news is that the Ruby version  
is like four times faster. I'd love to understand that. So I uploaded  
that too: . Of  
course it must be benefiting to some extent from the fact that the  
Ruby version has a lot less abstraction, but I don't see how the  
approach is fundamentally any different or why there would be such a  
large performance disparity. I must be missing something big.

On May 28, 2009, at 6:50 AM, Korny Sietsma wrote:
> 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 point it at my archive disk, and have it find the biggest identical
> subdirectories.  Duplicate file checking is needed for this, but it's
> only a tiny part.
>
> And I'm playing with sketching algorithms at work right now, which
> look very handy for the next phase, which is to find the biggest
> *similar* subdirectories.  That's the real goal - point a program at a
> terabyte archive disk, and have it spit out :
> "/archive/old_disks/laptop_2007a is 312gb and 99% similar to
> /archive/misc/stuff_from_2007"
> ... or sorting by file count:
> "/archive/source/old_projects/c_stuff/1996 is 20,324 files and 97%
> similar to /archive/old/disks/laptop2006/unsorted/old_drives/ 
> old_archive/c_cpp_stuff/90s"


I can think of three ways to approach this, none of which are  
particularly easy.

The first is to take the duplicate file finding function and look for  
common suffixes of paths. It could almost be like running a fuzzy  
duplicate finder against your duplicates. I suspect the performance  
here will blow for no particular reason I can put my finger on.

The second approach would be to use something like rsync's rolling  
checksum. I bet you could use a rather stupid heuristic to find  
candidate directories for similarity and then apply this algorithm  
amongst the candidates. It would be handy if you could have a version  
of diff that would look at two directories recursively and give up if  
they were sufficiently different.

Another option would be to ignore the filesystem altogether and look  
for runs of similar blocks on the device directly. For some reason I  
think this will perform better but it'll probably be harder to reason  
about during development and I doubt it will be a cakewalk from Java.

In any event, that's a very interesting problem, but for some reason  
it's setting off my alarm bells. I think if it's going to be useful  
it'll probably wind up being exponential time, and that compromises to  
make it run acceptably will probably wind up diminishing the value. I  
have no idea why I think these things though... maybe I'm just up too  
late.

Another point: most OSes and filesystems have a change notification  
API now (or an emulation of one) which you could use to maintain  
indices, if you want to do something more than once. This probably  
isn't relevant to this problem though. It's on my mind because I was  
just recently hacking on something for a friend that uses Mac OS X's  
API to do that.

Hope any of this helps and looking forward to (all) your feedback, :)

—
Daniel Lyons
http://www.storytotell.org -- Tell It!


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 worth a look.

-- 
Chris Wilson 

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 around since Clojure 1.0.

On May 28, 3:03 pm, kotor  wrote:
> 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)]
>     (/ (count (filter prime? xy)) (count xy
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 method in Number.java that accepts two
ints as arguments.  Right now there is a method with (int Object) and
(Object int), but not (int int).  While we are at it, we should
probably create the same method for other numeric types.  Just like
the other methods that call divide by changing the primitive to an
object and calling divide on the two, just make a call to divide with
both of them being objects, and you will get the same performance
without the reflection.  I would post the code, but I don't have a CA
turned in.

On May 28, 3:03 pm, kotor  wrote:
> 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)]
>     (/ (count (filter prime? xy)) (count xy
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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, and well used in a hurry.
>
> Congratulations Stuart!
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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() != other.quickhash()
>      return hash() != other.hash()
>   end
>
> quickhash and hash store their results in instance variables so they
> only need to do the expensive calculations once - and quite often they
> never need to get calculated at all

I'm surprised no-one has yet mentioned force and delay:

(defn exact-match [a b]
  (and (= (:size a) (:size b))
   (= (force (:quickhash a)) (force (:quickhash b)))
   (= (force (:hash a)) (force (:hash b)

- James
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 foo# form will replace the foo symbol statically in the
> syntax-quote form. So when you call deftemp the second
> time, you basically reassign the same Var you assigned
> to before.
>
> With gensym you always create a new symbols. Hence
> there is no conflict.

That's a fascinating point, and I hadn't considered it
before.  It's subtle enough it might be worth go over again.

Here are two functions the do roughly the same thing --
return a list with a single gensym'ed symbol in it:

(defn f-auto []
  `(foo#))

(defn f-gen []
  (let [foo (gensym "foo_")]
`(~foo)))

But when called multiple times, you can clearly see the
difference, where f-auto's auto-gensym produces the same
symbol every time:

user=> (f-gen)
(foo_442)
user=> (f-gen)
(foo_446)
user=> (f-gen)
(foo_450)

user=> (f-auto)
(foo__425__auto__)
user=> (f-auto)
(foo__425__auto__)
user=> (f-auto)
(foo__425__auto__)

Thanks for bringing this up.
--Chouser

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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.lang.Class.asSubclass(java.lang.Class)>
>
> This shows that the entry point is at some level "really" expecting a
> Class and returning a Class.

Yeah, that makes sense.  Thanks!

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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
ups, one for introspective debugging etc).

I used to have sbcl set up to work with clojure using the same config
(as per Bill's blog) but I found that really wasn't working for me and
I decided that to just have different init files.

Again great write up, the community of emacs and clojure users are
lucky to have you!

On Thu, May 28, 2009 at 12:54 PM, Phil Hagelberg  wrote:
>
>
> 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 on this, particularly about using Common Lisp
> together with Clojure as this supposedly makes things a bit trickier.
>
> Hope this is useful to folks getting started.
>
> -Phil
>
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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)
   (= :end (last args1)) (apply f (pop args1

I don't know if apply partial will work, and the arity and function
was pulled out of a hat. I'll get it working tonight.

But this should let you do

(((curry + 4 5 6)  6 8 10) 1 1 :end) => 41

or

(def add5 (curry #(+ %1 %2) 5))

(add5 6) => 11


I don't like the :end hack, but currying doesn't work with variable
arity functions otherwise.


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 make sense?  I seem to
recall that generics are just hints for the java compiler and not
actually enforced by the runtime, which would imply that clojure has
no need to support them.  Is that the case?


I think your conclusion is correct.

Here's an example with java.lang.Class and clojure.contrib.repl-utils/ 
show:


The Java 1.5 docs for Class.asSubClass show that it takes a generic as  
an argument and returns a generic:


 Class asSubclass(Class clazz)
	  Casts this Class object to represent a subclass of the  
class represented by the specified class object.


http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html

Compare that with the reflection info shown by clojure.contrib.repl- 
utils/show:


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.lang.Class.asSubclass(java.lang.Class)>


This shows that the entry point is at some level "really" expecting a  
Class and returning a Class.


I've done this in practice in a different context and it worked fine.

--Steve



smime.p7s
Description: S/MIME cryptographic signature


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 make sense?  I seem to
recall that generics are just hints for the java compiler and not
actually enforced by the runtime, which would imply that clojure has
no need to support them.  Is that the case?


Just ignore the generics. When you say in Java:

BlockingQueue q = new BlockingQueue();

you just say in Clojure:

(def q (BlockingQueue.))

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


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.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 form. So when you call deftemp the second
time, you basically reassign the same Var you assigned
to before.

With gensym you always create a new symbols. Hence
there is no conflict.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


(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:
(deftemp temp1 "temp1")
(deftemp temp2 "temp2")

(temp1) returns "temp2" <= incorrect.

BUT this does work:
(defmacro deftemp [name text]
  (let [temp (gensym "temp")]
`(do (def ~temp ~text)
 (defn ~name [] ~temp

In Repl:
(deftemp temp1 "temp1")
(deftemp temp2 "temp2")

(temp1) correct returns "temp1" <= correct.

I originally thought that # uses (gensym) internally. But it seems
that's not the case?
Thanks for your help
  -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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 just hints for the java compiler and not
actually enforced by the runtime, which would imply that clojure has
no need to support them.  Is that the case?

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 params)]
`(do (defn func# ~params ~...@body)
 (defmacro ~function [...@butlast_params & tail#]
   `(~'func# ~...@butlast_params (fn [] ~...@tail#))
-

This allows us to define "modifier" macros, like such:

(defblockfn with_surrounding_text [text func]
  (println text)
  (func)
  (println text))

And you can use it like such:

(with_surrounding_text "surround"
  (println "within surrounding text: line1")
  (println "within surrounding text: line2"))

I'm personally using it to wrap openGL commands:
(defblockfn with_shape [shape func]
  (glBegin shape)
  (func)
  (glEnd))

so that I can type:

(with_shape GL11/GL_QUADS
  (glVertex ...)
  (glVertex ...))

The point of this macro is not to accomplish any specific function.
It's to allow you to define your own "wrapping" functions.

Thanks to Meikel and Sean for their input and help.
  -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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 bad idea.  We
> already have a perfectly good macro facility in clojure.  Let's use
> what we've got.


I think between the #() reader macro and (fn) we're mostly covered. My  
0.02¢. :)

On May 28, 2009, at 1:23 PM, CuppoJava wrote:
> 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))


We've also got with-open already... http://clojure.org/api#toc612

(with-open [file (java.io.FileWriter. "write-test.txt")]
   (.write file "Hello"))

And doto: http://clojure.org/api#toc228

(doto (java.io.FileWriter. "write-test.txt")
   (.write "Hello")
   (.close))

And spit, if we're using Contrib:

(clojure.contrib.duck-streams/spit "write-test.txt" "Hello")

I think if there were a way to combine doto and with-open it would  
probably do what you want without needing another macro.

—
Daniel Lyons
http://www.storytotell.org -- Tell It!


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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)]
(/ (count (filter prime? xy)) (count xy

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 on this, particularly about using Common Lisp
together with Clojure as this supposedly makes things a bit trickier.

Hope this is useful to folks getting started.

-Phil

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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. =)
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 can write a version of
defblockfn that accepts functions that take arguments. This is as far
as Ruby takes the concept, and no further.

This allows us to write, for example:

(my_map list_of_numbers
  [num] (* num num))

It's up to you to judge whether this looks nice enough to consider
using it. In my opinion, this is starting to look a little
unappealing.
  -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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 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 arguably no difference. I just prefer the first one.
>   -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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 is very good style for macro writing. Most macros need
to control only a tiny bit of the evaluation. The rest can be safely
packed into a function which receives a thunk. This has many
advantages as I detailed in another mail of this thread.

I'm not sure your macro is too simple, though. I will have to have
look at the use cases I have for it. Whether it is powerful enough.


One technique, which was
helpful was to just call the defblockfn macro and then
expand the call to freshly defined macro.

(defblockfn foo [a b c] ...)
(macroexpand-1 '(foo :a :b :c))


Could you explain a bit more what you mean by that? I don't quite
understand what you're saying, but it sounds potentially very useful.


When you expand the defblockfn macro you get the "garbage" you
described for the inner macro. I just made outer macro useable.
Then I simply called it and expanded the resulting inner macro.
The you a nice expansion. As I showed in the example. First simply
use the defblockfn macro to define the foo macro. And then simply
macroexpand a call to it, to see whether it expands to the right thing.
It basically just one level of indirection.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


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 arguably no difference. I just prefer the first one.
  -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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 one of the parameters."

Could you provide and example?  I don't see how this isn't
accomplished by a normal function.


>
> 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.
>
> "One technique, which was
> helpful was to just call the defblockfn macro and then
> expand the call to freshly defined macro.
>
> (defblockfn foo [a b c] ...)
> (macroexpand-1 '(foo :a :b :c)) "
>
> Could you explain a bit more what you mean by that? I don't quite
> understand what you're saying, but it sounds potentially very useful.
>
> Thanks again
>   -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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 Clojure, and hopefully that will
> > explain things.
>
> > Let's start by creating a collect function.
>
> > (defn collect
> >  [pred coll]
> >  (loop [remaining coll
> >         output []]
> >    (if (empty? remaining)
> >      output
> >      (recur (rest remaining)
> >        (conj output (pred (first remaining)))
>
> This can be written more concise with reduce:
>
> (defn collect
>    [f coll]
>    (reduce #(conj %1 (f %2)) (empty coll) coll))
>
> Whenever you do loop/recur and return one argument
> when the input is used up, you probably can turn it into
> a nice reduce.

1.  collect is the ruby version of map, not reduce.  An interesting
use of reduce, though.
2.  I was trying to show how one would explicitly write map.  I agree,
using standard clojure is much much much better.

>
>
>
> > And a quick test shows
>
> > (collect (fn[x](* 2 x)) [1 2 3])
> > =>[2 4 6]
>
> > Notice that the clojure collect takes a function, pred as an
> > argument.  The s-expression (pred (first remaining)) automatically
> > applies the right function do to the *pure genius* that is eval.  It's
> > pretty slick.
>
> > Here's my best attempt at writing an all-purpose collect-m macro.
> > It's ugly, and I don't like it.
>
> > (defmacro collect-m
> >  [coll & body]
> >  `(let [~'pred (fn [~'elemen...@body)]
> >     (loop [~'remaining ~coll
> >         ~'output []]
> >    (if (empty? ~'remaining)
> >      ~'output
> >      (recur (rest ~'remaining)
> >        (conj ~'output (~'pred (first ~'remaining
>
> > (collect-m [1 2 3] (* 2 element))
> > =>[2 4 6]
>
> Please don't write a macro like that! This captures
> the names you chose for your locals. Imagine a
> call like this (collect-m (do-something-with-another pred) ...),
> where the pred comes from outside the macro. This
> call will fail, because you captured pred in your macro
> expansion. Use auto-gensym via the # suffix.
>
> `(let [pred# ...])
>
> This will generate and new symbol like pred__AUTO_412
> or something similar, which is unlikely to be used by the
> surrounding code, which calls the macro.
>
> The parameter problem can be solved by providing an
> additional parameter, which is then used in the function
> argument vector.
>

This is exactly the problem I wanted to highlight, thanks for
providing a better way to write that macro.

>
>
> > Notice that the term element is fixed as a parameter name.  I assume
> > that there is ONLY on input in the function.  The macro is ugly to
> > read.  Maybe someone else can do better.
>
> > Revisiting the function version, notice:
>
> > (collect (fn[x](* 2 x)) [1 2 3])
>
> > Feels very similar to
>
> > [1, 2, 3].collect(){|x| 2*x}
>
> > You have much more control of the function.
>
> > The main point I'm getting at is that I don't think the blockfn macro
> > approach is the way to go.  Either write a function that take
> > functions, or use a traditional macro.
>
> I find this defblockfn actually quite interesting. A lot of macros
> boil down to wrap some body in a thunk and pass it to a driver
> function, which does the work, which can be defered to runtime.
> This approach has several advantages:
>
> - smaller code size since the macro expands to a simply function call
> - changing the logic in the driver function does not require  
> recompilation
>    of the macro users.
> - the driver function is easier to write than the macro
>
> So maybe 95% of my macros are paired with a function.
>

This is exactly why I think creating defblockfn is a bad idea.  We
already have a perfectly good macro facility in clojure.  Let's use
what we've got.

> YMMV of course...
>
> Sincerely
> Meikel
>
>  smime.p7s
> 5KViewDownload
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 and more error-prone to write than functions,
so almost all of my macros do nothing but wrap a body in a function.

"One technique, which was
helpful was to just call the defblockfn macro and then
expand the call to freshly defined macro.

(defblockfn foo [a b c] ...)
(macroexpand-1 '(foo :a :b :c)) "

Could you explain a bit more what you mean by that? I don't quite
understand what you're saying, but it sounds potentially very useful.

Thanks again
  -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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 creating a collect function.

(defn collect
 [pred coll]
 (loop [remaining coll
output []]
   (if (empty? remaining)
 output
 (recur (rest remaining)
   (conj output (pred (first remaining)))


This can be written more concise with reduce:

(defn collect
  [f coll]
  (reduce #(conj %1 (f %2)) (empty coll) coll))

Whenever you do loop/recur and return one argument
when the input is used up, you probably can turn it into
a nice reduce.


And a quick test shows

(collect (fn[x](* 2 x)) [1 2 3])
=>[2 4 6]

Notice that the clojure collect takes a function, pred as an
argument.  The s-expression (pred (first remaining)) automatically
applies the right function do to the *pure genius* that is eval.  It's
pretty slick.

Here's my best attempt at writing an all-purpose collect-m macro.
It's ugly, and I don't like it.

(defmacro collect-m
 [coll & body]
 `(let [~'pred (fn [~'elemen...@body)]
(loop [~'remaining ~coll
~'output []]
   (if (empty? ~'remaining)
 ~'output
 (recur (rest ~'remaining)
   (conj ~'output (~'pred (first ~'remaining

(collect-m [1 2 3] (* 2 element))
=>[2 4 6]


Please don't write a macro like that! This captures
the names you chose for your locals. Imagine a
call like this (collect-m (do-something-with-another pred) ...),
where the pred comes from outside the macro. This
call will fail, because you captured pred in your macro
expansion. Use auto-gensym via the # suffix.

`(let [pred# ...])

This will generate and new symbol like pred__AUTO_412
or something similar, which is unlikely to be used by the
surrounding code, which calls the macro.

The parameter problem can be solved by providing an
additional parameter, which is then used in the function
argument vector.


Notice that the term element is fixed as a parameter name.  I assume
that there is ONLY on input in the function.  The macro is ugly to
read.  Maybe someone else can do better.

Revisiting the function version, notice:

(collect (fn[x](* 2 x)) [1 2 3])

Feels very similar to

[1, 2, 3].collect(){|x| 2*x}

You have much more control of the function.

The main point I'm getting at is that I don't think the blockfn macro
approach is the way to go.  Either write a function that take
functions, or use a traditional macro.


I find this defblockfn actually quite interesting. A lot of macros
boil down to wrap some body in a thunk and pass it to a driver
function, which does the work, which can be defered to runtime.
This approach has several advantages:

- smaller code size since the macro expands to a simply function call
- changing the logic in the driver function does not require  
recompilation

  of the macro users.
- the driver function is easier to write than the macro

So maybe 95% of my macros are paired with a function.

YMMV of course...

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


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 arg1 arg2 (fn [] ~...@tail)))

The recursive backquotes are really confusing me. I would be extremely
appreciative if someone can explain step-by-step how to reason with
backquotes within backquotes.


(defmacro defblockfn
  [fn-name args & body]
  (let [fn-name-star (symbol (name (ns-name *ns*))
 (str (name fn-name) "*"))]
`(do
   (defn ~fn-name-star
 ~args
 ~...@body)
   (defmacro ~fn-name
 [a# b# & tail#]
 `(~'~fn-name-star ~a# ~b# (fn [] ~...@tail#))

You are right with the nested backticks. It's confusing.
I didn't find out how to resolve function name other
than doing it explicitly. One technique, which was
helpful was to just call the defblockfn macro and then
expand the call to freshly defined macro.

(defblockfn foo [a b c] ...)
(macroexpand-1 '(foo :a :b :c))

Hope this helps.

Sincerely
Meikel



smime.p7s
Description: S/MIME cryptographic signature


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 collect function.

(defn collect
  [pred coll]
  (loop [remaining coll
 output []]
(if (empty? remaining)
  output
  (recur (rest remaining)
(conj output (pred (first remaining)))

And a quick test shows

(collect (fn[x](* 2 x)) [1 2 3])
=>[2 4 6]

Notice that the clojure collect takes a function, pred as an
argument.  The s-expression (pred (first remaining)) automatically
applies the right function do to the *pure genius* that is eval.  It's
pretty slick.

Here's my best attempt at writing an all-purpose collect-m macro.
It's ugly, and I don't like it.

(defmacro collect-m
  [coll & body]
  `(let [~'pred (fn [~'elemen...@body)]
 (loop [~'remaining ~coll
 ~'output []]
(if (empty? ~'remaining)
  ~'output
  (recur (rest ~'remaining)
(conj ~'output (~'pred (first ~'remaining

(collect-m [1 2 3] (* 2 element))
=>[2 4 6]

Notice that the term element is fixed as a parameter name.  I assume
that there is ONLY on input in the function.  The macro is ugly to
read.  Maybe someone else can do better.

Revisiting the function version, notice:

(collect (fn[x](* 2 x)) [1 2 3])

Feels very similar to

[1, 2, 3].collect(){|x| 2*x}

You have much more control of the function.

The main point I'm getting at is that I don't think the blockfn macro
approach is the way to go.  Either write a function that take
functions, or use a traditional macro.

Hope this helps.

Sean


On May 28, 1:37 pm, CuppoJava  wrote:
> 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.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 executable jar
I can see some value of the doc with the cp parameter in. Thanks for
explanation.

Jacek

-- 
Jacek Laskowski
Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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)
>   (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 arg1 arg2 (fn [] ~...@tail)))
>
> The recursive backquotes are really confusing me. I would be extremely
> appreciative if someone can explain step-by-step how to reason with
> backquotes within backquotes.
>   -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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 arg2 & tail]
  `(-my_block_fn arg1 arg2 (fn [] ~...@tail)))

The recursive backquotes are really confusing me. I would be extremely
appreciative if someone can explain step-by-step how to reason with
backquotes within backquotes.
  -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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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
> > 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, because the replacement happens *before* macro  
> expansion. The backquote is expanded by the reader.
>
> To see what happens, just type
>
>         `(level1 `(level2))
>
> into the REPL. The result is
>
>         (user/level1 (clojure.core/seq (clojure.core/concat (clojure.core/
> list (quote user/level2)
>
> Konrad.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 point it at my archive disk, and have it find the biggest identical
subdirectories.  Duplicate file checking is needed for this, but it's
only a tiny part.

And I'm playing with sketching algorithms at work right now, which
look very handy for the next phase, which is to find the biggest
*similar* subdirectories.  That's the real goal - point a program at a
terabyte archive disk, and have it spit out :
"/archive/old_disks/laptop_2007a is 312gb and 99% similar to
/archive/misc/stuff_from_2007"
... or sorting by file count:
"/archive/source/old_projects/c_stuff/1996 is 20,324 files and 97%
similar to 
/archive/old/disks/laptop2006/unsorted/old_drives/old_archive/c_cpp_stuff/90s"

- Korny (who may have made some bad decisions in the past about how to
archive files. Many times. :)

On Thu, May 28, 2009 at 7:06 PM, Timothy Pratley
 wrote:
>
> 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 memorizing is possibly a bad idea -
> what if the file gets replaced - kind of defeats the purpose?
> This solution only checks the minimal amount of information which is
> great. But actually I suspect a more useful application would like to
> check file additions also. We can avoid even more work if we are
> willing to retain a uniqueness tree, however this is again susceptible
> to the files changing underneath and would only work if all additions
> and removals were controlled.
>
> In retrospect, reduce-by pretty much mirrors group-by... I should have
> looked at that first!
>
>
> Regards,
> Tim.
>
>
>
> >
>



-- 
Kornelis Sietsma  korny at my surname dot com
"Every jumbled pile of person has a thinking part
that wonders what the part that isn't thinking
isn't thinking of"

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 is lazy now.
>
> more sample code:
>
> (nth (get-info "a.txt") 0)
> (nth (get-info "b.txt") 0)
> (nth (get-info "b.txt") 1)
>
> result:
> size a.txt
> size b.txt
> quickhash b.txt
>
> Output result shows it.
> When
>  (nth (get-info "a.txt") 0)
> is evaluated, only get-size function runs.
> Evaluation of get-quickhash and get-hash is delayed.
>
> Eval
>  (nth (get-info "a.txt") 1)
> cause evaluation of get-quickhash,
> but not get-hash.
>
> 2009/5/28 Timothy Pratley :
>>
>> Sounds like a job for lazy-map to me!
>> http://kotka.de/projects/clojure/lazy-map.html
>>
>>
>> On May 28, 11:52 am, Korny Sietsma  wrote:
>>> Hi all,
>>>
>>> I have some ruby code that I'm thinking of porting to clojure, but I'm
>>> not sure how to translate this idiom to a functional world:
>>> I have objects that are externally immutable, but have internal
>>> mutable state they use for optimisation, specifically in this case to
>>> defer un-needed calculations.
>>>
>>> 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() != other.quickhash()
>>>      return hash() != other.hash()
>>>   end
>>>
>>> quickhash and hash store their results in instance variables so they
>>> only need to do the expensive calculations once - and quite often they
>>> never need to get calculated at all;  I'm looking for duplicate files,
>>> but many files have no duplicate, so probably never need to have their
>>> contents hashed.
>>>
>>> How would I do this in a functional way?  My first effort would be
>>> something like
>>>     (defn hash [filename] (memoize (... hash function ...)))
>>> but I have a couple of problems with this:
>>>   - it doesn't seem to store the hash value with the rest of the file
>>> information, which feels a bit ugly
>>>   - I assume it means storing the full filename three times, once in
>>> the original file info structure, once in the memoized hash function,
>>> and once in the memoized quickhash function.  My program struggles to
>>> get enough RAM to track as many files as I'd like already - storing
>>> the filename multiple times would blow out memory quite badly.
>>>
>>> I guess I could define a unique key for each filename, and define hash
>>> as a function on that key, but then hash would need to be able to
>>> access the list of filenames somehow.  It's starting to get beyond me
>>> - I'm hoping there's a simpler option!
>>>
>>> Any suggestions?  I'd hope this is not an uncommon idiom.
>>>
>>> - Korny
>>>
>>> --
>>> Kornelis Sietsma  korny at my surname dot com
>>> "Every jumbled pile of person has a thinking part
>>> that wonders what the part that isn't thinking
>>> isn't thinking of"
>> >
>>
>
> >
>



-- 
Kornelis Sietsma  korny at my surname dot com
"Every jumbled pile of person has a thinking part
that wonders what the part that isn't thinking
isn't thinking of"

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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  
recommended entry point is clojure.main:


java -cp clojure.jar clojure.main

and

java -cp clojure.jar:clojure-contrib.jar:some-other.jar clojure.main

See also:

java -cp clojure.jar clojure.main -h

http://clojure.org/repl_and_main

--Steve



smime.p7s
Description: S/MIME cryptographic signature


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 solution, I think.

>
> Once the bundle is uploaded to Central, one of the following two
> snippets can be used to declare a dependency to Clojure:
>
> 
> 
>  org.clojure
>  clojure
>  1.0.0
> 
>
> 
> 
>  org.clojure
>  clojure
>  1.0.0
>  slim
> 
>
> I'll submit patches to reflect the changed POM.
>
> Thank you all for your support!
> Stefan Hübner
>
>
> >
>



-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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)
([x y] 2)
([x y & more]
   (+ (argcount x y) (count more

Replace thisfn with argcount and it should work. That was just a
placeholder or something which Rich forgot to fix in the slides.

Or may be thisfn used to be something and doesn't exist anymore.

Regards,
BG

-- 
Baishampayan Ghose 
oCricket.com



signature.asc
Description: OpenPGP digital signature


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 you want to add other libraries.

You can do:

java -cp clojure.jar:clojure-contrib.jar:some-other.jar clojure.lang.Repl

but not:

java -cp clojure-contrib.jar:some-other.jar -jar clojure.jar

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".

-- 
Michael Wood 

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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]
> (+ (thisfn x y) (count more
>
>(argcount 1 2 3 4 5)
>-> 5

However, when I evaluate this function in the REPL, the following
error is returned:

>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.

Forgive me if I am missing something very obvious, but does anybody
know where I can find the definition of "thisfn"?

-- Benjamin L. Russell
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
"Furuike ya, kawazu tobikomu mizu no oto." 
-- Matsuo Basho^ 


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 shorter :P


On May 28, 7:05 pm, Daniel Lyons  wrote:
> 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 -> in find-duplicate-files but it didn't  
> seem to work out the way I thought it would.
>
> Style hints would be greatly appreciated as well. :)
>
> Thanks,
>
> http://clojure.googlegroups.com/web/file_dup_finder.clj
>
> On May 27, 2009, at 11:51 PM, Timothy Pratley wrote:
>
>
>
>
>
> > Yes that is a very elegant solution.
> > For convenience you might want another function:
> > (defn fast-compare
> >  "Given two filenames returns true if the files are identical"
> >  [fn1 fn2]
> >  (let [i1 (get-info fn1), i2 (get-info fn2)]
> >    (and (= (first i1) (first i2))
> >         (= (second i1) (second i2))
> >         (= (third i1) (third i2)
>
> > I wonder if there is a more idiomatic way to compare two lazy
> > sequences... lazily?
>
> > Regarding lazy-hash-map it just allows you to name the fields instead
> > of using an index, but I think without is better for something that
> > can be expressed like you have. No need for an external dependency.
> > (ooops I called it lazy-map before).
>
> > Regards,
> > Tim.
>
> > On May 28, 2:34 pm, Mikio Hokari  wrote:
> >> Hash calculation runs only when necessary, because
> >> Clojure's map function is lazy now.
>
> >> more sample code:
>
> >> (nth (get-info "a.txt") 0)
> >> (nth (get-info "b.txt") 0)
> >> (nth (get-info "b.txt") 1)
>
> >> result:
> >> size a.txt
> >> size b.txt
> >> quickhash b.txt
>
> >> Output result shows it.
> >> When
> >>  (nth (get-info "a.txt") 0)
> >> is evaluated, only get-size function runs.
> >> Evaluation of get-quickhash and get-hash is delayed.
>
> >> Eval
> >>  (nth (get-info "a.txt") 1)
> >> cause evaluation of get-quickhash,
> >> but not get-hash.
>
> >> 2009/5/28 Timothy Pratley :
>
> >>> Sounds like a job for lazy-map to me!
> >>>http://kotka.de/projects/clojure/lazy-map.html
>
> >>> On May 28, 11:52 am, Korny Sietsma  wrote:
>  Hi all,
>
>  I have some ruby code that I'm thinking of porting to clojure,  
>  but I'm
>  not sure how to translate this idiom to a functional world:
>  I have objects that are externally immutable, but have internal
>  mutable state they use for optimisation, specifically in this  
>  case to
>  defer un-needed calculations.
>
>  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() != other.quickhash()
>       return hash() != other.hash()
>    end
>
>  quickhash and hash store their results in instance variables so  
>  they
>  only need to do the expensive calculations once - and quite often  
>  they
>  never need to get calculated at all;  I'm looking for duplicate  
>  files,
>  but many files have no duplicate, so probably never need to have  
>  their
>  contents hashed.
>
>  How would I do this in a functional way?  My first effort would be
>  something like
>      (defn hash [filename] (memoize (... hash function ...)))
>  but I have a couple of problems with this:
>    - it doesn't seem to store the hash value with the rest of the  
>  file
>  information, which feels a bit ugly
>    - I assume it means storing the full filename three times, once  
>  in
>  the original file info structure, once in the memoized hash  
>  function,
>  and once in the memoized quickhash function.  My program  
>  struggles to
>  get enough RAM to track as many files as I'd like already - storing
>  the filename multiple times would blow out memory quite badly.
>
>  I guess I could define a unique key for each filename, and define  
>  hash
>  as a function on that key, but then hash would need to be able to
>  access the list of filenames somehow.  It's starting to get  
>  beyond me
>  - I'm hoping there's a simpler option!
>
>  Any suggestions?  I'd hope this is not an uncommon idiom.
>
>  - Korny
>
>  --
>  Kornelis Sietsma  korny at my surname dot com
>  "Every jumbled pile of person has a thinking part
>  that wonders what the part that isn't thinking
>  isn't thinking of"
>
> —
> Daniel Lyonshttp://www.storytotell.org-- Tell It!
--~--~-~-

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 memorizing is possibly a bad idea -
what if the file gets replaced - kind of defeats the purpose?
This solution only checks the minimal amount of information which is
great. But actually I suspect a more useful application would like to
check file additions also. We can avoid even more work if we are
willing to retain a uniqueness tree, however this is again susceptible
to the files changing underneath and would only work if all additions
and removals were controlled.

In retrospect, reduce-by pretty much mirrors group-by... I should have
looked at that first!


Regards,
Tim.



--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 -> in find-duplicate-files but it didn't  
seem to work out the way I thought it would.

Style hints would be greatly appreciated as well. :)

Thanks,

http://clojure.googlegroups.com/web/file_dup_finder.clj

On May 27, 2009, at 11:51 PM, Timothy Pratley wrote:

>
> Yes that is a very elegant solution.
> For convenience you might want another function:
> (defn fast-compare
>  "Given two filenames returns true if the files are identical"
>  [fn1 fn2]
>  (let [i1 (get-info fn1), i2 (get-info fn2)]
>(and (= (first i1) (first i2))
> (= (second i1) (second i2))
> (= (third i1) (third i2)
>
> I wonder if there is a more idiomatic way to compare two lazy
> sequences... lazily?
>
>
> Regarding lazy-hash-map it just allows you to name the fields instead
> of using an index, but I think without is better for something that
> can be expressed like you have. No need for an external dependency.
> (ooops I called it lazy-map before).
>
>
> Regards,
> Tim.
>
> On May 28, 2:34 pm, Mikio Hokari  wrote:
>> Hash calculation runs only when necessary, because
>> Clojure's map function is lazy now.
>>
>> more sample code:
>>
>> (nth (get-info "a.txt") 0)
>> (nth (get-info "b.txt") 0)
>> (nth (get-info "b.txt") 1)
>>
>> result:
>> size a.txt
>> size b.txt
>> quickhash b.txt
>>
>> Output result shows it.
>> When
>>  (nth (get-info "a.txt") 0)
>> is evaluated, only get-size function runs.
>> Evaluation of get-quickhash and get-hash is delayed.
>>
>> Eval
>>  (nth (get-info "a.txt") 1)
>> cause evaluation of get-quickhash,
>> but not get-hash.
>>
>> 2009/5/28 Timothy Pratley :
>>
>>
>>
>>> Sounds like a job for lazy-map to me!
>>> http://kotka.de/projects/clojure/lazy-map.html
>>
>>> On May 28, 11:52 am, Korny Sietsma  wrote:
 Hi all,
>>
 I have some ruby code that I'm thinking of porting to clojure,  
 but I'm
 not sure how to translate this idiom to a functional world:
 I have objects that are externally immutable, but have internal
 mutable state they use for optimisation, specifically in this  
 case to
 defer un-needed calculations.
>>
 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() != other.quickhash()
  return hash() != other.hash()
   end
>>
 quickhash and hash store their results in instance variables so  
 they
 only need to do the expensive calculations once - and quite often  
 they
 never need to get calculated at all;  I'm looking for duplicate  
 files,
 but many files have no duplicate, so probably never need to have  
 their
 contents hashed.
>>
 How would I do this in a functional way?  My first effort would be
 something like
 (defn hash [filename] (memoize (... hash function ...)))
 but I have a couple of problems with this:
   - it doesn't seem to store the hash value with the rest of the  
 file
 information, which feels a bit ugly
   - I assume it means storing the full filename three times, once  
 in
 the original file info structure, once in the memoized hash  
 function,
 and once in the memoized quickhash function.  My program  
 struggles to
 get enough RAM to track as many files as I'd like already - storing
 the filename multiple times would blow out memory quite badly.
>>
 I guess I could define a unique key for each filename, and define  
 hash
 as a function on that key, but then hash would need to be able to
 access the list of filenames somehow.  It's starting to get  
 beyond me
 - I'm hoping there's a simpler option!
>>
 Any suggestions?  I'd hope this is not an uncommon idiom.
>>
 - Korny
>>
 --
 Kornelis Sietsma  korny at my surname dot com
 "Every jumbled pile of person has a thinking part
 that wonders what the part that isn't thinking
 isn't thinking of"
> >

—
Daniel Lyons
http://www.storytotell.org -- Tell It!


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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)
-
clojure.core/partial
([f arg1] [f arg1 arg2] [f arg1 arg2 arg3] [f arg1 arg2 arg3 & more])
  Takes a function f and fewer than the normal arguments to f, and
  returns a fn that takes a variable number of additional args. When
  called, the returned function calls f with args + additional args.
nil
user=> (def add5 (partial + 5))
#'user/add5
user=> (add5 3)
8

-- 
Michael Wood 

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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, because the replacement happens *before* macro  
expansion. The backquote is expanded by the reader.

To see what happens, just type

`(level1 `(level2))

into the REPL. The result is

(user/level1 (clojure.core/seq (clojure.core/concat (clojure.core/ 
list (quote user/level2)

Konrad.

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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
user=> (or (prn "Hello") (prn "World"))
"Hello"
"World"
nil

This shows what I mean about evaluation: the parameter (prn "World")
gets evaluated before (prn "Hello"), so the messages get sent in a
different order than if you had not used partial application. I tried
to figure out a way for a macro to return a macro, to try to further
delay the evaluation of the non-partially-applied parameters, but
couldn't figure out a way to do it.

Thanks for showing me the auto-gensym facility. I couldn't look up the
documentation when I wrote this because my internet was out. All I had
to consort me was core.clj.

On May 28, 1:22 am, Laurent PETIT  wrote:
> 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 uses a literal integer), and it's also not clear to me
> what uses cases may require this macro. Could you elaborate a little
> more on the subject ?
>
> Please also note the gensym facility of clojure (get rid  of the
> gensym, and autocreate a gensym by suffixing a # to a symbol inside a
> syntax quote expression) :
>
> (defmacro $ [f & args]
>    `(fn [& args2#]
>       (eval (cons (quote ~f) (concat (quote ~args) args2#)
>
> See:
> user=> (macroexpand `(args2# args2#))
> (args2__44__auto__ args2__44__auto__)
> user=>
>
> Regards,
>
> --
> Laurent
>
> 2009/5/28 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 occur in an
> > unexpected order.
>
>
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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 uses a literal integer), and it's also not clear to me
what uses cases may require this macro. Could you elaborate a little
more on the subject ?

Please also note the gensym facility of clojure (get rid  of the
gensym, and autocreate a gensym by suffixing a # to a symbol inside a
syntax quote expression) :

(defmacro $ [f & args]
   `(fn [& args2#]
  (eval (cons (quote ~f) (concat (quote ~args) args2#)

See:
user=> (macroexpand `(args2# args2#))
(args2__44__auto__ args2__44__auto__)
user=>

Regards,

-- 
Laurent

2009/5/28 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 occur in an
> unexpected order.
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



"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 occur in an
unexpected order.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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. Which  
would look like this:

(defn span [f coll]
   (if (empty? coll)
   ['() '()]
 (if (f (first coll))
(let [[more & rest] (span f rest)]
  [(cons (first coll) more) rest])
   ['() coll])))

(defn group-by [f [x & xs :as coll]]
   (if (empty? coll)
   '()
 (let [[ys zs] (span #(f x %) xs)]
   (cons (cons x ys) (lazy-seq (group-by f zs))

Now you ought to be able to do this with = on a sorted list as I  
described in the huge message I sent a bit ago. (remove #(= (length %)  
1) (group-by = (sort ...))). Sorting is still the question for me  
though.

—
Daniel Lyons
http://www.storytotell.org -- Tell It!


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



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
> -3
> false

Seems odd to me that = works with sequences but compare doesn't. Is  
this a Java thing?

In other words, it seems odd that this works:

user> (defn get-comparators [str]
   (cons (nth str 0)
(lazy-seq (do
  (println "Looking at second element")
  (Thread/sleep 1000)
  (list (nth str 1))

user>  (sort-by get-comparators = ["ab" "cd" "ef" "gh"])
("ab" "cd" "ef" "gh")

But this doesn't:

user>  (sort-by get-comparators ["ab" "cd" "ef" "gh"])
java.lang.RuntimeException: java.lang.RuntimeException:  
java.lang.ClassCastException: clojure.lang.Cons (NO_SOURCE_FILE:0)
   [Thrown class clojure.lang.Compiler$CompilerException]

(Of course, if you use = instead of compare, it won't really sort the  
list...)

—
Daniel Lyons
http://www.storytotell.org -- Tell It!


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---