Re: Calling .close() on resources -- with-open macro

2011-01-25 Thread Laurent PETIT
2011/1/25 Meikel Brandmeyer :
> Hi,
>
> On 25 Jan., 01:57, Laurent PETIT  wrote:
>
>> (try (. ~(bindings 0) close) (catch Throwable _))
>
> New code should use (.close foo) instead of (. foo close), IIRC.

Sure, but it's an enhancement over existing code, so I've followed the
convention (and I was not sure that (.close ...) would work at this
point in core.clj, so I adopted a rather conservative choice.

-- 
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: Calling .close() on resources -- with-open macro

2011-01-25 Thread Laurent PETIT
2011/1/25 Ken Wesson :
> Huh. We came up with almost the same final version. I guess I took 13
> minutes longer because I tested mine

And also because I was in a hurry to go to bed ! :)

>-- yours still has the missing #.
> :)

This was intentional, I had to let something for you to bite ;)

-- 
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: Calling .close() on resources -- with-open macro

2011-01-25 Thread Laurent PETIT
2011/1/25 Shantanu Kumar :
> The changed code should catch 'Exception', not 'Throwable' because the
> latter is a common ancestor of both 'Exception' and 'Error'. An
> 'Error' must not be swallowed at any point in the system, unless you
> are writing an app server or a JVM implementation. ;-)

True enough.

Does this mean that, with the change from Throwable to Exception,
you're ok with the new implementation and it fullfills the
expectations of your original email ?

>
> Regards,
> Shantanu
>
> On Jan 25, 6:11 am, Ken Wesson  wrote:
>> On Mon, Jan 24, 2011 at 7:43 PM, Laurent PETIT  
>> wrote:
>> > 2011/1/25 Ken Wesson :
>> >> Ah, I guess it may be a bit cleaner to just eschew "finally"
>> >> altogether and close in the try and in the catch. The one thing that's
>> >> a bit icky about that is that if the body close throws, the catch
>> >> clause tries to close the stream again.
>>
>> > argh yes, this may be a problem ...
>>
>> There's also a bug: _ instead of _# in the close exception discarder. :)
>>
>> How's about:
>>
>> (in-ns 'clojure.core)
>> (defmacro with-open
>>   "bindings => [name init ...]
>>
>>    Evaluates body in a try expression with names bound to the values
>>    of the inits, and a finally clause that calls (.close name) on each
>>    name in reverse order."
>>   {:added "1.0"}
>>   [bindings & body]
>>   (assert-args with-open
>>     (vector? bindings) "a vector for its binding"
>>     (even? (count bindings)) "an even number of forms in binding vector")
>>   (cond
>>     (= (count bindings) 0) `(do ~@body)
>>     (symbol? (bindings 0)) `(let ~(subvec bindings 0 2)
>>                               (let [res# (try
>>                                            (with-open ~(subvec
>> bindings 2) ~@body)
>>                                            (catch Throwable t#
>>                                              (try
>>                                                (. ~(bindings 0) close)
>>                                                (catch Throwable _#))
>>                                              (throw t#)))]
>>                                 (. ~(bindings 0) close)
>>                                 res#))
>>    :else (throw (IllegalArgumentException.
>>                   "with-open only allows Symbols in bindings"
>>
>> No double-closing and no vector. If the body throws, the exception is
>> caught, the close is done with any close exception suppressed, and the
>> original exception rethrown and that's it. If the body doesn't throw,
>> we store it in res and then close. If the close throws here, the
>> exception is allowed to propagate. Otherwise we return res.
>>
>> I've tested this with Foo and it works; modifying Foo to replace the
>> close throw with (println "closed"), the doit throw with the integer
>> literal 42, or both, I get:
>>
>> Both throw:
>> #
>>
>> Close throws:
>> #
>>
>> Doit throws:
>> closed
>> #
>>
>> Neither throws:
>> closed
>> 42
>>
>> The right exception escapes if any exceptions are thrown, and "closed"
>> is printed exactly once if close doesn't throw.
>
> --
> 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: Calling .close() on resources -- with-open macro

2011-01-25 Thread Shantanu Kumar


On Jan 25, 2:30 pm, Laurent PETIT  wrote:
> 2011/1/25 Shantanu Kumar :
>
> > The changed code should catch 'Exception', not 'Throwable' because the
> > latter is a common ancestor of both 'Exception' and 'Error'. An
> > 'Error' must not be swallowed at any point in the system, unless you
> > are writing an app server or a JVM implementation. ;-)
>
> True enough.
>
> Does this mean that, with the change from Throwable to Exception,
> you're ok with the new implementation and it fullfills the
> expectations of your original email ?

Yes.

Regards,
Shantanu

>
>
>
>
>
>
>
>
>
> > Regards,
> > Shantanu
>
> > On Jan 25, 6:11 am, Ken Wesson  wrote:
> >> On Mon, Jan 24, 2011 at 7:43 PM, Laurent PETIT  
> >> wrote:
> >> > 2011/1/25 Ken Wesson :
> >> >> Ah, I guess it may be a bit cleaner to just eschew "finally"
> >> >> altogether and close in the try and in the catch. The one thing that's
> >> >> a bit icky about that is that if the body close throws, the catch
> >> >> clause tries to close the stream again.
>
> >> > argh yes, this may be a problem ...
>
> >> There's also a bug: _ instead of _# in the close exception discarder. :)
>
> >> How's about:
>
> >> (in-ns 'clojure.core)
> >> (defmacro with-open
> >>   "bindings => [name init ...]
>
> >>    Evaluates body in a try expression with names bound to the values
> >>    of the inits, and a finally clause that calls (.close name) on each
> >>    name in reverse order."
> >>   {:added "1.0"}
> >>   [bindings & body]
> >>   (assert-args with-open
> >>     (vector? bindings) "a vector for its binding"
> >>     (even? (count bindings)) "an even number of forms in binding vector")
> >>   (cond
> >>     (= (count bindings) 0) `(do ~@body)
> >>     (symbol? (bindings 0)) `(let ~(subvec bindings 0 2)
> >>                               (let [res# (try
> >>                                            (with-open ~(subvec
> >> bindings 2) ~@body)
> >>                                            (catch Throwable t#
> >>                                              (try
> >>                                                (. ~(bindings 0) close)
> >>                                                (catch Throwable _#))
> >>                                              (throw t#)))]
> >>                                 (. ~(bindings 0) close)
> >>                                 res#))
> >>    :else (throw (IllegalArgumentException.
> >>                   "with-open only allows Symbols in bindings"
>
> >> No double-closing and no vector. If the body throws, the exception is
> >> caught, the close is done with any close exception suppressed, and the
> >> original exception rethrown and that's it. If the body doesn't throw,
> >> we store it in res and then close. If the close throws here, the
> >> exception is allowed to propagate. Otherwise we return res.
>
> >> I've tested this with Foo and it works; modifying Foo to replace the
> >> close throw with (println "closed"), the doit throw with the integer
> >> literal 42, or both, I get:
>
> >> Both throw:
> >> # >> (NO_SOURCE_FILE:46)>
>
> >> Close throws:
> >> # >> (NO_SOURCE_FILE:48)>
>
> >> Doit throws:
> >> closed
> >> # >> (NO_SOURCE_FILE:46)>
>
> >> Neither throws:
> >> closed
> >> 42
>
> >> The right exception escapes if any exceptions are thrown, and "closed"
> >> is printed exactly once if close doesn't throw.
>
> > --
> > 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: Calling .close() on resources -- with-open macro

2011-01-25 Thread David Powell
On 25 Jan 2011 06:04, "Shantanu Kumar"  wrote:
>
> The changed code should catch 'Exception', not 'Throwable' because the
> latter is a common ancestor of both 'Exception' and 'Error'. An
> 'Error' must not be swallowed at any point in the system, unless you
> are writing an app server or a JVM implementation. ;-)

Throwable is better I think.  The idea is to be a more robust try/finally
construct, and finally still runs if an Error is thrown.  There is no
problem temporarily catching Throwable as long as you don't swallow 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
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: Calling .close() on resources -- with-open macro

2011-01-25 Thread Shantanu Kumar


On Jan 25, 4:22 pm, David Powell  wrote:
> On 25 Jan 2011 06:04, "Shantanu Kumar"  wrote:
>
>
>
> > The changed code should catch 'Exception', not 'Throwable' because the
> > latter is a common ancestor of both 'Exception' and 'Error'. An
> > 'Error' must not be swallowed at any point in the system, unless you
> > are writing an app server or a JVM implementation. ;-)
>
> Throwable is better I think.  The idea is to be a more robust try/finally
> construct, and finally still runs if an Error is thrown.  There is no
> problem temporarily catching Throwable as long as you don't swallow it.

I can't see the value in catching Throwable and then re-throwing it;
idiomatically Throwable is rarely caught. Looking at code example, the
following two snippets below are just the same:

(try
  (.close resource)
  (catch Throwable t
(when (instance? Error t)
  (throw t

(try
  (.close resource)
  (catch Exception e))

Besides, looking at the Java spec
http://download.oracle.com/javase/6/docs/api/java/lang/Error.html

--
An Error is a subclass of Throwable that indicates serious problems
that a reasonable application should not try to catch. Most such
errors are abnormal conditions. The ThreadDeath error, though a
"normal" condition, is also a subclass of Error because most
applications should not try to catch it.

A method is not required to declare in its throws clause any
subclasses of Error that might be thrown during the execution of the
method but not caught, since these errors are abnormal conditions that
should never occur.
--

Regards,
Shantanu

-- 
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: Getting started with Counterclockwise

2011-01-25 Thread NovusTiro
Hello,

Seems like this might be a good time to say thanks to Laurent for all
the work he's done on CCW.  FWIW, I've been using it for a while, and
never had any issues installing it (at least not from a clean
Eclipse), nor any of the other described issues.

So thanks Laurent, and keep up the good work!

MBL

On Jan 20, 8:45 am, Ken Wesson  wrote:
> On Wed, Jan 19, 2011 at 9:56 AM, Luc Prefontaine
>
>  wrote:
> > Not reading wiki pages available, not investigating available links
> > about ccw are more a sign of mental laziness than anything else or
> > some form of disdain.
>
> Or, they can be a sign of not having been pointed to the links by the
> install process, and none of them looking particularly promising when
> returned as Google hits.
>
> > If these mundane activities are not important to you then maybe you
> > should balance your post contents a bit and change the ranting/facts
> > ratio. You cannot hold others responsible for your lack of knowledge
> > in some areas.
>
> True. But I can certainly hold others responsible for a) not setting
> up conditions where a majority of the people in some group G will
> naturally encounter certain information I, but then b) expressing an
> expectation that the people in group G will know I anyway, and c)
> being condescending towards anyone you encounter from G that does not
> know I.
>
> > I see the same pattern with your ranting against the numeric
> > optimizations in 1.3. All of these discussions are available in the
> > google group mailing list but it seems you did not read them to fully
> > understand the pros and cons of each approach that where evaluated.
>
> Because it was a long, rambling discussion thread full of all manner
> of tangents, plus stuff that was in flux and later changed, plus ...
> etc.
>
> I asked if someone could point me to a summary or precis of the key,
> still-relevant facts and arguments, something that could get me up to
> speed with, you know, *actual speed* instead of taking days. The
> closest I got was a four-page-or-so summary of two proposed versions
> of the changes, and I did read that.
>
> > You have been asked kindly to change your tone.
>
> Are you implying a threat?
>
> The next part of your post seemed to descend into name-calling, more
> threats, and other unconstructive material, so I did not bother to
> read further.
>
> Have a good day.

-- 
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: Why won't leiningen install for me?

2011-01-25 Thread Larry Travis

Mark, John, Gaz:
Your responses are all suggestive but I don't know where to go from here 
so I am going to make one more cry for help -- and to this group rather 
than the leiningen-specific one suggested by Mark because my basic 
problem is really how-to-get-clojure/emacs-running-under-MacOsX.


Here is the situation, and my further questions:

-- I am running OsX 10.6 on a machine that has never had an earlier OsX 
version running on it so there should not be problems involving 10.5 to 
10.6 upgrade.


-- I have downloaded and installed Macports -- including a recent 
upgrade. If Macports' version of curl is indeed the culprit, how do I 
get it replaced with a version that could download leiningen?  Do I dare 
just simply uninstall Macports -- which I am not using right now in any 
case? (All I want to do right now is work with Clojure!)


-- Although it surprised me, when I checked to see to what kernel my 
iMac was defaulting, I was told i386. What else could the leiningen 
installation process be asking for? Surely it wouldn't be expecting x86_64.


-- In the webpage Mark pointed me to is the assertion: "If only ppc and 
i386 are present, while you require x86_64, then the library cannot be 
loaded."  But also, from a different commentator: "This issue was fixed 
in a later version of MacPorts with better 10.6 x86_64 compatibility." 
Is there some way to determine if the installation process is indeed 
expecting an x86_64 architecture?


Thanks again.
  --Larry

-- 

On 1/22/11 2:16 PM, gaz jones wrote:

are you sure you dont have curl installed by macports or something?
/usr/bin/curl on mac os x works fine with https for me... someone at
work had this problem and they had (unknowingly) installed curl
through macports...

On Sat, Jan 22, 2011 at 1:28 PM, Bizics  wrote:

Hi Larry,
I had problems installing too.
Turns out curl on mac os x does not support https as required by
github now.
I had to download and rebuild curl with the +ssl flag for https to be
supported and then things worked fine.
I could dig up my notes from when I did it if you need more
information.

Cheers,
John


On Jan 21, 4:49 pm, Larry Travis  wrote:

I get the following when I try to install Leiningen:

---
larrytravis$   lein-install.sh   self-install

Downloading Leiningen now...

dyld: Library not loaded: /opt/local/lib/libintl.8.dylib
Referenced from: /opt/local/bin/curl
Reason: no suitable image found.  Did find:
  /opt/local/lib/libintl.8.dylib: mach-o, but wrong architecture

/Users/larrytravis/bin/lein-install.sh: line 175:  2851 Trace/BPT
trap  $HTTP_CLIENT "$LEIN_JAR" "$LEIN_URL"

Failed to 
downloadhttps://github.com/downloads/technomancy/leiningen/leiningen-1.4.2-st...


Can anybody advise me as to what I am doing wrong?

/lein-install.sh/ is the script available at:

https://github.com/technomancy/leiningen/raw/stable/bin/lein

Also I can't download /leiningen-1.4.2-standalone.jar/ directly 
fromhttps://github.com/technomancy/leiningen/downloads, but I don't think I
would know what to do with it if I could! I am a Java tyro (who knows
some other lisps reasonably well) trying to use clojure under Mac Os X
and Emacs, but I am having a lot of problems getting clojure to run
conveniently in that environment.

Thanks for your help.
--Larry Travis

--
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: Calling .close() on resources -- with-open macro

2011-01-25 Thread David Powell
On Tue, Jan 25, 2011 at 1:04 PM, Shantanu Kumar wrote:

I can't see the value in catching Throwable and then re-throwing it;
> idiomatically Throwable is rarely caught. Looking at code example, the
> following two snippets below are just the same:
>
> (try
>  (.close resource)
>  (catch Throwable t
>(when (instance? Error t)
>  (throw t
>
> (try
>  (.close resource)
>  (catch Exception e))
>

(I don't think we want to discard the exception from close - Ken's code
still throws it if the body didn't throw an exception.)


> Besides, looking at the Java spec
> http://download.oracle.com/javase/6/docs/api/java/lang/Error.html


Clojure isn't Java though.  Bytecode corresponding to Java source code for a
try/finally block effectively catches Throwable via an 'any' entry in the
exception table, and then rethrows it.  Clojure should do something similar
or better.

See:
http://java.sun.com/docs/books/jvms/second_edition/html/Compiling.doc.html#13789

(although compilers generally inline the finally block nowadays, rather than
using the slower jsr instruction).

-- 
Dave

-- 
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: Why won't leiningen install for me?

2011-01-25 Thread Sean Allen
I wiped my macports a while back, reinstalled everything I needed and
stopped having problems like this.

On Mon, Jan 24, 2011 at 9:38 PM, Mark Rathwell wrote:

>
> Seems pretty clear that your macports version of curl is the problem, it's
> up to you what you want to do about it.  I don't know if uninstalling it
> would leave you with the OS X version of curl or not.  Link to get you
> started:
>
>
> http://www.richarddooling.com/index.php/2009/09/12/macports-on-snow-leopard/
>
> 
>
> On Mon, Jan 24, 2011 at 7:29 PM, Larry Travis  wrote:
>
>> Mark, John, Gaz:
>> Your responses are all suggestive but I don't know where to go from here
>> so I am going to make one more cry for help -- and to this group rather than
>> the leiningen-specific one suggested by Mark because my basic problem is
>> really how-to-get-clojure/emacs-running-under-MacOsX.
>>
>> Here is the situation, and my further questions:
>>
>> -- I am running OsX 10.6 on a machine that has never had an earlier OsX
>> version running on it so there should not be problems involving 10.5 to 10.6
>> upgrade.
>>
>> -- I have downloaded and installed Macports -- including a recent upgrade.
>> If Macports' version of curl is indeed the culprit, how do I get it replaced
>> with a version that could download leiningen?  Do I dare just simply
>> uninstall Macports -- which I am not using right now in any case? (All I
>> want to do right now is work with Clojure!)
>>
>> -- Although it surprised me, when I checked to see to what kernel my iMac
>> was defaulting, I was told i386. What else could the leiningen installation
>> process be asking for? Surely it wouldn't be expecting x86_64.
>>
>> -- In the webpage Mark pointed me to is the assertion: "If only ppc and
>> i386 are present, while you require x86_64, then the library cannot be
>> loaded."  But also, from a different commentator: "This issue was fixed in a
>> later version of MacPorts with better 10.6 x86_64 compatibility." Is there
>> some way to determine if the installation process is indeed expecting an
>> x86_64 architecture?
>>
>> Thanks again.
>>  --Larry
>>
>> --
>> 
>>
>>
>> On 1/22/11 2:16 PM, gaz jones wrote:
>>
>>> are you sure you dont have curl installed by macports or something?
>>> /usr/bin/curl on mac os x works fine with https for me... someone at
>>> work had this problem and they had (unknowingly) installed curl
>>> through macports...
>>>
>>> On Sat, Jan 22, 2011 at 1:28 PM, Bizics
>>>  wrote:
>>>
 Hi Larry,
 I had problems installing too.
 Turns out curl on mac os x does not support https as required by
 github now.
 I had to download and rebuild curl with the +ssl flag for https to be
 supported and then things worked fine.
 I could dig up my notes from when I did it if you need more
 information.

 Cheers,
 John


 On Jan 21, 4:49 pm, Larry Travis  wrote:

> I get the following when I try to install Leiningen:
>
> ---
> larrytravis$   lein-install.sh   self-install
>
> Downloading Leiningen now...
>
> dyld: Library not loaded: /opt/local/lib/libintl.8.dylib
>Referenced from: /opt/local/bin/curl
>Reason: no suitable image found.  Did find:
>  /opt/local/lib/libintl.8.dylib: mach-o, but wrong architecture
>
> /Users/larrytravis/bin/lein-install.sh: line 175:  2851 Trace/BPT
> trap  $HTTP_CLIENT "$LEIN_JAR" "$LEIN_URL"
>
> Failed to downloadhttps://
> github.com/downloads/technomancy/leiningen/leiningen-1.4.2-st...
>
> 
> Can anybody advise me as to what I am doing wrong?
>
> /lein-install.sh/ is the script available at:
>
> https://github.com/technomancy/leiningen/raw/stable/bin/lein
>
> Also I can't download /leiningen-1.4.2-standalone.jar/ directly
> fromhttps://github.com/technomancy/leiningen/downloads, but I don't
> think I
> would know what to do with it if I could! I am a Java tyro (who knows
> some other lisps reasonably well) trying to use clojure under Mac Os X
> and Emacs, but I am having a lot of problems getting clojure to run
> conveniently in that environment.
>
> Thanks for your help.
>--Larry Travis
>
 --
 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

defrecord constructor woes

2011-01-25 Thread Mike
Quick question...I am trying to populate a record with values provided
in a list.  I'm definitely doing it the wrong way...but maybe there's
no good way to do it.

Here's what I do (clojure 1.2.0 by the way):

(defrecord Foo [x y z])
(Foo. 1 2 3)

#:user.Foo{:x 1, :y 2, :z 3}

but then:

(apply Foo. (range 1 4))

java.lang.ClassCastException: java.lang.Class (NO_SOURCE_FILE:0)

I'm running into syntax issues here...I can't apply new:

(apply new '(Foo 1 2 3))

java.lang.Exception: Unable to resolve symbol: new in this context
(NO_SOURCE_FILE:28)

Do I need to make a macro here to expand my argument list at compile
time?  I'm thinking this is a pretty fast solution, but I'd hate to
make a macro if I'm just doing it wrong.

Thanks in advance,
Mike

-- 
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: defrecord constructor woes

2011-01-25 Thread Meikel Brandmeyer
Hi,

constructors (like methods) are not first class. You have to wrap it
in a factory function.

(defn make-foo
  [a b c d]
  (Foo. a b c d))

(apply make-foo [1 2 3 4])

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: Calling .close() on resources -- with-open macro

2011-01-25 Thread Ken Wesson
On Tue, Jan 25, 2011 at 1:03 AM, Shantanu Kumar
 wrote:
> The changed code should catch 'Exception', not 'Throwable' because the
> latter is a common ancestor of both 'Exception' and 'Error'. An
> 'Error' must not be swallowed at any point in the system, unless you
> are writing an app server or a JVM implementation. ;-)

Remember, we're no longer using a "finally" clause, so for the .close
to be exception-safe *everything* must be caught. But it's rethrown
unless both threw exceptions, and then we were only ever going to be
able to keep one exception anyway.

-- 
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: defrecord constructor woes

2011-01-25 Thread Mike
thanks!!!

On Jan 25, 8:55 am, Meikel Brandmeyer  wrote:
> Hi,
>
> constructors (like methods) are not first class. You have to wrap it
> in a factory function.
>
> (defn make-foo
>   [a b c d]
>   (Foo. a b c d))
>
> (apply make-foo [1 2 3 4])
>
> 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: Calling .close() on resources -- with-open macro

2011-01-25 Thread Meikel Brandmeyer
Hi,

Disclaimer: I have no clue, what I'm talking about. Just making up
contrived examples, which probably never happen in reality.

On 25 Jan., 15:13, Ken Wesson  wrote:

> Remember, we're no longer using a "finally" clause, so for the .close
> to be exception-safe *everything* must be caught. But it's rethrown
> unless both threw exceptions, and then we were only ever going to be
> able to keep one exception anyway.

What should be done, when the body throws an Exception and the close
throws an Error? What happens at the moment when the body throws an
Error and the close throws an Exception?

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: How does pmap partition its work?

2011-01-25 Thread Michael Gardner
I have run across something else I don't understand about pmap. Why does the 
following:

(pmap (fn [_] (clojure.java.shell/sh "sleep" "10")) (range 32))

result in all 32 "sleep" processes being run at once? I thought pmap used n+2 
threads, where n is the number of processors/cores available (I have two cores).

-- 
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: How does pmap partition its work?

2011-01-25 Thread Ken Wesson
On Tue, Jan 25, 2011 at 9:45 AM, Michael Gardner  wrote:
> I have run across something else I don't understand about pmap. Why does the 
> following:
>
> (pmap (fn [_] (clojure.java.shell/sh "sleep" "10")) (range 32))
>
> result in all 32 "sleep" processes being run at once? I thought pmap used n+2 
> threads, where n is the number of processors/cores available (I have two 
> cores).

sh is asynchronous. It calls Runtime/exec, which launches the sleep as
a separate process and immediately returns a Process object (which
your pmap should be returning a seq of). It may produce n+2 Process
objects at a time but it produces them all before the first of the
asynchronous sleep processes finishes, so for a while all of the
latter are running at the same time.

-- 
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: How does pmap partition its work?

2011-01-25 Thread Michael Gardner
On Jan 25, 2011, at 9:06 AM, Ken Wesson wrote:

> sh is asynchronous. It calls Runtime/exec, which launches the sleep as
> a separate process and immediately returns a Process object (which
> your pmap should be returning a seq of). It may produce n+2 Process
> objects at a time but it produces them all before the first of the
> asynchronous sleep processes finishes, so for a while all of the
> latter are running at the same time.

Really? The documentation for sh claims to return a map, which is what I 
observe. And the call to sh doesn't return until the sub-process has finished, 
even if I discard its return value (so it can't be the case that the resulting 
"map" is actually some lazy thing that blocks when I try to access its 
contents).

-- 
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: How does pmap partition its work?

2011-01-25 Thread Ken Wesson
On Tue, Jan 25, 2011 at 10:21 AM, Michael Gardner  wrote:
> On Jan 25, 2011, at 9:06 AM, Ken Wesson wrote:
>
>> sh is asynchronous. It calls Runtime/exec, which launches the sleep as
>> a separate process and immediately returns a Process object (which
>> your pmap should be returning a seq of). It may produce n+2 Process
>> objects at a time but it produces them all before the first of the
>> asynchronous sleep processes finishes, so for a while all of the
>> latter are running at the same time.
>
> Really? The documentation for sh claims to return a map, which is what I 
> observe.

Well, that's weird, because the documentation *I* read says it
composits the arguments together into a command line and hands off to
Runtime/exec. And the documentation of *that* says it returns a
Process object and the process it launches runs asynchronously.

> And the call to sh doesn't return until the sub-process has finished

If that were the case, though, your pmap should indeed only be running
cores+2 instances at once. Which is not what you observed.

Something's hinky here.

-- 
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: How does pmap partition its work?

2011-01-25 Thread Michael Gardner
On Jan 25, 2011, at 9:33 AM, Ken Wesson wrote:

> Well, that's weird, because the documentation *I* read says it
> composits the arguments together into a command line and hands off to
> Runtime/exec. And the documentation of *that* says it returns a
> Process object and the process it launches runs asynchronously.

That doesn't necessarily contradict what I observed. The way I read the docs[1] 
is that sh does indeed use Runtime.exec(), but then waits for the sub-process 
to complete and returns a map of its exit status, etc. That's not explicitly 
stated, but it's the only explanation consistent with what I observe. For 
comparison, what behavior do you observe with (do (clojure.java.shell/sh 
"sleep" "10") nil)?

> If that were the case, though, your pmap should indeed only be running
> cores+2 instances at once. Which is not what you observed.
> 
> Something's hinky here.

Indeed. According to a previous thread[2], something similar happens with 
Thread/sleep; my guess is that sh sleeps (or something similar) while it waits 
for the sub-process to finish and thus suffers from the same issue.

[1] 
http://clojure.github.com/clojure/clojure.java.shell-api.html#clojure.java.shell/sh
[2] http://groups.google.com/group/clojure/browse_thread/thread/9b3581d9f4b4afd6

-- 
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: Calling .close() on resources -- with-open macro

2011-01-25 Thread Shantanu Kumar


On Jan 25, 7:32 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> Disclaimer: I have no clue, what I'm talking about. Just making up
> contrived examples, which probably never happen in reality.
>
> On 25 Jan., 15:13, Ken Wesson  wrote:
>
> > Remember, we're no longer using a "finally" clause, so for the .close
> > to be exception-safe *everything* must be caught. But it's rethrown
> > unless both threw exceptions, and then we were only ever going to be
> > able to keep one exception anyway.
>
> What should be done, when the body throws an Exception and the close
> throws an Error? What happens at the moment when the body throws an
> Error and the close throws an Exception?

>From what I know about Java idioms, 'Error' must be upheld at all
times because it represents a system-level fault (grave incident),
something that cannot be dealt with by the application. For example,
OutOfMemoryError is not something that can be generally handled by
application and hence must not be swallowed.

Regards,
Shantanu

-- 
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: Why no def- ?

2011-01-25 Thread Benjamin Teuber
Ok, I think I've got it - so basically all private variants should go
in contrib now and moving defn- now would break a lot of people's code
"just" for a little more coherency.

But in this case, I'd like def- to be included in clojure.contrib.def.
I dislike defvar as it's just name and docstring positions are non-
clojuresque (no surprise with a Common Lisp macro).

I like the private macro btw. - maybe also put this in contrib.def?

-- 
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: How does pmap partition its work?

2011-01-25 Thread Andy Fingerhut
In my original message describing pmap's behavior, there was a little  
"gotcha" near the end:


"Note: Sometimes working at odds with pmap's "Don't work too far  
ahead" approach is if the input sequence to pmap is chunked.  When a  
chunk is reached, all elements in that chunk have threads start in  
parallel, so the number of parallel threads can easily exceed  
(availableProcessors+2) during those times."



(range n) produces heavily chunked sequences.  Chunks are an  
optimization on time and memory when representing large sequences, but  
they do cause pmap as written today to suddenly fire off all futures  
in the chunk as parallel threads when it reaches the chunk.


A modified version of pmap called (boringly) "modified-pmap" that does  
not behave this way when reaching a chunk in its input sequence is  
part of one of my submissions to the shootout web site, because I did  
not want the extra parallelism:


http://shootout.alioth.debian.org/u32/program.php?test=knucleotide&lang=clojure&id=2

It is nearly identical to the original pmap.  Comparing to the source  
of the original is the easiest way to see the changes, if you are  
curious.


Andy


On Jan 25, 2011, at 6:45 AM, Michael Gardner wrote:

I have run across something else I don't understand about pmap. Why  
does the following:


(pmap (fn [_] (clojure.java.shell/sh "sleep" "10")) (range 32))

result in all 32 "sleep" processes being run at once? I thought pmap  
used n+2 threads, where n is the number of processors/cores  
available (I have two cores).


--
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: How does pmap partition its work?

2011-01-25 Thread Michael Gardner
On Jan 25, 2011, at 12:13 PM, Andy Fingerhut wrote:

> In my original message describing pmap's behavior, there was a little 
> "gotcha" near the end:
> 
> "Note: Sometimes working at odds with pmap's "Don't work too far ahead" 
> approach is if the input sequence to pmap is chunked.  When a chunk is 
> reached, all elements in that chunk have threads start in parallel, so the 
> number of parallel threads can easily exceed (availableProcessors+2) during 
> those times."
> 
> 
> (range n) produces heavily chunked sequences.  Chunks are an optimization on 
> time and memory when representing large sequences, but they do cause pmap as 
> written today to suddenly fire off all futures in the chunk as parallel 
> threads when it reaches the chunk.

Interesting! Sorry I missed this gotcha from your original email; I hadn't run 
across this problem at the time and thus the info didn't stick in my head. 
Thanks for the link to modified-pmap, too.

This seems like undesirable behavior from pmap to me (and/or unwanted 
chunking-induced behavior[1]). At the least I would like to see pmap adopt an 
optional extra argument that works like your modified-pmap's num-threads 
argument, and possibly also the arrival of Clojure's promised de-chunking 
interface.

[1] http://disclojure.org/documents/clojure-1-1-0-rc1-release-notes/ (section 
2.3: "Please share any use cases where chunked processing has resulted in 
behavioral differences that matter to you on the Clojure google group.")

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


ANN: Midje ready for production use (#testing #clojure.test)

2011-01-25 Thread Brian Marick
Midje is a testing framework that "provides a migration path from clojure.test 
to a more flexible, readable, abstract, and gracious style of testing." I've 
bumped it to version 1. That means I feel safe offering it to you for 
production use. 

Here's a video showing how to migrate from clojure.test to Midje:
http://www.youtube.com/watch?v=a7YtkcIiLGI  (8 minutes)

The entry point to the documentation is here:
https://github.com/marick/Midje/blob/master/README.md

Thank you.

-
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Author of /Ring/ (forthcoming; sample: http://exampler.com/tmp/ring.pdf)
www.exampler.com, www.exampler.com/blog, www.twitter.com/marick

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


ANN: Sisyphus - mapreduce implemented in Clojure

2011-01-25 Thread Olek
Hi!

It is nice to announce that Sisyphus - the google's mapreduce
implemented in Clojure - has been released.
Here are the sources: https://github.com/njoanna/Sisyphus

Some comments are still in polish but they will be gradually replaced
with english version.

Right now there are 5 tasks (zadanie 1 - 5):

1. Count number of occurences of a particular word in a set of text
documents. The result is a pair of: searched word, its number of
occurences.

2. Look up for a sequence of chars in a set of text documents. The
result is a set of pairs of: name of a file, line where the sequence
has occured.

3. Sort words in a set of text documents. The results is a set of
sorted unique words.

4. Create an index of words which length is higher then given value.
The result is a sorted list of pairs of: words, list of files where
the word occures.

5. Create statistic of used words. The result is a sorted list of
pairs: word, numer of occurences.

Hope you enjoy that.

Bye!

-- 
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: Why won't leiningen install for me? (NOW IT DOES!)

2011-01-25 Thread Larry Travis
You guys are great!  As my dad used to say when he had been greatly 
helped: Each of you is a scholar and a gentleman.


I admire your expertise. You each had knowledgeable and quite helpful 
suggestions. I ended up using Alex's ideas for getting the Leiningen 
installation process to avoid Macports' version of /curl/ and go back to 
the Mac OsX's original version, and from there on everything has worked 
well. Later I will install a version of Macports specifically adapted to 
Snow Leopard, /a la/ the link from Mark -- or replace Macports with 
Homebrew, as recommended by Gaz -- but right now I don't need either, 
and I want to spend my time digging more deeply into how Clojure enables 
one to utilize multi-core processors.


And the Clojure IDE I've got running to support that digging is just 
beautiful: Snow Leopard + Aquamacs + Slime.


Thanks again.
  --Larry






On 1/24/11 8:44 PM, Alex Osborne wrote:

Hi Larry,

As a quick temporary workaround you could just set your PATH environment
variable so that it picks up the curl executable from /usr/bin instead
of the broken MacPorts one from /opt/local/bin.

$ which curl
/opt/local/bin/curl
$ export PATH=/usr/bin:$PATH
$ which curl
/usr/bin/curl

You'll need to do that each time you install/upgrade Leiningen though.

Since you're not using MacPorts, personally I'd opt to just rename the
entire MacPorts directory (/opt/local) out of the way:

$ sudo mv /opt/local /opt/local.broken

You could then delete it or reinstall it at a later time, whatever you
prefer.

Cheers,

Alex


Mark Rathwell  writes:



 Seems pretty clear that your macports version of curl is the problem, it's up 
to you what you want to do about it.  I don't know if uninstalling it would 
leave you with the OS X version of
 curl or not.  Link to get you started:

 http://www.richarddooling.com/index.php/2009/09/12/macports-on-snow-leopard/




--
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: ANN: Sisyphus - mapreduce implemented in Clojure

2011-01-25 Thread kovas boguta
Hi Olek,

Could you explain how this differs from Hadoop in concept and in
execution? Thanks.


On Tue, Jan 25, 2011 at 2:26 PM, Olek  wrote:
> Hi!
>
> It is nice to announce that Sisyphus - the google's mapreduce
> implemented in Clojure - has been released.
> Here are the sources: https://github.com/njoanna/Sisyphus
>
> Some comments are still in polish but they will be gradually replaced
> with english version.
>
> Right now there are 5 tasks (zadanie 1 - 5):
>
> 1. Count number of occurences of a particular word in a set of text
> documents. The result is a pair of: searched word, its number of
> occurences.
>
> 2. Look up for a sequence of chars in a set of text documents. The
> result is a set of pairs of: name of a file, line where the sequence
> has occured.
>
> 3. Sort words in a set of text documents. The results is a set of
> sorted unique words.
>
> 4. Create an index of words which length is higher then given value.
> The result is a sorted list of pairs of: words, list of files where
> the word occures.
>
> 5. Create statistic of used words. The result is a sorted list of
> pairs: word, numer of occurences.
>
> Hope you enjoy that.
>
> Bye!
>
> --
> 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


Conduit and LBQ

2011-01-25 Thread jim
Edmund Jackson has put up a blog post that describes how integrate
LinkedBlockingQueue's with Conduit. It's a pretty good example of what
you can do with Conduit without too much trouble.

Jim

http://boss-level.com/?p=89

-- 
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: Why no def- ?

2011-01-25 Thread OGINO Masanori
Hello.

If def- remains for historical reason, def- may be marked as
duplicated and will be moved, for example, in 1.4, 2.0 or so?

Thank you.

-- 
Name:  OGINO Masanori (荻野 雅紀)
E-mail: masanori.og...@gmail.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
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