Scoping question

2009-05-27 Thread Mark Engelberg

Is there any practical difference between:

(let [x 2]
  (defn f [] x))

and

(def f (let [x 2] (fn [] x)))?

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



Rich Hickey interview from QCon London

2009-05-27 Thread Stephen C. Gilardi
For those without a Google Alert set up for Clojure:

"In this interview taped at QCon London 2009 Rich Hickey talks about  
Clojure, shortly before the 1.0 release."

http://www.infoq.com/news/2009/05/hickey-clojure

42 minute video:

http://www.infoq.com/interviews/hickey-clojure

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Clojure equivalent to Ruby's ERB

2009-05-27 Thread markgunnels

Hopefully this doesn't get me booed off the message board but is there
a Clojure equivalent to Ruby's ERB? I'm try to use Clojure to perform
code generation and, while it makes for an excellent language to write
a parser in, I can't quite figure out the best way to actually
template out the code.

Thanks for any help,
Mark

P.S. Rich -- if you read this, Clojure is terrific.

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



Exit from clojure box?

2009-05-27 Thread Muhammad Alkarouri

Hi everyone,

I have just started learning Clojure, and I found Clojure Box (http://
clojure.bighugh.com/) to be an easy installation for that.
Unfortunately, I am not sure about the right way to exit from the
prompt.
After starting Clojure Box and using the prompt (possibly including
loading and saving files), when I try to exit using C-x C-c I get the
message "Active processes exist; kill them and exit anyway? (yes or
no)" which tries to kill SLIME Lisp and inferior-lisp buffers.
Answering yes will kill them and exit, but is this the proper way, or
is there a more sensible one?

Many thanks in advance,

Muhammad Alkarouri

--~--~-~--~~~---~--~~
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: Exit from clojure box?

2009-05-27 Thread Baishampayan Ghose

> I have just started learning Clojure, and I found Clojure Box (http://
> clojure.bighugh.com/) to be an easy installation for that.
> Unfortunately, I am not sure about the right way to exit from the
> prompt.
> After starting Clojure Box and using the prompt (possibly including
> loading and saving files), when I try to exit using C-x C-c I get the
> message "Active processes exist; kill them and exit anyway? (yes or
> no)" which tries to kill SLIME Lisp and inferior-lisp buffers.
> Answering yes will kill them and exit, but is this the proper way, or
> is there a more sensible one?

In the SLIME REPL, press , (comma) and then type 'quit' and press Enter.

That'd close your REPL gracefully after which you can exit Emacs by
pressing C-x C-c.

Regards,
BG

-- 
Baishampayan Ghose 
oCricket.com



signature.asc
Description: OpenPGP digital signature


Re: Scoping question

2009-05-27 Thread Rich Hickey



On May 27, 4:12 am, Mark Engelberg  wrote:
> Is there any practical difference between:
>
> (let [x 2]
>   (defn f [] x))
>
> and
>
> (def f (let [x 2] (fn [] x)))?

No, are you experiencing one?

Rich
--~--~-~--~~~---~--~~
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: Clojure equivalent to Ruby's ERB

2009-05-27 Thread Krukow

On May 27, 4:47 am, markgunnels  wrote:
> Hopefully this doesn't get me booed off the message board but is there
> a Clojure equivalent to Ruby's ERB?

I don't think there is a Clojure equivalent (i.e. for general purpose
text generation), but given Clojure's great Java integration you could
easily use e.g. Freemarker. An advantage here is that you can use
Clojure datastructures (think PersistentHashMap, PersistentVector) as
Freemarker models.

There is also StringTemplate which is a functional approach to
templating which might match Clojure better (but I haven't tried out
ST).

If you are doing HTML/XML generation I think there are many pure-
Clojure options...

/Karl
--~--~-~--~~~---~--~~
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: Scoping question

2009-05-27 Thread Mark Engelberg

No, I was just worried that using def/defn not at the top level, but
inside a let, might have unforeseen consequences.

On Wed, May 27, 2009 at 3:48 AM, Rich Hickey  wrote:
> No, are you experiencing one?
>

--~--~-~--~~~---~--~~
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: svn r1370 appears to have broken binding

2009-05-27 Thread Frantisek Sodomka

Thanks for the help and your feedback, Steve!

Clojure needs some unit tests and I like writing them, so it is a win-
win situation :-)

Yes, this is our first test in clojure-contrib.test-clojure.vars. I
checked it in together with other changes as revision 846.

Frantisek


On May 26, 9:27 pm, "Stephen C. Gilardi"  wrote:
> Hi Frantisek!
>
> On May 25, 2009, at 7:11 AM, Frantisek Sodomka wrote:
>
> > (def a)
> > (deftest test-binding
> >  (are (= _1 _2)
> >      (binding [a 4] a) 4     ; regression in Clojure SVN r1370
> >  ))
>
> I see those tests going in over time... Thanks so much for making them!
>
> The checkin notes for this change mention "top level". I suspect  
> that's related to why the test you posted gave a false pass.
>
> We can use eval to bring the test up to the top level:
>
>         (def a)
>         (deftest test-binding
>          (are (= _1 _2)
>               (eval `(binding [a 4] a)) 4     ; regression in Clojure SVN 
> r1370
>          ))
>
> This passes with r1375 and fails with r1370.
>
> Will this be our first test in clojure-contrib.test-clojure.vars?
>
> Feel free to check this in or let me know if you'd like me to.
>
> Thanks,
>
> --Steve
>
>  smime.p7s
> 3KViewDownload
--~--~-~--~~~---~--~~
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: ns :use with :rename

2009-05-27 Thread tsuraan

> Here's the correct syntax:
>
> (ns namespace
>(:use [other-namespace :rename {existing newname}]))

aha, brackets.  Is there a plan to flesh out the API page to have more
examples of things like that?  As it stands, I think the API page is
probably great for somebody who needs a reminder, but for a newbie, it
could probably be a little more friendly.

--~--~-~--~~~---~--~~
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: Clojure equivalent to Ruby's ERB

2009-05-27 Thread ritchie turner

Hi there

Find attached some code that uses apache velocity for command line based
processing, i.e. it's not setup for servlets; i use this as an offline
pre processor for web sites.

It does hierarchical templating of files in a source directory and
copies to a target directory. The templating maps are contained in (by
default) __pp.clj files in the source tree. Further, your __pp.clj maps
can also contain functions for dynamically populating the template.

The nice thing is that each directory can contain it's own __pp.clj file
each of which can override it's parent definitions (in a zope like
'aquisition').

Processing can also be controlled by passing command line arguments
which are added to the templates top level context.

It's not documented, but if anyone is interested I can do some.


cheers 

bd

On Tue, 2009-05-26 at 19:47 -0700, markgunnels wrote:
> Hopefully this doesn't get me booed off the message board but is there
> a Clojure equivalent to Ruby's ERB? I'm try to use Clojure to perform
> code generation and, while it makes for an excellent language to write
> a parser in, I can't quite figure out the best way to actually
> template out the code.
> 
> Thanks for any help,
> Mark
> 
> P.S. Rich -- if you read this, Clojure is terrific.
> 
> > 

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


(ns ipowerhouse.live
	(:import java.io.File
	(org.apache.velocity VelocityContext Template)
	(org.apache.velocity.app Velocity)
	(org.apache.velocity.app.event InvalidReferenceEventHandler EventCartridge)
	java.util.Properties
	(org.apache.commons.io FileUtils FilenameUtils))

	(:use ipowerhouse.utils.useful))

(declare *pp*)
(declare *extensions*)
(declare *src*)
(declare *dst*)
(declare *ignore*)
(declare *verbose*)

(def *rvc* (VelocityContext.))
(def Rcontexts (ref (hash-map)))
(def Rdirty (ref (vector)))

(defn printIt [& m]
	(if (= *verbose* "yes")
		(println m)))

; event handler stuff unused as of now ...
(comment
	(defn getIRH []
		(proxy [InvalidReferenceEventHandler] []
			(invalidGetMethod [ctx rf obj prop info]
(printIt "**get:" info)
)

			(invalidSetMethod [ctx left right info]
(printIt "**set:" info)

)
			(invalidMethod [ctx rf obj method info]
 (printIt "**method:" info)

)))

	(defn addEventHandler [vc]
		(let [ec (EventCartridge.)]
			(.addEventHandler ec (getIRH))
			(.attachToContext ec vc)))

	(addEventHandler *rvc*)
)

(defn removeSrc [#^File f]
	(let [p (.getPath f)
			ctop (count *src*)]
		(subs p ctop)))

(defn check-dirty [p fileName]
	(let [src (File. (str *src* "/" p fileName))
dst (File. (str *dst* "/" p fileName))]

	 (when (and (.exists src) (.exists dst))
		 (when (FileUtils/isFileNewer src dst)
			 (printIt src "is dirty")
			 (dosync
	(commute Rdirty conj p))

(defn dirty? [f]
		(some #(.startsWith f %1) @Rdirty))

(defn forced? []
		(.containsKey *rvc* "force"))

(defn getDir [f]
	(FilenameUtils/getPath (FilenameUtils/normalizeNoEndSeparator f)))

(defn closestContext [curdir]
	(loop [d curdir]
		(let [p  (getDir d)]
			(if (contains? @Rcontexts p)
(do
	;(printIt "ctx for " curdir " is " p)
	(@Rcontexts p))
(if (= p "")
	*rvc*
	(recur  p))


;(def getClosestContext (memoize MgetClosestContext))

(defn keyCheck [k]
	(if (keyword? k) (name k) k))

(defn keywordsToStrings [z]
	(if (map? z)
		(reduce (fn [a k] (assoc a	(keyCheck k)	(keywordsToStrings (z k
			{} (keys z))
		z))

(defn execute [f prms]
	 (if (fn? f) (f prms) 	f))

(defn mapIntoContext [m context]
	(let [conv (keywordsToStrings m)]
			(doseq [[k v] conv]
(.put context k v)) context))

(defn construct [#^File f]
	"this only checks dirs where *pp* are actually present"
		(let [fr (java.io.FileReader. f)
	p (removeSrc f)
	ctxKey (getDir p)]

		(if-not (contains? @Rcontexts ctxKey)
		 (let [
vc (if (= ctxKey "")
			(VelocityContext. *rvc*)
		 (VelocityContext. (closestContext p)))]
			 (let [m (load-reader fr)]
 (when m
	 (let [conv (keywordsToStrings m)
tmpParams { :parentFile (.getParentFile f)
		:context vc
		:uri p }]
		 (reduce (fn [a k] (.put a k (execute (conv k)  tmpParams)) a) vc (keys conv)

(check-dirty ctxKey (str "/" *pp*))

			 (dosync
 (alter Rcontexts assoc ctxKey vc))

(defn context[top]
	(let [
		pps (filter #(re-find (re-pattern (str *pp* "$")) (.getAbsolutePath %1))
	(file-seq (java.io.File. top)))
		pathlen (fn [f]
			(.length (.getAbsolutePath f)))]
		(doseq [s (sort-by pathlen pps)]
			(construct s

(defn newer? [srcf dstf] (FileUtils/

Re: svn r1370 appears to have broken binding

2009-05-27 Thread Rich Hickey



On May 27, 7:59 am, Frantisek Sodomka  wrote:
> Thanks for the help and your feedback, Steve!
>
> Clojure needs some unit tests and I like writing them, so it is a win-
> win situation :-)
>

Let me add my thanks as well - this is a great (and otherwise
thankless :) contribution.

I also wanted to let you know: I'm running your tests, so your work is
not in vain.

Many thanks,

Rich

--~--~-~--~~~---~--~~
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: Scoping question

2009-05-27 Thread Boris Mizhen - 迷阵

It seems to me that the first would be immune to redefining what
closure/core.let means at the point where f is invoked, while the
second one would not be.

I was unable to actually redefine closure/core.let - probably because
it is a macro. But some function was used in place of let, than it
could be rebound.

Or am I betraying my total luck of understanding?
:)

Thanks,
Boris


On Wed, May 27, 2009 at 6:48 AM, Rich Hickey  wrote:
>
>
>
> On May 27, 4:12 am, Mark Engelberg  wrote:
>> Is there any practical difference between:
>>
>> (let [x 2]
>>   (defn f [] x))
>>
>> and
>>
>> (def f (let [x 2] (fn [] x)))?
>
> No, are you experiencing one?
>
> Rich
> >
>

--~--~-~--~~~---~--~~
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: Scoping question

2009-05-27 Thread Konrad Hinsen

On May 27, 2009, at 17:11, Boris Mizhen - 迷阵 wrote:

> It seems to me that the first would be immune to redefining what
> closure/core.let means at the point where f is invoked, while the
> second one would not be.

No. Both definitions create a closure inside which x has the fixed  
value 2. When f is invoked, neither x nor let can change that any more.

Moreover, given that let is a macro, changing its definition after  
the evaluation of the initial let form can never make a difference.

> I was unable to actually redefine closure/core.let - probably because
> it is a macro. But some function was used in place of let, than it
> could be rebound.

If let were a function, then the two forms would be different even  
without any redefinition, as the function would be called with  
different arguments in the two cases.

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: Feedback on new persistentmatrix datatype

2009-05-27 Thread Konrad Hinsen

On May 27, 2009, at 1:03, aperotte wrote:

> I think I understand your point now.  You would like the indexing to
> match the implicit dimension order of the nested structure.

Right.

> I was also concerned about storage order because I wanted to at some
> point integrate this datastructure with colt or parallel colt and the
> incanter library.

Both handle only 1D and 2D arrays, so they look rather limited. But  
compatibility for those is of course a nice feature to have.

> I thought the idea was that if while
> stepping through the backing array the right-most index varied fastest
> you were in column-major and if the left-most index varied fastest you
> were in row-major.

True, but as you say this is ultimately a feature of the backing  
array, not of the client interface to the N-D array.

> My main reasoning for doing things this way is so that dimension
> numbers are stable through data structure building.

They are always stable at one end and not on the other. To me it  
doesn't really matter which end gets to be variable.

> I was considering the slices of the outer-most dimension of the nested
> array (or the right-most dimension of the matrix) to be the "elements"
> of the collection when dealing with it in a lispy way.  If I start
> with a 2 dimensional structure with elements in the 0 and 1
> dimensions, and I conj it with another 2 dimensional structure, I
> would not like to see the two structures juxtaposed along a new 0
> dimension.  I would rather they maintain their original dimensions and
> be juxtaposed along a new dimension, 2.

That's certainly a nice operation to have, but I wouldn't call it  
conj, because conj takes a collection and an element, whereas what  
you describe is the combination of two elements into a new collection.

One way to create a higher-dimensional collection would be to first  
add a new dimension to the future elements (this is a low-cost  
operation, as only the shape information is updated), and then use  
concat or an n-d generalization of it.

> The two ways of doing this that we're describing are very similar.  I
> think in what you're describing, the outermost layer of the nested
> structure that goes into the constructor becomes the left-most index
> and nth operates on that index.  In what I'm describing, the outermost
> layer becomes the right-most index and nth operates on that index.

Right.

> The sole reason for this is to maintain stable dimension numbers when
> indexing, but since nth operates on the last dimension it maintains
> the same semantics as what your describing (as well as the same
> semantics as vectors).  I admit it might be a bit confusing to have
> nth operate in the opposite direction as index, but I think keeping
> stable dimension numbers is a worthwhile reason.
>
> Do you disagree?

Let's say my priorities are different: I consider it more important  
to have consistent index order across all operations, and I don't  
attach much importance to which end of the shape array remains stable  
when higher-dimensional structures are built.

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: Scoping question

2009-05-27 Thread Boris Mizhen - 迷阵

Makes sense, thanks!

On Wed, May 27, 2009 at 11:30 AM, Konrad Hinsen
 wrote:
>
> On May 27, 2009, at 17:11, Boris Mizhen - 迷阵 wrote:
>
>> It seems to me that the first would be immune to redefining what
>> closure/core.let means at the point where f is invoked, while the
>> second one would not be.
>
> No. Both definitions create a closure inside which x has the fixed
> value 2. When f is invoked, neither x nor let can change that any more.
>
> Moreover, given that let is a macro, changing its definition after
> the evaluation of the initial let form can never make a difference.
>
>> I was unable to actually redefine closure/core.let - probably because
>> it is a macro. But some function was used in place of let, than it
>> could be rebound.
>
> If let were a function, then the two forms would be different even
> without any redefinition, as the function would be called with
> different arguments in the two cases.
>
> 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: ns :use with :rename

2009-05-27 Thread Matt Clark

+1 for better info on :use/:require. I find I tend to go digging into
the clojure-contrib source for decent examples just because I'm not
sure where else to look.

On May 27, 11:03 am, tsuraan  wrote:
> > Here's the correct syntax:
>
> > (ns namespace
> >    (:use [other-namespace :rename {existing newname}]))
>
> aha, brackets.  Is there a plan to flesh out the API page to have more
> examples of things like that?  As it stands, I think the API page is
> probably great for somebody who needs a reminder, but for a newbie, it
> could probably be a little more friendly.
--~--~-~--~~~---~--~~
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: Clojure equivalent to Ruby's ERB

2009-05-27 Thread markgunnels

Thanks. This looks awesome.

On May 27, 10:28 am, ritchie turner  wrote:
> Hi there
>
> Find attached some code that uses apache velocity for command line based
> processing, i.e. it's not setup for servlets; i use this as an offline
> pre processor for web sites.
>
> It does hierarchical templating of files in a source directory and
> copies to a target directory. The templating maps are contained in (by
> default) __pp.clj files in the source tree. Further, your __pp.clj maps
> can also contain functions for dynamically populating the template.
>
> The nice thing is that each directory can contain it's own __pp.clj file
> each of which can override it's parent definitions (in a zope like
> 'aquisition').
>
> Processing can also be controlled by passing command line arguments
> which are added to the templates top level context.
>
> It's not documented, but if anyone is interested I can do some.
>
> cheers
>
> bd
>
> On Tue, 2009-05-26 at 19:47 -0700, markgunnels wrote:
> > Hopefully this doesn't get me booed off the message board but is there
> > a Clojure equivalent to Ruby's ERB? I'm try to use Clojure to perform
> > code generation and, while it makes for an excellent language to write
> > a parser in, I can't quite figure out the best way to actually
> > template out the code.
>
> > Thanks for any help,
> > Mark
>
> > P.S. Rich -- if you read this, Clojure is terrific.
>
>
>
>  pp.clj
> 6KViewDownload
>
>  __pp.clj
> < 1KViewDownload
>
>  __pp.clj
> < 1KViewDownload
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[PATCH] Validating Symbols/Keywords readability

2009-05-27 Thread Phil Hagelberg


I wrote a patch for issue #13 a few weeks back, but it was right around
the 1.0 push, so I didn't want to destabilize things. Now seems like a
good time to discuss it:

  http://code.google.com/p/clojure/issues/detail?id=13

This uses the reader to ensure that symbols and keywords have names that
are actually readable when created with the "symbol" or "keyword"
function.

Please let me know if there are any problems with this approach.

thanks,
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: JVM hanging after -main

2009-05-27 Thread Drew Raines

billh04 wrote:

> I think you are responsible for ending the currently running
> agents.  The usual method is to set up some field which the agents
> monitor looking for some value indicating the application is
> ending.

By "ending currently running agents" do you mean the action run on
the agent?  My problem doesn't seem to be action-related because when
I take out the agents and execute the same code synchronously, the
JVM exits as I expect.

For the record, I was able to consistently hang the JVM indefinitely
from the command line in addition to invocation from cron, contrary
to my claim in my other message.  I suspect that others are not
seeing any issues because most Java environments are persistent.
Anyone else scripting with Clojure using agents?

Thanks.

-Drew


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



Modular Contrib build with Ivy

2009-05-27 Thread Meikel Brandmeyer

Dear Clojurians,

this is the next iteration of my Ivy experiments
to provide a modular build of contrib. With the
support of Kresimir Sojat I restructured the build.

Previously the different contrib modules were
provided as configurations. This is now changed
in that every contrib module is also an Ivy module.

Each module provides three configurations:
compiled providing AOT, source providing the
sources and default which extends the other two.
lazy-xml also provides a with-xmlpull configuration
to suck in the optional xmlpull dependency.

To specify eg. a dependency on a pre-compiled c.c.def use:




To use the repository add it to your ivysettings.xml:



http://kotka.de/ivy/ivysettings.xml"/>


Concerning clojure itself I renamed the module from
clojure-lang to clojure to match the .pom nomenclature.

Feedback appriciated!

Sincerely
Meikel



clojure-ivy2-rev1375.diff
Description: Binary data


contrib-ivy4-rev845.diff
Description: Binary data


smime.p7s
Description: S/MIME cryptographic signature


Re: Clojure equivalent to Ruby's ERB

2009-05-27 Thread Max Suica

I think you could do a hack using macros and eval at runtime in order
to expand them into your code, but I think one of the fellas in the
chat room said to be wary if that's the only approach I can see to a
problem, because it's easy to screw up, and not entirely good
practice.

Btw, does clojure have string interpolation?
--~--~-~--~~~---~--~~
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: Clojure equivalent to Ruby's ERB

2009-05-27 Thread Stuart Sierra

On May 26, 10:47 pm, markgunnels  wrote:
> Hopefully this doesn't get me booed off the message board but is there
> a Clojure equivalent to Ruby's ERB? I'm try to use Clojure to perform
> code generation

I've had success with StringTemplate.  Very functional design, easy to
call from Clojure.  And it's designed for code generation (the ANTLR
parser generator).

-Stuart Sierra
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



replacing java + xml (possible java1 demo)

2009-05-27 Thread Raoul Duke

wow. the fact that people use java+somehatefullibs+xml and apparently
think that is something "good", completely drives me insane. i mean,
it isn't just additional bloat, it is more like
ackermann-function-scale bloat. gargh! has anybody done something
like:

1) convert the bloody XML to Clojure lispy goodness
2) ok well you are done, it is now code! :-}

?

ack. barf.

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



Macro Writing Helper?

2009-05-27 Thread CuppoJava

Hi,
I'm trying to write some macro-defining macros, and the recursive
backquotes are making my brain spin circles. Is there a macro writing
helper so that I can expand my macros level by level and see the
intermediate result?

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

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


Is there something like this out there?
  -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: JVM hanging after -main

2009-05-27 Thread Timothy Pratley

Hi Drew,

I've been trying to recreate your issue
(defn forever[x] (while true (Thread/sleep 100) (print \-) (flush)))
(let [a (agent 0)] (send (agent 0) forever))
(println (Thread/activeCount) "threads active")
(shutdown-agents)
(println "I'm here")
;(System/exit 0)

Notably shutdown-agents is a non-blocking call, and without the exit
the program runs forever.
With the exit, for me the program terminates - but I believe this is
where the behavior which may vary...
something different occurring in your environment to mine - shutodown
hooks? JVM?
My only other stab in the dark is could your (flush) actually block
before System/exit is called?

Can you try my example and see if it hangs for you, and/or if there
some code you can paste that hangs?

Regards,
Tim.



On May 28, 6:08 am, Drew Raines  wrote:
> billh04 wrote:
> > I think you are responsible for ending the currently running
> > agents.  The usual method is to set up some field which the agents
> > monitor looking for some value indicating the application is
> > ending.
>
> By "ending currently running agents" do you mean the action run on
> the agent?  My problem doesn't seem to be action-related because when
> I take out the agents and execute the same code synchronously, the
> JVM exits as I expect.
>
> For the record, I was able to consistently hang the JVM indefinitely
> from the command line in addition to invocation from cron, contrary
> to my claim in my other message.  I suspect that others are not
> seeing any issues because most Java environments are persistent.
> Anyone else scripting with Clojure using agents?
>
> Thanks.
>
> -Drew
--~--~-~--~~~---~--~~
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: replacing java + xml (possible java1 demo)

2009-05-27 Thread kkw

Hello,

Here's what I've done in times past:

(ns process-xml-in-a-file
 (:require [clojure.zip :as zip])
 (:require [clojure.contrib.zip-filter.xml :as zfx])
 (:require [clojure.xml :as xml]))

; creating list of all checkable instances
(def dev2-cfg-xml
 (-> "c:/dl/tibsup/Prod_Stg_auto_shutdown/dev2/dev2_config_start.xml"
  (xml/parse)
  (zip/xml-zip)))

(def instances
  (fn [cfg-xml]
(zfx/xml-> cfg-
xml :Phases :Phase :ServiceInstances :Sequence :group :instances zfx/
text)))

(instances dev2-cfg-xml)

I can't provide dev2_config_start.xml as there's confidential info
in the dev2_config_start.xml, and I'm pressed for time. I'm not sure
if it's exactly what you had in mind, but I hope it helps nonetheless.

Kev

On May 28, 10:19 am, Raoul Duke  wrote:
> wow. the fact that people use java+somehatefullibs+xml and apparently
> think that is something "good", completely drives me insane. i mean,
> it isn't just additional bloat, it is more like
> ackermann-function-scale bloat. gargh! has anybody done something
> like:
>
> 1) convert the bloody XML to Clojure lispy goodness
> 2) ok well you are done, it is now code! :-}
>
> ?
>
> ack. barf.
--~--~-~--~~~---~--~~
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 would I do this functionally? (internally mutable state)

2009-05-27 Thread Korny Sietsma

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"

--~--~-~--~~~---~--~~
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-27 Thread Mikio Hokari

Hello.

I am new to clojure, but try it.

code:

(defn get-size [filename]
 (println 'size filename)
 (count filename))
(defn get-quickhash [filename]
 (println 'quickhash filename)
 (hash (take 3 filename)))
(defn get-hash [filename]
 (println 'hash filename)
 (hash filename))

(def get-info (memoize
  (fn [filename]
(map #(% filename) [get-size get-quickhash get-hash]

(println "A")
(nth (get-info "abc") 0)
(nth (get-info "abc") 0)
(println "B")
(nth (get-info "abc") 0)
(nth (get-info "abc") 1)
(println "C")
(nth (get-info "abc") 0)
(nth (get-info "abc") 1)
(nth (get-info "abc") 2)
(println "D")
(nth (get-info "abc") 0)
(nth (get-info "abc") 1)
(nth (get-info "abc") 2)

result:

A
size abc
B
quickhash abc
C
hash abc
D


For memory efficiency, I suppose you may use state-monads and trie.
But it will need a lot of lines of code, and too hard for me.

Regards,

-
Mikio Hokari

2009/5/28 Korny Sietsma :
>
> 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"
>
> >
>

--~--~-~--~~~---~--~~
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-27 Thread Korny Sietsma

Trouble here is, I only want to call the hash functions as needed.
This is doing file differencing, and if I only have a single file of
(say) 200 megabytes, I never need to calculate it's hash, as I'll
never actually compare it to another file of exactly the same size.

- Korny

On Thu, May 28, 2009 at 1:25 PM, Mikio Hokari  wrote:
>
> Hello.
>
> I am new to clojure, but try it.
>
> code:
>
> (defn get-size [filename]
>         (println 'size filename)
>         (count filename))
> (defn get-quickhash [filename]
>         (println 'quickhash filename)
>         (hash (take 3 filename)))
> (defn get-hash [filename]
>         (println 'hash filename)
>         (hash filename))
>
> (def get-info (memoize
>              (fn [filename]
>                (map #(% filename) [get-size get-quickhash get-hash]
>
> (println "A")
> (nth (get-info "abc") 0)
> (nth (get-info "abc") 0)
> (println "B")
> (nth (get-info "abc") 0)
> (nth (get-info "abc") 1)
> (println "C")
> (nth (get-info "abc") 0)
> (nth (get-info "abc") 1)
> (nth (get-info "abc") 2)
> (println "D")
> (nth (get-info "abc") 0)
> (nth (get-info "abc") 1)
> (nth (get-info "abc") 2)
>
> result:
>
> A
> size abc
> B
> quickhash abc
> C
> hash abc
> D
>
>
> For memory efficiency, I suppose you may use state-monads and trie.
> But it will need a lot of lines of code, and too hard for me.
>
> Regards,
>
> -
> Mikio Hokari
>
> 2009/5/28 Korny Sietsma :
>>
>> 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: how would I do this functionally? (internally mutable state)

2009-05-27 Thread 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"
--~--~-~--~~~---~--~~
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: Exit from clojure box?

2009-05-27 Thread Muhammad Alkarouri

On 27/05/2009, Baishampayan Ghose  wrote:
..
> In the SLIME REPL, press , (comma) and then type 'quit' and press Enter.
>
> That'd close your REPL gracefully after which you can exit Emacs by
> pressing C-x C-c.
>
> Regards,
> BG
>
> --

Exactly what I wanted. Many thanks!

Regards,

Muhammad
> Baishampayan Ghose 
> oCricket.com
>

--~--~-~--~~~---~--~~
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-27 Thread Mikio Hokari

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

--~--~-~--~~~---~--~~
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-27 Thread Timothy Pratley

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"
--~--~-~--~~~---~--~~
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-27 Thread Daniel Lyons


On May 27, 2009, at 7:52 PM, Korny Sietsma wrote:
> 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!

OK, I'm probably talking out of turn here, but I thought I would share  
some of my thoughts.

First of all, though you probably already thought of this, you can  
improve time complexity from O(N^2) to O(N log N) if you sort the  
files looking for duplicates rather than comparing every file to every  
other file. In other words, make a list of files and their hashes, and  
sort by the hashes, then walk the list comparing each hash to the  
previous hash.

I can think of two ways to do this. The first one I thought of might  
be more functional, which would be to successively narrow down a list  
of potential duplicates comparison by comparison. It would have a  
structure something like this: generate a list of files by size; group  
by files of the same size; remove all sublists of length 1 (unique  
sizes). Pass that list to a function which generates a list of files  
by the quick hash; group by them by it; remove all sublists of length  
1. Pass that to a function which does the same thing only with the  
more expensive hash. I suspect you could make each of the three steps  
a function and then make a fourth function which combines those three  
and takes a function as a parameter to produce the hash. Then you  
could use the comp function to combine those three functions and  
presto, you have your list of duplicates.

Another possible way that more closely resembles what you're doing  
right now would be to have a function which looks at a file and lazily  
produces the three comparison values, then do the sort/group procedure  
with a comparison function that is smart enough to only compare as  
much as it has to. I think you could build this with what Mikio was  
proposing, because map is lazy.

As another example of this:

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

This function returns a list of two values which are just the first  
two characters of a string, but it prints a message and waits a second  
if the second value in the list is actually forced. If you never look  
at the second value, you never pay the penalty for computing it. So  
supposing a compare a list of strings which differ on the first  
character, it should return immediately without printing anything, and  
it does:

user> (sort-by get-comparators #(some (complement zero?) (map compare  
%1 %2)) ["ab" "cd" "ef" "gh"])
("ab" "cd" "ef" "gh")

But if some of them have the same first character, it should have a  
delay and then return the values:

user> (sort-by get-comparators #(some (complement zero?) (map compare  
%1 %2)) ["ab" "cd" "ef" "eg"])
Looking at second element
Looking at second element
("ab" "cd" "ef" "eg")

So you can see that even though it had to use the second values to  
compare 'ef' and 'eg', it only had to "compute" their second  
characters, not the second characters of any of the other elements.

There is a group-by function in clojure.contrib.seq-utils which would  
be of use. Unfortunately I don't see how to do filter with a hash-map  
to produce another hash-map. The best I came up with was this:

(def groupings
  (clojure.contrib.seq-utils/group-by
   #(first (get-comparators %))
   ["abc" "abd" "hello" "gravy" "stuff" "stripes"]))

(apply hash-map (apply concat (filter (fn [[key value]] (> (count  
value) 1)) groupings)))

I don't trust apply, and double apply seems really fishy. I'm probably  
missing something obvious there. Also, it would probably be better to  
either be able to furnish group-by with a comparison function a la  
sort-by or else somehow make lists be instances of comparable to make  
this work using get-comparators.

One more note, because you mentioned some concern over having  
filenames in memory. I'm not sure but I don't think Java and therefore  
Clojure can do this, but in general (at least on Unix-based systems)  
you ought to be able to store t

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

2009-05-27 Thread Daniel Lyons


On May 27, 2009, at 11:51 PM, Timothy Pratley wrote:
> I wonder if there is a more idiomatic way to compare two lazy
> sequences... lazily?

I came up with (some (complement zero?) (map compare list-1 list-2))  
in my response which missed yours by seconds. :) I'm not sure it's  
great but it does seem to work.

—
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: regression

2009-05-27 Thread Daniel Lyons


On May 26, 2009, at 10:56 PM, kyle smith wrote:

> Thanks for the feedback Daniel, I've incorporated your ideas and re-
> uploaded.  I'm not sure where you're seeing mutable data structures.

I'm hallucinating, that's where. :)

> Anyhow, I now only call eval once each time scorer is called, which is
> massively faster.
> This has allowed for additional testing points, and now I get a
> perfect fit in under a minute!
>
> On a related note, it looks like I've essentially written a better
> version of this:
> http://www.jakevoytko.com/blog/2008/12/16/evolving-genetic-algorithms-in-lisp/

This is really great! Thanks for sharing it with us! Cool stuff.

—
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-27 Thread Michael Wood

On Thu, May 28, 2009 at 7:58 AM, Daniel Lyons  wrote:
>
>
> On May 27, 2009, at 11:51 PM, Timothy Pratley wrote:
>> I wonder if there is a more idiomatic way to compare two lazy
>> sequences... lazily?
>
> I came up with (some (complement zero?) (map compare list-1 list-2))
> in my response which missed yours by seconds. :) I'm not sure it's
> great but it does seem to work.

Except if one of them is a prefix of the other.

(some (complement zero?) (map compare [1 2 3] [4 5 6])) => true
(some (complement zero?) (map compare [1 2 3] [1 2 3])) => nil
(some (complement zero?) (map compare [1 2 3] [1 2])) => nil

-- 
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: how would I do this functionally? (internally mutable state)

2009-05-27 Thread Mikio Hokari

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

How sweet!

2009/5/28 Daniel Lyons :
>
>
> On May 27, 2009, at 11:51 PM, Timothy Pratley wrote:
>> I wonder if there is a more idiomatic way to compare two lazy
>> sequences... lazily?
>
> I came up with (some (complement zero?) (map compare list-1 list-2))
> in my response which missed yours by seconds. :) I'm not sure it's
> great but it does seem to work.
>
> —
> 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
-~--~~~~--~~--~--~---