Java / clojure interop, invoking methods and perserving thread binding

2011-11-17 Thread Michael Jaaka
Hi!

I'm using Clojure from Java via RT.loadResourceScript(...) and then 
RT.var(...)
However this only works when I do 

Var.pushThreadBindings(THREAD_BINDING)
and 
Var.popThreadBindings()

around RT.var().invoke(), where THREAD_BINDING is a thread binding got 
during script loading via (def ^:dynamic *current-context* 
(get-thread-bindings))
and then getting it via RT.var(namespace, *current-context*)

Without restoring thread binding from script load time, I got errors about 
functions which are defined by script but not found during invocation time.
It is probably caused by fact, that I'm using Proxy.newProxyInstance to 
facade RT.var().invoce() around Java Interfaces, so maybe accessing to 
Clojure ClassLoader and passing it to newProxyInstance would help? Now I'm 
just putting there ClassLoader.getSystemClassLoader().



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Java / clojure interop, invoking methods and perserving thread binding

2011-11-17 Thread Michael Jaaka
Well, I have checked different possibilites and the problem is not
about facade but lies in Clojure "eval" which is called on Clojure
structure done from transforming XML to Clojure structures. This eval
doesn't see context defined during loading time only if thread binding
is not restored. Any help?

On Nov 17, 9:55 am, Michael Jaaka 
wrote:
> Hi!
>
> I'm using Clojure from Java via RT.loadResourceScript(...) and then
> RT.var(...)
> However this only works when I do
>
> Var.pushThreadBindings(THREAD_BINDING)
> and
> Var.popThreadBindings()
>
> around RT.var().invoke(), where THREAD_BINDING is a thread binding got
> during script loading via (def ^:dynamic *current-context*
> (get-thread-bindings))
> and then getting it via RT.var(namespace, *current-context*)
>
> Without restoring thread binding from script load time, I got errors about
> functions which are defined by script but not found during invocation time.
> It is probably caused by fact, that I'm using Proxy.newProxyInstance to
> facade RT.var().invoce() around Java Interfaces, so maybe accessing to
> Clojure ClassLoader and passing it to newProxyInstance would help? Now I'm
> just putting there ClassLoader.getSystemClassLoader().

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Java / clojure interop, invoking methods and perserving thread binding

2011-11-17 Thread Michael Jaaka
Ok. I have solved this. I have replaced eval with eval-data
which is

(defmacro eval-data[ & body ]
(defonce this-current-context (get-thread-bindings) )
   `(do (push-thread-bindings this-current-context)
(try (eval ~@body)  (finally (pop-thread-bindings)

On Nov 17, 10:08 am, Michael Jaaka 
wrote:
> Well, I have checked different possibilites and the problem is not
> about facade but lies in Clojure "eval" which is called on Clojure
> structure done from transforming XML to Clojure structures. This eval
> doesn't see context defined during loading time only if thread binding
> is not restored. Any help?
>
> On Nov 17, 9:55 am, Michael Jaaka 
> wrote:
>
>
>
>
>
>
>
> > Hi!
>
> > I'm using Clojure from Java via RT.loadResourceScript(...) and then
> > RT.var(...)
> > However this only works when I do
>
> > Var.pushThreadBindings(THREAD_BINDING)
> > and
> > Var.popThreadBindings()
>
> > around RT.var().invoke(), where THREAD_BINDING is a thread binding got
> > during script loading via (def ^:dynamic *current-context*
> > (get-thread-bindings))
> > and then getting it via RT.var(namespace, *current-context*)
>
> > Without restoring thread binding from script load time, I got errors about
> > functions which are defined by script but not found during invocation time.
> > It is probably caused by fact, that I'm using Proxy.newProxyInstance to
> > facade RT.var().invoce() around Java Interfaces, so maybe accessing to
> > Clojure ClassLoader and passing it to newProxyInstance would help? Now I'm
> > just putting there ClassLoader.getSystemClassLoader().

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: adding metadata to java objects

2011-11-17 Thread Chas Emerick

On Nov 17, 2011, at 1:01 AM, Ben Smith-Mannschott wrote:

>> (def o (Object.))
>> 
>> (def om (with-meta* o {:foo true}))
>> 
>> (def whatever (with-meta* o {:foo false}))
>> 
>> (meta* om) ;=> {:foo false}
>> 
>> Doesn't really support Clojure's concept of metadata if it's shared
>> global mutable state.
> 
> Yes, that's true. Though it wouldn't occur to me to expect some random
> POJO to behave as if it were persistent WRT metadata. POJOs generally
> conflate state and identity and are mutable. That's life. If that's a
> problem, then you'll need to wrap it in something that supports
> metadata.

Mechanisms like what Ben proposed have been discussed before, but declined for 
core (which is probably a good decision).  However, something is generally 
better than nothing.

meta* isn't clojure.core/meta, so it can have weaker/different semantics 
without apologizing for it, IMO.

- Chas



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: adding metadata to java objects

2011-11-17 Thread Chas Emerick
Ben,

It's a good idea, but it's going to bite you:

- what if the class in question has fields or package-private methods that are 
touched by Java code?
- what if the class take ctor arguments?
- what if the ctor has side effects?

- Chas

On Nov 16, 2011, at 11:28 AM, Ben Mabey wrote:

> Hi,
> I would like to be able to add metadata to arbitrary java objects that have 
> already been instantiated.  I know that you can use proxy to add metadata to 
> objects that you create but in my case the object already exists (i.e. it is 
> returned from another method call outside of my control).
> 
> It seems like the best solution would be to create a delegate class/object 
> that wraps the original one.  Being able to write something like this would 
> be ideal:
> 
> (defn wrap-with-meta
>  ([obj]
> (wrap-with-meta obj nil))
>  ([obj meta]
>   (delegate obj
> clojure.lang.IObj
> (withMeta [this new-meta] (wrap-with-meta obj 
>   
>
> new-meta))
> (meta [this] meta
> 
> The delegate function would operate very similar to proxy, but instead of 
> taking a class it takes an object.  A class would be created that extends the 
> object's class, just like a class is generated for proxy. However, instead of 
> stubs being generated that call super the stubs would delegate to the given 
> object.  (Also note, I am also using reify-like syntax since I prefer that to 
> the syntax in proxy.)
> 
> I'm curious to hear people's thoughts on this approach.  I'd also be really 
> interested to see how other people have addressed this in the past (I doubt 
> I'm the first one to run into this).
> 
> I know that clojure mentality is to avoid wrappers, but I don't see this as 
> being much different than what proxy already does.  Of course, I may be 
> missing something... if so, please enlighten me. :)
> 
> Thanks,
> Ben
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Overused phrases in the Clojure community

2011-11-17 Thread thenwithexpandedwingshesteershisflight
Firstly, sorry about this thread :-D

I wasn't trolling, honest, I just thought it was getting to the point
where the word was loosing its meaning.

There are many ways to express the notion of applying Clojure's
characteristics to one's code:

"here's a more Clojurian version of that function..."
"that's the Clojure way of doing it"
"how can I write this function Clojure-style ?"
"how could I Clojurify this code ?"
"what's the Clojure way of doing X ?"

Often people actually mean a slightly different thing, but use
"idiomatic" because it's popular -- for instance, (in particular) they
might mean "functional".

The rest of the time, people are usually just asking how to do
something in Clojure. Stackoverflow is brimming with questions like
"what's the idiomatic way to do X in Clojure ?" when really all they
want to know is "how do I do X in Clojure" - anyone answering is
unlikely to provide an example written in say, a Smalltalk or Python
style, but written in Clojure! Any answers given are likely to be
implicitly idiomatic, just because they're written by Clojurians, in
Clojure. In fact I challenge anyone to give an example of the least
idiomatic code written in Clojure (using Java interop is cheating).


On Nov 16, 5:53 pm, Ben Smith-Mannschott 
wrote:
> On Wed, Nov 16, 2011 at 02:16, thenwithexpandedwingshesteershisflight
>
>  wrote:
> > Can we please get bored of saying "idiomatic" and "in particular"
> > please ?
>
> can you think of some more idiomatic way to say "idiomatic", in particular? :P
>
> // ben

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Overused phrases in the Clojure community

2011-11-17 Thread Sergey Didenko
I coded mutable Dejkstra algorithm isolated in a single function,
because it's easier for me to maintain it - I used to write a lot of
mutable algorithms. But I consider this code not idiomatic though
useful in my case.

So I think idiomatic Clojure code is not as ubiquitous as you probably
mean and the word "idiomatic" is quite useful for discussions.

> In fact I challenge anyone to give an example of the least
> idiomatic code written in Clojure (using Java interop is cheating).

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: start-process-shell-command: Spawning child process: invalid argument

2011-11-17 Thread Andrew
Thanks Do I need Cygwin at all for Clojure work on 
Windows/Emacs/Swank/clojure-mode/lein? Or can I remove Cygwin from my 
machine?

And are these two functionally equivalent?

   - clojure-jack-in 
   - lein swank and slime-connect
   

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: start-process-shell-command: Spawning child process: invalid argument

2011-11-17 Thread Mark Rathwell
> Do I need Cygwin at all for Clojure work on
> Windows/Emacs/Swank/clojure-mode/lein?

I don't think so.  If lein.bat is on your path and is working, and if
emacs and clojure-mode are working, that's really all you need.  There
are utilities and tools out there that you may want to use at some
point, though, that do assume a unixy environment.

> And are these two functionally equivalent?
>   clojure-jack-in
>   lein swank and slime-connect

Basically, yes.  They both start a swank server, connect emacs to it,
and give you a repl.  clojure-jack-in is meant to simplify that
process and hide any complexity.


On Thu, Nov 17, 2011 at 9:50 AM, Andrew  wrote:
> Thanks Do I need Cygwin at all for Clojure work on
> Windows/Emacs/Swank/clojure-mode/lein? Or can I remove Cygwin from my
> machine?
>
> And are these two functionally equivalent?
>
> clojure-jack-in
> lein swank and slime-connect
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure on PyPy

2011-11-17 Thread Brent Millare
Couple of clarifications. My main point is the maturity of the JVM, so when 
comparing what is presented in the article (which isn't much), it can do 
what is listed. That's not to say the converse isn't true, that PyPy's JIT 
can do things the JVM can't do. Like I said, there are a lot of research 
oriented work that's being put into PyPy, I don't want to take anything 
away from it. The main point the poster should take away is the lack of any 
library/runtime tools, you have to build from the ground up many things you 
take for granted when targeting the JVM.

Also, Timothy, can you elaborate on the point that Clojure-CLR and 
ClojureScript is not a "real" clojure. With the clojureclr for example, it 
supports pretty much everything clojure does sans java, and gains all the 
.net interop.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Clojure on PyPy

2011-11-17 Thread Timothy Baldridge
> I also felt that sticking with the official Java implementation of Clojure 
> would be more practical.  It would certainly be fun to put Clojure on PyPy, 
> though.

There is one insanely off-the-wall idea I've been thinking about
recently, however:

1) Implement a full JVM in PyPy using GNU Classpath. Write a Java
bytecode interpreter in PyPy. This way you get the power of PyPy
(tracing JIT) with the power of Java (classpath)
2) Run stock JVM Clojure on this interpreter
3) 
4) Profit!

Timothy

-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure on PyPy

2011-11-17 Thread Gary Poster

On Nov 17, 2011, at 10:45 AM, Brent Millare wrote:

> ...The main point the poster should take away is the lack of any 
> library/runtime tools, you have to build from the ground up many things you 
> take for granted when targeting the JVM.

I've thought about Clojure on PyPy too.  My thought was that you would make 
Clojure an RPython addition to the RPython Python.  That would give you a 
pretty good start at a library, at least.

When I glanced at it, PyPy's build tools didn't seem to be sophisticated enough 
to handle this as some kind of add-in to the Python implementation: you would 
have had to fork PyPy to get this to work, or spend some time on the build 
tools.  Maybe I missed something.

I also felt that sticking with the official Java implementation of Clojure 
would be more practical.  It would certainly be fun to put Clojure on PyPy, 
though.

Gary

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure on PyPy

2011-11-17 Thread Timothy Baldridge
> With the clojureclr for example, it
> supports pretty much everything clojure does sans java, and gains all the
> .net interop.
>

True...true, it supports it, but it's still a "2nd class citizen". For
instance, we don't have lein, ring, parts of contrib, IDEs, etc. All
the examples, all the books are all about Clojure on the JVM. Do
anything else and you can forget using Clojars, and 90% of the
ecosystem built around Clojure.


The other issue here, is that translating Clojure to CLR is a fairly
straight forward task. C# and Java support most of the same language
features. No so in Python. For instance, Python does not have
anonymous classes, anonymous multi line lambdas (e.g. #(do (expr1)
(expr2)) ), or overloaded constructors. So now, the entire structure
of the code has to change.

Now, what should be done at some point (IMO) is to implement Clojure
in Clojure. This is why PyPy is so successful. They have written a
Python interpreter in Python and then written a translator that can
take a Python program and write a JIT for it. That JIT generator can
then output many different code types. For instance, backends for C,
LLVM, .NET and JVM all exist for PyPy...IMO this is what Clojure would
need to be completely portable.

ClojureScript comes close, all of ClojureScript is written in Clojure.
However the actual code generation of ClojureScript is complected into
the compiler. So there's a function in the compiler called "emit-call"
but that function assumes you will always use it to emit js code. If
we were able to abstract this compiler a bit more, we could write
backends for Java/.NET/JS/PyPy/PHP(yuck) or whatever.

Finally Clojure does make a few assumptions about the underlying VM.
Clojure assumes that the entire system will run on a VM that only
supports OOP. Hence every single function is a object. Now look at
PyPy or JS, here functions are true values in the VM. So the best way
to implement Clojure in PyPy would be to take advantage of these
facilities. But then you're really re-defining what clojure is and how
it runs. PyPy has a very advanced JIT that works well with dynamic
typing, but if you implement stock Clojure on PyPy you'd be ignoring
all that. Look at RT.java, you'll see tons of "if (obj is ISeq)... if
(obj is Array)...". Much of that could be thrown away in a PyPy
implementation, but if you threw that away, now you have a headache
when the Clojure devs start updating the code, and you have to port
those changes to your code base.

Sorry for the rambling...

Timothy

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure on PyPy

2011-11-17 Thread Gary Poster

On Nov 17, 2011, at 11:09 AM, Timothy Baldridge wrote:

>> I also felt that sticking with the official Java implementation of Clojure 
>> would be more practical.  It would certainly be fun to put Clojure on PyPy, 
>> though.
> 
> There is one insanely off-the-wall idea I've been thinking about
> recently, however:
> 
> 1) Implement a full JVM in PyPy using GNU Classpath. Write a Java
> bytecode interpreter in PyPy. This way you get the power of PyPy
> (tracing JIT) with the power of Java (classpath)
> 2) Run stock JVM Clojure on this interpreter
> 3) 
> 4) Profit!

LOL, that is awesomely insane!  It would certainly be fascinating to see how it 
turned out in terms of comparative performance.

Gary

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Relationship between .clj and .class files?

2011-11-17 Thread Terje Dahl
What is the relationship between the .clj source-file(s) and its gen-
class compiled class-files?

The reason I ask is that my app is an applet, written in Clojure
(obviously), and compiled.
The resulting class-files are then bundled into a jar-file, but
without the source clj-file.
(I don't want to incude my source-code in the deployed applet jar-file
- for business reasons, obviously).

The applet loads and runs just fine, but not before requesting clj-
files from the server.
In my server log files I see failed requests for "user.clj" and
"applet.clj" (the file containing all my source-code).
The applet doesn't recieve the files from the server, but runs just
fine all the same, so obviously doesn't need them.

1.  Why are these files requested in the first place, when not needed?

2. How do I prevent these files from being requested at all?

(When I have 100 kids in the same school, loading my applet at the
same time, all the extra failed and unneccessary request are unwelcome
on an already slow school network)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


clojure-opennlp

2011-11-17 Thread labwork07
That's probably an OpenNLP question, but here it goes. Is there a way to  
tell the tokenizer to make tokens of more than one word according to a  
multi-word lexicon?


Thanks for any ideas.
melipone

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Overused phrases in the Clojure community

2011-11-17 Thread Duane Searsmith
Perhaps "idiot-magic" would sub?

On Thu, Nov 17, 2011 at 8:30 AM, Sergey Didenko
 wrote:
> I coded mutable Dejkstra algorithm isolated in a single function,
> because it's easier for me to maintain it - I used to write a lot of
> mutable algorithms. But I consider this code not idiomatic though
> useful in my case.
>
> So I think idiomatic Clojure code is not as ubiquitous as you probably
> mean and the word "idiomatic" is quite useful for discussions.
>
>> In fact I challenge anyone to give an example of the least
>> idiomatic code written in Clojure (using Java interop is cheating).
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: adding metadata to java objects

2011-11-17 Thread Ben Mabey

On 11/17/11 4:21 AM, Chas Emerick wrote:

Ben,

It's a good idea, but it's going to bite you:

- what if the class in question has fields or package-private methods that are 
touched by Java code?


Yeah, there are some use cases where this would fall apart in.  Assuming 
that you use only public methods then everything should delegate as 
expected. Point taken about the potential of unpleasant surprises.



- what if the class take ctor arguments?
- what if the ctor has side effects?
I don't think these last two points apply.. in my use case the object 
has already been created and so the original constructor never is 
called.  The instantiated object is simply passed from one delegate to 
another with the different metadata associated on to it.


-Ben




On Nov 16, 2011, at 11:28 AM, Ben Mabey wrote:


Hi,
I would like to be able to add metadata to arbitrary java objects that have 
already been instantiated.  I know that you can use proxy to add metadata to 
objects that you create but in my case the object already exists (i.e. it is 
returned from another method call outside of my control).

It seems like the best solution would be to create a delegate class/object that 
wraps the original one.  Being able to write something like this would be ideal:

(defn wrap-with-meta
  ([obj]
 (wrap-with-meta obj nil))
  ([obj meta]
   (delegate obj
 clojure.lang.IObj
 (withMeta [this new-meta] (wrap-with-meta obj  

new-meta))
 (meta [this] meta

The delegate function would operate very similar to proxy, but instead of 
taking a class it takes an object.  A class would be created that extends the 
object's class, just like a class is generated for proxy. However, instead of 
stubs being generated that call super the stubs would delegate to the given 
object.  (Also note, I am also using reify-like syntax since I prefer that to 
the syntax in proxy.)

I'm curious to hear people's thoughts on this approach.  I'd also be really 
interested to see how other people have addressed this in the past (I doubt I'm 
the first one to run into this).

I know that clojure mentality is to avoid wrappers, but I don't see this as 
being much different than what proxy already does.  Of course, I may be missing 
something... if so, please enlighten me. :)

Thanks,
Ben

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Relationship between .clj and .class files?

2011-11-17 Thread Daniel Solano Gomez
On Thu Nov 17 09:06 2011, Terje Dahl wrote:
> What is the relationship between the .clj source-file(s) and its gen-
> class compiled class-files?
> 
> The reason I ask is that my app is an applet, written in Clojure
> (obviously), and compiled.
> The resulting class-files are then bundled into a jar-file, but
> without the source clj-file.
> (I don't want to incude my source-code in the deployed applet jar-file
> - for business reasons, obviously).
> 
> The applet loads and runs just fine, but not before requesting clj-
> files from the server.
> In my server log files I see failed requests for "user.clj" and
> "applet.clj" (the file containing all my source-code).
> The applet doesn't recieve the files from the server, but runs just
> fine all the same, so obviously doesn't need them.
> 
> 1.  Why are these files requested in the first place, when not needed?

By default, when loading a namespace, Clojure will try to find both the
source file and a class that loads the namespace.  For example, given
the namespace "example.core", it will look for both "example/core.clj"
and "example/core__init.class".  I believe the reasoning goes that if
the source file is more recent than the AOT-compiled class, it will
recompile the namespace at runtime.

The reason why its looking for "user.clj" is that by default when
Clojure loads up it will create the "user" namespace that is used in the
REPL.

> 2. How do I prevent these files from being requested at all?

I don't think there is a way to do this without modifying Clojure's
code.  If you're up to making your own custom build of Clojure, the
changes should be relatively simple to do.

To prevent the lookup of the Clojure file, I think you might be able to
just change line 405 of RT.java

so that "cljURL" is simply set to null.  I haven't tested it, but I
think it should work.

To prevent the "user" namespace from being created, you should be able
to remove lines 436-452 of RT.java
.
I do not remember if this change will keep you from being able to
compile your applet, but I do think it'd keep the REPL from running.

> 
> (When I have 100 kids in the same school, loading my applet at the
> same time, all the extra failed and unneccessary request are unwelcome
> on an already slow school network)
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


signature.asc
Description: Digital signature


Re: Clojure on PyPy

2011-11-17 Thread dmiller


On Nov 17, 10:07 am, Timothy Baldridge  wrote:
> > With the clojureclr for example, it
> > supports pretty much everything clojure does sans java, and gains all the
> > .net interop.
>
> True...true, it supports it, but it's still a "2nd class citizen". For
> instance, we don't have lein, ring, parts of contrib, IDEs, etc. All
> the examples, all the books are all about Clojure on the JVM. Do
> anything else and you can forget using Clojars, and 90% of the
> ecosystem built around Clojure.
>
> Now, what should be done at some point (IMO) is to implement Clojure
> in Clojure.

Although implementing Clojure-in-Clojure no doubt should be done, that
does not make lein work on other platforms, it does not create IDEs
that are effective for other platforms (Visual Studio), it does not
translate the contrib libs, etc.

-David

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clj-time and clojure 1.3

2011-11-17 Thread Sean Corfield
On Wed, Nov 16, 2011 at 5:39 PM, Sean Corfield  wrote:
> I have taken over clj-time from Mark McGranahan:
>
> https://github.com/seancorfield/clj-time
>
> (although github seems to be omitting the navigation bar on that repo
> - I'll open a support ticket).

github fixed that problem - apparently it was a "weird caching issue"...

Now if we can get KirinDave to put a notice on his repo saying mine's
the master, given that in the absence of the getwoven repo, github now
says mine's a clone of his, rather than the getwoven one...
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Probabilistic programming in clojure

2011-11-17 Thread Nils Bertschinger
Hi everyone,

inspired by the bher compiler for the probabilistic scheme dialect MIT
Church, I have implemented a version of the probability monad which
uses Metropolis Hastings to draw samples from runs of monadic
programs. You can find the code on github: 
https://github.com/bertschi/ProbClojureNice.

The monadic version is more a proof of principle and not very fast. It
might nevertheless be useful, e.g. for educational purposes. Have a
look and decide for yourself ...
For the future, I'm working on a different approach to embed
probabilistic operations into clojure which scales better and allows
to run somewhat larger models.

Any comments and feedback are welcome. Best,

Nils

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure on PyPy

2011-11-17 Thread Timothy Baldridge
>Although implementing Clojure-in-Clojure no doubt should be done, that
>does not make lein work on other platforms,

Very true. But what it does do is abstract away the core elements of
Clojure. ISeq, IPersistentList, PersistentList, etc. are all cross
platform. All you need is a "emit-class" function that understands how
to generate private members, methods, and handle inheritance. All of
the concurrency routines can be handled via classes and
CompareAndSwap. What I would love, is to be able to tell the Clojure
compiler "here is how you generate classes, here is how you call
CompareAndSwapnow go and build me classes found in Ref.java,
LockingTransaction.java, Atom.java, etc."

This is pretty much the way GNU Classpath works. You have to define
the lowest level structs (VMInt, VMObject, VMFile, VMSocket, etc.) and
from there every single part of the class library is simply Java
abstractions of those base classes.

Timothy

On Thu, Nov 17, 2011 at 11:46 AM, dmiller  wrote:
>
>
> On Nov 17, 10:07 am, Timothy Baldridge  wrote:
>> > With the clojureclr for example, it
>> > supports pretty much everything clojure does sans java, and gains all the
>> > .net interop.
>>
>> True...true, it supports it, but it's still a "2nd class citizen". For
>> instance, we don't have lein, ring, parts of contrib, IDEs, etc. All
>> the examples, all the books are all about Clojure on the JVM. Do
>> anything else and you can forget using Clojars, and 90% of the
>> ecosystem built around Clojure.
>>
>> Now, what should be done at some point (IMO) is to implement Clojure
>> in Clojure.
>
> Although implementing Clojure-in-Clojure no doubt should be done, that
> does not make lein work on other platforms, it does not create IDEs
> that are effective for other platforms (Visual Studio), it does not
> translate the contrib libs, etc.
>
> -David
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en



-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Review my code - delay-map

2011-11-17 Thread Chris Perkins
I'm trying to implement this: I want an object that behaves just like a 
normal clojure map, except in one very specific case - if a value is a 
Delay, then getting that value out of the map will force it.

Other than that one difference, it should be indistinguishable from a 
regular map (or as close to indistinguishable as is reasonable).

After some false starts, I have most of an implementation.

(defn delay-map
  "Wraps the given map such that any value that is a Delay will be
  forced when extracted."
  [& [m]]
  (proxy [clojure.lang.APersistentMap
  clojure.lang.IObj
  clojure.lang.IEditableCollection] []

;; This method implements the "real" funtionality:
(valAt
  ([k] (force (get m k)))
  ([k not-found] (force (get m k not-found

;; These methods are to preserve the type by returning
;; new delay-map instances when required.
(assoc [k v]
  (delay-map (assoc m k v)))
;;(assocEx [k v] ???)
(without [k]
  (delay-map (dissoc m k)))
(withMeta [md]
  (delay-map (with-meta m md)))

;; boilerplate - just delegate:
(containsKey [k] (contains? m k))
(count [] (count m))
(entryAt [k] (.entryAt ^clojure.lang.Associative m))
(iterator [] (.iterator ^java.util.Map m))
(meta [] (meta m))
(seq [] (seq m))

(asTransient []
  (throw (Exception. "I don't know how to implement this yet.")))
))


I also made a couple of macros to help out:

(defmacro lazy-map [& keyvals]
  (when (odd? (count keyvals))
(throw (Exception. "lazy-map requires an even number of forms")))
  (list
   `delay-map
   (into {}
 (for [[k v] (partition 2 keyvals)]
   [k (if (and (list? v) (symbol? (first v)))
(list `delay v)
v)]

(defmacro lazy-assoc [m & keyvals]
  `(delay-map (merge ~m (lazy-map ~@keyvals


This mostly seems to work they way I want:

user> (def m (lazy-map :normal-value "hello"
   :delayed-value (do (println "working...") 
(Thread/sleep 2000) "hi")))
#'user/m
user> m
{:normal-value "hello", :delayed-value #}
user> (:delayed-value m)
working...
"hi"
user> (:delayed-value m)
"hi"


Now, my questions are:
1) Does proxy seem like the right way to do this (as opposed to reify, 
etc.)?
2) What is assocEx (from IPersistentMap), and do I need to implement it?
3) Any idea how I could implement asTransient (or whether I should)?
4) Is there a way in clojure to find out what methods are abstract in a 
class (i.e. APersistentMap)? I struggled for a while trying to figure out 
which methods I needed to write - eventually I just had Eclipse generate a 
java class for me with method stubs.
5) Most importantly: good idea? bad idea? If so, why? Are there any holes 
in this that I'm not seeing. Are there ways that a user could accidentally 
turn a delay-map into a regular map (I know of one: (into {} my-delay-map))?


Finally, in case you're wondering why I want this: I was reading through 
the code of a large, complex web application, and I realized that there are 
two competing forces at work when considering performance:
1) If there is data that you will need in several places, you want to avoid 
calculating it repeatedly.
2) If there is data that you will not need at all, you dont' want to 
calculate it at all.

Take session-state as an example. Suppose there is a session-store library, 
and as a consumer of it I have to call a function, say (get-session), when 
I want to use it. Maybe I end up calling that function in half-a-dozen 
places. That's wasteful. So I do the smart thing and use Ring middleware 
that loads the session only once and adds it to the request map. Then I can 
pull it out when I need it, and it's only loaded once. But what if I never 
need it for a particular request? Then I have loaded it for nothing.

In other words, point 1 above encourages us to put stuff in the map 
pre-emptively, and point 2 encourages us not to.

If the request map was a delay-map, then session state could be loaded 
exactly one time or zero times, as required, transparently to the consumer. 
Existing code that extracts :session from the request would still work, but 
now code-paths that do not use :session do not pay the cost of loading it.

Anyway, that's just the example that motivated the idea. Whether it turns 
out to be useful in practice remains to be seen.


thanks,

- Chris Perkins



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Review my code - delay-map

2011-11-17 Thread Meikel Brandmeyer
Hi,

without looking too much at your code, I might suggest you have look at my lazy 
map library: http://bit.ly/vNA56f. It basically solves the same problem. You 
can compare your solution to mine. If you want to discuss anything, feel free 
to go ahead.

Sincerely
Meikel

PS: It's also on clojars as de.kotka/lazymap. The lazymap was already taken. :/

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Overused phrases in the Clojure community

2011-11-17 Thread Luc Prefontaine

Maybe we should qualify non-idiomatic code as being "idiotmatic", that may help 
reducing the # of posts
referencing "idiomatic". However this only a letter way from making (slight) 
mistakes in the posts :)

I just spent my day's quota of idiotic writing ...

Luc

On Thu, 17 Nov 2011 11:22:27 -0600
Duane Searsmith  wrote:

> Perhaps "idiot-magic" would sub?
> 
> On Thu, Nov 17, 2011 at 8:30 AM, Sergey Didenko
>  wrote:
> > I coded mutable Dejkstra algorithm isolated in a single function,
> > because it's easier for me to maintain it - I used to write a lot of
> > mutable algorithms. But I consider this code not idiomatic though
> > useful in my case.
> >
> > So I think idiomatic Clojure code is not as ubiquitous as you
> > probably mean and the word "idiomatic" is quite useful for
> > discussions.
> >
> >> In fact I challenge anyone to give an example of the least
> >> idiomatic code written in Clojure (using Java interop is cheating).
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient
> > with your first post. To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/clojure?hl=en
> 



-- 
Luc P.


The rabid Muppet

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


ClojureScript: Correct way to call an instance method with parameters?

2011-11-17 Thread Base
HI

I am attempting to manipulate a goog.date.Date object and am a little
confused on how to call a method on this object in ClojureScript

If I have a date object, how do I , for example, to set the day of the
month to a different day

Both

(. (goog.date.fromIsoString "2010-12-31") (setDate) 1)

and

(. (goog.date.fromIsoString "2010-12-31") (setDate 1))

yield Undefined.

Any thoughts?  I am sure this is an easy one but I am stuck.

Thanks in advance

Base

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: ClojureScript: Correct way to call an instance method with parameters?

2011-11-17 Thread Matt Hoyt
(.setDate (goog.date.fromIsoString "2010-12-31") 1)
 
Matt Hoyt



From: Base 
To: Clojure 
Sent: Thursday, November 17, 2011 2:26 PM
Subject: ClojureScript: Correct way to call an instance method with parameters?

HI

I am attempting to manipulate a goog.date.Date object and am a little
confused on how to call a method on this object in ClojureScript

If I have a date object, how do I , for example, to set the day of the
month to a different day

Both

(. (goog.date.fromIsoString "2010-12-31") (setDate) 1)

and

(. (goog.date.fromIsoString "2010-12-31") (setDate 1))

yield Undefined.

Any thoughts?  I am sure this is an easy one but I am stuck.

Thanks in advance

Base

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: ClojureScript: Correct way to call an instance method with parameters?

2011-11-17 Thread David Nolen
setDate mutates the date and does not return a value.

David

On Thu, Nov 17, 2011 at 3:26 PM, Base  wrote:

> HI
>
> I am attempting to manipulate a goog.date.Date object and am a little
> confused on how to call a method on this object in ClojureScript
>
> If I have a date object, how do I , for example, to set the day of the
> month to a different day
>
> Both
>
> (. (goog.date.fromIsoString "2010-12-31") (setDate) 1)
>
> and
>
> (. (goog.date.fromIsoString "2010-12-31") (setDate 1))
>
> yield Undefined.
>
> Any thoughts?  I am sure this is an easy one but I am stuck.
>
> Thanks in advance
>
> Base
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: ClojureScript: Correct way to call an instance method with parameters?

2011-11-17 Thread Base
Hi Matt -

I forgot to add that one, but that also returned Undefined.

Looking at this:  
https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure

It mentions:

"The one important difference is in calling no-argument methods. In
Java (. x toString), where toString is a method, would unambiguously
mean "call the toString method of x". JavaScript is more flexible,
separating "method" lookup from invocation. So in ClojureScript you
have to make a choice:

(. sb toString) => returns a function
(. sb (toString))   => calls the function"

On Nov 17, 2:33 pm, Matt Hoyt  wrote:
> (.setDate (goog.date.fromIsoString "2010-12-31") 1)
>
> Matt Hoyt
>
> 
> From: Base 
> To: Clojure 
> Sent: Thursday, November 17, 2011 2:26 PM
> Subject: ClojureScript: Correct way to call an instance method with 
> parameters?
>
> HI
>
> I am attempting to manipulate a goog.date.Date object and am a little
> confused on how to call a method on this object in ClojureScript
>
> If I have a date object, how do I , for example, to set the day of the
> month to a different day
>
> Both
>
> (. (goog.date.fromIsoString "2010-12-31") (setDate) 1)
>
> and
>
> (. (goog.date.fromIsoString "2010-12-31") (setDate 1))
>
> yield Undefined.
>
> Any thoughts?  I am sure this is an easy one but I am stuck.
>
> Thanks in advance
>
> Base
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: ClojureScript: Correct way to call an instance method with parameters?

2011-11-17 Thread Base
Doh!  I am so used to Clojure at this point I actually forgot about
about mutable data structures.

Thanks David!

On Nov 17, 2:38 pm, David Nolen  wrote:
> setDate mutates the date and does not return a value.
>
> David
>
>
>
>
>
>
>
> On Thu, Nov 17, 2011 at 3:26 PM, Base  wrote:
> > HI
>
> > I am attempting to manipulate a goog.date.Date object and am a little
> > confused on how to call a method on this object in ClojureScript
>
> > If I have a date object, how do I , for example, to set the day of the
> > month to a different day
>
> > Both
>
> > (. (goog.date.fromIsoString "2010-12-31") (setDate) 1)
>
> > and
>
> > (. (goog.date.fromIsoString "2010-12-31") (setDate 1))
>
> > yield Undefined.
>
> > Any thoughts?  I am sure this is an easy one but I am stuck.
>
> > Thanks in advance
>
> > Base
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: ClojureScript: Correct way to call an instance method with parameters?

2011-11-17 Thread David Nolen
On Thu, Nov 17, 2011 at 3:39 PM, Base  wrote:

> It mentions:
>
> "The one important difference is in calling no-argument methods. In
> Java (. x toString), where toString is a method, would unambiguously
> mean "call the toString method of x". JavaScript is more flexible,
> separating "method" lookup from invocation. So in ClojureScript you
> have to make a choice:
>
> (. sb toString) => returns a function
> (. sb (toString))   => calls the function"


It's very likely there are language changes coming soon that will address
this.

David

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: start-process-shell-command: Spawning child process: invalid argument

2011-11-17 Thread Phil Hagelberg
On Thu, Nov 17, 2011 at 6:50 AM, Andrew  wrote:
> Thanks Do I need Cygwin at all for Clojure work on
> Windows/Emacs/Swank/clojure-mode/lein? Or can I remove Cygwin from my
> machine?
>
> And are these two functionally equivalent?
>
> clojure-jack-in
> lein swank and slime-connect

If you have installed the right versions of slime and slime-repl
manually then they should be equivalent.

-Phil

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: ClojureScript: Correct way to call an instance method with parameters?

2011-11-17 Thread Base
I look forward to it.

On Nov 17, 2:42 pm, David Nolen  wrote:
> On Thu, Nov 17, 2011 at 3:39 PM, Base  wrote:
> > It mentions:
>
> > "The one important difference is in calling no-argument methods. In
> > Java (. x toString), where toString is a method, would unambiguously
> > mean "call the toString method of x". JavaScript is more flexible,
> > separating "method" lookup from invocation. So in ClojureScript you
> > have to make a choice:
>
> > (. sb toString)     => returns a function
> > (. sb (toString))   => calls the function"
>
> It's very likely there are language changes coming soon that will address
> this.
>
> David

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Probabilistic programming in clojure

2011-11-17 Thread Konrad Hinsen
On 17 nov. 2011, at 18:57, Nils Bertschinger wrote:

> inspired by the bher compiler for the probabilistic scheme dialect MIT
> Church, I have implemented a version of the probability monad which
> uses Metropolis Hastings to draw samples from runs of monadic
> programs. You can find the code on github: 
> https://github.com/bertschi/ProbClojureNice.

There's also this one in clojure-contrib (old, not yet moved to the new contrib 
collection):


https://github.com/richhickey/clojure-contrib/tree/master/src/main/clojure/clojure/contrib/probabilities

Konrad.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Debugging Java heap space memory error with lazy sequences.

2011-11-17 Thread Julian Kelsey
I was working on a few of the Project Euler puzzles. The first involves
picking the nth element from a particular series, (sum the numbers factored
either by 3 or 5 below 1000). One forum comment on the very first puzzle
raised the criticism that it's easy to solve the question as presented
(i.e. below 1000), but what if you wanted the sum below 10^18?

I started working towards the big number goal using lazy sequences.

First, a lazy sequence of numbers that are factored by 3 or 5. Second,
another lazy sequence such that the nth element is the sum of the first n
elements of the input sequence. Finally, pick the nth element, (it doesn't
quite match the question, but it's of similar complexity):

  (def seq-3s-n-5s
(filter
  (fn [n] (or (= 0 (mod n 5)) (= 0 (mod n 3)) ) )
  (iterate inc 1)))

  (defn sums [coll n]
(lazy-seq
  (when-let [s (seq coll)]
(let [x (+ n (first s))]
  (cons x (sums (rest s) x))

  (nth (sums seq-3s-n-5s 0) (Math/pow 10 6))

However some where between (Math/pow 10 6) and (Math/pow 10 7) It throws an
error: java.lang.OutOfMemoryError: Java heap space. I'm wondering if I'm
crossing some threshold into a different number type? Or perhaps I've
missed some point and got the lazy sequence stuff wrong?

So my question has two parts:
(1) How can I fix this code so that it will run to further into the
sequence?
(2) What actually has gone wrong? How could you debug something like this?

Notes: we can trust that (nth seq N) is not the problem, it returns in
reasonable time for a test like this: (nth (iterate inc 1) (Math/pow 10 9))


Cheers,
Julian Kelsey.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Debugging Java heap space memory error with lazy sequences.

2011-11-17 Thread Meikel Brandmeyer
Hi,

this is a “hold unto head” problem.

Am 17.11.2011 um 15:06 schrieb Julian Kelsey:

>   (def seq-3s-n-5s 
> (filter 
>   (fn [n] (or (= 0 (mod n 5)) (= 0 (mod n 3)) ) ) 
>   (iterate inc 1)))

Here you keep a reference to the head of the generated by iterate. Make it a 
function:

(defn seq-3s-n-5s
  []
  (filter #(or (zero? (mod % 5)) (zero? (mod % 3))) (iterate inc 1)))

Then call it like this:

(nth (sums (seq-3s-n-5s 0) (Math/pow 10 6))

That should fix your problem.

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


ClojureScript: Should 'advanced optimizations' lead to faster execution? (or just faster loading)

2011-11-17 Thread Paul Richards
Hi,
I'm interested in the differences between the default ClojureScript
compile, and the {:optimizations :advanced} mode.

Aside from loading times (due to different file sizes) and memory
usage (again due to different file sizes, minified field names, etc),
do we expect the optimized version to execute faster?

It might be argued that the client side compiler in a modern
JavaScript engine will be capable of reproducing (at runtime) any of
the performance optimizations that the static compiler is able to
perform ahead of time.  Has anyone measured this?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: ClojureScript: Should 'advanced optimizations' lead to faster execution? (or just faster loading)

2011-11-17 Thread David Nolen
I haven't seen performance gains from advanced optimization.

David

On Thu, Nov 17, 2011 at 5:18 PM, Paul Richards wrote:

> Hi,
> I'm interested in the differences between the default ClojureScript
> compile, and the {:optimizations :advanced} mode.
>
> Aside from loading times (due to different file sizes) and memory
> usage (again due to different file sizes, minified field names, etc),
> do we expect the optimized version to execute faster?
>
> It might be argued that the client side compiler in a modern
> JavaScript engine will be capable of reproducing (at runtime) any of
> the performance optimizations that the static compiler is able to
> perform ahead of time.  Has anyone measured this?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Clojure type selection flowchart: add a translation for your language

2011-11-17 Thread Chas Emerick
For those that haven't seen it, I produced a flowchart earlier this year to 
help guide your selection of a Clojure type-definition form:

http://cemerick.com/2011/07/05/flowchart-for-choosing-the-right-clojure-type-definition-form/

I wanted to make it easier for others to produce translations of the flowchart, 
since it seems to be very helpful to people, especially as they are learning 
Clojure. Thus, I created a github repo and added the original OmniGraffle file 
to it. I hope that, _if you know a language well_ that does not yet have a 
translation of the flowchart, you’ll take a few minutes to produce one.

https://github.com/cemerick/clojure-type-selection-flowchart

Thanks,

- Chas

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Probabilistic programming in clojure

2011-11-17 Thread Nils Bertschinger
Hi Konrad,

thanks for the link. I know your very nice library and actually use
clojure.contrib.monads to implement my probability monad.
The two approaches are somewhat complementary to each other. Your
monad does exact inference on discrete distributions by running
through all possibilities. Mine is sampling based and does approximate
inference using MCMC. This makes it feasible to simulate larger
discrete models and also continuous distributions can easily be
incorporated. In the demos section you can find a Gaussian mixture
model demonstrating these features.

Nils

On Nov 17, 9:58 pm, Konrad Hinsen 
wrote:
> There's also this one in clojure-contrib (old, not yet moved to the new 
> contrib collection):
>
>        
> https://github.com/richhickey/clojure-contrib/tree/master/src/main/cl...
>
> Konrad.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure-opennlp

2011-11-17 Thread Lee Hinman
On Nov 17, 10:15 am, labwor...@gmail.com wrote:
> That's probably an OpenNLP question, but here it goes. Is there a way to
> tell the tokenizer to make tokens of more than one word according to a
> multi-word lexicon?
>
> Thanks for any ideas.
> melipone

Not sure I understand what you're trying to get at 100%, but you
should be able to train the tokenizer to split words however you'd
like, take a look at the training documentation[1] and feel free to
email me if you run into any snags.

- Lee Hinman

[1]: https://github.com/dakrone/clojure-opennlp/blob/master/TRAINING.markdown

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Change var in other namespace

2011-11-17 Thread vitalyper
clojure.tools.logging defines *logger-factory* and initializes it with
first logger implementation on the class path

(def ^{:doc
  "An instance satisfying the impl/LoggerFactory protocol. Used
internally to
   obtain an impl/Logger. Defaults to the value returned from impl/
find-factory."
  :dynamic true}
  *logger-factory*
  (impl/find-factory))

In my own namespace I want to redefine *logger-factory* to log4j one.
Tried different variations (def, set!, etc) in 1.3.0 with no avail.
(ns my.foo
  (:gen-class)
  (:use
[clojure.tools.logging :only (*logger-factory* info debug)])
  (:require
[clojure.string :as s1]
[clojure.tools.logging.impl :as log-impl])
)

(defn init-logging
  "Force log4j factory for core tools logging"
  []
  (def *logger-factory* (log-impl/log4j-factory)))
; CompilerException java.lang.IllegalStateException: *logger-factory*
already refers to: #'clojure.tools.logging/*logger-factory* in
namespace: infrared.common

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Reactions to google dart?

2011-11-17 Thread Qihui Sun
Google Dart vs. ClojureScript
*Dart ->*
*Dart is a new class-based programming language for creating structured web
applications. Developed with the goals of simplicity, efficiency, and
scalability, the Dart language combines powerful new language features with
familiar language constructs into a clear, readable syntax.*
*
*
*1,Isolates as basic concurrent construct*
*2,rich web browser lib,such html,DOM...*
*3,more*
*
*
*ClojureScript ->*
*ClojureScript is a new compiler for Clojure  that
targets JavaScript. It is designed to emit JavaScript code which is
compatible with the advanced compilation mode of the Google
Closure optimizing
compiler.*
*1,macro*
*2,more*
*
*
Both are used to web browser and server side,complies to JavaScript,cross
browers.

2011/10/15 Isaac Gouy 

>
>
> On Oct 11, 7:43 am, Timothy Washington  wrote:
> > I believe this is google's official blog  to
> discuss
> > and track issues around Dart  ...
>
>
> H - "Dart Inside The Unofficial Google Dart Blog"
>
> "Dart Inside is an online service from Trifork A/S, and is not
> affiliated with Google®. "
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>



-- 
Solomon
HUAWEI 
Google+: Qihui Sun 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Change var in other namespace

2011-11-17 Thread Mark Rathwell
You rebind dynamic vars with binding, so your use would look something
like this:

(binding [*logger-factory* (log-impl/log4j-factory)]
  (do-stuff-with-the-logger-factory-rebound))


On Thu, Nov 17, 2011 at 5:17 PM, vitalyper  wrote:
> clojure.tools.logging defines *logger-factory* and initializes it with
> first logger implementation on the class path
>
> (def ^{:doc
>  "An instance satisfying the impl/LoggerFactory protocol. Used
> internally to
>   obtain an impl/Logger. Defaults to the value returned from impl/
> find-factory."
>  :dynamic true}
>  *logger-factory*
>  (impl/find-factory))
>
> In my own namespace I want to redefine *logger-factory* to log4j one.
> Tried different variations (def, set!, etc) in 1.3.0 with no avail.
> (ns my.foo
>  (:gen-class)
>  (:use
>    [clojure.tools.logging :only (*logger-factory* info debug)])
>  (:require
>            [clojure.string :as s1]
>            [clojure.tools.logging.impl :as log-impl])
> )
>
> (defn init-logging
>  "Force log4j factory for core tools logging"
>  []
>  (def *logger-factory* (log-impl/log4j-factory)))
> ; CompilerException java.lang.IllegalStateException: *logger-factory*
> already refers to: #'clojure.tools.logging/*logger-factory* in
> namespace: infrared.common
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Change var in other namespace

2011-11-17 Thread Sean Corfield
Note: if you just want something that will execute at startup and
force _all_ logging to use log4j, instead of wrapping code in (binding
..) then you probably want something like this:

(ns your.namespace
  (:require [clojure.tools.logging :as log])
  (:require [clojure.tools.logging.impl :as impl]))

(alter-var-root (var log/*logger-factory*) (constantly (impl/log4j-factory)))

This is what we ended with in our code to ensure log4j was selected at
startup...

Sean

On Thu, Nov 17, 2011 at 7:04 PM, Mark Rathwell  wrote:
> You rebind dynamic vars with binding, so your use would look something
> like this:
>
> (binding [*logger-factory* (log-impl/log4j-factory)]
>  (do-stuff-with-the-logger-factory-rebound))
>
>
> On Thu, Nov 17, 2011 at 5:17 PM, vitalyper  wrote:
>> clojure.tools.logging defines *logger-factory* and initializes it with
>> first logger implementation on the class path
>>
>> (def ^{:doc
>>  "An instance satisfying the impl/LoggerFactory protocol. Used
>> internally to
>>   obtain an impl/Logger. Defaults to the value returned from impl/
>> find-factory."
>>  :dynamic true}
>>  *logger-factory*
>>  (impl/find-factory))
>>
>> In my own namespace I want to redefine *logger-factory* to log4j one.
>> Tried different variations (def, set!, etc) in 1.3.0 with no avail.
>> (ns my.foo
>>  (:gen-class)
>>  (:use
>>    [clojure.tools.logging :only (*logger-factory* info debug)])
>>  (:require
>>            [clojure.string :as s1]
>>            [clojure.tools.logging.impl :as log-impl])
>> )
>>
>> (defn init-logging
>>  "Force log4j factory for core tools logging"
>>  []
>>  (def *logger-factory* (log-impl/log4j-factory)))
>> ; CompilerException java.lang.IllegalStateException: *logger-factory*
>> already refers to: #'clojure.tools.logging/*logger-factory* in
>> namespace: infrared.common

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Reactions to google dart?

2011-11-17 Thread daly
Doug Crockford was asked for his reaction to coffeescript.
He loved it.

He was asked for his reaction to Dart
and he said that the set of features that Dart chose are 
not the set of features he would have chosen.

Crockford on JavaScript - Section 8: Programming Style & Your Brain
http://www.youtube.com/watch?v=taaEzHI9xyY

On Thu, 2011-11-17 at 22:22 +0530, Qihui Sun wrote:
> Google Dart vs. ClojureScript
> Dart ->
> Dart is a new class-based programming language for creating structured
> web applications. Developed with the goals of simplicity, efficiency,
> and scalability, the Dart language combines powerful new language
> features with familiar language constructs into a clear, readable
> syntax.
> 
> 
> 1,Isolates as basic concurrent construct
> 2,rich web browser lib,such html,DOM...
> 3,more
> 
> 
> ClojureScript ->
> ClojureScript is a new compiler for Clojure that targets JavaScript.
> It is designed to emit JavaScript code which is compatible with the
> advanced compilation mode of the Google Closure optimizing compiler.
> 1,macro
> 2,more
> 
> 
> Both are used to web browser and server side,complies to
> JavaScript,cross browers.
> 
> 2011/10/15 Isaac Gouy 
> 
> 
> On Oct 11, 7:43 am, Timothy Washington 
> wrote:
> > I believe this is google's official blog
>  to discuss
> > and track issues around Dart  ...
> 
> 
> H - "Dart Inside The Unofficial Google Dart Blog"
> 
> "Dart Inside is an online service from Trifork A/S, and is not
> affiliated with Google®. "
> 
> --
> You received this message because you are subscribed to the
> Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be
> patient with your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> 
> 
> 
> 
> 
> -- 
> Solomon
> HUAWEI
> Google+: Qihui Sun
> 
> 
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient
> with your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Probabilistic programming in clojure

2011-11-17 Thread Konrad Hinsen
--On 17 novembre 2011 15:09:11 -0800 Nils Bertschinger 
 wrote:



The two approaches are somewhat complementary to each other. Your
monad does exact inference on discrete distributions by running
through all possibilities. Mine is sampling based and does approximate
inference using MCMC.


I tried that approach as well:


https://github.com/richhickey/clojure-contrib/blob/master/src/main/clojure/clojure/contrib/probabilities/monte_carlo.clj

but I never used it much because for my own applications, exact inference 
was very doable. I'll check out yours for comparison!


Konrad.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en