Re: RuntimeException: Can't embed object in code, maybe print-dup not defined

2011-03-11 Thread Ken Wesson
On Fri, Mar 11, 2011 at 11:52 PM, Stuart Sierra
 wrote:
> `eval` invokes the Clojure compiler, which transforms data structures into
> Java bytecode.  The Clojure compiler understands Clojure data structures
> like lists, vectors, and symbols, plus a few Java types like String and
> numbers.  It doesn't know what to do with a java.util.Date.  "Can't embed
> object in code" is the compiler telling you "I don't know what to do with
> this."

Yes, but "create a static final member in the class I'm generating
bytecode for, stuff the object in that static member, and embed a
reference to the static member here" seems like a sensible thing for
it to do.

private static final Date blah = somedate;

...

something.somemethod(blah);

works in javac, but clojure's compiler hates

(eval '(.somemethod something ~somedate))

for whatever reason.

> The #= is a Clojure reader macro that means "evaluate the following code."
> The error message "maybe print-dup not defined" is suggesting that, if you
> really did mean to stick a java.util.Date in your compiled code, you have to
> provide your own implementation of print-dup.  Specifically, you need a
> method of print-dup that takes a java.util.Date and returns a data structure
> representing the Clojure code that *creates* a java.util.Date.

So, there is a workaround of sorts. A general one for serializable
objects could even be constructed: serialize to a byte array, embed
the byte array as a seq in code that turns it back into a byte array
and then deserializes an object from it. Not very efficient though.

A true fix requires changing the compiler to add static final members
to the generated class, as suggested above.

-- 
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: RuntimeException: Can't embed object in code, maybe print-dup not defined

2011-03-11 Thread Ken Wesson
On Fri, Mar 11, 2011 at 11:12 PM, Armando Blancas
 wrote:
> You need to quote the vector so the date will be created inside eval,
> instead of having the date go into eval as an element of the
> (evaluated) vector.

A more interesting question is "why does this error exist in the first
place"? Why doesn't eval (or macro expansion) accept general objects
in the input rather than just a few specific types (strings, numbers,
keywords, lists, sets, maps, vectors, etc.)? There are use cases where
it would be quite convenient if all objects that presently produced
that error were instead self-evaluating in the manner of numbers,
strings, and keywords. For one thing, as an optimization you could
precompute some expensive-to-construct object and directly embed it in
compiled code instead of having to calculate it at runtime, or muck
about with computing it, saving it out to a file, reading it on
startup, and adding all the file and directory configuration options
that start to be needed as soon as your app has external data files it
depends on.

Possibly-related (and sometimes equally inconvenient) is that actual
compiled Clojure function objects do *not* produce that error, and
work if they are not closures, but produce cryptic errors when
subsequently invoked if they *are* closures, as though they got copied
without the closed-over values or something instead of just embedded
directly.

Here is the weird behavior of function objects in eval (same result in
macro expansions, when the macro-generated code is actually run):

user=> (def f (let [x 10] (fn [] x))) ; f is a closure
#'user/f
user=> (f) ; works when directly called at repl
10
user=> (eval '((let [x 10] (fn [] x ; create the closure and call
it inside eval -- works
10
user=> (eval f) ; eval the closure itself -- returns the function object
#
user=> (eval '(f)) ; eval can call the function through its var, and it works
10
user=> (eval `(~f)) ; eval calling the closure directly embedded in
the call expression -- weird exception
#
user=> (def f (fn [] 10)) ; replace f with a non-closure function with
the same return value
#'user/f
user=> (eval `(~f)) ; eval calling the function directly embedded in
the call expression -- works!
10
user=>

-- 
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: RuntimeException: Can't embed object in code, maybe print-dup not defined

2011-03-11 Thread Stuart Sierra
`eval` invokes the Clojure compiler, which transforms data structures into 
Java bytecode.  The Clojure compiler understands Clojure data structures 
like lists, vectors, and symbols, plus a few Java types like String and 
numbers.  It doesn't know what to do with a java.util.Date.  "Can't embed 
object in code" is the compiler telling you "I don't know what to do with 
this."

`print-dup` is an internal multimethod used by the Clojure compiler to 
transform complex objects, like sorted sets, into data structures 
representing the Clojure code to construct them.  For example,

user=>  (print-dup (sorted-set) *out*)
#=(clojure.lang.PersistentTreeSet/create [])

The #= is a Clojure reader macro that means "evaluate the following code."

The error message "maybe print-dup not defined" is suggesting that, if you 
really did mean to stick a java.util.Date in your compiled code, you have to 
provide your own implementation of print-dup.  Specifically, you need a 
method of print-dup that takes a java.util.Date and returns a data structure 
representing the Clojure code that *creates* a java.util.Date.  For example:

user=>  (defmethod print-dup java.util.Date [d stream]
  (.write stream "#=(java.util.Date. ")
  (.write stream (str (.getTime d)))
  (.write stream ")"))

user=>  (eval [(java.util.Date.)])
[#]

However, this is probably not what you really meant to do.  More likely, you 
have a macro or `eval` somewhere that is using code that is incorrectly 
quoted.

-Stuart Sierra
clojure.com

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

RuntimeException: Can't embed object in code, maybe print-dup not defined

2011-03-11 Thread Jeffrey Schwab
What does eval'ing a form containing an object reference cause an 
exception?  What am I doing wrong?

user=> (eval [(java.util.Date.)])
java.lang.RuntimeException: Can't embed object in code, maybe print-dup not 
defined: Fri Mar 11 19:33:04 EST 2011 (NO_SOURCE_FILE:153)

This is the simplest example could contrive, but in the real code, I'm 
trying to rename a bunch of files.  I have two sequences of File objects; I 
build up a list of commands in a do block, then try to eval it.  I am using 
eval because I want to inspect the whole form at the REPL before evaluating 
it.

user=> (eval [1])
[1]
user=> (eval (java.util.Date.))
#

user=> (doc print-dup)
-
clojure.core/print-dup
nil
  nil
nil

-- 
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: RuntimeException: Can't embed object in code, maybe print-dup not defined

2011-03-11 Thread Armando Blancas
You need to quote the vector so the date will be created inside eval,
instead of having the date go into eval as an element of the
(evaluated) vector.

user=> (eval '[(java.util.Date.)])
[#]

On Mar 11, 4:37 pm, Jeffrey Schwab  wrote:
> What does eval'ing a form containing an object reference cause an
> exception?  What am I doing wrong?
>
> user=> (eval [(java.util.Date.)])
> java.lang.RuntimeException: Can't embed object in code, maybe print-dup not
> defined: Fri Mar 11 19:33:04 EST 2011 (NO_SOURCE_FILE:153)
>
> This is the simplest example could contrive, but in the real code, I'm
> trying to rename a bunch of files.  I have two sequences of File objects; I
> build up a list of commands in a do block, then try to eval it.  I am using
> eval because I want to inspect the whole form at the REPL before evaluating
> it.
>
> user=> (eval [1])
> [1]
> user=> (eval (java.util.Date.))
> #
>
> user=> (doc print-dup)
> -
> clojure.core/print-dup
> nil
>   nil
> nil

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


Re: ANN: Clojure Toolbox (Early Beta)

2011-03-11 Thread James Reeves
Fixed. Thanks for pointing that out!

- James

On 6 March 2011 19:10, Nebojsa Stricevic  wrote:
> Greetings,
>
> First, thanks for setting up Clojure Toolbox.
>
> Second, ring-json-params link should be fixed. (Missing "s" at the
> end.)
>
> Cheers,
>
> --
> Nebojša Stričević
>
> --
> 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 1.3 testbuild1, enlive, and dependency ranges

2011-03-11 Thread Stuart Sierra

>
> I should have mentioned that I had tried both these before posting, and  
> they don't seem to help in this case. All clojure version artifacts were  
> still being downloaded.
>

Huh. That's surprising.  Don't know why.

  *-SNAPSHOT dependency resolution is a bit strange, which is why it's 
discouraged in public releases.

-S

-- 
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 1.3 testbuild1, enlive, and dependency ranges

2011-03-11 Thread Hugo Duncan
On Fri, 11 Mar 2011 16:40:46 -0500, Stuart Sierra  
 wrote:



I created the testbuild-* artifacts, but they were never uploaded to the
Maven Central Repository.  I had previously deleted the staging  
repositories

from oss.sonatype.org, and today I deleted the remaining
1.3.0-testbuild*-SNAPSHOT artifacts from oss.sonatype.org.


Many thanks for this.


FYI, you can also exclude transitive dependencies with Maven/Leiningen.

In Leiningen, like this:
https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L35

In Maven, like this:
http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html#Dependency_Exclusions


I should have mentioned that I had tried both these before posting, and  
they don't seem to help in this case. All clojure version artifacts were  
still being downloaded.


--
Hugo Duncan

--
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: DOM API for Clojure

2011-03-11 Thread Stuart Sierra
Theoretically, yes, you could build this with Monads.  But I'm not the one 
to ask about that. :)

There's also something that Rich Hickey was working on last year called 
"Pods" or "Cells" -- basically a new reference type that allows safe access 
to a mutable object.  As far as I know, the design was never finished, but 
you can find video of Rich talking about it here: 
http://www.infoq.com/interviews/hickey-clojure-protocols

And some notes at 
http://dev.clojure.org/display/design/Mutex+references+%28pods%2C+nee+cells%29

-Stuart Sierra
clojure.com

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

Re: clojure 1.3 testbuild1, enlive, and dependency ranges

2011-03-11 Thread Stuart Sierra
I created the testbuild-* artifacts, but they were never uploaded to the 
Maven Central Repository.  I had previously deleted the staging repositories 
from oss.sonatype.org, and today I deleted the remaining 
1.3.0-testbuild*-SNAPSHOT artifacts from oss.sonatype.org.

FYI, you can also exclude transitive dependencies with Maven/Leiningen.  

In Leiningen, like this:
https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L35

In Maven, like this:
http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html#Dependency_Exclusions

-Stuart Sierra
clojure.com

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

Deleted clojure-1.3.0-testbuild*-SNAPSHOT artifacts

2011-03-11 Thread Stuart Sierra
I have deleted the Clojure build artifacts with version numbers like 
"1.3.0-testbuild*-SNAPSHOT" from the public snapshot repository at 
oss.sonatype.org.

This will not affect you unless you use "oss.sonatype.org" as a snapshot 
repository in your Maven/Ivy/Leiningen builds.  If you were using it, you 
should no longer see "testbuild-*" artifacts in your builds.

-Stuart Sierra
clojure.com

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

Re: Clojure 1.3 alpha 1 report - bitwise operations extremely slow

2011-03-11 Thread Stuart Halloway
> That doesn't sound like the same bug discussed in this thread though.
> We were talking about how operators like bit-shift-left were
> super-slow under certain circumstances in 1.3.  It's a reflection
> issue, sure enough, but is it the same issue discussed at ticket #446?

http://dev.clojure.org/jira/browse/CLJ-380 documents slow bit operations, and 
they should be fixed in the Alpha 6 build.

Stu

Stuart Halloway
Clojure/core
http://clojure.com

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

Clojure 1.3 Alpha 6

2011-03-11 Thread Stuart Halloway
Clojure 1.3 Alpha 6 is now available at

http://clojure.org/downloads

 0 Changes from 1.3 Alpha 5 to 1.3 Alpha 6
 1 Changes from 1.3 Alpha 4 to 1.3 Alpha 5
 2 Changes from 1.3 Alpha 3 to 1.3 Alpha 4
 3 Changes from 1.3 Alpha 2 to 1.3 Alpha 3
 4 Changes from 1.3 Alpha 1 to 1.3 Alpha 2
 5 Changes from 1.2 to 1.3 Alpha 1
 6 About Alpha Releases

Issue Tracking: http://dev.clojure.org/jira

= 0 Changes from 1.3 Alpha 5 to 1.3 Alpha 6 (03/11/2011)

  * improved startup time 
  * several "holding onto head" fixes (CLJ-708)
  * internal keyword map uses weak refs 
  * fix perf on some numeric overloads (CLJ-380)
  * detect and report cyclic load dependencies (CLJ-8)

= 1 Changes from 1.3 Alpha 4 to 1.3 Alpha 5 (01/14/2011)

  * pprint respects *print-length*
  * into-array now coerces numeric types
  * Java's line.separator property for newline
  * compilation and deployment via Maven

= 2 Changes from 1.3 Alpha 3 to 1.3 Alpha 4 (12/12/2010)
 
  * normalized unchecked-* fn names
  * added *unchecked-math* support
  * fixes to binding conveyance (and *agent*)
  
= 3 Changes from 1.3 Alpha 2 to 1.3 Alpha 3 (11/05/2010)
  
  * fixed filter performance issue introduced in 1.3A2 
  * with-redefs macro (useful for stubbing)
  * print-table

= 4 Changes from 1.3 Alpha 1 to 1.3 Alpha 2 (10/10/2010)

  * code path for using vars is now *much* faster for the common case,
and you must explicitly ask for :dynamic bindability
  * new: clojure.reflect/reflect
http://dev.clojure.org/display/design/Reflection+API 
  * new: clojure.data/diff

= 5 Changes from 1.2 to 1.3 Alpha 1 (09/23/2010)

  * enhanced primitive support 
(http://dev.clojure.org/display/doc/Enhanced+Primitive+Support)
  * better exception reporting
  * ancillary namespaces no longer auto-load on startup:
clojure.set, clojure.xml, clojure.zip

= 6 About Alpha Releases

1.3 is the first release of Clojure that will include a series of
alpha builds. We are adding these builds to support maven and
leiningen users, who want a specific artifact that they can target (as
opposed to building from master or "moving-target" snapshots).

If you are the kind of person who used to track master by building
from source, but no longer do so because you are using maven or
leiningen, alpha releases are for you.


Stuart Halloway
Clojure/core
http://clojure.com

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

Re: Monad Lessons

2011-03-11 Thread Daniel Werner
On Mar 9, 8:15 pm, jim  wrote:
> So, my question is how many would be interested in such a session?
> This would be a basic introduction to monads. Future session could be
> about more advanced monad topics, if there was a demand for that.

I'd *love* to attend. Even with such a vast amount of online resources
available, I've yet to grasp how monads can be used to solve real-
world problems. Maybe an interactive session (and a bunch of
enthusiastic fellow students) can provide for that.

Daniel

-- 
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 1.3 testbuild1, enlive, and dependency ranges

2011-03-11 Thread Stuart Halloway
> Hi,
> 
> I have a project that depends on enlive, which uses a dependency range in its 
> clojure dependency.  This seems to cause all possible versions of clojure to 
> be pulled down, including clojure-1.3.0-testbuild1-SNAPSHOT, which is broken 
> (parent pom is in a release repo which isn't listed in the testbuild1 pom).  
> This in turn breaks my build.
> 
> At the moment the only remedy I can see is to re-package enlive to remove the 
> dependency range.  Anyone have any other ideas?

There is some maven fu for ignoring dependencies which should work around this, 
and I am looking into what it takes to remove something from central.


Stuart Halloway
Clojure/core
http://clojure.com

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

clojure 1.3 testbuild1, enlive, and dependency ranges

2011-03-11 Thread Hugo Duncan

Hi,

I have a project that depends on enlive, which uses a dependency range in  
its clojure dependency.  This seems to cause all possible versions of  
clojure to be pulled down, including clojure-1.3.0-testbuild1-SNAPSHOT,  
which is broken (parent pom is in a release repo which isn't listed in the  
testbuild1 pom).  This in turn breaks my build.


At the moment the only remedy I can see is to re-package enlive to remove  
the dependency range.  Anyone have any other ideas?


--
Hugo Duncan

--
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: overriding keyword behavior?

2011-03-11 Thread Joost
On Mar 10, 5:31 pm, kurtharriger  wrote:
> That was basically my question, protocols are designed for this but
> ILookup isn't a protocol.  Is it possible to make ILookup into a
> protocol?  I haven't looked at the java code much at all, but I might
> take a stab at creating a patch it that seems possible.
>
> Converting java.util.Properties into a map isn't hard, but converting
> java objects to native maps is extreamly common (bean, reflect, ring,
> etc...) and perhaps unnecessary in many situations if one could just
> extend an existing java type with ILookup so that if it looks like a
> duck, its a duck.

I've had the same idea a couple of day ago; specifically, looking up
public members of an object.

In the end, I think the actual use cases generally are more involved
than just :keyword lookup, so I wrote some code to automatically do
the conversion to map:

https://github.com/joodie/clj-java-fields

-- 
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: setup and propagation of config-params

2011-03-11 Thread faenvie
> (set-opt :development) ; this is what you want
> ...
> (get-opt :show-sql) ; need this flag

hi armando,

this is more of an OO style but as there is no
def- , the state is still accessible from the
outside. also the api is kinda asymetric.

as described in 'the joy of clojure 7.2 -
sharing closure context' closures can be
used for an OO-style encapsulation of state.

looks more functional to me atm.

cheers

-- 
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: DOM API for Clojure

2011-03-11 Thread K.
Could monads help me to build a pure functional Clojure interface for
this while the underlying DOM manipulations would be not pure?

-- 
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: DOM API for Clojure

2011-03-11 Thread Stuart Sierra
If you want to receive a DOM object from Java, manipulate it, and then 
return a DOM object back to Java, without rebuilding it, you're probably 
stuck manipulating it through the Java DOM APIs.

-Stuart Sierra
clojure.com

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

Re: DOM API for Clojure

2011-03-11 Thread K.
> It's not the DOM API, but take a look at Zippers as an efficient way to
> manipulate tree-like structures, including XML.

I can see how it could be used to walk the tree but I don't see how it
could be used to modify just a few branches / leafs in the tree.
Calling zip/root reconstructs the whole tree. In short: I don't see
how this can be mixed up with a non-functional interface like the one
of Java DOM. Or is it possible somehow?

-- 
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: Comparing clojure speed to java speed

2011-03-11 Thread Chouser
On Thu, Mar 10, 2011 at 11:26 PM, Jarl Haggerty  wrote:
> Hmm, I should have thought of that.
>
> New Clojure:
>
> (ns hello.test
>  (import org.jbox2d.common.Vec2)
>  (:gen-class))
>
> (defn -main [& args]
>  (dotimes [q 5]
>    (let [#^Vec2 a (Vec2. 1 2)
>          #^Vec2 b (Vec2. 3 4)]
>      (time (loop [x (int 0)]
>              (when (< x (int 1e9))
>                (.addLocal a b)
>                (recur (unchecked-inc x

I think if you turn on reflection warnings and remove those type
hints, you'll find those hints aren't useful.  In which case I'd
recommend leaving them out.

--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
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: DOM API for Clojure

2011-03-11 Thread Stuart Sierra
It's not the DOM API, but take a look at Zippers as an efficient way to 
manipulate tree-like structures, including XML.

Luke VanderHart's Clojure Conj talk on Zippers is 
here: http://clojure.blip.tv/file/4503162/

-Stuart Sierra
clojure.com

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

Re: clojure.string/replace-first return nil when not matched

2011-03-11 Thread Stuart Sierra

>
> (require '[clojure.string :as str]) 
> (str/replace-first "abc def" #"ghi" (fn [a] (str a a))) 
> => nil 
>

That's a bug.  Created http://dev.clojure.org/jira/browse/CLJ-753

Thanks for the report.

-Stuart Sierra
clojure.com 

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

Re: overriding keyword behavior?

2011-03-11 Thread Stuart Sierra
It is not possible to turn an interface into a protocol. When protocols 
first appeared, the idea was floated to replace the low-level interfaces 
like ILookup with equivalent protocols, but this idea has not received 
substantial attention since.

-Stuart Sierra
clojure.com

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

Re: Why does this break memoization?

2011-03-11 Thread Ken Wesson
On Fri, Mar 11, 2011 at 3:54 AM, Tassilo Horn  wrote:
> Ken Wesson  writes:
>
> Hi Ken & Alan,
>
>> Adding metadata to an object produces a new object, rather than
>> altering the existing object.  Every time you increment the counter
>> for a function in p it becomes different, and the memoize treats it as
>> new.
>
> Then I've misread that statement on the homepage:
>
>  An important thing to understand about metadata is that it is not
>  considered to be part of the value of an object. As such, metadata
>  does not impact equality (or hash codes). Two objects that differ only
>  in metadata are equal

Actually, that statement is itself a bit misleading and should be
clarified. Collections and other things with value-equality semantics
are equal if they only differ on metadata, but things like functions
that use object identity in the heap as their equality test are not.

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


DOM API for Clojure

2011-03-11 Thread K.
Hello,

Is there a library to manipulate (create and modify) a XML DOM tree in
Clojure? If possible with the "classic" syntax (XML tags represented
as Clojure vectors.)

I need to keep an instance of a DOM tree in my program and modify it
and recreating the whole DOM tree every time would not be efficient or
convenient (because of event modifications tracking in the Java
library that use this DOM).


Thanks in advance for your suggestions.

-- 
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: Loading clojure code during runtime

2011-03-11 Thread finbeu
beautiful! Thx.

On 11 Mrz., 10:23, Benny Tsai  wrote:
> (read-string) converts a string into a Clojure object, which can then be
> (eval)ed:

-- 
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: Loading clojure code during runtime

2011-03-11 Thread Benny Tsai
(read-string) converts a string into a Clojure object, which can then be 
(eval)ed:

(let [f (eval (read-string "(fn [x] (* x 2))"))]
  (map f [1 2 3]))

user=> (2 4 6)

So you could do something like:

(let [f (eval (read-string (slurp "function.txt")))]
  (map f [1 2 3]))

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

Re: Why does this break memoization?

2011-03-11 Thread Tassilo Horn
Ken Wesson  writes:

Hi Ken & Alan,

> Adding metadata to an object produces a new object, rather than
> altering the existing object.  Every time you increment the counter
> for a function in p it becomes different, and the memoize treats it as
> new.

Then I've misread that statement on the homepage:

  An important thing to understand about metadata is that it is not
  considered to be part of the value of an object. As such, metadata
  does not impact equality (or hash codes). Two objects that differ only
  in metadata are equal

> So, each time p-apply-memoized gets called with "the same" p, because
> all the counters have been bumped, it's not actually the same p as far
> as memoize is concerned, and so you don't get the benefits of
> memoization anymore.

Yes, now I got it.  For the future, I should remember that I can put
metadata only on symbols and collections (which the docs already state).

> Solution: don't mess with the function metadata. Instead, use a global
> map from fns to counts, or something.

In fact, that was my first idea, but since I started doing clojure and
functional programming last week, I always have a bad gut feeling when
adding a global.  And what would happen if I executed many p-applys in
many threads?  Most probably, I have to establish a `binding' in the
entry function p-apply, right?

Bye,
Tassilo

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


Loading clojure code during runtime

2011-03-11 Thread finbeu
Hello,

I'm still fairly new to Clojure but what I can say so far is that it
is awesome :-)

I'm currently implementing a cache as an atom that gets updates from
an external application. I expose the cache items to clients via a
webservice using compojure. Actually I return a list for each
request.

What I want to do now is to allow the consumers (clients) to apply a
function to the list (with map) that my webservice returns.  The
definition of the function is saved in a file. So at runtime of my
application (no restart of the application is allowed) , I want to
read a file with the defintion of the function, apply the function
with map to the list the clients request from my webservice and return
the new list.

I think this task is pretty simple to accomplish with clojure. But how
would I do that? I think I need to eval the code somehow dynamically
and use it.

Thanks.

- finbeu

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