1.2 RC2 exception line numbering bug.

2010-08-07 Thread Jason Wolfe
This bug still seems to be present in 1.2 RC2, and is more general
than I previously thought:

jawo...@[~/Projects/testproj]: cat > src/test.clj


bla
jawo...@[~/Projects/testproj]: cat > src/test2.clj

(bla)
jawo...@[~/Projects/testproj]: lein repl
user=> (require 'test)
java.lang.Exception: Unable to resolve symbol: bla in this context
(test.clj:1)
user=> (require 'test)a
java.lang.Exception: Unable to resolve symbol: bla in this context
(test.clj:2)
user=> (require 'test)
java.lang.Exception: Unable to resolve symbol: bla in this context
(test.clj:3)
user=> (require 'test2)
java.lang.Exception: Unable to resolve symbol: bla in this context
(test2.clj:2)
user=> (require 'test2)
java.lang.Exception: Unable to resolve symbol: bla in this context
(test2.clj:2)
user=> (require 'test2)
java.lang.Exception: Unable to resolve symbol: bla in this context
(test2.clj:2)
user=> (require 'test)
java.lang.Exception: Unable to resolve symbol: bla in this context
(test.clj:7)
user=>

-Jason

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: slow raw io

2010-08-07 Thread cageface
Any chance of getting this in before 1.2?

On Jun 25, 7:43 am, cageface  wrote:
> Thanks Stuart & Peter for following up on this. Now I can get back to
> plowing through this mountain of ldiff data with 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
Note that posts from new members are moderated - please be patient with your 
first post.
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: Slightly Off Topic: .NET books

2010-08-07 Thread Dan Moniz
On Fri, 06 Aug 2010 17:49 -0400, "Mark Rathwell"
 wrote:

> +1 for:
>
> _The C# Programming Language, 3rd Edition_ by Anders Hejlsberg, Mads
> Torgersen, Scott Wiltamuth, and Peter Golde
>
> Pretty decent book, but I'm not sure if it's been updated since 2.0 (a
> lot of cool stuff came in 3.0 and 4.0 [LINQ, implicit type
> (inference), initializers, extension methods, lambdas, named and
> optional parameters, to name a few]).

My copy of Third Edition covers C# 3.0.


-- 
Dan Moniz  [http://pobox.com/~dnm/]

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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


maven compilation of a clojure project hangs due to still running thread pools

2010-08-07 Thread Christian Schuhegger
Hi all,

I just had a lengthy debugging session behind me to find out why maven
hangs when trying to execute the "clojure:compile" target of the
clojure-maven-plugin.

I found out that the problem does not lie in maven but in clojure (or
in my code if you want to see it that way). My code executes some
expressions that cause the clojure thread pools to be started. These
thread pools stay alive after the compilation phase is over. My intent
would be that such objects are only created when running the program
but not when compiling it.

The only reference where I found this problem discussed is from
2009-06-01:
http://code.google.com/p/clojure/issues/detail?id=120
but I did not find any follow up or recommendation on how to deal with
such issues?

What is the current recommended way on how to deal with this
situation?

Many thanks,
Christian

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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


take-while2?

2010-08-07 Thread bonega
Hi.

Are there some function like this:

(defn take-while2 [f pred coll] ...

usage: (take-while2 + #(< % 100) (iterate inc 0))
returns: (0 1 2 3 4 5 6 7 8 9 10 11 12 13)

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: slow raw io

2010-08-07 Thread Stuart Halloway
No. We want to collect more information and do more comparisons before moving 
away from the recommended Java buffering. 

Stu

> Any chance of getting this in before 1.2?
> 
> On Jun 25, 7:43 am, cageface  wrote:
>> Thanks Stuart & Peter for following up on this. Now I can get back to
>> plowing through this mountain of ldiff data with 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
> Note that posts from new members are moderated - please be patient with your 
> first post.
> 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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: 1.2 RC2 exception line numbering bug.

2010-08-07 Thread Stuart Halloway
I don't think this is a regression -- I can see the same thing in 1.1.

Can you please open a ticket, along with any additional information on which 
kinds of errors do/do not exhibit the problem?

Stu

> This bug still seems to be present in 1.2 RC2, and is more general
> than I previously thought:
> 
> jawo...@[~/Projects/testproj]: cat > src/test.clj
> 
> 
> bla
> jawo...@[~/Projects/testproj]: cat > src/test2.clj
> 
> (bla)
> jawo...@[~/Projects/testproj]: lein repl
> user=> (require 'test)
> java.lang.Exception: Unable to resolve symbol: bla in this context
> (test.clj:1)
> user=> (require 'test)a
> java.lang.Exception: Unable to resolve symbol: bla in this context
> (test.clj:2)
> user=> (require 'test)
> java.lang.Exception: Unable to resolve symbol: bla in this context
> (test.clj:3)
> user=> (require 'test2)
> java.lang.Exception: Unable to resolve symbol: bla in this context
> (test2.clj:2)
> user=> (require 'test2)
> java.lang.Exception: Unable to resolve symbol: bla in this context
> (test2.clj:2)
> user=> (require 'test2)
> java.lang.Exception: Unable to resolve symbol: bla in this context
> (test2.clj:2)
> user=> (require 'test)
> java.lang.Exception: Unable to resolve symbol: bla in this context
> (test.clj:7)
> user=>
> 
> -Jason
> 
> -- 
> 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
> Note that posts from new members are moderated - please be patient with your 
> first post.
> 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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Steve Purcell
On 7 Aug 2010, at 11:15, bonega wrote:

> Hi.
> 
> Are there some function like this:
> 
> (defn take-while2 [f pred coll] ...
> 
> usage: (take-while2 + #(< % 100) (iterate inc 0))
> returns: (0 1 2 3 4 5 6 7 8 9 10 11 12 13)


I'm feeling a bit stupid because I can't see from the above example how 
take-while2 is supposed to work. Can you clarify please?

-Steve

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: slow raw io

2010-08-07 Thread Peter Schuller
> No. We want to collect more information and do more comparisons before moving 
> away from the recommended Java buffering.

Interesting. Why do you consider it recommended to read one character
at a time in a case like this? Maybe there is such a recommendation
that I don't know about, but in general I would consider it contrary
to expected practice when doing I/O if performance is a concern.

Even discounting the fact of ensureOpen() and lock acquisition that
seems to be used as per my previous post, even the most efficient
implementation I can think of (do some index checking and bump a
positional pointer) would still be generally expected to be slower
when invoked one character/byte at a time than larger chunks being
coped with e.g. System.arraycopy() (though as with all things, within
reason; cranking up size too much will of course have other effects
such as GC overhead, poorer cache locality, etc).

(Note that I'm not arguing the point of whether or not it should be
committed before 1.2, but I'm genuinely interested in why not reading
one character (or byte) at a time would be a controversial change.)

-- 
/ Peter Schuller

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: Slightly Off Topic: .NET books

2010-08-07 Thread Mark Rathwell
> My copy of Third Edition covers C# 3.0.

Sorry about that, I just copied and pasted your entry, I have Second
Edition.

On Fri, Aug 6, 2010 at 7:34 PM, Dan Moniz  wrote:

> On Fri, 06 Aug 2010 17:49 -0400, "Mark Rathwell"
>  wrote:
>
> > +1 for:
> >
> > _The C# Programming Language, 3rd Edition_ by Anders Hejlsberg, Mads
> > Torgersen, Scott Wiltamuth, and Peter Golde
> >
> > Pretty decent book, but I'm not sure if it's been updated since 2.0 (a
> > lot of cool stuff came in 3.0 and 4.0 [LINQ, implicit type
> > (inference), initializers, extension methods, lambdas, named and
> > optional parameters, to name a few]).
>
> My copy of Third Edition covers C# 3.0.
>
>
> --
> Dan Moniz  [http://pobox.com/~dnm/]
>
> --
> 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
> Note that posts from new members are moderated - please be patient with
> your first post.
> 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
>

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: slow raw io

2010-08-07 Thread j-g-faustus
On Aug 7, 2:02 pm, Stuart Halloway  wrote:
> > No. We want to collect more information and do more comparisons before 
> > moving away from the recommended Java buffering.

Maybe this comparison can be of interest?
http://nadeausoftware.com/articles/2008/02/java_tip_how_read_files_quickly

Somebody tests 13 different ways to read a 100MB file with Java 1.5,
and get timings ranging from half a second to 10 min.

jf

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: System calls

2010-08-07 Thread j-g-faustus
On Aug 7, 7:27 am, Meikel Brandmeyer  wrote:
> (defn to-env
>   [env-vars-map]
>   (->> env-vars-map
>     (map #(str (name (key %)) "=" (val %)))
>     into-array))
>
> And an invocation:
>
> user=> (to-env {:PATH "/bin:/usr/bin" :HOME "/Users/mb" :foo "bar"})
> #
> user=> (seq *1)
> ("PATH=/bin:/usr/bin" "HOME=/Users/mb" "foo=bar")

Nice :)

jf

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Andreas Liljeqvist
It should use "+" for reducing the taken list.
Behind the scenes I would envision some accumulator passed to pred.
This examples takes elements while their total sum is less than 100.

2010/8/7 Steve Purcell 

> On 7 Aug 2010, at 11:15, bonega wrote:
>
> > Hi.
> >
> > Are there some function like this:
> >
> > (defn take-while2 [f pred coll] ...
> >
> > usage: (take-while2 + #(< % 100) (iterate inc 0))
> > returns: (0 1 2 3 4 5 6 7 8 9 10 11 12 13)
>
>
> I'm feeling a bit stupid because I can't see from the above example how
> take-while2 is supposed to work. Can you clarify please?
>
> -Steve
>
> --
> 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
> Note that posts from new members are moderated - please be patient with
> your first post.
> 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
>

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: System calls

2010-08-07 Thread Dave
Thanks everyone.  I have already tried the full path:

(defn get-msms-pts-OSX
  ;; Finds the msms points for a density (optional DEFAULT = 1.0) and
radius (optional DEFAULT = 1.5)
  [pdb-file density radius]
  (execute (str "/Users/daviddreisigmeyer/msms_MacOSX_2.6.1/
pdb_to_xyzr " pdb-file
" > /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr")))

Here it seemed to run (the above error isn't shown) but nothing
happened and the REPL become unresponsive again.  The call above only
takes a few seconds if I run it in a terminal using the output of (str
"...").

When I try:

(ns msms
  (:gen-class)
  (:use [clojure.contrib.duck-streams :only (read-lines)]
[clojure.contrib.shell-out :only (sh)]))

(defn get-msms-pts-OSX
  ;; Finds the msms points for a density (optional DEFAULT = 1.0) and
radius (optional DEFAULT = 1.5)
  [pdb-file density radius]
  (sh :in (str "/Users/daviddreisigmeyer/msms_MacOSX_2.6.1/pdb_to_xyzr
" pdb-file
" > /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr")))

I get the following:

No matching method found: exec for class java.lang.Runtime
  [Thrown class java.lang.IllegalArgumentException]

so I'll need to look at that a bit more.

Does anyone know why this doesn't seem to work:

(defn test-execute [ls-arg1 ls-arg2]
  (execute (str "ls -" ls-arg1))
  (execute (str "ls -" ls-arg2)))

Thanks again.

-Dave

On Aug 6, 11:06 pm, j-g-faustus  wrote:
> On Aug 6, 11:50 pm, Dave  wrote:
>
> > I get the error:
>
> > Cannot run program "pdb_to_xyzr": error=2, No such file or directory
> >   [Thrown class java.io.IOException]
>
> You may have a path problem.
> Try running "env" in the same fashion - I get a very basic path (just
> "/bin" and "/usr/bin") and none of my settings from .bashrc
> or .profile.
>
> Workarounds I know of:
>
> - Use clojure.contrib.shell-out and supply a map of the environment
> variables you need, including the 
> path:http://richhickey.github.com/clojure-contrib/shell-out-api.html
>
> - Put the "pdb_to_xyzr" call into a shell script that sets the path
> for you, and call the shell script from your program.
>
> - Use the full path to the executable rather than relying on
> environment variables.
>
> - Use one of the Java Runtime.exec variants that takes a String array
> of environment variables. (Although I would recommend one of the other
> options - I don't think there's a direct way to create a String array
> in Clojure, but you could do it indirectly through String.split or
> similar.):http://download-llnw.oracle.com/javase/1.5.0/docs/api/java/lang/Runti...
>
> Regards
> jf

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Steve Purcell
Oh, right, so maybe:

(last (take-while #(< (apply + %) 100) (reductions conj [] (iterate inc 0
=> [0 1 2 3 4 5 6 7 8 9 10 11 12 13]

-Steve


On 7 Aug 2010, at 13:57, Andreas Liljeqvist wrote:

> It should use "+" for reducing the taken list.
> Behind the scenes I would envision some accumulator passed to pred.
> This examples takes elements while their total sum is less than 100.
> 
> 2010/8/7 Steve Purcell 
> On 7 Aug 2010, at 11:15, bonega wrote:
> 
> > Hi.
> >
> > Are there some function like this:
> >
> > (defn take-while2 [f pred coll] ...
> >
> > usage: (take-while2 + #(< % 100) (iterate inc 0))
> > returns: (0 1 2 3 4 5 6 7 8 9 10 11 12 13)
> 
> 
> I'm feeling a bit stupid because I can't see from the above example how 
> take-while2 is supposed to work. Can you clarify please?
> 
> -Steve
> 
> --
> 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
> Note that posts from new members are moderated - please be patient with your 
> first post.
> 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
> 
> 
> -- 
> 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
> Note that posts from new members are moderated - please be patient with your 
> first post.
> 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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Joop Kiefte
Maybe you should call that take-until or something like that :)

2010/8/7 Steve Purcell :
> Oh, right, so maybe:
> (last (take-while #(< (apply + %) 100) (reductions conj [] (iterate inc
> 0
> => [0 1 2 3 4 5 6 7 8 9 10 11 12 13]
> -Steve
>
> On 7 Aug 2010, at 13:57, Andreas Liljeqvist wrote:
>
> It should use "+" for reducing the taken list.
> Behind the scenes I would envision some accumulator passed to pred.
> This examples takes elements while their total sum is less than 100.
>
> 2010/8/7 Steve Purcell 
>>
>> On 7 Aug 2010, at 11:15, bonega wrote:
>>
>> > Hi.
>> >
>> > Are there some function like this:
>> >
>> > (defn take-while2 [f pred coll] ...
>> >
>> > usage: (take-while2 + #(< % 100) (iterate inc 0))
>> > returns: (0 1 2 3 4 5 6 7 8 9 10 11 12 13)
>>
>>
>> I'm feeling a bit stupid because I can't see from the above example how
>> take-while2 is supposed to work. Can you clarify please?
>>
>> -Steve
>>
>> --
>> 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
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> 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
>
> --
> 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
> Note that posts from new members are moderated - please be patient with your
> first post.
> 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
>
> --
> 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
> Note that posts from new members are moderated - please be patient with your
> first post.
> 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



-- 
Communication is essential. So we need decent tools when communication
is lacking, when language capability is hard to acquire...

- http://esperanto.net  - http://esperanto-jongeren.nl

Linux-user #496644 (http://counter.li.org) - first touch of linux in 2004

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: Bug: contains? doesn't work on transient maps or sets

2010-08-07 Thread Nicolas Oury
Same here.
get does not work either on set.
But works on transient map.

Very difficult to workaround for Sets (as get do not work)

On Sun, Aug 1, 2010 at 8:25 PM, Mark Engelberg  wrote:
> I just tested this in Clojure 1.2, and the bug is still there:
>
> (contains? (transient #{1 2}) 1) -> false          ;should return true
>
> On Mon, Mar 22, 2010 at 5:46 PM, Mark Engelberg 
> wrote:
>>
>> Disturbingly, it doesn't error, it just always returns false.
>> This is in version 1.1.  Can someone check and see if this is still a
>> problem on the latest version?
>>
>> Thanks,
>>
>> Mark
>
> --
> 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
> Note that posts from new members are moderated - please be patient with your
> first post.
> 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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: maven compilation of a clojure project hangs due to still running thread pools

2010-08-07 Thread Armando Blancas
It seems to me that agents and functions like pmap should require
additional coding. Given the problem you've encounter, maybe a cached
thread pool isn't the best choice, especially if one proposal to deal
with this situation is to lower the keep alive value to the point that
this thing isn't much of a pool anymore.

A simple thread-per-task executor service implementation as the
default could work just as well and not require a shutdown. For other
needs, something like an *executor* for client code to provide custom
executors tweaked or implemented as needed, instead of trying to agree
on some policy.

For you case, I'd go for a custom thingy and avoid code that will
leave threads alive.

On Aug 7, 1:46 am, Christian Schuhegger
 wrote:
> Hi all,
>
> I just had a lengthy debugging session behind me to find out why maven
> hangs when trying to execute the "clojure:compile" target of the
> clojure-maven-plugin.
>
> I found out that the problem does not lie in maven but in clojure (or
> in my code if you want to see it that way). My code executes some
> expressions that cause the clojure thread pools to be started. These
> thread pools stay alive after the compilation phase is over. My intent
> would be that such objects are only created when running the program
> but not when compiling it.
>
> The only reference where I found this problem discussed is from
> 2009-06-01:http://code.google.com/p/clojure/issues/detail?id=120
> but I did not find any follow up or recommendation on how to deal with
> such issues?
>
> What is the current recommended way on how to deal with this
> situation?
>
> Many thanks,
> Christian

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: maven compilation of a clojure project hangs due to still running thread pools

2010-08-07 Thread Armando Blancas
> It seems to me that agents and functions like pmap should require
> additional coding.

Wait, don't commit! I meant should NOT require that...

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread gary ng
On Sat, Aug 7, 2010 at 8:14 AM, Steve Purcell  wrote:
> Oh, right, so maybe:
> (last (take-while #(< (apply + %) 100) (reductions conj [] (iterate inc
> 0
> => [0 1 2 3 4 5 6 7 8 9 10 11 12 13]
> -Steve

or

user=> (map second (take-while (fn [e] (< (first e) 100)) (rest
(reductions (fn [a x] [(+ (first a) x) x]) [0 0] (iterate inc 0)
(0 1 2 3 4 5 6 7 8 9 10 11 12 13)

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Steve Purcell
On 7 Aug 2010, at 20:23, gary ng wrote:

> On Sat, Aug 7, 2010 at 8:14 AM, Steve Purcell  wrote:
>> Oh, right, so maybe:
>> (last (take-while #(< (apply + %) 100) (reductions conj [] (iterate inc
>> 0
>> => [0 1 2 3 4 5 6 7 8 9 10 11 12 13]
>> -Steve
> 
> or
> 
> user=> (map second (take-while (fn [e] (< (first e) 100)) (rest
> (reductions (fn [a x] [(+ (first a) x) x]) [0 0] (iterate inc 0)
> (0 1 2 3 4 5 6 7 8 9 10 11 12 13)
> 


Nice - that's about twice as fast as my version (with the 100 limit scaled up 
to 1 million), though perhaps a less general pattern since the code structure 
assumes knowledge of +'s cumulative nature.

-Steve

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread gary ng
On Sat, Aug 7, 2010 at 12:46 PM, Steve Purcell  wrote:
>
> Nice - that's about twice as fast as my version (with the 100 limit scaled up 
> to 1 million), though perhaps a less general pattern since the code structure 
> assumes knowledge of +'s cumulative nature.
>

Yes, it needs a proper initializer(or Zero() in monad speak)  which
needs to be passed in to make it generic.

What it does is simply carrying the accumulator in the sequence as a
tuple(or vector in clojure term, I am still more familar with
Haskell/F#) so the accumulator can be anything. There was a quirk
where I need a [0 0] which can be fixed in the following:

user=> (map second (take-while #(< (first %) 100) (reductions #(vector (+ (first
 %1) (first %2)) (first %2)) (map #(vector % %) (iterate inc 0)
(0 1 2 3 4 5 6 7 8 9 10 11 12 13)

here the #(vector % %) kind of work around by producing the
initializer, assuming the accumulator and the element are the same
type. If this assumption doesn't hold, it would become:

(map #(vector Zero(%) %) collection)

where Zero(%) needs to be something that produce the initializer, say
(list) if the accumulator is a list.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Andreas Liljeqvist
Thanks that works.

What I really want is a function like in my initial posting.
Is there something like that in core or contrib?

Your example code can be quite slow since all sublists are summed before
comparision.
I would like a function that does this with a accumulator for the reduced
values.

I am not asking somebody to write this for me - I just want to know if it
exists

btw: take-until isn't a bad name

2010/8/7 Steve Purcell 

> Oh, right, so maybe:
>
> (last (take-while #(< (apply + %) 100) (reductions conj [] (iterate inc
> 0
> => [0 1 2 3 4 5 6 7 8 9 10 11 12 13]
>
> -Steve
>
>
> On 7 Aug 2010, at 13:57, Andreas Liljeqvist wrote:
>
> It should use "+" for reducing the taken list.
> Behind the scenes I would envision some accumulator passed to pred.
> This examples takes elements while their total sum is less than 100.
>
> 2010/8/7 Steve Purcell 
>
>> On 7 Aug 2010, at 11:15, bonega wrote:
>>
>> > Hi.
>> >
>> > Are there some function like this:
>> >
>> > (defn take-while2 [f pred coll] ...
>> >
>> > usage: (take-while2 + #(< % 100) (iterate inc 0))
>> > returns: (0 1 2 3 4 5 6 7 8 9 10 11 12 13)
>>
>>
>> I'm feeling a bit stupid because I can't see from the above example how
>> take-while2 is supposed to work. Can you clarify please?
>>
>> -Steve
>>
>> --
>> 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
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> 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
>>
>
>
> --
> 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
> Note that posts from new members are moderated - please be patient with
> your first post.
> 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
>
>
>  --
> 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
> Note that posts from new members are moderated - please be patient with
> your first post.
> 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
>

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

TextMate users, what bundle are you using?

2010-08-07 Thread frou
Searching Google, I see there are several TextMate bundles for Clojure
support. Some old, some new-ish. I'm sure there are others I didn't
find.

Who's using TextMate for Clojure? What's your tip for the best
bundle / auxiliary tools?

Thank you

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Meikel Brandmeyer
Hi,

Am 07.08.2010 um 19:44 schrieb Andreas Liljeqvist:

> Your example code can be quite slow since all sublists are summed before 
> comparision.
> I would like a function that does this with a accumulator for the reduced 
> values.

You can always go low-level:

(defn take-until
  [f initial pred coll]
  (lazy-seq
(when-let [s (seq coll)]
  (let [fst (first s)
x   (f initial fst)]
(when (pred x)
  (cons fst (take-until f x pred (rest s

Sincerely
Meikel

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread gary ng
On Sat, Aug 7, 2010 at 10:44 AM, Andreas Liljeqvist  wrote:
> Thanks that works.
> What I really want is a function like in my initial posting.
> Is there something like that in core or contrib?
> Your example code can be quite slow since all sublists are summed before
> comparision.
I believe my version is doing what you are asking.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: TextMate users, what bundle are you using?

2010-08-07 Thread David Nolen
On Sat, Aug 7, 2010 at 4:47 PM, frou  wrote:

> Searching Google, I see there are several TextMate bundles for Clojure
> support. Some old, some new-ish. I'm sure there are others I didn't
> find.
>
> Who's using TextMate for Clojure? What's your tip for the best
> bundle / auxiliary tools?
>
> Thank you
>

I don't think there are any that are satisfactory beyond syntax
highlighting. For that I've find Mark McGranaghan's to be the best:
http://github.com/mmcgrana/textmate-clojure.

I've forked it and have been working on adding decent REPL interactions via
cake: http://github.com/ninjudd/cake. cake supports persistent REPLs and
allows for quickly eval'ing sexprs from the command line. This makes
TextMate integration pretty straightforward.

Been a bit busy so it might a be a week or two before I have anything worth
using.

David

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

looking for a simpler implementation of a function I'm using

2010-08-07 Thread David Cabana
Here are a couple of implementations of a function I'm calling
'partition-when'.  I feel like there should be a simpler way than
either of these. If you have one, I'd love to see it.

(defn partition-when;;version 1
  "Partition a sequence into subsequences; begin a new
   subseq whenever the predicate f? returns true.
   Example: (partition-when even? [ 1 2 3 7 5 4 1]) returns [[1] [2 3
7 5] [4 1]]."
  [f? ys]
  (let [xs (vec ys)
indices (positions f? xs) ;; uses
clojure.contrib.seq-utils/positions
n (count xs)]
(->> (concat [0] indices [n])
 (distinct) ;; handle possible
repeated leading zero
 (partition 2 1)
 (map #(apply (partial subvec xs) %)

(defn partition-when;; version 2
  [f? xs]
  (when (seq xs)
(loop [ys(rest xs)
   work  [(first xs)]
   accum []]
  (if (empty? ys)
(conj accum work)
(let [y (first ys)]
  (if (f? y)
(recur (rest ys) [y] (conj accum work))
(recur (rest ys) (conj work y) accum )))

Speed is no big deal for me; the sequences I'm handling are short, say
about length100. BTW, one of these is considerably faster than the
other for longish sequences. Can you guess which?

What I'm looking for is a natural, conceptually clean approach.

Thanks,
David

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread Michael Gardner
(partition-by #(when (even? %) (gensym))

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread gary ng
On Sat, Aug 7, 2010 at 6:12 PM, David Cabana  wrote:
> Speed is no big deal for me; the sequences I'm handling are short, say
> about length100. BTW, one of these is considerably faster than the
> other for longish sequences. Can you guess which?
>
if you don't mind about performance, this seems to be natural to me

user=> (reverse (map reverse (reduce (fn [a e] (if (even? e) (cons [e] a) (cons
(cons e (first a)) (rest a (list) [1 2 3 7 5 4 1])))
((1) (2 3 7 5) (4 1))

Othewise, I would look for a foldr solution. Talking about foldr, is
it in clojure.core ?

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread gary ng
On Sat, Aug 7, 2010 at 6:35 PM, Michael Gardner  wrote:
> (partition-by #(when (even? %) (gensym))
nice, why do I need the gensym ?

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread gary ng
On Sat, Aug 7, 2010 at 6:39 PM, gary ng  wrote:
> On Sat, Aug 7, 2010 at 6:35 PM, Michael Gardner  wrote:
>> (partition-by #(when (even? %) (gensym))
> nice, why do I need the gensym ?

ah, the gensym is for 'break'. but why does it behave like this

user=> (partition-by #(when (even? %) (gensym)) [1 2 3 7 5 4 1]
)
((1) (2) (3 7 5) (4) (1))

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread Michael Gardner
On Aug 7, 2010, at 8:35 PM, Michael Gardner wrote:

> (partition-by #(when (even? %) (gensym))

Whoops, hit 'send' too soon. And it doesn't actually work, since it splits 
before and after the even values.

On Aug 7, 2010, at 8:39 PM, gary ng wrote:

> nice, why do I need the gensym ?

The gensym was just a cheesy way of generating a unique value.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread Michael Gardner
On Aug 7, 2010, at 8:48 PM, Michael Gardner wrote:

> On Aug 7, 2010, at 8:39 PM, gary ng wrote:
> 
>> nice, why do I need the gensym ?
> 
> The gensym was just a cheesy way of generating a unique value.

To elaborate a bit more on my failure, I was reading the docs for partition-by 
thinking that "new value" meant a value not before seen, not simply a different 
value from the previous one. Then I accidentally hit 'send' before I could test 
it and realize my mistake.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread gary ng
On Sat, Aug 7, 2010 at 6:55 PM, Michael Gardner  wrote:
> On Aug 7, 2010, at 8:48 PM, Michael Gardner wrote:
>
>> On Aug 7, 2010, at 8:39 PM, gary ng wrote:
>>
>>> nice, why do I need the gensym ?
>>
>> The gensym was just a cheesy way of generating a unique value.
>
> To elaborate a bit more on my failure, I was reading the docs for 
> partition-by thinking that "new value" meant a value not before seen, not 
> simply a different value from the previous one. Then I accidentally hit 
> 'send' before I could test it and realize my mistake.
>
Using your partition-by help, this is what I come up

user=> (map (fn [l] (map second l)) (partition-by first (rest (reductions (fn [a
 e] [(if (even? e) (gensym) (first a)) e]) [(gensym)] [1 2 3 7 5 4 1]
((1) (2 3 7 5) (4 1))

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: 1.2 RC2 exception line numbering bug.

2010-08-07 Thread Jason Wolfe
OK, done.

http://www.assembla.com/spaces/clojure/tickets/420-some-compiler-exceptions-erroneously-using-repl-line-numbers-

I don't have more details on what kinds of errors are affected; but, I
believe the wrong line numbers are the REPL line numbers, if that
helps..

Thanks, Jason

On Aug 7, 5:08 am, Stuart Halloway  wrote:
> I don't think this is a regression -- I can see the same thing in 1.1.
>
> Can you please open a ticket, along with any additional information on which 
> kinds of errors do/do not exhibit the problem?
>
> Stu
>
> > This bug still seems to be present in 1.2 RC2, and is more general
> > than I previously thought:
>
> > jawo...@[~/Projects/testproj]: cat > src/test.clj
>
> > bla
> > jawo...@[~/Projects/testproj]: cat > src/test2.clj
>
> > (bla)
> > jawo...@[~/Projects/testproj]: lein repl
> > user=> (require 'test)
> > java.lang.Exception: Unable to resolve symbol: bla in this context
> > (test.clj:1)
> > user=> (require 'test)a
> > java.lang.Exception: Unable to resolve symbol: bla in this context
> > (test.clj:2)
> > user=> (require 'test)
> > java.lang.Exception: Unable to resolve symbol: bla in this context
> > (test.clj:3)
> > user=> (require 'test2)
> > java.lang.Exception: Unable to resolve symbol: bla in this context
> > (test2.clj:2)
> > user=> (require 'test2)
> > java.lang.Exception: Unable to resolve symbol: bla in this context
> > (test2.clj:2)
> > user=> (require 'test2)
> > java.lang.Exception: Unable to resolve symbol: bla in this context
> > (test2.clj:2)
> > user=> (require 'test)
> > java.lang.Exception: Unable to resolve symbol: bla in this context
> > (test.clj:7)
> > user=>
>
> > -Jason
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.> To post to this group, send email 
> > tocloj...@googlegroups.com
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > 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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread David Cabana
On Sat, Aug 7, 2010 at 9:36 PM, gary ng  wrote:
> if you don't mind about performance, this seems to be natural to me
>
> user=> (reverse (map reverse (reduce (fn [a e] (if (even? e) (cons [e] a) 
> (cons
> (cons e (first a)) (rest a (list) [1 2 3 7 5 4 1])))
> ((1) (2 3 7 5) (4 1))

I reworked that a bit, to parameterize it:

(defn pw [f? x]
  (let [phi (fn [a e]
  (if (f? e)
(cons [e] a)
(cons (cons e (first a))
  (rest a]
(reverse
 (map reverse
  (reduce phi () x)

This is in the same family as my version 2, but I think it is much
cleaner.  This approach gets rid of the recursion, a definite win.
Thanks, Gary.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread David Cabana
Using a vector instead of a list as the accumulator makes it possible
to skip the mapping of reverse used in the earlier version of pw:

(defn pw [f? x]
  (let [phi (fn [a e]
  (if (f? e)
(cons [e] a )
(cons (conj (first a) e)
  (rest a]
(reverse
 (reduce phi []  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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread gary ng
On Sat, Aug 7, 2010 at 8:27 PM, David Cabana  wrote:
> Using a vector instead of a list as the accumulator makes it possible
> to skip the mapping of reverse used in the earlier version of pw:
>
> (defn pw [f? x]
>  (let [phi (fn [a e]
>              (if (f? e)
>                (cons [e] a )
>                (cons (conj (first a) e)
>                      (rest a]
>    (reverse
>     (reduce phi []  x
>

conj sounds like 'append' to me which I have no idea about the
performance characteristics in clojure(it is a no-no in F#, Haskell ++
is better but would grow the stack). list cons then reverse would give
me predictable O(2n). That is why I usually rather go for the cons
then reverse route.

thanks for the example BTW, as I am learning my clojure basics via
these excercises.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Randy Hudson
Andreas, there's no such function in Clojure core, and I'm fairly sure
there's not one in contrib.

Stop reading if you don't want to see my version; it was a fun little
puzzle.

(defn take-while-reduction [f pred coll]
  (let [rf (juxt #(reductions f %) identity)]
(->> coll rf (apply map vector) (take-while #(-> % first pred))
(map second

On Aug 7, 1:44 pm, Andreas Liljeqvist  wrote:
> Thanks that works.
>
> What I really want is a function like in my initial posting.
> Is there something like that in core or contrib?
>
> Your example code can be quite slow since all sublists are summed before
> comparision.
> I would like a function that does this with a accumulator for the reduced
> values.
>
> I am not asking somebody to write this for me - I just want to know if it
> exists
>
> btw: take-until isn't a bad name
>
> 2010/8/7 Steve Purcell 
>
>
>
> > Oh, right, so maybe:
>
> > (last (take-while #(< (apply + %) 100) (reductions conj [] (iterate inc
> > 0
> > => [0 1 2 3 4 5 6 7 8 9 10 11 12 13]
>
> > -Steve
>
> > On 7 Aug 2010, at 13:57, Andreas Liljeqvist wrote:
>
> > It should use "+" for reducing the taken list.
> > Behind the scenes I would envision some accumulator passed to pred.
> > This examples takes elements while their total sum is less than 100.
>
> > 2010/8/7 Steve Purcell 
>
> >> On 7 Aug 2010, at 11:15, bonega wrote:
>
> >> > Hi.
>
> >> > Are there some function like this:
>
> >> > (defn take-while2 [f pred coll] ...
>
> >> > usage: (take-while2 + #(< % 100) (iterate inc 0))
> >> > returns: (0 1 2 3 4 5 6 7 8 9 10 11 12 13)
>
> >> I'm feeling a bit stupid because I can't see from the above example how
> >> take-while2 is supposed to work. Can you clarify please?
>
> >> -Steve
>
> >> --
> >> 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
> >> Note that posts from new members are moderated - please be patient with
> >> your first post.
> >> 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
>
> > --
> > 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
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > 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
>
> >  --
> > 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
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > 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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Michał Marczyk
Yet another version:

(defn take-while-acc [f pred coll]
  (map (fn [_ x] x)
   (take-while pred (reductions f coll))
   coll))

Seems to work:

user> (take-while-acc + #(< % 100) (range))
(0 1 2 3 4 5 6 7 8 9 10 11 12 13)

Note that reductions does use an "accumulator" (in the form of a
closed over local), so the above works as requested. Also, this
version constructs no auxiliary data structures, not even two-element
vectors.

Sincerely,
Michał

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: System calls

2010-08-07 Thread j-g-faustus
On Aug 7, 4:46 pm, Dave  wrote:
>   (execute (str "/../pdb_to_xyzr " pdb-file " > /..")))
>
> Here it seemed to run (the above error isn't shown) but nothing
> happened and the REPL become unresponsive again.  

I think the issue is that Runtime.exec doesn't start a shell, just a
subprocess, so things that are normally handled by the shell (like
redirection and pipes) doesn't work.
On
(execute "env | grep PATH")
I get "env: |: no such file or directory" - pipes and redirections are
passed as arguments to the first command rather than being handled by
the shell.


> When I try:
>   (sh :in (str "/...pdb_to_xyzr" pdb-file " > /...hold.xyzr")))
> I get the following:
> No matching method found: exec for class java.lang.Runtime

:in is the "standard in" for a command, but you haven't specified
which command.

If you use "sh" as the command you get a shell and can use normal
shell syntax for the :in parameter.

So this works:
user=> (sh "sh" :in "env | grep PATH")
"PATH=/usr/bin:/bin:/usr/sbin:/sbin\n"
user=> (sh "sh" :in "env > tmp.txt")
""


> Does anyone know why this doesn't seem to work:
>
> (defn test-execute [ls-arg1 ls-arg2]
>   (execute (str "ls -" ls-arg1))
>   (execute (str "ls -" ls-arg2)))

As far as I can tell it does - it executes both commands, but returns
only the result of the last one.
If you want both, wrap them in a list or vector:
(defn test-execute [ls-arg1 ls-arg2]
  (list
(execute (str "ls -" ls-arg1))
    (execute (str "ls -" ls-arg2


Regards
jf

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: take-while2?

2010-08-07 Thread Randy Hudson
Nice!

On Aug 7, 11:56 pm, Michał Marczyk  wrote:
> Yet another version:
>
> (defn take-while-acc [f pred coll]
>   (map (fn [_ x] x)
>        (take-while pred (reductions f coll))
>        coll))
>
> Seems to work:
>
> user> (take-while-acc + #(< % 100) (range))
> (0 1 2 3 4 5 6 7 8 9 10 11 12 13)
>
> Note that reductions does use an "accumulator" (in the form of a
> closed over local), so the above works as requested. Also, this
> version constructs no auxiliary data structures, not even two-element
> vectors.
>
> Sincerely,
> Michał

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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: looking for a simpler implementation of a function I'm using

2010-08-07 Thread David Cabana
> conj sounds like 'append' to me which I have no idea about the
> performance characteristics in clojure(it is a no-no in F#, Haskell ++
> is better but would grow the stack).

conj is not the same as append; it will insert the new element in the
smart (most efficient) way. For instance:
user> (conj  '(1 2 3) 0)
(0 1 2 3)
user> (conj [1 2 3] 0)
[1 2 3 0]

There is no performance hit from using conj to insert at the end of a vector.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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