ClassNotFoundException for an fn in 1067

2008-10-13 Thread Mike Hinchey

I know the #= and the AOT changes are new and not explained yet.  It
seems to break a macro I'm writing, which does something like this
example.  It does what I want in 1064, but not 1067.

user> (defmacro aa [f x] `(~(var-get (resolve f)) ~x))
nil
user> (aa inc 3)
java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4094)
at clojure.eval__778.invoke(boot.clj:1431)
at swank.commands.basic.eval_region__2884.invoke(basic.clj:34)
at swank.commands.basic.listener_eval__2893.invoke(basic.clj:48)
at clojure.lang.Var.invoke(Var.java:319)
at user.eval__3447.invoke(Unknown Source)
at clojure.lang.Compiler.eval(Compiler.java:4083)
at clojure.eval__778.invoke(boot.clj:1431)
at swank.core.eval_in_emacs_package__2720.invoke(core.clj:49)
at swank.core.eval_for_emacs__2761.invoke(core.clj:104)
at clojure.lang.Var.invoke(Var.java:327)
at clojure.lang.AFn.applyToHelper(AFn.java:190)
at clojure.lang.Var.applyTo(Var.java:436)
at clojure.apply__135.doInvoke(boot.clj:364)
at clojure.lang.RestFn.invoke(RestFn.java:428)
at swank.core.eval_from_control__2723.invoke(core.clj:56)
at swank.core.eval_loop__2726.invoke(core.clj:61)
at
swank.core.spawn_repl_thread__2781$fn__2790$fn__2792.invoke(core.clj:
137)
at clojure.lang.AFn.applyToHelper(AFn.java:182)
at clojure.lang.AFn.applyTo(AFn.java:175)
at clojure.apply__135.doInvoke(boot.clj:364)
at clojure.lang.RestFn.invoke(RestFn.java:428)
at swank.core.spawn_repl_thread__2781$fn__2790.doInvoke(core.clj:134)
at clojure.lang.RestFn.invoke(RestFn.java:402)
at clojure.lang.AFn.run(AFn.java:38)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at clojure.lang.Compiler$FnExpr.eval(Compiler.java:3170)
at clojure.lang.Compiler.eval(Compiler.java:4082)
... 25 more
Caused by: java.lang.RuntimeException:
java.lang.ClassNotFoundException: clojure.inc__305
at clojure.lang.RT.readString(RT.java:1184)
at user.eval__3450.(Unknown Source)
... 33 more
Caused by: java.lang.ClassNotFoundException: clojure.inc__305
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:
52)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at clojure.lang.RT.classForName(RT.java:1509)
at clojure.lang.LispReader$EvalReader.invoke(LispReader.java:876)
at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:509)
at clojure.lang.LispReader.read(LispReader.java:141)
at clojure.lang.RT.readString(RT.java:1180)
... 34 more


I get a similar exception with the example below.  Am I
misunderstanding, or should I be able to eval the #=form printed for a
fn?

user> inc
#=(clojure.inc__305. "[EMAIL PROTECTED]")
user> #=(clojure.inc__305. "[EMAIL PROTECTED]")
clojure.lang.LispReader$ReaderException:
java.lang.ClassNotFoundException: clojure.inc__305 (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4094)
at clojure.eval__778.invoke(boot.clj:1431)
at swank.core.eval_in_emacs_package__2720.invoke(core.clj:49)
at swank.core.eval_for_emacs__2761.invoke(core.clj:104)
at clojure.lang.Var.invoke(Var.java:327)
at clojure.lang.AFn.applyToHelper(AFn.java:190)
at clojure.lang.Var.applyTo(Var.java:436)
at clojure.apply__135.doInvoke(boot.clj:364)
at clojure.lang.RestFn.invoke(RestFn.java:428)
at swank.core.eval_from_control__2723.invoke(core.clj:56)
at swank.core.eval_loop__2726.invoke(core.clj:61)
at
swank.core.spawn_repl_thread__2781$fn__2790$fn__2792.invoke(core.clj:
137)
at clojure.lang.AFn.applyToHelper(AFn.java:182)
at clojure.lang.AFn.applyTo(AFn.java:175)
at clojure.apply__135.doInvoke(boot.clj:364)
at clojure.lang.RestFn.invoke(RestFn.java:428)
at swank.core.spawn_repl_thread__2781$fn__2790.doInvoke(core.clj:134)
at clojure.lang.RestFn.

recur question

2008-10-13 Thread michael

Giving the factorial function as:

(def factorial
(fn [n] (cond (= n 1)
  (> n 1) (* n (recur (dec n))

the compiler complains "Can only recur from tail position".
Isn't really the recur in tail position? It is the last expresson to
be evaluated.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: ClassNotFoundException for an fn in 1067

2008-10-13 Thread Rich Hickey



On Oct 13, 3:17 am, Mike Hinchey <[EMAIL PROTECTED]> wrote:
> I know the #= and the AOT changes are new and not explained yet.  It
> seems to break a macro I'm writing, which does something like this
> example.  It does what I want in 1064, but not 1067.
>
> user> (defmacro aa [f x] `(~(var-get (resolve f)) ~x))
> nil
> user> (aa inc 3)

> I get a similar exception with the example below.  Am I
> misunderstanding, or should I be able to eval the #=form printed for a
> fn?
>
> user> inc
> #=(clojure.inc__305. "[EMAIL PROTECTED]")
> user> #=(clojure.inc__305. "[EMAIL PROTECTED]")
> clojure.lang.LispReader$ReaderException:
> java.lang.ClassNotFoundException: clojure.inc__305 (NO_SOURCE_FILE:0)

You cannot, and might never be able to, print/read fns.

I would examine carefully whether your macro really should be doing
this, as this is likely to become disallowed once Clojure can AOT
compile.

The other option would be to allow some things dynamically but not
AOT, which is definitely not my preference.

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Paul Barry

Now that clojure maps are Java Maps, it is easier to inter-operate
with Java code that has methods that take a Map as one of its
arguments, because you can just pass the Map right into the Java
code.  The problem is that often times, the Java method is expecting
the Map to have String values in the keys, definitely not clojure's
Keywords.  So if you have a {:foo 1} clojure map that you pass to a
Java method, which then calls map.get("foo"), you won't find that
value.

Does anyone have any suggestions for how to handle this?  You could
just use Strings for the keys in the clojure map, but then that map
might not work with other clojure functions that expect the keys to be
Keywords, not Strings.  You could pass the map through a function that
converts the Keywords to Strings before using it in Java, but I
thought that was the whole point of making clojure maps implement Map,
so I wouldn't have to do (jmap {:foo 1}) everytime I want to pass a
Map to Java.

I'm wondering if there is some way to make a clojure Map be smart
enough to return the value even if you give it string.  Probably not,
because then what do you do with {:foo 1 "foo" 2}.  Anyway, just
wondering if anyone else has run into this Keyword/String mismatch
problem and if you have an elegant solution.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Stuart Halloway

Hi Paul,

I think that I would rather see things remain explicit, i.e. if you  
need to interoperate with Java you convert manually before throwing  
the map over.

In the Rails world they tried to solve a similar problem (string vs.  
symbol keys) by wrappering Hash to be indifferent between string and  
symbol keys, and it is still confusing. Now you have to remember  
whether you have the wrappered kind or not...

Stuart

> Now that clojure maps are Java Maps, it is easier to inter-operate
> with Java code that has methods that take a Map as one of its
> arguments, because you can just pass the Map right into the Java
> code.  The problem is that often times, the Java method is expecting
> the Map to have String values in the keys, definitely not clojure's
> Keywords.  So if you have a {:foo 1} clojure map that you pass to a
> Java method, which then calls map.get("foo"), you won't find that
> value.
>
> Does anyone have any suggestions for how to handle this?  You could
> just use Strings for the keys in the clojure map, but then that map
> might not work with other clojure functions that expect the keys to be
> Keywords, not Strings.  You could pass the map through a function that
> converts the Keywords to Strings before using it in Java, but I
> thought that was the whole point of making clojure maps implement Map,
> so I wouldn't have to do (jmap {:foo 1}) everytime I want to pass a
> Map to Java.
>
> I'm wondering if there is some way to make a clojure Map be smart
> enough to return the value even if you give it string.  Probably not,
> because then what do you do with {:foo 1 "foo" 2}.  Anyway, just
> wondering if anyone else has run into this Keyword/String mismatch
> problem and if you have an elegant solution.
>
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: are pr & friends correct for regexps?

2008-10-13 Thread Chouser

On Mon, Oct 13, 2008 at 9:06 AM, Stuart Halloway
<[EMAIL PROTECTED]> wrote:
>
> (prn #"\\w+")
> -> \w+

Works for me, SVN 1067:
user=> #"\\w+"
#"\\w+"
user=> (prn #"\\w+")
#"\\w+"
nil

--Chouser

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Aaron Brooks

All,

I would think that changing or wrapping the map would create confusion
and additional overhead. In my mind the most natural interaction would
be to provide a way for Java code to create references to keywords:

x = map.get(clojure.keyword("foo"));// ... or something along
these lines

I'll take a look at the Clojure code but I expect that this would be
easy to do. Any methods that try to mash strings and keywords into the
same space seems like it would be mostly application specific as it
would need to resolve cases where identically named keywords and
strings exist. The only safe cases would be when a map exclusively
contains strings or keywords.

Naturally, wouldn't want to demand that you don't want to do what, in
fact, you want to do. I think Clojure would best cater to the safe,
predictable cases and leave the hairy cases up to individual
developers.

-Aaron
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Paul Barry

I'm thinking about cases where you are using existing java libraries
that you don't want to/can't re-write to have Clojure specific code in
them.  I think the rule for dealing with conflicts would be to give me
the value for the String if it's there, if it's not, try to give me
the value for the Keyword that corresponds to the String.

On Oct 13, 9:33 am, Aaron Brooks <[EMAIL PROTECTED]> wrote:
> All,
>
> I would think that changing or wrapping the map would create confusion
> and additional overhead. In my mind the most natural interaction would
> be to provide a way for Java code to create references to keywords:
>
>     x = map.get(clojure.keyword("foo"));    // ... or something along
> these lines
>
> I'll take a look at the Clojure code but I expect that this would be
> easy to do. Any methods that try to mash strings and keywords into the
> same space seems like it would be mostly application specific as it
> would need to resolve cases where identically named keywords and
> strings exist. The only safe cases would be when a map exclusively
> contains strings or keywords.
>
> Naturally, wouldn't want to demand that you don't want to do what, in
> fact, you want to do. I think Clojure would best cater to the safe,
> predictable cases and leave the hairy cases up to individual
> developers.
>
> -Aaron
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Aaron Brooks

Having looked at Keyword.java, I'll amend my example:

import clojure.lang.Keyword;
x map.get(new Keyword("myns","foo"));

The above may well reveal that I remember very little Java from
previous lives so feel free to correct any errors.

-Aaron.

On Oct 13, 9:33 am, Aaron Brooks <[EMAIL PROTECTED]> wrote:
> All,
>
> I would think that changing or wrapping the map would create confusion
> and additional overhead. In my mind the most natural interaction would
> be to provide a way for Java code to create references to keywords:
>
>     x = map.get(clojure.keyword("foo"));    // ... or something along
> these lines
>
> I'll take a look at the Clojure code but I expect that this would be
> easy to do. Any methods that try to mash strings and keywords into the
> same space seems like it would be mostly application specific as it
> would need to resolve cases where identically named keywords and
> strings exist. The only safe cases would be when a map exclusively
> contains strings or keywords.
>
> Naturally, wouldn't want to demand that you don't want to do what, in
> fact, you want to do. I think Clojure would best cater to the safe,
> predictable cases and leave the hairy cases up to individual
> developers.
>
> -Aaron
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Rich Hickey



On Oct 13, 9:34 am, Paul Barry <[EMAIL PROTECTED]> wrote:
> I was thinking this is a little different because the Keyword data
> type is unique to Clojure.  So once in the Java land, you are never
> going to want to use Keywords.  In Clojure, I agree, the difference
> between Keyword and String should be explicit, but in Java, I feel
> like it's just pragmatic to be able to pass in a String and get the
> value with the matching Keyword.
>
> I think this might be possible to do because many of the methods that
> implement java.util.Map are wrappers on the clojure methods.  For
> example, in APersistentMap, you could change get from:
>
> public Object get(Object key){
> return valAt(key);
>
> }
>
> To something like:
>
> public Object get(Object key){
>   if(key instanceof String) {
> if(contains(key)) {
>   return valAt(key);
> } else {
>   return valAt(stringToKeyword(key));
> }
>   } else {
> return valAt(key);
>   }
>
> }
>
> I'd have to look at all the other methods that implement
> java.util.Map, but if they are all separate from the actual methods
> that make clojure maps work like they do, you could get the best of
> both words.  But if everyone thinks this is a bad idea, then I'll just
> write my function to convert all Keywords in a Map to a String before
> passing them to Java.
>
> > Hi Paul,
>
> > I think that I would rather see things remain explicit, i.e. if you
> > need to interoperate with Java you convert manually before throwing
> > the map over.
>
> > In the Rails world they tried to solve a similar problem (string vs.
> > symbol keys) by wrappering Hash to be indifferent between string and
> > symbol keys, and it is still confusing. Now you have to remember
> > whether you have the wrappered kind or not...
>
> > Stuart
>
> > > Now that clojure maps are Java Maps, it is easier to inter-operate
> > > with Java code that has methods that take a Map as one of its
> > > arguments, because you can just pass the Map right into the Java
> > > code.  The problem is that often times, the Java method is expecting
> > > the Map to have String values in the keys, definitely not clojure's
> > > Keywords.  So if you have a {:foo 1} clojure map that you pass to a
> > > Java method, which then calls map.get("foo"), you won't find that
> > > value.
>
> > > Does anyone have any suggestions for how to handle this?  You could
> > > just use Strings for the keys in the clojure map, but then that map
> > > might not work with other clojure functions that expect the keys to be
> > > Keywords, not Strings.  You could pass the map through a function that
> > > converts the Keywords to Strings before using it in Java, but I
> > > thought that was the whole point of making clojure maps implement Map,
> > > so I wouldn't have to do (jmap {:foo 1}) everytime I want to pass a
> > > Map to Java.
>
> > > I'm wondering if there is some way to make a clojure Map be smart
> > > enough to return the value even if you give it string.  Probably not,
> > > because then what do you do with {:foo 1 "foo" 2}.  Anyway, just
> > > wondering if anyone else has run into this Keyword/String mismatch
> > > problem and if you have an elegant solution.

If a Java method took a String, you'd pass it a String. If it takes a
map with String keys you should pass it exactly that. There seems to
me to be absolutely no reason not to use strings for keys in that map
on the Clojure side too. Nothing in Clojure expects maps to have
keywords for keys - strings, numbers, and Clojure collections all make
fine keys.

Keywords are often used as keys in examples, as that map usage idiom
stands in, in Clojure, for 'objects with properties' in many cases.

Automatic conversion is a slippery slope. Even manual conversion is
wasteful and counterproductive. All code using the same map should
have the same notion of what's in it, IMO.

OTOH, if you are the consumer of the map on the Java side, and just
need to supply its values as strings to other Java code,
Keyword.getName() is non-allocating/copying and guaranteed to return
an interned String (without the ':').

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Paul Barry

To give a specific example of what I'm trying to do, I'd like to use
velocity templates in Clojure.  So I have this code:

(in-ns 'velocity)
(clojure/refer 'clojure)

(import '(org.apache.velocity.app VelocityEngine))
(import '(org.apache.velocity VelocityContext))
(import '(java.io StringWriter))

(defn render [template context]
  (let
  [ve (new VelocityEngine)
   ctx (new VelocityContext context)
   out (new StringWriter)]
(.init ve)
(.evaluate ve ctx out "clojure" template)
(.toString out)))

And then I can do:

(velocity/render "foo is $foo" {"foo" "bar"})

But obviously this isn't going to work:

(velocity/render "foo is $foo" {:foo "bar"})

So short of modifying the Java implementation of either Clojure or
Velocity to be indifferent to Strings/Keywords, I either have to:

1) Only pass String-keyed maps into this method
2) Have this method turn all the Keywords into Strings before creating
the VelocityContext

I'm leaning towards #2, just because I would expect (velocity/render
"foo is $foo" {:foo "bar"}) to "work", and others might too.  I'm
thinking about how to build a MVC web app with Clojure, and I would
have the model layer return Keyword-keyed maps that represent data
stored in the database, and then I'd like to pass those values into a
method like this to be the view layer.

What are your thoughts?  Should I change the model layer to return
String-keyed maps?  Or convert the Keywords to Strings before building
the VelocityContext?

On Oct 13, 9:58 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Oct 13, 9:34 am, Paul Barry <[EMAIL PROTECTED]> wrote:
>
>
>
> > I was thinking this is a little different because the Keyword data
> > type is unique to Clojure.  So once in the Java land, you are never
> > going to want to use Keywords.  In Clojure, I agree, the difference
> > between Keyword and String should be explicit, but in Java, I feel
> > like it's just pragmatic to be able to pass in a String and get the
> > value with the matching Keyword.
>
> > I think this might be possible to do because many of the methods that
> > implement java.util.Map are wrappers on the clojure methods.  For
> > example, in APersistentMap, you could change get from:
>
> > public Object get(Object key){
> >         return valAt(key);
>
> > }
>
> > To something like:
>
> > public Object get(Object key){
> >   if(key instanceof String) {
> >     if(contains(key)) {
> >       return valAt(key);
> >     } else {
> >       return valAt(stringToKeyword(key));
> >     }
> >   } else {
> >     return valAt(key);
> >   }
>
> > }
>
> > I'd have to look at all the other methods that implement
> > java.util.Map, but if they are all separate from the actual methods
> > that make clojure maps work like they do, you could get the best of
> > both words.  But if everyone thinks this is a bad idea, then I'll just
> > write my function to convert all Keywords in a Map to a String before
> > passing them to Java.
>
> > > Hi Paul,
>
> > > I think that I would rather see things remain explicit, i.e. if you
> > > need to interoperate with Java you convert manually before throwing
> > > the map over.
>
> > > In the Rails world they tried to solve a similar problem (string vs.
> > > symbol keys) by wrappering Hash to be indifferent between string and
> > > symbol keys, and it is still confusing. Now you have to remember
> > > whether you have the wrappered kind or not...
>
> > > Stuart
>
> > > > Now that clojure maps are Java Maps, it is easier to inter-operate
> > > > with Java code that has methods that take a Map as one of its
> > > > arguments, because you can just pass the Map right into the Java
> > > > code.  The problem is that often times, the Java method is expecting
> > > > the Map to have String values in the keys, definitely not clojure's
> > > > Keywords.  So if you have a {:foo 1} clojure map that you pass to a
> > > > Java method, which then calls map.get("foo"), you won't find that
> > > > value.
>
> > > > Does anyone have any suggestions for how to handle this?  You could
> > > > just use Strings for the keys in the clojure map, but then that map
> > > > might not work with other clojure functions that expect the keys to be
> > > > Keywords, not Strings.  You could pass the map through a function that
> > > > converts the Keywords to Strings before using it in Java, but I
> > > > thought that was the whole point of making clojure maps implement Map,
> > > > so I wouldn't have to do (jmap {:foo 1}) everytime I want to pass a
> > > > Map to Java.
>
> > > > I'm wondering if there is some way to make a clojure Map be smart
> > > > enough to return the value even if you give it string.  Probably not,
> > > > because then what do you do with {:foo 1 "foo" 2}.  Anyway, just
> > > > wondering if anyone else has run into this Keyword/String mismatch
> > > > problem and if you have an elegant solution.
>
> If a Java method took a String, you'd pass it a String. If it takes a
> map with String keys you should

Re: recur question

2008-10-13 Thread Stuart Halloway

Hi Michael,

The multiplication by n comes after the recur.

Cheers,
Stuart

>
> Giving the factorial function as:
>
> (def factorial
>(fn [n] (cond (= n 1)
>  (> n 1) (* n (recur (dec n))
>
> the compiler complains "Can only recur from tail position".
> Isn't really the recur in tail position? It is the last expresson to
> be evaluated.
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Suggest changing update-in to accept additional args for "f"

2008-10-13 Thread Stephen C. Gilardi

I've enclosed a modified definition of update-in that allows the  
update function "f" to take arguments in addition to "old" value being  
updated. The new definition does everything the old definition does  
(when additional arguments are not supplied), but it allows "f" to be  
an existing function more of the time rather than a new closure that  
packages up additional arguments.

Here's an example:

user=> (def m {:a {:b 1}})
#=(var user/m)
user=> (update-in m [:a :b] inc)
{:a {:b 2}}
user=> (update-in m [:a :b] #(+ % 2)) ; current or new
{:a {:b 3}}
user=> (update-in m [:a :b] + 2) ; new
{:a {:b 3}}

Suggested update-in:

(defn update-in
   "'Updates' a value in a nested associative structure, where ks is a
   sequence of keys and f is a function that will take the old value  
and any
   supplied args and return the new value, and returns a new nested
   structure.  If any levels do not exist, hash-maps will be created."
   ([m [k & ks] f & args]
(if ks
  (assoc m k (apply update-in (get m k) ks f args))
  (assoc m k (apply f (get m k) args)

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



are pr & friends correct for regexps?

2008-10-13 Thread Stuart Halloway

(prn #"\\w+")
-> \w+

I was expecting something the reader could handle...

Cheers,
Stuart


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Rich Hickey



On Oct 13, 10:17 am, Paul Barry <[EMAIL PROTECTED]> wrote:
> To give a specific example of what I'm trying to do, I'd like to use
> velocity templates in Clojure.  So I have this code:
>
> (in-ns 'velocity)
> (clojure/refer 'clojure)
>
> (import '(org.apache.velocity.app VelocityEngine))
> (import '(org.apache.velocity VelocityContext))
> (import '(java.io StringWriter))
>
> (defn render [template context]
>   (let
>   [ve (new VelocityEngine)
>ctx (new VelocityContext context)
>out (new StringWriter)]
> (.init ve)
> (.evaluate ve ctx out "clojure" template)
> (.toString out)))
>
> And then I can do:
>
> (velocity/render "foo is $foo" {"foo" "bar"})
>
> But obviously this isn't going to work:
>
> (velocity/render "foo is $foo" {:foo "bar"})
>
> So short of modifying the Java implementation of either Clojure or
> Velocity to be indifferent to Strings/Keywords, I either have to:
>
> 1) Only pass String-keyed maps into this method
> 2) Have this method turn all the Keywords into Strings before creating
> the VelocityContext
>
> I'm leaning towards #2, just because I would expect (velocity/render
> "foo is $foo" {:foo "bar"}) to "work", and others might too.  I'm
> thinking about how to build a MVC web app with Clojure, and I would
> have the model layer return Keyword-keyed maps that represent data
> stored in the database, and then I'd like to pass those values into a
> method like this to be the view layer.
>
> What are your thoughts?  Should I change the model layer to return
> String-keyed maps?  Or convert the Keywords to Strings before building
> the VelocityContext?
>

It depends on how much you are going to do with your model, other than
pass it to Velocity. But doing what's right for the model should
dominate. If that's keywords, you have 2 options here. One is to clone
the map with string keys and pass to VelocityContext ctor. The other
is to proxy Context (a simple interface above VelocityContext, or
AbstractContext, an implementation helper) on the map in situ, instead
of using VelocityContext. The tradeoff will be between a one-time copy
of the entire map, using fast conversions of keywords to strings, vs
no map copy, but more overhead per lookup as strings will have to be
turned into keywords using Keyword.intern(null,str). Map size vs
number of lookups will determine which is more efficient.

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Paul Barry

Thanks Rich, that worked great.  Here's what I ended up using:

(in-ns 'velocity)
(clojure/refer 'clojure)

(import '(org.apache.velocity.app VelocityEngine))
(import '(org.apache.velocity.context Context))
(import '(java.io StringWriter))

(defn make-context [context]
  (proxy [Context] []
(containsKey [key] (contains? context (keyword key)))
(get [key] (context (keyword key)))
(getKeys [] (keys context))
(put [key value] false)
(remove [key] false)))

(defn render [template context]
  (let
  [ve (new VelocityEngine)
   ctx (make-context context)
   out (new StringWriter)]
(.init ve)
(.evaluate ve ctx out "clojure" template)
(.toString out)))

The VelocityEngine gets re-created every time, so I'll have to fix
that, but other than that, this seems to work.  Probably should have
put and remove throw an Exception rather than return false also.

On Oct 13, 11:22 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Oct 13, 10:17 am, Paul Barry <[EMAIL PROTECTED]> wrote:
>
>
>
> > To give a specific example of what I'm trying to do, I'd like to use
> > velocity templates in Clojure.  So I have this code:
>
> > (in-ns 'velocity)
> > (clojure/refer 'clojure)
>
> > (import '(org.apache.velocity.app VelocityEngine))
> > (import '(org.apache.velocity VelocityContext))
> > (import '(java.io StringWriter))
>
> > (defn render [template context]
> >   (let
> >       [ve (new VelocityEngine)
> >        ctx (new VelocityContext context)
> >        out (new StringWriter)]
> >     (.init ve)
> >     (.evaluate ve ctx out "clojure" template)
> >     (.toString out)))
>
> > And then I can do:
>
> > (velocity/render "foo is $foo" {"foo" "bar"})
>
> > But obviously this isn't going to work:
>
> > (velocity/render "foo is $foo" {:foo "bar"})
>
> > So short of modifying the Java implementation of either Clojure or
> > Velocity to be indifferent to Strings/Keywords, I either have to:
>
> > 1) Only pass String-keyed maps into this method
> > 2) Have this method turn all the Keywords into Strings before creating
> > the VelocityContext
>
> > I'm leaning towards #2, just because I would expect (velocity/render
> > "foo is $foo" {:foo "bar"}) to "work", and others might too.  I'm
> > thinking about how to build a MVC web app with Clojure, and I would
> > have the model layer return Keyword-keyed maps that represent data
> > stored in the database, and then I'd like to pass those values into a
> > method like this to be the view layer.
>
> > What are your thoughts?  Should I change the model layer to return
> > String-keyed maps?  Or convert the Keywords to Strings before building
> > the VelocityContext?
>
> It depends on how much you are going to do with your model, other than
> pass it to Velocity. But doing what's right for the model should
> dominate. If that's keywords, you have 2 options here. One is to clone
> the map with string keys and pass to VelocityContext ctor. The other
> is to proxy Context (a simple interface above VelocityContext, or
> AbstractContext, an implementation helper) on the map in situ, instead
> of using VelocityContext. The tradeoff will be between a one-time copy
> of the entire map, using fast conversions of keywords to strings, vs
> no map copy, but more overhead per lookup as strings will have to be
> turned into keywords using Keyword.intern(null,str). Map size vs
> number of lookups will determine which is more efficient.
>
> Rich
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: recur question

2008-10-13 Thread Stewart Griffin

2008/10/13 Stuart Halloway <[EMAIL PROTECTED]>:
>
> Hi Michael,
>
> The multiplication by n comes after the recur.
>
> Cheers,
> Stuart
>
>>
>> Giving the factorial function as:
>>
>> (def factorial
>>(fn [n] (cond (= n 1)
>>  (> n 1) (* n (recur (dec n))
>>
>> the compiler complains "Can only recur from tail position".
>> Isn't really the recur in tail position? It is the last expresson to
>> be evaluated.
>>
>> >
>
>
> >
>

Hello,

Following on from what Stuart said, here is a version with recur that
uses an accumulator to avoid your problem:

(defn factorial
([n]
(factorial n 1))
([n acc]
(if  (= n 0)   acc
 (recur (dec n) (* acc n)

Also, your method would return nil for (factorial 0), which should be
1, so I adjusted the termination condition to: (= n 0).

Regards,

Stewart Griffin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Paul Barry

I was thinking this is a little different because the Keyword data
type is unique to Clojure.  So once in the Java land, you are never
going to want to use Keywords.  In Clojure, I agree, the difference
between Keyword and String should be explicit, but in Java, I feel
like it's just pragmatic to be able to pass in a String and get the
value with the matching Keyword.

I think this might be possible to do because many of the methods that
implement java.util.Map are wrappers on the clojure methods.  For
example, in APersistentMap, you could change get from:

public Object get(Object key){
return valAt(key);
}

To something like:

public Object get(Object key){
  if(key instanceof String) {
if(contains(key)) {
  return valAt(key);
} else {
  return valAt(stringToKeyword(key));
}
  } else {
return valAt(key);
  }
}

I'd have to look at all the other methods that implement
java.util.Map, but if they are all separate from the actual methods
that make clojure maps work like they do, you could get the best of
both words.  But if everyone thinks this is a bad idea, then I'll just
write my function to convert all Keywords in a Map to a String before
passing them to Java.


> Hi Paul,
>
> I think that I would rather see things remain explicit, i.e. if you  
> need to interoperate with Java you convert manually before throwing  
> the map over.
>
> In the Rails world they tried to solve a similar problem (string vs.  
> symbol keys) by wrappering Hash to be indifferent between string and  
> symbol keys, and it is still confusing. Now you have to remember  
> whether you have the wrappered kind or not...
>
> Stuart
>
> > Now that clojure maps are Java Maps, it is easier to inter-operate
> > with Java code that has methods that take a Map as one of its
> > arguments, because you can just pass the Map right into the Java
> > code.  The problem is that often times, the Java method is expecting
> > the Map to have String values in the keys, definitely not clojure's
> > Keywords.  So if you have a {:foo 1} clojure map that you pass to a
> > Java method, which then calls map.get("foo"), you won't find that
> > value.
>
> > Does anyone have any suggestions for how to handle this?  You could
> > just use Strings for the keys in the clojure map, but then that map
> > might not work with other clojure functions that expect the keys to be
> > Keywords, not Strings.  You could pass the map through a function that
> > converts the Keywords to Strings before using it in Java, but I
> > thought that was the whole point of making clojure maps implement Map,
> > so I wouldn't have to do (jmap {:foo 1}) everytime I want to pass a
> > Map to Java.
>
> > I'm wondering if there is some way to make a clojure Map be smart
> > enough to return the value even if you give it string.  Probably not,
> > because then what do you do with {:foo 1 "foo" 2}.  Anyway, just
> > wondering if anyone else has run into this Keyword/String mismatch
> > problem and if you have an elegant solution.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Suggest changing update-in to accept additional args for "f"

2008-10-13 Thread mb

Hello,

On 13 Okt., 17:02, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
>         user=> (update-in m [:a :b] + 2) ; new
>         {:a {:b 3}}

I think this is a good idea. This would also be in-line with things
like
alter and commute.

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



Re: Formatted printing?

2008-10-13 Thread Michel Salim
On Sat, Oct 11, 2008 at 9:58 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:

>> Starting from some Scheme or CL code is a good idea.  I'll just adapt
>> it to support literal maps, vectors, and such.
>>
>
> A pretty-print for Clojure would be a welcome contribution. In order
> to be an acceptable contribution, though, it would have to be free of
> connections to other code.
>
Just to clarify: free of connections meaning something written from
scratch, or would you accepted borrowed code as long as there are no
licensing problem?

Best regards,


-- 
miʃel salim  •  http://hircus.jaiku.com/
IUCS •  [EMAIL PROTECTED]
Fedora   •  [EMAIL PROTECTED]
MacPorts •  [EMAIL PROTECTED]

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Formatted printing?

2008-10-13 Thread Rich Hickey



On Oct 13, 1:57 pm, "Michel Salim" <[EMAIL PROTECTED]> wrote:
> On Sat, Oct 11, 2008 at 9:58 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:
> >> Starting from some Scheme or CL code is a good idea.  I'll just adapt
> >> it to support literal maps, vectors, and such.
>
> > A pretty-print for Clojure would be a welcome contribution. In order
> > to be an acceptable contribution, though, it would have to be free of
> > connections to other code.
>
> Just to clarify: free of connections meaning something written from
> scratch, or would you accepted borrowed code as long as there are no
> licensing problem?
>

>From scratch. Contributions to Clojure must be original work submitted
under the CA. This gives Clojure the flexibility to move to multiple
or more permissive licenses in the future.

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: ClassNotFoundException for an fn in 1067

2008-10-13 Thread Mike Hinchey

On Oct 13, 5:31 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> You cannot, and might never be able to, print/read fns.

Okay, it just looked like something that could be read.

>
> I would examine carefully whether your macro really should be doing
> this, as this is likely to become disallowed once Clojure can AOT
> compile.

With a let and gensym outside of the backquote, I don't need the var-
get and resolve.  That works.

>
> The other option would be to allow some things dynamically but not
> AOT, which is definitely not my preference.
>
> Rich
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: GUIs in Clojure

2008-10-13 Thread JumpingJupiter

I wrote some code to enable declarative swing definitions pretty much
identical in form to Michael's suggestion:

(let [gui
  (swingset
   (JFrame frame {:setSize [500 500]}
   (JPanel panel {:setBackground (. Color orange)}
   (JLabel {:setText "Hello World. Welcome to my Swing GUI
created from Clojure."})
   (JPanel {:setLayout (new BorderLayout)}
   (JTextArea { :setText "type here and marvel as 
nothing
happens!"}))
   (JButton btn {:setText "Close"})))
   (GridLayout layout {:setColumns 1 :setRows 3})
   (JMenuBar menubar
 (JMenu {:setText "File"}
(JMenuItem {:setText "Save" :addActionListener 
(actionListener (fn
[e] (println "Sorry, can't save")))}))
 (JMenu {:setText "Edit"}
(JMenuItem {:setText "Cut" :addActionListener 
(actionListener (fn
[e] (println "You clicked Cut")))})
(JMenuItem {:setText "Paste" :addActionListener 
(actionListener (fn
[e] (println "You clicked Paste")))}]

  (. (gui 'frame) setJMenuBar (gui 'menubar))
  (. (gui 'panel) setLayout (gui 'layout))
  (. (gui 'frame) setVisible true)
  (. (gui 'btn) addActionListener (actionListener (fn [e] (. (gui
'frame) setVisible false)

It works for the simple examples I've tried. It returns a map of
selected controls which you might need access to.

As Michael mentioned, getting the layout manager to do what you want
is difficult. I haven't used Swing before, so maybe this isn't
specific to using a declarative style.

I can't see a tidy way to let the components refer to each other
within the definition which might be handy, and as you can see it's
pretty verbose even for simply windows. Some parts could be shortened
with some extra macro - menu's in particular, but I'm starting to
think UI code is going to look pretty ugly unless you drastically
limit the options for customisation - there's just too many widgets
with too may variables involved.

And I haven't even thought about using the UI once it's been
constructed.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: ClassNotFoundException for an fn in 1067

2008-10-13 Thread Jeffrey Chu

Hi,

I'm having similar issues with r1067 in swank-clojure; but it's not
printing/reading fns. Instead it's reading, inserting vars, and
evaling. The weird thing is that I can't seem to reproduce it on a
small scale. Anyways, that's my problem and I'll keep trying to figure
it out.

I found a different peculiarity while poking about and I was wondering
if it's expected behavior:

 (cons 'first '((quote (1 2 3
   ;; => (first (quote (1 2 3)))
 (eval (cons 'first '((quote (1 2 3)
   ;; => 1

 (cons 'first `((quote (1 2 3
   ;; => (first (quote (1 2 3)))
 (eval (cons 'first `((quote (1 2 3)
   ;; java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0)

 (list 'first (list 'quote '(1 2 3)))
   ;; => (first (quote (1 2 3)))
 (eval (list 'first (list 'quote '(1 2 3
   ;; => 1

 (list 'first (list 'quote (map identity '(1 2 3
   ;; => (first (quote (1 2 3)))
 (eval (list 'first (list 'quote (map identity '(1 2 3)
   ;; java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0)

Thanks,
- Jeff


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: ClassNotFoundException for an fn in 1067

2008-10-13 Thread Rich Hickey



On Oct 13, 4:28 pm, Jeffrey Chu <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm having similar issues with r1067 in swank-clojure; but it's not
> printing/reading fns. Instead it's reading, inserting vars, and
> evaling. The weird thing is that I can't seem to reproduce it on a
> small scale. Anyways, that's my problem and I'll keep trying to figure
> it out.
>
> I found a different peculiarity while poking about and I was wondering
> if it's expected behavior:
>
>  (cons 'first '((quote (1 2 3
>;; => (first (quote (1 2 3)))
>  (eval (cons 'first '((quote (1 2 3)
>;; => 1
>
>  (cons 'first `((quote (1 2 3
>;; => (first (quote (1 2 3)))
>  (eval (cons 'first `((quote (1 2 3)
>;; java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0)
>
>  (list 'first (list 'quote '(1 2 3)))
>;; => (first (quote (1 2 3)))
>  (eval (list 'first (list 'quote '(1 2 3
>;; => 1
>
>  (list 'first (list 'quote (map identity '(1 2 3
>;; => (first (quote (1 2 3)))
>  (eval (list 'first (list 'quote (map identity '(1 2 3)
>;; java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0)

Ok, found and fixed, here. Not yet in SVN as I'm in the middle of AOT
compilation.

Thanks for the report and the examples.

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: help a journalist: why Clojure?

2008-10-13 Thread estherschindler

Thanks to everyone for their help -- the article is live!

6 Scripting Languages Your Developers Wish You'd Let Them Use
Several up-and-coming scripting languages--some open-source--are
gaining popularity among software developers. These dynamic
programming languages, including Groovy, Scala, Lua, F#, Clojure and
Boo, deserve more attention for your enterprise software development,
even if your shop is dedicated to Java or .NET. Here's why.
http://cio.com/article/454520/_Scripting_Languages_Your_Developers_Wish_You_d_Let_Them_Use

(and as a bonus... I also wrote...)

7 Cool, Weird and Useful Computer Keyboards
Not every computer keyboard or input device is a boring hunk of
plastic. We look at several ergonomic, wireless, high-tech and just
plain fun keyboards to brighten your day and give joy to your
fingertips.
http://www.cio.com/special/slideshows/cool_keyboards/index
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: help a journalist: why Clojure?

2008-10-13 Thread estherschindler

It's live! Thanks to everyone for their help.

6 Scripting Languages Your Developers Wish You'd Let Them Use
Several up-and-coming scripting languages--some open-source--are
gaining popularity among software developers. These dynamic
programming languages, including Groovy, Scala, Lua, F#, Clojure and
Boo, deserve more attention for your enterprise software development,
even if your shop is dedicated to Java or .NET. Here's why.
http://cio.com/article/454520/_Scripting_Languages_Your_Developers_Wish_You_d_Let_Them_Use

and as a bonus... I also wrote...

7 Cool, Weird and Useful Computer Keyboards
Not every computer keyboard or input device is a boring hunk of
plastic. We look at several ergonomic, wireless, high-tech and just
plain fun keyboards to brighten your day and give joy to your
fingertips.
http://www.cio.com/special/slideshows/cool_keyboards/index
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



with-open binding form

2008-10-13 Thread Kevin Downey

I noticed with-open kind of stuck out because it doesn't use vectors
for binding like let, loop, and others. it was a quick fix using
destructuring to make the macro use square backets
example:
(with-open [f (new java.io.FileWriter "test")] do-stuff)

but as I was writing an email to this list I realized that let,loop,
etc do multiple bindings. so a few hours later I had this:

(defmacro better-with-open [b & f]
  (let [q b
h (map (fn[x] `(. ~x (close))) (take-nth 2 q))]
`(let ~q (try [EMAIL PROTECTED] (finally [EMAIL PROTECTED])

sorry about all the single letter variables, I am not exaggerating
about how long this took. Still wrapping my head around macros.

usage example:

(better-with-open [f (new java.io.FileWriter "foo" true)
   q (new java.io.FileWriter "bar")]
  (. f (write "one"))
  (. q (write "two")))



-- 
The Mafia way is that we pursue larger goals under the guise of
personal relationships.
Fisheye

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: GUIs in Clojure

2008-10-13 Thread Martin DeMello

On Oct 13, 12:37 pm, JumpingJupiter <[EMAIL PROTECTED]>
wrote:
> pretty verbose even for simply windows. Some parts could be shortened
> with some extra macro - menu's in particular, but I'm starting to
> think UI code is going to look pretty ugly unless you drastically
> limit the options for customisation - there's just too many widgets
> with too may variables involved.

Yeah, it does pretty much always seem to turn ugly, no matter what you
do :( I've lately been leaning towards the "define your widgets, then
lay them out" style, rather than customising inline in the layout. The
chicken bb egg has some other interesting ideas [http://
chicken.wiki.br/bb] but even there it ends up looking ugly sooner or
later.

Another way to go is the "design your gui in a gui designer, then
connect code to the resulting interface file" method, which I've seen
Ruby/(Qt, Gtk, Swing) projects use with decent success. In particular
the developers of Monkeybars (JRuby/Swing) project have come out and
said that manually laying out widgets in code is counterproductive.

What did look very promising was the approach taken by the Chicken/Qt
egg, which has widget constructors take a UIXML string (as generated
by QtDesigner) to instantiate themselves. In theory, that should let
you build up an application-specific rich widget collection quickly
and easily, then manipulate it from code, and also work on SXML->UIXML
methods that would let you generate widgets programmatically. I had
problems getting the egg up and running, though (this was a few years
ago), and used PLT instead, but when I have the free time I plan to go
take another look at it.

martin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: GUIs in Clojure

2008-10-13 Thread Randall R Schulz

On Monday 13 October 2008 16:39, Martin DeMello wrote:
> On Oct 13, 12:37 pm, JumpingJupiter <[EMAIL PROTECTED]>
>
> wrote:
> > pretty verbose even for simply windows. Some parts could be
> > shortened with some extra macro - menu's in particular, but I'm
> > starting to think UI code is going to look pretty ugly unless you
> > drastically limit the options for customisation - there's just too
> > many widgets with too may variables involved.
>
> Yeah, it does pretty much always seem to turn ugly, no matter what
> you do :( I've lately been leaning towards the "define your widgets,
> then lay them out" style, rather than customising inline in the
> layout. The chicken bb egg has some other interesting ideas [http://
> chicken.wiki.br/bb] but even there it ends up looking ugly sooner or
> later.

I've done rather little GUI programming in my day (it doesn't appeal to 
me), but I've been hearing about JavaFX lately and just today took a 
quick look at what it's all about (someone on one of the IDEA forums 
suggested it will ultimately take the place of Swing, and that got me 
curious).

So I'm wondering, how does JavaFX factor into matters of GUI programming 
and good APIs and frameworks to facilitate it?


> ...


Randall Schulz

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



java.lang.ExceptionInInitializerError in r1068

2008-10-13 Thread Perry

Hi Rich,

Hope this is a helpful report: I'm getting an
ExceptionInInitializerError in SVN revision 1068, on OS X 10.5.5, w/
both Java 1.5 & 1.6.

Transcript below.

Best,
Perry

--

[mac_book]~/all_docs/software/clojure/svnhead $ svn info
Path: .
URL: https://clojure.svn.sourceforge.net/svnroot/clojure/trunk
Repository Root: https://clojure.svn.sourceforge.net/svnroot/clojure
Repository UUID: b4165764-bd0f-0410-b771-ab16a44d2305
Revision: 1068
Node Kind: directory
Schedule: normal
Last Changed Author: rhickey
Last Changed Rev: 1068
Last Changed Date: 2008-10-13 18:57:11 -0500 (Mon, 13 Oct 2008)

[mac_book]~/all_docs/software/clojure/svnhead $ java -version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-
b06-284)
Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)

[mac_book]~/all_docs/software/clojure/svnhead $ java -cp clo jure.jar
clojure.lang.Repl
Exception in thread "main" java.lang.ExceptionInInitializerError
at clojure.lang.Repl.(Repl.java:23)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.ClassNotFoundException: clojure.eval__1 (boot.clj:0)
at clojure.lang.RT.(RT.java:324)
... 1 more
Caused by: java.lang.RuntimeException:
java.lang.ClassNotFoundException: clojure.eval__1 (boot.clj:0)
at clojure.lang.Compiler.eval(Compiler.java:4116)
at clojure.lang.Compiler.load(Compiler.java:4432)
at clojure.lang.RT.loadResourceScript(RT.java:365)
at clojure.lang.RT.loadResourceScript(RT.java:356)
at clojure.lang.RT.doInit(RT.java:379)
at clojure.lang.RT.(RT.java:320)
... 1 more
Caused by: java.lang.RuntimeException:
java.lang.ClassNotFoundException: clojure.eval__1
at clojure.lang.Compiler$FnExpr.getCompiledClass(Compiler.java:3184)
at clojure.lang.Compiler$FnExpr.eval(Compiler.java:3190)
at clojure.lang.Compiler.eval(Compiler.java:4104)
... 6 more
Caused by: java.lang.ClassNotFoundException: clojure.eval__1
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:
52)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:242)
at clojure.lang.RT.classForName(RT.java:1509)
at clojure.lang.Compiler$FnExpr.getCompiledClass(Compiler.java:3180)
... 8 more

[mac_book]~/all_docs/software/clojure/svnhead $ java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode)

[mac_book]~/all_docs/software/clojure/svnhead $ java -   cp
clojure.jar clojure.lang.Repl
Exception in thread "main" java.lang.ExceptionInInitializerError
at clojure.lang.Repl.(Repl.java:23)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException:
java.lang.ClassNotFoundException: clojure.eval__1 (boot.clj:0)
at clojure.lang.RT.(RT.java:324)
... 1 more
Caused by: java.lang.RuntimeException:
java.lang.ClassNotFoundException: clojure.eval__1 (boot.clj:0)
at clojure.lang.Compiler.eval(Compiler.java:4116)
at clojure.lang.Compiler.load(Compiler.java:4432)
at clojure.lang.RT.loadResourceScript(RT.java:365)
at clojure.lang.RT.loadResourceScript(RT.java:356)
at clojure.lang.RT.doInit(RT.java:379)
at clojure.lang.RT.(RT.java:320)
... 1 more
Caused by: java.lang.RuntimeException:
java.lang.ClassNotFoundException: clojure.eval__1
at clojure.lang.Compiler$FnExpr.getCompiledClass(Compiler.java:3184)
at clojure.lang.Compiler$FnExpr.eval(Compiler.java:3190)
at clojure.lang.Compiler.eval(Compiler.java:4104)
... 6 more
Caused by: java.lang.ClassNotFoundException: clojure.eval__1
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:
52)
at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.classForName(RT.java:1509)
at clojure.lang.Compiler$FnExpr.getCompiledClass(Compiler.java:3180)
... 8 more



--~--~-~--~~~---~--~---

Re: java.lang.ExceptionInInitializerError in r1068

2008-10-13 Thread Rich Hickey



On Oct 13, 8:14 pm, Perry <[EMAIL PROTECTED]> wrote:
> Hi Rich,
>
> Hope this is a helpful report: I'm getting an
> ExceptionInInitializerError in SVN revision 1068, on OS X 10.5.5, w/
> both Java 1.5 & 1.6.
>

1068 is an interim release. If you want to try it, you'll need to
put ./gen in your classpath.

1068 generates and loads all classfiles to/from disk, as a prelude to
AOT compilation.

Rich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: java.lang.ExceptionInInitializerError in r1068

2008-10-13 Thread Perry

On Oct 13, 7:28 pm, Rich Hickey <[EMAIL PROTECTED]> wrote:

> If you want to try it, you'll need to put ./gen in your classpath.

Okay, good to know -- sorry for the noise, then.

> 1068 generates and loads all classfiles to/from disk, as a prelude to
> AOT compilation.

I'm very excited about this.

Thanks,
Perry
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Refs and ensure

2008-10-13 Thread jim

Rich,

I've been working with refs tonight and I appreciate the validate-fn
addition.  Makes my life a lot easier.

>From reading the docs, 'ensure' keeps a ref from changing inside a
dosync.  But if accesses to refs are contained in function calls that
are called during the transaction, the programmer might overlook them
when writing the dosync.

A hack I came up with to deal with this is to bind a new value to
'deref' that saves the ref to a list before calling the normal deref
function.  Then as a final step in the transaction, to go through the
list of deref'd refs and call 'ensure' on each one.

Do you have any thoughts on how to handle the situation better?

Thanks,
Jim
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Nested Multimethods

2008-10-13 Thread CuppoJava

Is there anyway to do the following with the existing multi-method
facilities?

There is a general multi-method length(object) that splits off to
different methods depending on the :class of the object.

And then specifically for objects with :class = :stateMachine, I want
to define it's method to split off further depending on the :state of
the object.

(defmulti length :class)
(defmethod-multi length :stateMachine :state)

(defmethod length :stateMachine :walking
  (println "Short distance"))

(defmethod length :stateMachine :running
  (println "Long distance"))

Thanks very much for your help.
  -Patrick
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: Nested Multimethods

2008-10-13 Thread Stuart Halloway

Hi Patrick,

How about:

(defmulti length (fn [x]
  (if (= :stateMachine  (:class x))
(:state x)
(:class x

(defmethod length :yardstick [x] 36)
(defmethod length :walking [x] "short")
(defmethod length :running [x] "long")

user=> (length {:class :yardstick})
36
user=> (length {:class :stateMachine :state :walking})
"short"
user=> (length {:class :stateMachine :state :running})
"long"

It would probably be better to have the fn return a vector so you  
don't have to worry about :state and :class values with colliding  
names, but that's the basic idea.

Cheers,
Stuart

> Is there anyway to do the following with the existing multi-method
> facilities?
>
> There is a general multi-method length(object) that splits off to
> different methods depending on the :class of the object.
>
> And then specifically for objects with :class = :stateMachine, I want
> to define it's method to split off further depending on the :state of
> the object.
>
> (defmulti length :class)
> (defmethod-multi length :stateMachine :state)
>
> (defmethod length :stateMachine :walking
>  (println "Short distance"))
>
> (defmethod length :stateMachine :running
>  (println "Long distance"))
>
> Thanks very much for your help.
>  -Patrick
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---



Re: with-open binding form

2008-10-13 Thread Allen Rohner

> I noticed with-open kind of stuck out because it doesn't use vectors
> for binding like let, loop, and others.

I had a similar comment about doseq. I don't think the obstacle is the
technical challenge, but rather Rich's decision about whether to do it
or not. This would be a breaking change, or else we'd have to come up
with new names for the new versions. Personally I'm in favor of it.

Allen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~--~~~~--~~--~--~---