Re: Anonymous function syntax in R1053

2008-10-06 Thread Stephen C. Gilardi
On Oct 7, 2008, at 1:21 AM, Matthew D. Swank wrote:
>
> Typing #(nil) at a repl gives me:
>
> java.lang.NullPointerException (NO_SOURCE_FILE:1)
>  [Thrown class clojure.lang.Compiler$CompilerException]
> [...]
> However, (fn [] nil) is fine.
>
> Shouldn't they be equivalent?
>
> Thanks,
> Matt

Here's a similar question and answer from the list archive that  
includes a cool tip for seeing the effect of reader macros:

> On Fri, Mar 14, 2008 at 11:58 AM, Stephen C. Gilardi
> <[EMAIL PROTECTED]> wrote:
>> In SVN 748, the anonymous version of the identity function doesn't  
>> work as I
>> expected:
> [...]
>> user=> (filter #(%) '(1 2 3))
>> java.lang.ClassCastException: clojure.lang.FixNum
>
> #(stuff) translates to (fn [args] (stuff)), so #(%) is (fn [x] (x)) -
> you're trying to call the parameter as a no-arg function, which your
> fixnums do not appreciate.
>
> #(do %) does what you want, but you may as well use identity directly
> in this case.
>
> You can look at the expansion of reader macros (those that produce an
> expansion) by quoting the form:
>
> user=> '#(%)
> (fn* [p1__1016] (p1__1016))
>
> Cheers,
> Darshan

Cheers,

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



Anonymous function syntax in R1053

2008-10-06 Thread Matthew D. Swank

Typing #(nil) at a repl gives me:

java.lang.NullPointerException (NO_SOURCE_FILE:1)
  [Thrown class clojure.lang.Compiler$CompilerException]

Restarts:
 0: [ABORT] Return to SLIME's top level.
 1: [CAUSE] Throw cause of this exception

Backtrace:
  0:  clojure.lang.Compiler.analyzeSeq(Compiler.java:3968)

However, (fn [] nil) is fine.

Shouldn't they be equivalent?

Thanks,
Matt
--~--~-~--~~~---~--~~
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: For socket repl: request redirectable *err* var

2008-10-06 Thread Stephen C. Gilardi
It's either attached to this message or uploaded to the group as:	redirectable-stderr.patchThanks,--Steve


redirectable-err.patch
Description: Binary data
On Oct 6, 2008, at 8:42 PM, Rich Hickey wrote:On Oct 6, 8:37 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:Rich,Would you accept a patch to implement this?Sure - thanks.RichOn Sep 30, 2008, at 12:25 AM, Craig McDaniel wrote:Yes, I'd like to see *err* added too. I did my own *err* for a customREPL and was surprised it wasn't already part of the environment justlike *out*.On Sep 29, 9:24 am, Thorsen Eric <[EMAIL PROTECTED]>wrote:I would love to see this change as well.EricOn Sep 28, 2008, at 1:28 PM, Stephen C. Gilardi wrote:For a socket repl, I'd like to have error output sent across thewire as well as normal output. Clojure currently provides vars (*in*and *out*) that allow a thread to redirect input and output. Isuggest a new var *err* which allows redirecting error output aswell.I can mostly do this without a change to Clojure by using my ownalternative to Repl.java, but there are several instances in Clojurewhere System.err is accessed directly. If those were made indirectthrough a new *err*, one could reliably redirect all of *in*, *out*,and *err*.Here's the *err* definition I suggest for RT.java:final static public Var ERR =   Var.intern(CLOJURE_NS, Symbol.create("*err*"),  new PrintWriter(newOutputStreamWriter(System.err,UTF8), true));(A PrintWriter with auto-flush.)I think PrintWriter is a good choice because Throwable offers amethod to dump stack traces to a PrintWriter.--Steve

genclass error message

2008-10-06 Thread Chouser
Currently if you fail to provide or mis-name the main fn in a
gen-class implementation, you get an error like:

Exception in thread "main" java.lang.UnsupportedOperationException:
net.n01se/main not defined

This is wrong, since the name shouldn't be just "main".  Attached is a
patch to change this error to:

Exception in thread "main" java.lang.UnsupportedOperationException:
net.n01se/TestObj-main not defined

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

diff --git a/src/clj/clojure/genclass.clj b/src/clj/clojure/genclass.clj
index f45f845..d2d10a1 100644
--- a/src/clj/clojure/genclass.clj
+++ b/src/clj/clojure/genclass.clj
@@ -418,7 +418,7 @@
 (. gen goTo end-label)
 ;no main found
 (. gen mark no-main-label)
-(. gen (throwException ex-type (str pkg-name "/" main-name " not defined")))
+(. gen (throwException ex-type (str pkg-name "/" sname "-" main-name " not defined")))
 (. gen mark end-label)
 (. gen (returnValue))
 (. gen (endMethod


Re: For socket repl: request redirectable *err* var

2008-10-06 Thread Rich Hickey



On Oct 6, 8:37 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> Rich,
>
> Would you accept a patch to implement this?
>

Sure - thanks.

Rich

>
> On Sep 30, 2008, at 12:25 AM, Craig McDaniel wrote:
>
>
>
> > Yes, I'd like to see *err* added too. I did my own *err* for a custom
> > REPL and was surprised it wasn't already part of the environment just
> > like *out*.
>
> > On Sep 29, 9:24 am, Thorsen Eric <[EMAIL PROTECTED]>
> > wrote:
> >> I would love to see this change as well.
>
> >> Eric
>
> >> On Sep 28, 2008, at 1:28 PM, Stephen C. Gilardi wrote:
>
> >>> For a socket repl, I'd like to have error output sent across the
> >>> wire as well as normal output. Clojure currently provides vars (*in*
> >>> and *out*) that allow a thread to redirect input and output. I
> >>> suggest a new var *err* which allows redirecting error output as
> >>> well.
>
> >>> I can mostly do this without a change to Clojure by using my own
> >>> alternative to Repl.java, but there are several instances in Clojure
> >>> where System.err is accessed directly. If those were made indirect
> >>> through a new *err*, one could reliably redirect all of *in*, *out*,
> >>> and *err*.
>
> >>> Here's the *err* definition I suggest for RT.java:
>
> >>> final static public Var ERR =
> >>>Var.intern(CLOJURE_NS, Symbol.create("*err*"),
> >>>   new PrintWriter(new
> >>> OutputStreamWriter(System.err,
> >>> UTF8), true));
>
> >>> (A PrintWriter with auto-flush.)
>
> >>> I think PrintWriter is a good choice because Throwable offers a
> >>> method to dump stack traces to a PrintWriter.
>
> >>> --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
-~--~~~~--~~--~--~---



Re: For socket repl: request redirectable *err* var

2008-10-06 Thread Stephen C. Gilardi
Rich,

Would you accept a patch to implement this?

--Steve

On Sep 30, 2008, at 12:25 AM, Craig McDaniel wrote:

>
> Yes, I'd like to see *err* added too. I did my own *err* for a custom
> REPL and was surprised it wasn't already part of the environment just
> like *out*.
>
> On Sep 29, 9:24 am, Thorsen Eric <[EMAIL PROTECTED]>
> wrote:
>> I would love to see this change as well.
>>
>> Eric
>>
>> On Sep 28, 2008, at 1:28 PM, Stephen C. Gilardi wrote:
>>
>>> For a socket repl, I'd like to have error output sent across the
>>> wire as well as normal output. Clojure currently provides vars (*in*
>>> and *out*) that allow a thread to redirect input and output. I
>>> suggest a new var *err* which allows redirecting error output as  
>>> well.
>>
>>> I can mostly do this without a change to Clojure by using my own
>>> alternative to Repl.java, but there are several instances in Clojure
>>> where System.err is accessed directly. If those were made indirect
>>> through a new *err*, one could reliably redirect all of *in*, *out*,
>>> and *err*.
>>
>>> Here's the *err* definition I suggest for RT.java:
>>
>>> final static public Var ERR =
>>>Var.intern(CLOJURE_NS, Symbol.create("*err*"),
>>>   new PrintWriter(new  
>>> OutputStreamWriter(System.err,
>>> UTF8), true));
>>
>>> (A PrintWriter with auto-flush.)
>>
>>> I think PrintWriter is a good choice because Throwable offers a
>>> method to dump stack traces to a PrintWriter.
>>
>>> --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
-~--~~~~--~~--~--~---



Re: What "reasoner"?

2008-10-06 Thread Parth Malwankar



Josip Gracin wrote:
> Hi!
>
> Rich, in the Boston talk you mentioned that you're considering some
> kind of a "reasoner" (if I understood correctly) for working with
> databases.  You also mentioned a project whose name sounded like "ios
> reasoner".  I can't find references on anything spelled "ios
> reasoner".  Could you tell me the actual name of the project.  Thanks!

I think it was the iris-reasoner datalog, also mentioned on
IRC here:
http://clojure-log.n01se.net/date/2008-10-02.html#14:45

http://iris-reasoner.org/

Parth

--~--~-~--~~~---~--~~
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: Using Java frameworks from Clojure

2008-10-06 Thread James Reeves

On Oct 6, 11:51 pm, "Hans Huebner" <[EMAIL PROTECTED]> wrote:
> Your simple example, creating a wrapper around the http client, really
> shows off the problem quite well:  True, for most use cases, people
> will just have the library fetch the given URL and be done with it.
> But what about query parameters, how would the be usefully
> represented?  POST-requests with bodies?  What about cookies?

I'm not sure if this helps, but in my Compojure project, I build up
response objects based on the type of the object being returned.

(GET "/" 200)   ; returns HTTP code 200
(GET "/" "Hello"); adds to the response body
(GET "/" {"X-Header" "something}); adds a header
(GET "/" (new Cookie ...)); adds a cookie to the response
(GET "/" (new File ...)); streams a file to the response
(GET "/" [200 {"X-Test" "Foo"} "Hello"]); vector combines multiple
effects

Maybe you could take a similar approach with your xlightweb interface?

(post-url "http://example.com"; {:name "blah"} (new Cookie ...)
callback-function)

> For object property getters and setters, I would like to be able to
> read properties using a keyword as the key, similar to hash table
> access, instead of having to invoke a getter.  I would like this to be
> both lazy and fast at the same time, and as getters might have
> arbitary performance characteristics, creating a hash table on the fly
> and populate it by calling all the getters would not be the right
> thing (also, there would be suprising caching in the wrapper).

This could be useful. I've written some functions that find all of an
object's getters and use them to populate a hash-map, but it would be
nice to have a direct proxy onto the object.

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



Re: Using Java frameworks from Clojure

2008-10-06 Thread Hans Huebner

On Mon, Oct 6, 2008 at 17:47, James Reeves <[EMAIL PROTECTED]> wrote:
> The most important thing I can think of is to remember that your
> wrapper doesn't have to be comprehensive. [...]

> So long as people can go back and use the Java API to do the complex
> stuff, I figure the best way to approach wrapper libraries is to make
> it as easy and as straightforward as possible for people to start
> using it.

My use case for this library involves a lot of the more complex stuff,
so my wrapper actually needs to be comprehensive enough.  I will need
all asynchronous functionality that I can find, and I will need a lot
of the methods that the classes provide.  Rather than just moving
forward with my application and extend the wrapper as needed, my plan
therefore is to first invest enough into the infrastructure so that I
won't have to return to it again and again while writing application
code, maybe correcting ad-hoc wrapper design decisions and having to
redesign things when I was hoping to make progress on the application.

Your simple example, creating a wrapper around the http client, really
shows off the problem quite well:  True, for most use cases, people
will just have the library fetch the given URL and be done with it.
But what about query parameters, how would the be usefully
represented?  POST-requests with bodies?  What about cookies?  If one
is lucky, one finds good on the fly solutions, or can get away with a
few native API calls intermixed with wrapper invocations.  If one is
not, there will be existing code using an existing API that needs to
be rewritten, and maybe even users that depend on the simplicistic
design and now somehow expect you to support it.

Thus, I somehow need to either transform much of the whole thing into
a functional library, or I need to use the Java API from my
application, maybe applying a little syntatic sugar here and there.

For the callback interfaces, just using 'proxy' will propably be the
easiest, although I will propably go with a 'proxy-fns' macro that
expect fns instead of function bodies for the handler - any sizeable
application will dispatch to a named function from the interface
anyway, and repeating the argument names in the invocation of the
function seems redundant.  Maybe 'proxy' should work like this in the
first place.  http://paste.lisp.org/display/68075 has an example of
what proxy-fns would do.

For object property getters and setters, I would like to be able to
read properties using a keyword as the key, similar to hash table
access, instead of having to invoke a getter.  I would like this to be
both lazy and fast at the same time, and as getters might have
arbitary performance characteristics, creating a hash table on the fly
and populate it by calling all the getters would not be the right
thing (also, there would be suprising caching in the wrapper).  Thus,
what I propably want is a mechanism that establishes the mapping
between a keyword and a getter (and setter) method of the class at
compile time.  Is that a sensible approach?

Again, thank you, James, for your input.  Your and any additional
input is greatly appreciated.

-Hans

--~--~-~--~~~---~--~~
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: Using Java frameworks from Clojure

2008-10-06 Thread James Reeves

On Oct 6, 6:58 pm, Hans Hübner <[EMAIL PROTECTED]> wrote:
> The API I am working with is xlightweb, an asynchronous HTTP client/
> server framework based on xSocket.  API docs are 
> athttp://xlightweb.sourceforge.net/core/apidocs/2_1/
>
> Any thoughts would be greatly appreciated.

I've been thinking about this, and I think I have a few points of
advice to give.

The most important thing I can think of is to remember that your
wrapper doesn't have to be comprehensive. Clojure has various
functions in the standard library to handle regular expressions, but
they don't attempt to be a complete replacement for working with
Pattern and Matcher objects. Falling back to Java classes is okay for
complex and unusual cases.

So keep it simple, and write wrappers for the common use-cases. Try to
stay functional, and take full advantage of all the standard Clojure
data structures, the Clojure standard library, and of first class
functions and macros.

For instance, here's a cut down version of some example code from the
xlightweb docs:

   HttpClient httpClient = new HttpClient();

   IHttpResponse response = httpClient.call(new GetRequest("http://
www.gmx.com/index.html"));
   System.out.println(response.getStatus());

   BlockingBodyDataSource bodyChannel = response.getBlockingBody();
   System.out.println(bodyChannel.readString());

   httpClient.send(new HttpRequestHeader("GET", "http://www.gmx.com/
index.html"), respHdl);

   httpClient.close();

A more Clojure-like way of writing it might be:

  (with-open client (new HttpClient)
(let [response (get-url client "http://www.gmx.com/index.html";)]
  (.printLn *out* (read-body response)))
(get-url client "http://www.gmx.com/index.html"; handler-function))

Although, since this is HTTP, you're not actually keeping any
connections open, unless they happen to belong to the same domain. So
maybe you could cut out the client altogether, by generating a new one
each time:

  (let [response (get-url "http://www.gmx.com/index.html";)]
(.printLn *out* (read-body response)))
  (get-url "http://www.gmx.com/index.html"; handler-function))

Really, it depends what you think you'll be using the library for most
often, and what other people will want to do. Maybe most of the time
all people want is the body of the HttpResponse, so:

  (.printLn *out* (read-url "http://www.gmx.com/index.html";))

So long as people can go back and use the Java API to do the complex
stuff, I figure the best way to approach wrapper libraries is to make
it as easy and as straightforward as possible for people to start
using it.

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



Re: Clojure at Boston Lisp Meeting videos

2008-10-06 Thread Bjorn Ludvigsen

> Note that this talk was for a crowd of experienced Lispers, so may not
> be the best intro if you don't know some Lisp already.

I knew no Lisp, and found this talk to be the best by far. More
enthusiasm and jokes, a smarter audience, and the faster speed and
greater detail suited the subject matter well. For people with some
programming experience this presentation is excellent. If you don't
know Lisp you can't always tell if the greatness of Clojure is really
the greatness of Lisp, but you still end up knowing why Clojure is
great.

-Bjorn

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



swank-clojure chokes reading definitions after update to svn 1053

2008-10-06 Thread Matthew D. Swank

In the *inferior-lisp* after typing a form:

 Exception in thread "Read Loop Thread" java.lang.RuntimeException:
clojure.lang.LispReader$ReaderException: java.lang.Exception: Invalid
token: swank::*load-path*
at clojure.lang.AFn.run(AFn.java:42)
at java.lang.Thread.run(Thread.java:619)
Caused by: clojure.lang.LispReader$ReaderException:
java.lang.Exception: Invalid token: swank::*load-path*
at clojure.lang.LispReader.read(LispReader.java:174)
at clojure.read__856.invoke(boot.clj:1617)
at clojure.read__856.invoke(boot.clj:1615)
at clojure.read__856.invoke(boot.clj:1613)
--~--~-~--~~~---~--~~
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: Using Java frameworks from Clojure

2008-10-06 Thread Hans Hübner

On 6 Okt., 10:34, James Reeves <[EMAIL PROTECTED]> wrote:
> On Oct 6, 4:21 am, Hans Hübner <[EMAIL PROTECTED]> wrote:
>
> > for a project, I would like to use a Java framework that exposes a
> > very Javaesque API, with dozens of classes that need to be
> > instantiated or used and with several interfaces that one needs to
> > implement in order to be called back by the framework.
> > ...
> > How do others approach this kind of problem?  Are you just ignoring
> > the functional vs. object oriented mismatch and access Java objects
> > from everywhere?  Do you use hand-written wrappers around the
> > libraries?  Tools?
>
> I don't think there's any one answer to this, as it really depends on
> the library.

Certainly so - I am not looking for all-for-one solutions, but I would
like to learn what others think about this and how they handle the
functional/object-oriented mismatch.  To me, this is a little ironic
as I have spent a good portion of my professional life writing object
wrappers around functional APIs, and now suddenly I need to do it the
other way round :)

> I've written a functional wrapper around the Java servlet
> interface, and I use a number of techniques. Which API in particular
> are you trying to convert?

The API I am working with is xlightweb, an asynchronous HTTP client/
server framework based on xSocket.  API docs are at
http://xlightweb.sourceforge.net/core/apidocs/2_1/

Any thoughts would be greatly appreciated.

Thanks,
-Hans
--~--~-~--~~~---~--~~
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: slurp is in Clojure, but spit is in Contrib?

2008-10-06 Thread Paul Barry

+1

On Oct 6, 10:43 am, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
> If this gets traction, please also consider a name change to something  
> more along the lines of "read-file" and "write-file".
>
> --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
-~--~~~~--~~--~--~---



Re: class weirdness

2008-10-06 Thread Rich Hickey



On Oct 3, 3:17 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> Thanks Stephen, Chouser, and Rich.
>
> Understanding the historical reason that (. SomeClass method) doesn't
> work, I would be in favor of the deprecation Rich mentioned, leading
> to (. SomeClass method) being able to work in the future.
>

(. SomeClass method) works - it just calls static methods. We're just
talking about limiting . to instance members, which would make it work
differently.

Many of the people who get stuck on this (not you Stuart) don't even
know the difference between static methods of SomeClass and instance
methods of Class - they presume all would be available with the same
syntax! I imagine lots of complaints to the effect of, why doesn't
this work anymore:

(. Integer parseInt "42")

The flipside is, the only additional methods that you could call if I
were to change this would be the instance methods of Class. Many of
them could be made much easier with some helper functions that wrap
reflection.

If I were to change this, we would lose any static member support in
macros that leverage the . op, like .. - i.e. no more:

(.. System out (println "Hello World"))

It would _have_ to be:

(.println System/out "Hello World") or (. System/out println "Hello
World")

I much prefer treating classnames as namespaces for static members
(i.e. the latter forms), but it won't be intuitive for those used to
ClassName.staticMethod() in Java.

That may be no big deal, I don't know. I guess with a deprecation
warning in place I'd find out soon enough :)

The original design was - if you say x.y() in Java, static or
instance, you can say (. x y) in Clojure, and that idea still has the
merits of being very easy to explain, and possibly the target of
mechanical transformations of Java code.

People just got spoiled by class object literals, and now we have this
alternative non-Java-like but snazzy static member syntax.

Still mulling...

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



Clojure 'to the metal'

2008-10-06 Thread cliffc

> Hi Cliff,
> It was great meeting you at the JVM Summit - I learned a lot, thanks!
> I know the test is over, but wanted to get you a version of your simple test 
> that demonstrates Clojure's ability to get to the metal on primitive numerics 
> when given type hints.
> Attached is a new clojure.jar and a simple.clj
> Run with:
>   java -server -cp clojure.jar clojure.lang.Script simple.clj
> Regards,
> Rich

Hi Rich - nice meeting you too - and Clojure is very impressive.  Here
is 1 copy of the inner loop HotSpot generates on Azul, the full thing
is unrolled 32 times.
R6 - the original 'i' at the start of all 32 copies
R0 - 'sum' for iteration#2
R5 - large masking constant 0x3FFF
R1 - 'sum' for iteration#3

0.07%   31  0x131870c0  add4 r9, r6, 2  // r9 = i+2 - this is the 2nd
unrolled body
0.10%   45  0x131870c4  xor r2, r0, r9  // r2 = sum ^ (i+2)
0.09%   41  0x131870c8  beq r9, 0, 0x01318750c // div-by-zero check
0.15%   66  0x131870cc  div4 r7, r2, r9 // r7 = (sum^(i+2)/(i+2)
2.33%   1,028   0x131870d0  add4 r3, r7, r0 // r3 = sum + (sum^i)/i
0.07%   30  0x131870d4  xor r2, r3, r0  // ??? - guess overflow check 
for
prior sum
0.05%   22  0x131870d8  blt0 r2, 0x0131874f8// ??? - guess overflow 
check
for prior sum
0.07%   30  0x131870dc  and r1, r3, r5  // sum = () & 0x3FFF


Cliff

--~--~-~--~~~---~--~~
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: slurp is in Clojure, but spit is in Contrib?

2008-10-06 Thread Matti Jagula

On Mon, Oct 6, 2008 at 5:43 PM, Stephen C. Gilardi <[EMAIL PROTECTED]> wrote:
> If this gets traction, please also consider a name change to something
> more along the lines of "read-file" and "write-file".

I guess that spit and slurp are more original and therefore less
likely to clash with existing function names. At least I'm quite sure
I've got quite a few "read-file"-s myself.

-- 
  Matti Jagula

--~--~-~--~~~---~--~~
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: slurp is in Clojure, but spit is in Contrib?

2008-10-06 Thread Parth Malwankar



On Oct 6, 6:40 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> Hi all
>
> For consistency, I would like to see spit moved into the boot.clj.
>
> This will play well with the Java crowd. For years I have poked fun of  
> Java for having megabytes of core library and no simple way to save a  
> file.

This would be a nice addition in my view.
It will be especially useful for people from non-java background
coming to Clojure. I know I was quite confused about how to
write to a file when I was ramping up on Clojure.

Parth


>
> 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: Hex literals

2008-10-06 Thread Jim Menard

On Mon, Oct 6, 2008 at 2:40 AM, Michael Wood <[EMAIL PROTECTED]> wrote:

> The previous release (from June) did not support hexadecimal numbers.
> Perhaps you're using that version?

You are correct; the files in my clojure.jar were all dated June 12,
2008. After downloading the latest version, all is well. Thank you for
your help.

> I don't know how you tell what version of clojure you're using, but if you 
> run:
>
> jar tvf clojure.jar
>
> all the files should have timestamps in September (mostly the 16th.)

Perhaps a "--version" command line flag would be helpful.

Jim
-- 
Jim Menard, [EMAIL PROTECTED], [EMAIL PROTECTED]
http://www.io.com/~jimm/

--~--~-~--~~~---~--~~
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: true?

2008-10-06 Thread Stuart Halloway

> What if I were to add sparse vectors?

Continuing down the ugly path I started, those *wouldn't* throw an  
exception. :-/

I am going to cease and desist now, and accept contains? as it is. But  
somebody is going to need to write a book to explain these odd corners  
to people coming from the Java world. Bwa ha ha ha ha. :-)

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: slurp is in Clojure, but spit is in Contrib?

2008-10-06 Thread Stephen C. Gilardi


On Oct 6, 2008, at 10:16 AM, Matti Jagula wrote:

> Hi all,
>
> On Mon, Oct 6, 2008 at 4:40 PM, Stuart Halloway
> <[EMAIL PROTECTED]> wrote:
>> For consistency, I would like to see spit moved into the boot.clj.
>
> I wholeheartedly agree.
>
> And I'd also like both slurp and spit to support encoding as an
> optional parameter as it is a bit of pain to write my own versions
> just to read/write files with non-default encoding.

If this gets traction, please also consider a name change to something  
more along the lines of "read-file" and "write-file".

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



Re: safe navigation operator

2008-10-06 Thread Parth Malwankar



On Oct 6, 7:00 pm, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Oct 6, 9:36 am, Stuart Halloway <[EMAIL PROTECTED]> wrote:
>
>
>
> > Yes, that's better. Glad you like the idea.
>
> > Does anybody not named Stuart also want to see this added to
> > Clojure? ;-)
>
> > Stuart
>
> > > On Oct 3, 3:13 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> > >> (defmacro ?.
> > >>    "like .. but drops out on null object"
> > >>    ([x form]
> > >>       `(. ~x ~form))
> > >>    ([x form & more]
> > >>       `(if-let x# (. ~x ~form) (.? x# [EMAIL PROTECTED]
>
> > > Interesting -- I like it.  It doesn't seem to be totally compatible
> > > with "..", though:
>
> > > user=> (?. System (getenv "SHELL") (startsWith "/bin") getClass
> > > getName)
> > > java.lang.Exception: Unable to resolve symbol: startsWith in this
> > > context (NO_SOURCE_FILE:62)
>
> > > Also, if-let could give the wrong result in the (admittedly unlikely)
> > > situation that one of the methods returns Boolean.FALSE.
> > > Here's another take:
>
> > > (defmacro ?..
> > >   "like .. but stops and returns nil if any method returns nil"
> > >   ([x form]
> > >      `(.. ~x ~form))
> > >   ([x form & more]
> > >      `(let [x# (?. ~x ~form)]
> > >         (if (nil? x#) nil
> > >             (?. x# [EMAIL PROTECTED])
>
> > > user=> (?.. System (getenv "SHELL") (startsWith "/bin") getClass
> > > getName)
> > > "java.lang.Boolean"
> > > user=> (?.. System (getenv "FOO") (startsWith "/bin") getClass
> > > getName)
> > > nil
>
> I'm not opposed, but we'll need to find another name. Leading ? is a
> likely candidate for rule syntax, and trailing means predicate.

This construct will be very useful.

How about the name "maybe" or similar along the lines of Haskell
"Maybe"
http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html

Parth

>
> .?.
>
> ?
>
> 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: safe navigation operator

2008-10-06 Thread Stuart Sierra

On Oct 6, 10:00 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> I'm not opposed, but we'll need to find another name. Leading ? is a
> likely candidate for rule syntax, and trailing means predicate.
>
> .?.
>
> ?

Or, more verbosely, "nilsafe.."
-Stuart Sierra

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



Re: safe navigation operator

2008-10-06 Thread Stuart Halloway

> .?.

OK with me. Needs a dorky name to match. :-)


--~--~-~--~~~---~--~~
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: slurp is in Clojure, but spit is in Contrib?

2008-10-06 Thread Matti Jagula

Hi all,

On Mon, Oct 6, 2008 at 4:40 PM, Stuart Halloway
<[EMAIL PROTECTED]> wrote:
> For consistency, I would like to see spit moved into the boot.clj.

I wholeheartedly agree.

And I'd also like both slurp and spit to support encoding as an
optional parameter as it is a bit of pain to write my own versions
just to read/write files with non-default encoding.

-- 
  Matti Jagula

--~--~-~--~~~---~--~~
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: safe navigation operator

2008-10-06 Thread Paul Stadig
.? kinda almost works. It's not exactly a predicate, but it means "access
this member if not null".

Or perhaps .* which would mean "access as many members as possible in the
following list".


Paul

On Mon, Oct 6, 2008 at 10:00 AM, Rich Hickey <[EMAIL PROTECTED]> wrote:

>
>
>
> On Oct 6, 9:36 am, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> > Yes, that's better. Glad you like the idea.
> >
> > Does anybody not named Stuart also want to see this added to
> > Clojure? ;-)
> >
> > Stuart
> >
> > > On Oct 3, 3:13 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> > >> (defmacro ?.
> > >>"like .. but drops out on null object"
> > >>([x form]
> > >>   `(. ~x ~form))
> > >>([x form & more]
> > >>   `(if-let x# (. ~x ~form) (.? x# [EMAIL PROTECTED]
> >
> > > Interesting -- I like it.  It doesn't seem to be totally compatible
> > > with "..", though:
> >
> > > user=> (?. System (getenv "SHELL") (startsWith "/bin") getClass
> > > getName)
> > > java.lang.Exception: Unable to resolve symbol: startsWith in this
> > > context (NO_SOURCE_FILE:62)
> >
> > > Also, if-let could give the wrong result in the (admittedly unlikely)
> > > situation that one of the methods returns Boolean.FALSE.
> > > Here's another take:
> >
> > > (defmacro ?..
> > >   "like .. but stops and returns nil if any method returns nil"
> > >   ([x form]
> > >  `(.. ~x ~form))
> > >   ([x form & more]
> > >  `(let [x# (?. ~x ~form)]
> > > (if (nil? x#) nil
> > > (?. x# [EMAIL PROTECTED])
> >
> > > user=> (?.. System (getenv "SHELL") (startsWith "/bin") getClass
> > > getName)
> > > "java.lang.Boolean"
> > > user=> (?.. System (getenv "FOO") (startsWith "/bin") getClass
> > > getName)
> > > nil
> >
>
> I'm not opposed, but we'll need to find another name. Leading ? is a
> likely candidate for rule syntax, and trailing means predicate.
>
> .?.
>
> ?
>
> 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: safe navigation operator

2008-10-06 Thread Rich Hickey



On Oct 6, 9:36 am, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> Yes, that's better. Glad you like the idea.
>
> Does anybody not named Stuart also want to see this added to
> Clojure? ;-)
>
> Stuart
>
> > On Oct 3, 3:13 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> >> (defmacro ?.
> >>"like .. but drops out on null object"
> >>([x form]
> >>   `(. ~x ~form))
> >>([x form & more]
> >>   `(if-let x# (. ~x ~form) (.? x# [EMAIL PROTECTED]
>
> > Interesting -- I like it.  It doesn't seem to be totally compatible
> > with "..", though:
>
> > user=> (?. System (getenv "SHELL") (startsWith "/bin") getClass
> > getName)
> > java.lang.Exception: Unable to resolve symbol: startsWith in this
> > context (NO_SOURCE_FILE:62)
>
> > Also, if-let could give the wrong result in the (admittedly unlikely)
> > situation that one of the methods returns Boolean.FALSE.
> > Here's another take:
>
> > (defmacro ?..
> >   "like .. but stops and returns nil if any method returns nil"
> >   ([x form]
> >  `(.. ~x ~form))
> >   ([x form & more]
> >  `(let [x# (?. ~x ~form)]
> > (if (nil? x#) nil
> > (?. x# [EMAIL PROTECTED])
>
> > user=> (?.. System (getenv "SHELL") (startsWith "/bin") getClass
> > getName)
> > "java.lang.Boolean"
> > user=> (?.. System (getenv "FOO") (startsWith "/bin") getClass
> > getName)
> > nil
>

I'm not opposed, but we'll need to find another name. Leading ? is a
likely candidate for rule syntax, and trailing means predicate.

.?.

?

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: Literal set

2008-10-06 Thread Arie van Wingerden
Hi Steve!

that last post makes it clear for me.
The example using "let" shows exactly what I needed to understand.

Thanks very much!
   Arie



2008/10/6 Stephen C. Gilardi <[EMAIL PROTECTED]>

>
>
> On Oct 6, 2008, at 9:07 AM, hotcore wrote:
>
> > I was playing around with data structures and found that I couldn't
> > type:
> >   (conj  #{aap noot mies} 'wim)
> > which results in:
> >   java.lang.Exception: Unable to resolve symbol: mies in this context
> >
> > Instead I have to type:
> >   (conj  '#{aap noot mies} 'wim)
> > or:
> >   (conj  (set '(aap noot mies)) 'wim)
> >
> > I wonder why the quote is needed. Normally the quote is only used to
> > prevent the first item of a list being interpreted as a (special)
> > operator / function; but that's not the case here. Or is it?
>
> In addition to literal lists, symbols also evaluate to something other
> than themselves. Without a quote:
>
>- a list evaluates to the result of a function call
>
>- a symbol is first "resolved" to identify a let-bound name or a var
> that it represents and evaluates to the value bound to that name or var.
>
> The error message you got is describing the latter case.
>
> The line you typed:
>
> >   (conj  #{aap noot mies} 'wim)
>
>
> is not meaningless--it just isn't the correct way to express what you
> wanted.
>
> Here's a context where it would have been accepted:
>
>user=> (let [aap 1 noot 2 mies 3]
>  (conj #{aap noot mies} 'wim))
>#{1 2 3 wim}
>user=>
>
> In addition to these:
>
> > Instead I have to type:
> >   (conj  '#{aap noot mies} 'wim)
> > or:
> >   (conj  (set '(aap noot mies)) 'wim)
>
>
> You could have also typed:
>
>(conj #{'aap 'noot 'mies} 'wim)
>
> Which makes it clear that it's symbol evaluation that you're
> suppressing with the quotes.
>
> --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
-~--~~~~--~~--~--~---



Re: string-functions, split/recur-problem

2008-10-06 Thread Stephen C. Gilardi


On Oct 6, 2008, at 5:16 AM, ssecorp wrote:

> (also, what is the best way to deal with strings in clojure, java-
> strings?)

Clojure strings are Java strings. Search for "java.lang.String split"  
on the web to find:

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

Try it in Clojure.

user=> (seq (.split "Hot-cross-buns" "-"))
("Hot" "cross" "buns")
user=> (seq (.split "Hot-cross-buns" "-" 1))
("Hot-cross-buns")
user=> (seq (.split "Hot-cross-buns" "-" 2))
("Hot" "cross-buns")
user=> (seq (.split "Hot-cross-buns" "-" 3))
("Hot" "cross" "buns")

Those expressions are idiomatic Clojure. If you wanted split and split- 
all as Clojure functions:

user=>
(defn split
   [str delim]
   (seq (.split str delim 2)))
#'user/split
user=>
(defn split-all
   [str delim]
   (seq (.split str delim)))
#'user/split-all

With example uses:

user=> (split "hot-cross-buns" "-")
("hot" "cross-buns")
user=> (split-all "hot-cross-buns" "-")
("hot" "cross" "buns")
user=>

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



slurp is in Clojure, but spit is in Contrib?

2008-10-06 Thread Stuart Halloway

Hi all

For consistency, I would like to see spit moved into the boot.clj.

This will play well with the Java crowd. For years I have poked fun of  
Java for having megabytes of core library and no simple way to save a  
file.

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: Literal set

2008-10-06 Thread Stephen C. Gilardi


On Oct 6, 2008, at 9:07 AM, hotcore wrote:

> I was playing around with data structures and found that I couldn't
> type:
>   (conj  #{aap noot mies} 'wim)
> which results in:
>   java.lang.Exception: Unable to resolve symbol: mies in this context
>
> Instead I have to type:
>   (conj  '#{aap noot mies} 'wim)
> or:
>   (conj  (set '(aap noot mies)) 'wim)
>
> I wonder why the quote is needed. Normally the quote is only used to
> prevent the first item of a list being interpreted as a (special)
> operator / function; but that's not the case here. Or is it?

In addition to literal lists, symbols also evaluate to something other  
than themselves. Without a quote:

- a list evaluates to the result of a function call

- a symbol is first "resolved" to identify a let-bound name or a var  
that it represents and evaluates to the value bound to that name or var.

The error message you got is describing the latter case.

The line you typed:

>   (conj  #{aap noot mies} 'wim)


is not meaningless--it just isn't the correct way to express what you  
wanted.

Here's a context where it would have been accepted:

user=> (let [aap 1 noot 2 mies 3]
  (conj #{aap noot mies} 'wim))
#{1 2 3 wim}
user=>

In addition to these:

> Instead I have to type:
>   (conj  '#{aap noot mies} 'wim)
> or:
>   (conj  (set '(aap noot mies)) 'wim)


You could have also typed:

(conj #{'aap 'noot 'mies} 'wim)

Which makes it clear that it's symbol evaluation that you're  
suppressing with the quotes.

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



Re: Quick way to kill slime with clojure

2008-10-06 Thread jv-lists

The Ubuntu package you probably want is "emacs-snapshot-gtk" (on Hardy this is 
Emacs 23.0.60). I couldn't reproduce your error with this package and Slime 
from the Hardy repos.

My installed clojure-swank is from 2008-09-23 and Clojure is rev-1043. Hope 
this helps.

Jeff

- Original Message -
From: "Paul Stadig" <[EMAIL PROTECTED]>
Sent: Thursday, October 02, 2008 20:54
To: clojure@googlegroups.com
Cc: 
Subject: Re: Quick way to kill slime with clojure

The Ubuntu package is emacs-22. Does emacs-23 fix the issue? Or does the
swank-clojure package need to be updated?

Paul

On Thu, Oct 2, 2008 at 7:17 PM, Hans Hübner <[EMAIL PROTECTED]> wrote:

>
> Hi Paul,
>
> Paul Stadig schrieb:
> > I have setup clojure-mode and swank-clojure with emacs on Ubuntu.
> Everything
> > has been working great so for, but I ran into a bug today. I am
> up-to-date
> > with the latest git commits as of this moment. When I enter "\227" into
> the
> > REPL I get a nasty debug message that I don't understand:
>
> I think you are running into the same sort of encoding issue that I
> see.  I had more success with emacs-23, but that could have been a
> coincidence.  Do you use emacs-23?
>
> -Hans
>
> >
>


--~--~-~--~~~---~--~~
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: safe navigation operator

2008-10-06 Thread Stuart Halloway

Yes, that's better. Glad you like the idea.

Does anybody not named Stuart also want to see this added to  
Clojure? ;-)

Stuart

> On Oct 3, 3:13 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote:
>> (defmacro ?.
>>"like .. but drops out on null object"
>>([x form]
>>   `(. ~x ~form))
>>([x form & more]
>>   `(if-let x# (. ~x ~form) (.? x# [EMAIL PROTECTED]
>
> Interesting -- I like it.  It doesn't seem to be totally compatible
> with "..", though:
>
> user=> (?. System (getenv "SHELL") (startsWith "/bin") getClass
> getName)
> java.lang.Exception: Unable to resolve symbol: startsWith in this
> context (NO_SOURCE_FILE:62)
>
> Also, if-let could give the wrong result in the (admittedly unlikely)
> situation that one of the methods returns Boolean.FALSE.
> Here's another take:
>
> (defmacro ?..
>   "like .. but stops and returns nil if any method returns nil"
>   ([x form]
>  `(.. ~x ~form))
>   ([x form & more]
>  `(let [x# (?. ~x ~form)]
> (if (nil? x#) nil
> (?. x# [EMAIL PROTECTED])
>
> user=> (?.. System (getenv "SHELL") (startsWith "/bin") getClass
> getName)
> "java.lang.Boolean"
> user=> (?.. System (getenv "FOO") (startsWith "/bin") getClass
> getName)
> nil
>
> -the other 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: Patch: java.util.Map support

2008-10-06 Thread Rich Hickey



On Sep 30, 11:17 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
> On Sep 30, 5:04 am, Achim Passen <[EMAIL PROTECTED]> wrote:
>
> > On Sep 30, 5:20 am, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
>
> > > After some more thought, I'm not sure whether this should be a concern
> > > or not. Since jmap's purpose is to wrap Clojure maps for passing to
> > > Java APIs, I'm not sure when it will be necessary to compare jmaps to
> > > Clojure maps. In the abstract, it would be nice if they could be
> > > compared for equality, but I'm not sure how important this is in
> > > practice.
>
> > I tend to agree. In most cases there should be no doubts whether a map
> > at hand is wrapped or not. If otherwise, you could safely unwrap both
> > via cmap (that's the reason why i wrote cmap to act "forgivingly" when
> > not applied to jmaps) and then compare afterwards.
>
> I've been thinking about this Map vs Collection issue for a while now
> and am considering making the move to: Clojure maps implement Java
> Map.
>
> The jmap workaround highlights the awkwardness of not aligning with
> Java here.
>
> My current thoughts are:
>
> - Java Maps not being Java Collections is truly sad, but not something
> I can do anything about.
>
> - For consumption from the Clojure side, I can hide that difference in
> coll?, count, to-array etc.
>
> - Code that looks for Collection currently matches Clojure maps but
> wouldn't anymore. It never matched Java Maps. clojure code should move
> to coll?, and for Java code I can provide RT.isCollection for
> replacing instanceof calls.
>
> - Using the ad hoc hierarchy support, I can unify Collection and Map
> by deriving both from :Collection, thus allowing matches for all
> collections in multimethods etc.
>
> - The real reason to implement Java interfaces is to support use from
> Java, where the limitations of Maps not being Collections is already a
> fact of life, and Clojure maps not implementing Map a problem.
>
> - If I'm going to do this, the sooner the better.
>
> Any change in this area may involve some breakage, but I'm confident
> there will be all necessary facilities to move existing code.
>

I've made maps implement java.util.Map
unified equality and hashCode semantics for sets/maps/lists with
java.util
enabled sort on all colls and strings
enabled to-array on Maps

In SVN rev 1052

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: Literal set

2008-10-06 Thread Randall R Schulz

On Monday 06 October 2008 06:07, hotcore wrote:
> Hi,
>
> I was playing around with data structures and found that I couldn't
> type:
>(conj  #{aap noot mies} 'wim)
> which results in:
>java.lang.Exception: Unable to resolve symbol: mies in this
> context
>
> Instead I have to type:
>(conj  '#{aap noot mies} 'wim)
> or:
>(conj  (set '(aap noot mies)) 'wim)
>
> I wonder why the quote is needed. Normally the quote is only used to
> prevent the first item of a list being interpreted as a (special)
> operator / function; but that's not the case here. Or is it?

Quote prevents evaluation of the thing it's applied to, whether that 
thing is atomic or structured. This is true throughoutthe world of Lisp 
(-like) languages.


> TIA,
>Arie


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



Literal set

2008-10-06 Thread hotcore

Hi,

I was playing around with data structures and found that I couldn't
type:
   (conj  #{aap noot mies} 'wim)
which results in:
   java.lang.Exception: Unable to resolve symbol: mies in this context

Instead I have to type:
   (conj  '#{aap noot mies} 'wim)
or:
   (conj  (set '(aap noot mies)) 'wim)

I wonder why the quote is needed. Normally the quote is only used to
prevent the first item of a list being interpreted as a (special)
operator / function; but that's not the case here. Or is it?

TIA,
   Arie

--~--~-~--~~~---~--~~
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: string-functions, split/recur-problem

2008-10-06 Thread Stephen C. Gilardi


On Oct 6, 2008, at 5:16 AM, ssecorp wrote:

> (defn splitall [str delim]
>(loop [s str acc nil]
>(if (= s nil)
>   (reverse acc)
>   (let [parts (split s delim)]
>   (recur (rest parts) (cons (first parts) acc))

As a debugging tool, I recommend inserting:

(prn s acc)

right after the line that contains "loop".

The book at  describes a systematic way to design  
loops like this.

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



string-functions, split/recur-problem

2008-10-06 Thread ssecorp

split is working fine, returns the parts on both sides of the
delimiter.
but for some reason splitall doesnt, it just does what split does.

(also, what si the best way to deal with strings in clojure, java-
strings?)

(defn split [str delim]
(loop [s str acc nil]
(cond
   (= s nil)
   (reverse acc)
   (not (= delim (first s)))
  (recur (rest s) (cons (first s) acc))
   :else
   (list (reverse acc) (rest s)


(defn splitall [str delim]
(loop [s str acc nil]
(if (= s nil)
(reverse acc)
(let [parts (split s delim)]
(recur (rest parts) (cons (first parts) acc))


(defn splitall [str delim]
(loop [s str acc nil]
(if (= s nil)
(reverse acc)
(recur (rest (split s delim))
   (cons (first (split s delim)) acc)
--~--~-~--~~~---~--~~
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: Hex literals

2008-10-06 Thread Michael Wood

On Mon, Oct 6, 2008 at 2:04 AM, Jim Menard <[EMAIL PROTECTED]> wrote:
>
> nimbus:/usr/local/src/Lisp/clojure> clojure
> Clojure
> user=> 0xff
> java.lang.IllegalArgumentException: Invalid number: 0xff
> java.lang.Exception: ReaderError:(2,1) Invalid number: 0xff
>at clojure.lang.LispReader.read(LispReader.java:160)
>at clojure.lang.Repl.main(Repl.java:68)
>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>at java.lang.reflect.Method.invoke(Method.java:585)
>at jline.ConsoleRunner.main(ConsoleRunner.java:69)
> Caused by: java.lang.IllegalArgumentException: Invalid number: 0xff
>at clojure.lang.LispReader.readNumber(LispReader.java:198)
>at clojure.lang.LispReader.read(LispReader.java:117)
>... 6 more
>
> I'm using OS X 10.5 (Leopard). I can't figure out how to determine the
> version of Clojure I am using from the command line, but I believe I'm
> using the latest version 20080916.

The previous release (from June) did not support hexadecimal numbers.
Perhaps you're using that version?

I don't know how you tell what version of clojure you're using, but if you run:

jar tvf clojure.jar

all the files should have timestamps in September (mostly the 16th.)

-- 
Michael Wood <[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: Hacking boot.clj, what else needs to be reloaded?

2008-10-06 Thread Stephen C. Gilardi


On Oct 6, 2008, at 7:55 AM, Stephen C. Gilardi wrote:

> put the directory "/src/clj/ 
> clojure"  into your classpath

Correction: "/src/clj"

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



Re: Hacking boot.clj, what else needs to be reloaded?

2008-10-06 Thread Stephen C. Gilardi


On Oct 6, 2008, at 5:13 AM, ssecorp wrote:

> If I want to add something to boot.clj so I always have it available.
>
> lets say h and t for head/first tail/rest (yes i find them annoyingly
> long).
>
> it doesn't work just adding something to the file, do i have to add it
> somewhere else too? recompile something?

To have something always available, consider putting a file called  
"user.clj" in the classpath used by the java command you use to launch  
Clojure. Clojure looks for such a file on startup and if it exists,  
Clojure will load it after loading boot.clj.

If you want to keep a local fork of boot.clj, you'll need to either  
put the directory "/src/clj/clojure"  
into your classpath before clojure.jar, or rebuild clojure.jar after  
making changes to boot.clj. I would do that by running "ant" from  
within "".

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



Re: Syntax highlighter and setup for Clojure in Context editor under Windows/XP

2008-10-06 Thread hotcore

Hi,

I uploaded a new version for the highlighter with a few improvements.
Maybe the moderator can delete the previous version?

TIA,
   Arie

On 4 okt, 17:59, hotcore <[EMAIL PROTECTED]> wrote:
> Thanks Hans, didn't know that feature yet!
>
> I uploaded the file as Clojure-Context.zip.
>
> Regards,
>    Arie
>
> On Oct 4, 3:57 pm, Hans Hübner <[EMAIL PROTECTED]> wrote:
>
> > On 4 Okt., 12:46, hotcore <[EMAIL PROTECTED]> wrote:
>
> > > I have created a zip file containing a syntax highlighter and a few
> > > Windows scripts to execute Clojure scripts from within theContext
> > > editor together with a doc file.
>
> > > Where can I upload the ZIP file so that interested people might use
> > > it?
>
> > Upload it to the files section of the Google Group.
>
> > -Hans
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Hacking boot.clj, what else needs to be reloaded?

2008-10-06 Thread ssecorp

If I want to add something to boot.clj so I always have it available.

lets say h and t for head/first tail/rest (yes i find them annoyingly
long).

it doesn't work just adding something to the file, do i have to add it
somewhere else too? recompile something?


--~--~-~--~~~---~--~~
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: Using Java frameworks from Clojure

2008-10-06 Thread James Reeves

On Oct 6, 4:21 am, Hans Hübner <[EMAIL PROTECTED]> wrote:
> for a project, I would like to use a Java framework that exposes a
> very Javaesque API, with dozens of classes that need to be
> instantiated or used and with several interfaces that one needs to
> implement in order to be called back by the framework.
> ...
> How do others approach this kind of problem?  Are you just ignoring
> the functional vs. object oriented mismatch and access Java objects
> from everywhere?  Do you use hand-written wrappers around the
> libraries?  Tools?

I don't think there's any one answer to this, as it really depends on
the library. I've written a functional wrapper around the Java servlet
interface, and I use a number of techniques. Which API in particular
are you trying to convert?

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



Re: complexity of subvec

2008-10-06 Thread Cesare

On Oct 3, 5:21 pm, Rich Hickey <[EMAIL PROTECTED]> wrote:
> Yes. If it is important to get access bounded by the subvector's N you
> can just call vec on it, at a one-time O(subvecN) cost.
>
> It is important to note that for vectors that are created by vec (and
> literals) that have never been updated, creating the tree
> representation is done lazily on update and used by the changed
> versions only, so access to this root value is in fact always O(1),
> for that vector and any subvectors.
>
> (class [1 2 3 4 5])
> -> clojure.lang.LazilyPersistentVector
>
> (class (vec (range 1000)))
> -> clojure.lang.LazilyPersistentVector
>
> i.e. LazilyPersistentVectors are O(1)

Thank a lot for the explanation, Rich.

I think that this should be somehow explicit in the documentation.

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