[ANN] edn-java 0.5.0 released

2016-12-11 Thread Ben Smith-Mannschott
edn-java [1] is a parser and printer for edn [2].

This release:

* Can read namespaced maps as per CLJ-1910 [47]
* Throws an exception when asked to read a map or set with duplicates [49]

It should be appearing on Maven Central shortly.

// Ben

[1] http://edn-java.bpsm.us

[2] https://github.com/edn-format/edn

[47] https://github.com/bpsm/edn-java/issues/47

[49] https://github.com/bpsm/edn-java/issues/49

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ANN] edn-java 0.4.6 released

2015-10-25 Thread Ben Smith-Mannschott
edn-java [1] is a parser and printer for edn [2].

This release:

* Teaches the default parser to produce values that can participate in Java
serialization. [3]

It should be appearing on Maven Central shortly.

// Ben

[1] http://edn-java.bpsm.us

[2] https://github.com/edn-format/edn

[3] https://github.com/bpsm/edn-java/issues/43

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a cheet sheet for some of the pure symbolic functions like #'

2015-06-05 Thread Ben Smith-Mannschott


try googling for clojure reader macros.

Dru Sellers mailto:d...@drusellers.com
June 5, 2015 at 22:05via Postbox 
https://www.postbox-inc.com/?utm_source=emailutm_medium=sumlinkutm_campaign=reach

Trying to google what #' means is tricky to say the least.

Is there a good name for these that I can google to read up on them?

Thank you.

-d
--
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 unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com 
mailto:clojure+unsubscr...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Sent from Postbox 
https://www.postbox-inc.com/?utm_source=emailutm_medium=siglinkutm_campaign=reach


--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: core.async: Deprecated - this function will be removed. Use transducer instead

2015-02-19 Thread Ben Smith-Mannschott
I'm unclear on one thing: what's the purpose of core.async/pipe? In your
blog article, you write:

(- source (pipe (chan)) payload-decoder payload-json-decoder)

(pipe source destination) just copies elements from source to destination.
How is that any different than just using source here directly?:

(- source payload-decoder payload-json-decoder)

What have I missed?

// Ben

On Thu, Feb 19, 2015 at 3:06 AM, Malcolm Sparks malc...@juxt.pro wrote:

 I have recently written a blog article which explains how to use
 transducers with core.async.

 You can find it here: http://malcolmsparks.com/posts/transducers.html


 On Wednesday, 18 February 2015 21:48:05 UTC, bsmith.occs wrote:

 I'm probably just especially dense today, but perhaps someone can give me
 a poke in the right direction.

 I'm trying to wrap my head around transducers.

 (1) For debugging purposes I'd like to be able to consume the values on a
 channel and put them in a collection to be printed.

 I'm doing this at the REPL:

 (async/!! (async/into [] channel))

 This seems needlessly clunky. Is this really the best way to accomplish
 this?

 (2) async/map is deprecated, what's the alternative, exactly?

 (let [ch (async/to-chan [1 2 3])]
   (async/map inc ch))

 AFAICT this would produce a channel, which when consumed would yield the
 values 2 3 4, correct?

 Now I suppose if I didn't already have the channel ch, I could create one
 with an associated transformation function, and then stuff the values 1 2 3
 into it somehow, right?

 (let [ch (async/chan nil (map inc))]
   (async/onto-chan ch [1 2 3])
   ch)
 ;; returns a channel yielding items 2, 3, 4

 But, I'm not clear at all how I can apply the operation (inc) to the all
 values yielded by a channel I already have in my hand.

 Any help would be appreciated. I feel like I'm missing some critical bit
 of insight and that async and transducers might just fall into place for me
 if I could only find out what that bit is.

 // 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


core.async: Deprecated - this function will be removed. Use transducer instead

2015-02-18 Thread Ben Smith-Mannschott
I'm probably just especially dense today, but perhaps someone can give me a
poke in the right direction.

I'm trying to wrap my head around transducers.

(1) For debugging purposes I'd like to be able to consume the values on a
channel and put them in a collection to be printed.

I'm doing this at the REPL:

(async/!! (async/into [] channel))

This seems needlessly clunky. Is this really the best way to accomplish
this?

(2) async/map is deprecated, what's the alternative, exactly?

(let [ch (async/to-chan [1 2 3])]
  (async/map inc ch))

AFAICT this would produce a channel, which when consumed would yield the
values 2 3 4, correct?

Now I suppose if I didn't already have the channel ch, I could create one
with an associated transformation function, and then stuff the values 1 2 3
into it somehow, right?

(let [ch (async/chan nil (map inc))]
  (async/onto-chan ch [1 2 3])
  ch)
;; returns a channel yielding items 2, 3, 4

But, I'm not clear at all how I can apply the operation (inc) to the all
values yielded by a channel I already have in my hand.

Any help would be appreciated. I feel like I'm missing some critical bit of
insight and that async and transducers might just fall into place for me if
I could only find out what that bit is.

// 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: core.async: Deprecated - this function will be removed. Use transducer instead

2015-02-18 Thread Ben Smith-Mannschott
Thanks Malcolm, you're blog post was a great help to me.

On Thu, Feb 19, 2015 at 3:06 AM, Malcolm Sparks malc...@juxt.pro wrote:

 I have recently written a blog article which explains how to use
 transducers with core.async.

 You can find it here: http://malcolmsparks.com/posts/transducers.html


 On Wednesday, 18 February 2015 21:48:05 UTC, bsmith.occs wrote:

 I'm probably just especially dense today, but perhaps someone can give me
 a poke in the right direction.

 I'm trying to wrap my head around transducers.

 (1) For debugging purposes I'd like to be able to consume the values on a
 channel and put them in a collection to be printed.

 I'm doing this at the REPL:

 (async/!! (async/into [] channel))

 This seems needlessly clunky. Is this really the best way to accomplish
 this?

 (2) async/map is deprecated, what's the alternative, exactly?

 (let [ch (async/to-chan [1 2 3])]
   (async/map inc ch))

 AFAICT this would produce a channel, which when consumed would yield the
 values 2 3 4, correct?

 Now I suppose if I didn't already have the channel ch, I could create one
 with an associated transformation function, and then stuff the values 1 2 3
 into it somehow, right?

 (let [ch (async/chan nil (map inc))]
   (async/onto-chan ch [1 2 3])
   ch)
 ;; returns a channel yielding items 2, 3, 4

 But, I'm not clear at all how I can apply the operation (inc) to the all
 values yielded by a channel I already have in my hand.

 Any help would be appreciated. I feel like I'm missing some critical bit
 of insight and that async and transducers might just fall into place for me
 if I could only find out what that bit is.

 // 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/d/optout.


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ANN] edn-java 0.4.5 released

2015-01-28 Thread Ben Smith-Mannschott
edn-java [1] is a parser and printer for edn [2].


This release:


* Incorporates a patch from 'redahe' to fix issue 40 where  and 

  were not recognized as symbols. [3]


It is available on Maven central as I write this.


[1] http://edn-java.bpsm.us

[2] https://github.com/edn-format/edn

[3] https://github.com/bpsm/edn-java/issues/40


// 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ANN] edn-java 0.4.4 released

2014-03-02 Thread Ben Smith-Mannschott
edn-java [1] is a parser and printer for edn [2].

This release:

* Provides a pretty printer for edn data [3].
* Recognizes 'foo//' as a symbol [4].
* Provides experimental more readable, but still compact, edn printing [5].

It should be available on Maven Central within a day.

[1] http://edn-java.bpsm.us
[2] https://github.com/edn-format/edn
[3] https://github.com/bpsm/edn-java/issues/13
[4] https://github.com/bpsm/edn-java/issues/30
[5] https://github.com/bpsm/edn-java/pull/37

// 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: I want to get sha1 of a string

2014-03-02 Thread Ben Smith-Mannschott
(- Hello, World! .getBytes create-hash ...)

Will get you the hash of the string encoded to bytes using *some random
encoding*. (Whatever the platform you're currently running on defaults to.)

You should explicitly choose an encoding and stick to it. I'd suggest UTF-8
since that can encode all the code points that might show up in a Java
String.

(- Hello, World! (.getBytes UTF-8) create-hash java.math.BigInteger.)

// Ben


On Sat, Mar 1, 2014 at 7:49 PM, Zach Oakes zsoa...@gmail.com wrote:

 You can use java.security.MessageDigest. For example:

 (defn create-hash
   [data-barray]
   (.digest (java.security.MessageDigest/getInstance SHA1) data-barray))

 It takes and returns a byte array, but converting from/to a string is
 fairly straight-forward:

 (- Hello, World!
  .getBytes
  create-hash
  java.math.BigInteger.
  (format %x)
  println)

 On Saturday, March 1, 2014 11:26:29 AM UTC-5, action wrote:

 do like this:
 (ns clojurewerkz.support.hashing
   (:require [clojurewerkz.support.internal :as i])
   (:import [com.google.common.hash Hashing HashFunction HashCode]))
 but:
 FileNotFoundException Could not locate clojurewerkz/support__init.class
 or cloju
 rewerkz/support.clj on classpath:   clojure.lang.RT.load (RT.java:443)
 how to set the dependencies, or other solution?

 Think you


  --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Proposed formal syntax for edn

2013-07-18 Thread Ben Smith-Mannschott
I think it would aid compatibility between edn implementations if we had an
agreed upon formal syntax. To that end, I've tried my hand at specifying
one. I've posted it as issue 56 on edn-format/edn:

https://github.com/edn-format/edn/issues/56

I'll incorporate fixes for any problems that are identified into a copy of
the syntax hosted here:

https://gist.github.com/bpsm/5951638

I think it would be helpful for any discussion to take place on the issue,
since then it would all be in once place.

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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Proposed formal syntax for edn

2013-07-18 Thread Ben Smith-Mannschott
On Thu, Jul 18, 2013 at 7:46 PM, kovas boguta kovas.bog...@gmail.comwrote:

 I agree that would be a Good Thing. This looks like an excellent start.

 Is this specification executable in Instaparse?

 IMO specs that are immediately computable are more useful and more likely
 to be correct.


No, not as it stands currently the syntax is surely inedible for
Instaparse. I do agree that encoding to work with Instaparse would be an
useful additional verification. It is something I've thought about. I may
tackle that once I'm confident that the obvious kinks have been worked out
of the syntax.

// 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: edn-format parsers (eg, Common Lisp)?

2013-07-09 Thread Ben Smith-Mannschott
Perhaps you've not seen this:

https://github.com/edn-format/edn/wiki/Implementations

(But there's no CL implementation listed there.)

//Ben

On Tuesday, July 9, 2013, Rich Morin wrote:

 I'm intrigued by edn (extensible data notation), as described here:

   https://github.com/edn-format/edn

 It seems cleaner and more expressive than JSON, so I'm looking into
 using it for a current project.  However, I haven't seen a summary
 of parser and/or generator implementations for this format.  I'm
 particularly interested in finding an edn parser for Common Lisp.

 If anyone has something of this nature, please post a note to the
 list (or contact me offline).  If I get some useful responses, I'll
 put together a wiki page.

 -r

  --
 http://www.cfcl.com/rdmRich Morin
 http://www.cfcl.com/rdm/resume r...@cfcl.com javascript:;
 http://www.cfcl.com/rdm/weblog +1 650-873-7841

 Software system design, development, and documentation


 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.comjavascript:;
 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 javascript:;
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com javascript:;.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [ANN] byte-streams: a rosetta stone for all the byte representations the jvm has to offer

2013-07-02 Thread Ben Smith-Mannschott
Ropes?

http://en.m.wikipedia.org/wiki/Rope_(data_structure)

Ben
--
This message was sent via electromagnetism.

On 02.07.2013, at 12:19, Mikera mike.r.anderson...@gmail.com wrote:

 This is cool, thanks Zach!
 
 Another set of mostly-isomporphic types that this could be applied to is 
 different matrix/array types in core.matrix. core.matrix already has generic 
 conversion mechanisms but they probably aren't as efficient as they could be. 
 I'll take a look and see if the same techniques might be applicable.
 
 Quick question for you and the crowd: does there exist or should we build a 
 standard immutable byte data representation for Clojure? 
 
 I think this is often needed: ByteBuffers and byte[] arrays work well enough 
 but are mutable. Byte sequences are nice and idiomatic but have a lot of 
 overhead, so people are often forced to resort to a variety of other 
 techniques. And it would be nice to support some higher level operations on 
 such types, e.g. production of efficient (non-copying) immutable subsequences.
 
 From a data structure perspective, I'm imagining something like a persistent 
 data structure with byte[] data arrays at the lowest level.
 
 Given the amount of data-processing stuff people are doing, it seems like a 
 reasonable thing to have in contrib at least? 
 
 
 On Saturday, 29 June 2013 18:57:58 UTC+1, Zach Tellman wrote:
 
 I've recently been trying to pull out useful pieces from some of my more 
 monolithic libraries.  The most recent result is 'byte-streams' [1], a 
 library that figures how how to convert between different byte 
 representations (including character streams), and how to efficiently 
 transfer bytes between various byte sources and sinks.  The net result is 
 that you can do something like:
 
   (byte-streams/convert (File. /tmp/foo) String {:encoding utf-8})
 
 and get a string representation of the file's contents.  Of course, this is 
 already possible using 'slurp', but you could also convert it to a 
 CharSequence, or lazy sequence of ByteBuffers, or pretty much anything else 
 you can imagine.  This is accomplished by traversing a graph of available 
 conversions (don't worry, it's memoized), so simply defining a new 
 conversion from some custom type to (say) a ByteBuffer will transitively 
 allow you to convert it to any other type.
 
 As an aside, this sort of conversion mechanism isn't limited to just byte 
 representations, but I'm not sure if there's another large collection of 
 mostly-isomorphic types out there that would benefit from this.  If anyone 
 has ideas on where else this could be applied, I'd be interested to hear 
 them.
 
 Zach
 
 [1] https://github.com/ztellman/byte-streams
 
 -- 
 -- 
 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 unsubscribe from this group and stop receiving emails from it, send an 
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.
  
  

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[ANN] edn-java 0.4.3 released

2013-06-18 Thread Ben Smith-Mannschott
edn-java [1] is a parser and printer for edn [2].

This release fixes issue #35 [3] Allow Symbols to contain $ %  =.

It should be available on Maven Central within a day.

// Ben

[1] http://edn-java.bpsm.us
[2] https://github.com/edn-format/edn
[3] https://github.com/bpsm/edn-java/issues/35

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[ANN] edn-java 0.4.2 released

2013-06-13 Thread Ben Smith-Mannschott
edn-java [1] is a parser and printer for edn [2].

This release fixes issue #32 [3] EDN List, Vector types indistinguishable
due to common RandomAccess interface.

It should be available on Maven Central within a day.

// Ben

[1] http://edn-java.bpsm.us
[2] https://github.com/edn-format/edn
[3] 
https://github.com/bpsm/edn-java/issues/3https://github.com/bpsm/edn-java/issues/31
2

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[ANN] edn-java 0.4.1 released

2013-06-05 Thread Ben Smith-Mannschott
edn-java [1] is a parser and printer for edn [2].

This release fixes issue31 [3] single quote in a string is incorrectly
escaped.

It is available on Maven Central [4].

// Ben

[1] http://edn-java.bpsm.us
[2] https://github.com/edn-format/edn
[3] https://github.com/bpsm/edn-java/issues/31
[4]
http://search.maven.org/#artifactdetails%7Cus.bpsm%7Cedn-java%7C0.4.1%7Cjar

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: LoL which style for Clojure

2013-03-24 Thread Ben Smith-Mannschott
Way back when I started with Clojure i was doing this:

(let [constant-data (something-expensive)]
  (defn my-fn [x]
(do-something-with x constant-data)))

But was advised instead to do this:

(def my-fn
  (let [constant-data (something-expensive)]
(fn [x]
  (do-something-with x constant-data

So, there's that (third) option as well.

// ben


On Sat, Mar 23, 2013 at 9:56 AM, Marko Topolnik marko.topol...@gmail.comwrote:

 What if there's some computation in there, but such that should be
 performed at compile time? I still prefer the outside let whenever I want
 to make dead sure it's not getting reallocated on each call. If there was
 some well-specified and easily understood guarantee (for example, like the
 one Java has for compile-time constants), only then I would prefer the
 inner let.


 On Friday, March 22, 2013 8:05:10 PM UTC+1, Laurent PETIT wrote:


 2013/3/22 jamieorc jami...@gmail.com

 Curious which style is preferred in Clojure and why:

 (defn f1 []
   (let [x {:foo 1 :bar 2 :baz 3}]
 (keys x)))

 (let [x {:foo 1 :bar 2 :baz 3}]
   (defn f2 []
 (keys x)))


 In either case, AFAIK, the compiler will recognize {:foo 1 :bar 2 :baz 3}
 as constant and will only create it once when compiling.

 First version is preferred.



 Cheers,

 Jamie

 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@**googlegroups.com

 For more options, visit this group at
 http://groups.google.com/**group/clojure?hl=enhttp://groups.google.com/group/clojure?hl=en
 ---
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to clojure+u...@**googlegroups.com.

 For more options, visit 
 https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
 .




  --
 --
 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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Java interop: Can't call public method of non-public class

2013-03-05 Thread Ben Smith-Mannschott
I found the following work-around since I have access to the java code I am
calling:

I had the package-visible ABC Bytes implement a (public) interface
declaring the toHexString method. This placated the compiler.

On Monday, March 4, 2013, Vladimir Tsichevski wrote:

 I think not. But upgrading to clojure 1.5 will do.

 On Friday, March 1, 2013 1:20:57 PM UTC+4, Marko Topolnik wrote:

 I'd say it's a bug. You are invoking a public class's method, which
 happens to be inherited from a package-private class. Clojure's reflective
 code accesses the superclass method directly so there's no distinction
 between direct invocation and invocation through inheritance.

 If you are interseted in a workaround, type-hinting the code will work
 (my guess).

 On Friday, March 1, 2013 10:13:57 AM UTC+1, bsmith.occs wrote:

 Simplified, from a more complex example:

 abstract class Bytes {
 public toHexString() { return ...; }
 Bytes { }
 }

 public class Hash extends Bytes {
 public Hash() { super(); }
 }

 This works in Java:

 new Hash().toHexString();

 This fails in Clojure:

 (.toHexString (Hash.))

 IllegalArgumentException Can't call public method of non-public class:
 public final java.lang.String at.gv.brz.bjuvj.hashpass.**Bytes.toHexString()
 clojure.lang.Reflector.**invokeMatchingMethod (Reflector.java:88)

 Bug?

 // 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.comjavascript:_e({}, 'cvml', 
 '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 javascript:_e({}, 'cvml',
 'clojure%2bunsubscr...@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 unsubscribe from this group and stop receiving emails from it, send an
 email to clojure+unsubscr...@googlegroups.com javascript:_e({}, 'cvml',
 'clojure%2bunsubscr...@googlegroups.com');.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Java interop: Can't call public method of non-public class

2013-03-01 Thread Ben Smith-Mannschott
Simplified, from a more complex example:

abstract class Bytes {
public toHexString() { return ...; }
Bytes { }
}

public class Hash extends Bytes {
public Hash() { super(); }
}

This works in Java:

new Hash().toHexString();

This fails in Clojure:

(.toHexString (Hash.))

IllegalArgumentException Can't call public method of non-public class:
public final java.lang.String at.gv.brz.bjuvj.hashpass.Bytes.toHexString()
clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:88)

Bug?

// 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[ANN] edn-java 0.4.0 a library to read and write edn data

2013-02-23 Thread Ben Smith-Mannschott
I'm happy to report that edn-java is now available on Maven Central.

What is edn-java?
-

Edn-java is a Java library for reading and writing edn data.
It has no dependencies other than Java 1.6.x or later.

A more detailed description, including usage examples is available
here: http://edn-java.bpsm.us

What is edn?


Edn is an extensible data notation used used by Datomic and other
applications as a data transfer format. It supports a rich set of
built-in elements, and the definition of extension elements in terms
of the others. edn is a system for the conveyance of values. It is
not a type system, and has no schemas. Edn is suitable for streaming
and interactive applications since there is no enclosing element at
the top level.

(Paraphrased form https://github.com/edn-format/edn)

Where can I get edn-java?
-

Edn-java is licensed under the Eclipse Public License 1.0.

Sources are on github: https://github.com/bpsm/edn-java
Patches  issues welcomed!

Maven coordinates are:

dependency
  groupIdus.bpsm/groupId
  artifactIdedn-java/artifactId
  version0.4.0/version
/dependency

Caveats
---

The Parser seems pretty solid (for 0.4.0). I use it in production.
I don't anticipate breaking API changes there.

Printing support is not as far along as parsing. It appears to work
correctly, but does not pretty print. Printing APIs may change.

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: the semantic of if-let macro

2013-01-30 Thread Ben Smith-Mannschott
I find it helpful to view if-let as a minor variation on if, with the only
difference being that you choose to bind the results of the test-expression
to some name(s). if-let doesn't care about the values bound to the
variables named in binding-target (which might be an arbitrarily complex
destructuring). If that's not what you want, then if-let isn't the right
tool for the job.

(if test-expression
expression-evaluated-when-test-expression-is-truthy
expression-evaluated-otherwise)

is similar to

(if-let [ binding-target test-expression ]
expression-evaluated-when-test-expression-is-truthy
expression-evaluated-otherwise)

expands to roughly this, except that test-expression is evaluated only once:

(if test-expression
  (let [binding-target test-expression]
 expression-evaluated-when-test-expression-is-truthy)
  expression-evaluated-otherwise)

It took me a little while to understand that this is how it worked when I
began with clojure, but it seems pretty natural now. if-let is really
simple-minded. don't over-think it.

// ben


On Wed, Jan 30, 2013 at 10:42 AM, Mimmo Cosenza mimmo.cose...@gmail.comwrote:

 that means never use if-let with sequential destructoring, which brings me
 to say: never use if-let, because I don't' like to remember such thing
 while coding and then become crazy to catch my error because of a
 misleading language feature.

 mimmo


 On Jan 30, 2013, at 10:32 AM, James Xu xumingming64398...@gmail.com
 wrote:

  Agree with you that it is very misleading when using map-destructure in
  if-let, the same applies to sequential-destructure:
 
  user= (if-let [[_ x] [1 nil]] true false)
  true
 
 
 
  On 13-1-30 下午5:23, Mimmo Cosenza mimmo.cose...@gmail.com wrote:
 
  Uhm, I do not agree.
 
  Suppose tha you have a function returning a map of errors (a valip
  validator lib real case) like the following
 
  {:email [Email can't be empty] :password [Password can't be empty]}
 
  If I want to select just the email errors I would write something like
  that
 
  (if-let [{errors :email} (function-returning-error email password)]
true
false)
 
  Reading the above code you're led to believe that if there are email
  errors, errors local binding will be true. Instead, it returns true even
  if the are no email errors but there are password errors and you never
  get the false branch.
 
  An if you want to catch password errors you would write something like
 
  (if-let [{errors :password} (function-returning-errors email password)]
true
false)
 
  In either case you never get the false branch when
  function-returning-errors return an error which is not the one you're
  looking for
 
  Mimmo
 
 
  On Jan 30, 2013, at 10:05 AM, James Xu xumingming64398...@gmail.com
  wrote:
 
  From the expansion we can see that if-let determine the result based on
  the second param, in your case: {:key2 a string}, not the local
  binding
  you assumed(key1), and
  I think it is reasonable, for example, if we have the following code:
 
  (if-let [{key1 key2} {:key2 a string}]
   true
   false))
 
 
  Should if-let determine the result based on key1? key2? IMO {key1 key2}
  in
  a whole is more reaonable. And {key1 key2} == {:key2 a string}, then
  the
  result is true.
 
 
 
  On 13-1-30 下午4:51, Mimmo Cosenza mimmo.cose...@gmail.com wrote:
 
  Hi all,
  I'm a little bit confused about the semantic of if-let macro.
 
  Suppose to call it as follows with map destructoring:
 
  (if-let [{key1 :key1} {:key2 a string}]
  true
  false))
 
  It returns true.
 
  But,
 
  (let [{key1 :key1} {:key2 a string}]
  (if key1
  true
  false))
 
  returns false.
 
 
  The macro expansion of the former explains why
 
  (macroexpand-1 '(if-let [{key1 :key1} {:key2 a string}] true false))
 
  returns
  (clojure.core/let [temp__3971__auto__ {:key2 a string}] (if
  temp__3971__auto__ (clojure.core/let [{key1 :key1} temp__3971__auto__]
  true) false))
 
  the consequence, IMHO, is that I would never suggest to use map
  restructuring inside and if-let binding, because the syntax let me
  think
  the result its the opposite of its semantic,
 
  Am I completely wrong?
 
  mimmo
 
 
  --
  --
  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 unsubscribe from this group and stop receiving emails from it, send
  an
  email to clojure+unsubscr...@googlegroups.com.
  For more options, visit https://groups.google.com/groups/opt_out.
 
 
 
 
  --
  --
  You received this message because you are subscribed to the Google
  

Re: seeking namespace-aware xml lib

2013-01-18 Thread Ben Smith-Mannschott
Not currently, alas, having hacked my primary motivating example
(publishing my wife's most recent novel for kindle) by hand. I'd like to
return to it, but probably not soon. First I want to get 0.4.0 of edn-java
released.

Ben

On Thursday, January 17, 2013, lewen7er9 wrote:

 Just wondering if this is still being actively worked.

 On Monday, July 16, 2012 3:53:21 PM UTC-4, bsmith.occs wrote:

 TL;DR: I'm looking for a Clojure library that round trips XML+namespaces
 through Clojure data structures and back again.


 I'm hacking on a chewing-gum-and-bailing-wire solution publish my wife's
 novels as EPUB.  I've got most of a prototype of the core functionality
 working, but an stubbing my toe an a lack of what  would consider
 sufficient XML support in the Clojure universe.

 I'm consuming Apple Pages (heavily namespaced XML) and will need to
 produce XML Plist, XHTML, OPF and NCX, all of which are namespaced as
 well.

 My first prototype parser for Pages documents used clojure.xml and
 works, provided Apple never changes the prefixes they use for the
 various namespaces the crop up in a Pages document. This is because
 clojure.xml is absolutely namespace ignorant. Also, there doesn't seem
 to be a way to write clojure.xml out as literal XML.

 I'm in the process of switching to clojure.data.xml, but have discovered
 that it parses namespace aware by default, but only uses this in order
 to have a simple way to ignore namespace information without getting
 confused by spurious namespace prefixes.

 That would be fine for parsing the Pages document, but it's a
 non-starter for producing my output files since these require the use of
 namespaces.

 I've looked at hiccup, which would solve my HTML production problem,
 save for the fact that it produces XHTML 1.0 while my current
 half-manual publishing process uses XHTML 1.1. I expect either version
 would work, but that still leaves me without a solution for Plist, OPF
 and NCX.


 What are my best options? Am I overlooking a Clojure library that
 already does what I need? I could try to teach data.xml to support XML
 namespaces, but the current half-hearted hack which conflates Clojure
 namespaces with XML namespaces would have to go, I fear. I could instead
 put my time into extending hiccup to support XML more generally, or at
 least provide explicit support for NCX, OPF and PList. Should I just
 write my own library? Maybe I could build atop XOM so as not to reinvent
 the heavy lifting.

 // 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.comjavascript:_e({}, 'cvml', 
 '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 javascript:_e({}, 'cvml',
 'clojure%2bunsubscr...@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: Why I get IllegalArgumentException: No matching ctor found

2012-12-17 Thread Ben Smith-Mannschott
Your macro:

 *(*~greeter user-name#*)*

*
*

Is producing a list of a function or closure followed by a symbol. The
first element of the list your macro builds must instead be an expression
that can be evaluated to a function. (For example a symbol naming a
function or an (fn [] ...) expression.)

Ben


On Sunday, December 16, 2012, jarppe wrote:

 Hi,

 I have this macro (complete file https://www.refheap.com/paste/7633):

 *(*defmacro defgreeter [greeter-name]

   *(*let [greeter *(*make-greeter*)*]

 `*(*do

*(*defn ~greeter-name [user-name#]

  *(*~greeter user-name#*)**)**)**)**)*


 It works as expected when make-greeter is defined like this:

 *(*defn make-greeter []

   *(*fn [user-name]

 *(*str Hello,  user-name*)**)**)*


 I can use it like this:

 *(*defgreeter hello*)*

 *(*hello jarppe*)*

 How ever, if I change make-greeter to this I get IllegalArgumentException:

 *(*defn make-greeter []

   *(*let [message hello]

 *(*fn [user-name]

   *(*str message ,  user-name*)**)**)**)*


 Interestingly, this does not work either:

 *(*defn make-greeter []

   *(*constantly what erver*)**)*

 What am I missing?

 --
 -jarppe

  --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to 
 clojure@googlegroups.comjavascript:_e({}, 'cvml', 
 '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 javascript:_e({}, 'cvml',
 'clojure%2bunsubscr...@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: Why I get IllegalArgumentException: No matching ctor found

2012-12-17 Thread Ben Smith-Mannschott
On Mon, Dec 17, 2012 at 11:08 AM, Alex Baranosky 
alexander.barano...@gmail.com wrote:

 Function values can't be read by the reader.  I'm not sure how any
 versions of this code work.


It is true that a function value can not be printed and then read back in,
but I don't think that's relevant here. The macro transforms one in-memory
list into another in-memory list structure. This doesn't involve the reader.



 On Mon, Dec 17, 2012 at 12:32 AM, Marko Topolnik marko.topol...@gmail.com
  wrote:

 On Monday, December 17, 2012 9:28:20 AM UTC+1, bsmith.occs wrote:

 Your macro:

  *(*~greeter user-name#*)*

 *
 *

 Is producing a list of a function or closure followed by a symbol. The
 first element of the list your macro builds must instead be an expression
 that can be evaluated to a function. (For example a symbol naming a
 function or an (fn [] ...) expression.)


 This doesn't help to explain how come it fails only for closures. Does it
 mean that, when it works, it works by accident?

 -Marko


Yes, I would *guess* that it works by accident.

-- 
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 videos deleted from blip.tv?

2012-12-12 Thread Ben Smith-Mannschott
I have no idea what is going on. Looks to me like blip decided to redo their 
web site and in the process throw out old content. or something.  I've got 
local copies of:

Alex Miller_ _Tree Editing with Zippers_.m4v
Chris Houser_ _Finger Trees_ Custom Persistent Collections_.m4v
Christophe Grand_ (not= DSL macros).m4v
Clojure Concurrency.m4v
Clojure Concurrency.mp4
Clojure Data Structures - Part 1.mov
Clojure Data Structures - Part 2.mov
Clojure for Java Programmers - 1 of 2.mov
Clojure for Java Programmers - 2 of 2.mov
Clojure for Lisp Programmers Part 1.mov
Clojure for Lisp Programmers Part 2.mov
Datomic-Introduction.mp4
Datomic-Query-Tutorial.mp4
David Liebke_ _From Concurrency to Parallelism_.m4v
Hammock-driven Development.m4v
Laurent Petit_ _State of Counterclockwise_ Past, Present and Future_.m4v
Luke VanderHart_ _Clojure Zippers_.m4v
Mark McGranaghan_ _One Ring to Bind Them_.m4v
Michael Fogus_ _Fertile Ground_ The Roots of Clojure_.m4v
Phil Hagelberg_ _Making Leiningen Work for You_.m4v
Rich Hickey Unveils ClojureScript.m4v
Sean Devlin_ Protocol XIII_ Clojure Protocols Explained.m4v
Starting Clojure 2012.mp4
Stuart Halloway_ _Simplicity Ain't Easy_.m4v
Tom Faulhaber_ Lisp, Functional Programming, and the State of Flow.m4v
Zach Tellman_ _Aleph_ A Framework for Asynchronous Communication_.m4v
clojure-sequences.mov

Some of these were originally hosted on blip.tv

// ben



On Dec 13, 2012, at 05:40, Alex Grigorovich alex.grigorov...@gmail.com wrote:

 Hi,
 
 I was trying to watch Rich's videos on http://clojure.blip.tv and got a 404 
 Not Found. Searching blip.tv for clojure brings up on entry that is 
 pending deletion. Are these videos available elsewhere? What's going on?
 
 -- 
 Thanks,
 Alex
 
 -- 
 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: with-open and line-seq

2012-10-28 Thread Ben Smith-Mannschott
On Sun, Oct 28, 2012 at 9:38 AM, Christian Sperandio
christian.speran...@gmail.com wrote:

 I've got a question about lazy-sequence and file reading.
 Is line-seq good to process lines from huge file?
 Let take this case, I want to process each line from a file with one or more
 functions. All lines must be processed. Line-seq return a lazy sequence, it
 means all already read lines stay in memory, doesn't it?
 So, if the processed file's size is many gigabytes, my heap size will
 explode, right?  Or did I miss something?


You missed something. All lines only stay in memory if you hold on to
a reference to the beginning of the sequence. (Holding on to the
head.) Generally, doing that is a bug. The whole point on lazy
sequences is that you don't need to hold the whole sequence in memory,
when you're processing it one item at a time.

// 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: what is the modern equivalent of clojure.contrib.java-utils/file?

2012-10-25 Thread Ben Smith-Mannschott
Anything that starts with clojure. is part of (some version of) clojure.

For Clojure 1.4, that's everything listed in Table of Contents on
the right side of the web page you'll find here:

http://clojure.github.com/clojure/

clojure.core
clojure.data
clojure.inspector
clojure.java.browse
clojure.java.io
clojure.java.javadoc
clojure.java.shell
clojure.main
clojure.pprint
clojure.reflect
clojure.repl
clojure.set
clojure.stacktrace
clojure.string
clojure.template
clojure.test
clojure.walk
clojure.xml
clojure.zip

That'll all be available without needing to add dependencies to your
project.clj. You'll just need to :require it as usual in your ns form.


On Thu, Oct 25, 2012 at 9:52 PM, larry google groups
lawrencecloj...@gmail.com wrote:
 Okay, if I look here:


 http://clojure.github.com


 Can I assume that anything that starts with clojure.core is not a
 dependency? And everything else is?


 So this would be listed as a dependency if I use it:



 clojure.test.junit



 but I would not have to list this as a dependency:


 clojure.core.protocols






 On Thursday, October 25, 2012 2:57:26 PM UTC-4, Sean Corfield wrote:

 On Thu, Oct 25, 2012 at 11:39 AM, larry google groups
 lawrenc...@gmail.com wrote:
  How do you know this? Where is this documented? I find myself baffled as
  to
  what is a dependency and what is not.

 http://clojure.github.com

 If it's listed separated there, it's a contrib you need to pull in
 explicitly. Otherwise it's part of Clojure itself.

 Clojure's namespaces are documented here (linked from 'clojure' in the
 left column of the above page):

 http://clojure.github.com/clojure/
 --
 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

-- 
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: XML parsing with namespace prefixes

2012-10-19 Thread Ben Smith-Mannschott
On Fri, Oct 19, 2012 at 12:03 AM, Maurits maurits.r...@gmail.com wrote:
 Bit of a late reaction, but there is nothing special about a tag with a
 namespace prefixed. For example I have been using:

 (zf/xml- zipper :ListRecords :record :metadata :oai_dc:dc :dc:language
 zf/text)

 which works perfectly well.

Yea, but it's a hack. It only works if you know ahead of time which
prefix(es) will be used for which namespaces. The prefixes themselves
can (and often are) completely arbitrary. What's important is the
lexically closest binding of a namespace URI to that prefix.

These are equivalent:

x xmlns=ns://foo/
a:x xmlns:a=ns://foo/
b:x xmlns:b=ns://foo/

But not equivalent to these:

x/
a:x xmlns:a=ns://bar xmlns=ns://foo/

// 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: Evaluating an anonymous function with closure

2012-10-15 Thread Ben Smith-Mannschott
On Mon, Oct 15, 2012 at 8:11 PM, Lee Spector lspec...@hampshire.edu wrote:
 On Oct 15, 2012, at 12:51 PM, Alan Malloy wrote:

 Evaluating function literals is not intended to work; that it works
 for non-closure functions should be treated as a coincidence.

 Really? Eval Evaluates the form data structure (not text!) and returns the 
 result. Why would certain things like function literals be excluded? IMHO 
 they shouldn't be, and in fact I've built some code around dynamically 
 constructed and evaluated function literals.

I think you're confusing:

(eval (list '(fn [x] x) 1))

with:

(eval (list (fn [x] x) 1))

In both cases, eval is being passed a list of two items. The first
element of the list differs, however:

In the first case, it is a list beginning with the special form fn: a
function literal that has not yet been evaluated. Eval will have no
trouble with this.

In the second case it is a reference to an object implementing the
clojure.lang.IFn interface. That's not a function literal, it's the
result of evaluating one. This, as you've discovered, may or may not
work with eval.

If the distinction I'm trying to make is not clear to you, I'd suggest
having a look at http://www.infoq.com/presentations/Clojure-Macros (It
does a good job exploring these kinds of distinctions as it's vital to
have an accurate mental model of how Clojure is evaluated if one
intends to write macros.)

// 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: basic quoting question

2012-10-08 Thread Ben Smith-Mannschott
On Mon, Oct 8, 2012 at 5:06 PM, Brian Craft craft.br...@gmail.com wrote:
 Thanks!

 Is the string vs symbol distinction peculiar to clojure, among lisps?


Yes, strings are distinct from symbols in every reputable lisp.

That symbol and keyword know how to look themselves up in an
associative collection is, as far as i know, unique to Clojure.

// Ben

 On Monday, October 8, 2012 8:03:00 AM UTC-7, Jack Moffitt wrote:

  user= ('X 'Y)
  nil
 
  All of these are as I expected except the last, which I thought would
  throw
  something like the 1st case. What's going on there?

 You've prevented X from being evaluated (it will be seen as the symbol
 X), but you haven't prevented evaluation of the function call. Symbols
 happen to be functions that look themselves up in collections. 'Y is
 not a collection, so it returns nil.

 Had you had something else in function position that wasn't actually a
 valid function, you would have gotten a ClassCastException.

 jack.

 --
 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: == is not transitive?

2012-10-05 Thread Ben Smith-Mannschott
On Fri, Oct 5, 2012 at 11:08 AM, Jean Niklas L'orange
jeann...@hypirion.com wrote:


 On Friday, October 5, 2012 2:39:05 AM UTC+2, Ben wrote:

 user [(== 0 0.0) (== 0.0 0.0M) (== 0.0M 0)]
 [true true false]


 When passing two arguments to ==, == will be transitive.


 user [(== 0 0.0 0.0M) (== 0 0.0M 0.0) (== 0.0 0 0.0M) (== 0.0 0.0M 0)
 (== 0.0M 0.0 0) (== 0.0M 0 0.0)]
 [true false false false true false]


 This is more of a problem with number equality, not the transitivity of ==.
 (== x1 x2 x3 ... xn) can be rewritten as (and (== x1 x2) (== x2 x3) ... (==
 xn-1 xn)).

 So if you compare (== x y z), then if x = y, then the result of (== x z) and
 (== y z) should be equivalent, considering the numbers are, well, numbers.

 I believe the issue lies within the bigdec-parsing, which seems to have two
 zeroes: (== 0M 0.0M) returns false, and their hashcode (0 and 1,
 respectively) are different.

Yea, I think this is the peculiar definition of BigDecimal.equals()
biting us here.

http://docs.oracle.com/javase/1.4.2/docs/api/java/math/BigDecimal.html

# Note: care should be exercised if BigDecimals are to be used as keys in a
# SortedMap or elements in a SortedSet, as BigDecimal's natural ordering is
# inconsistent with equals. See Comparable, SortedMap or SortedSet for more
# information.

equals():
# Compares this BigDecimal with the specified Object for equality. Unlike
# compareTo, this method considers two BigDecimals equal only if they are
# equal in *value* and *scale* (thus 2.0 is not equal to 2.00 when compared by
# this method)

-- 
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: performance in versions = 1.4.0

2012-10-04 Thread Ben Smith-Mannschott
nth only promises O(n) performance for all things sequential. However,
the implementation on master in RT.java appears to special case
indexed and random-access collections for faster access, so I'm not
sure why you're seeing such a difference. You could try using get in
place of nth, though from reading the source I'm not sure why it would
produce results that are any different from what you're already
seeing.

The code that looks like it runs when you call nth on a vector has
been in Clojure since:

# commit ff27522840fb3c1681c331ad1fb44a313bd44e0a
# Author: Rich Hickey richhic...@gmail.com
# Date:   2009-05-28 13:42:16 +
#
# first cut of chunked seqs
# Chunked seqs, initial Java-side support

So, I'm not finding any easy explanation for the performance
difference you're seeing.

Color me confused.

// Ben


On Thu, Oct 4, 2012 at 12:33 PM, Karsten Schmidt i...@toxi.co.uk wrote:
 Okay, after several hours of more testing  profiling it seems the culprit
 is the implementation of (nth) - and IMHO this is quite a biggie:

 (use 'macrochrono.core) ; only used for bench macro below

 (def t [[0 0] [100 0] [100 100] [[0 0] 1 100]])

 (defn foo [[a b c [[dx dy] r x2]] [px py]]
   (let [xx (- dx px) yy (- dy py)]
 ( (+ (* xx xx) (* yy yy)) r)))

 1.3.0

 user= (bench 100 (dotimes [i 10] (foo t [i i])))
 {:median 12.647, :max 31.255, :min 11.365, :avg 12.731339}

 1.4.0:

 (bench 100 (dotimes [i 10] (foo t [i i])))
 {:median 21.574, :max 32.243, :min 18.031, :avg 22.326779}

 1.5.0-master-SNAPSHOT:

 (bench 100 (dotimes [i 10] (foo t [i i])))
 {:median 21.429, :max 106.704, :min 17.7769997, :avg 22.94385}

 VisualVM shows most of the time is spent in calls to nth, which makes sense
 since the function makes heavy use of destructuring.

 However, could someone please explain why its implementation is now almost
 half the speed as compared to 1.3.0? nth is such a fundamental function that
 it should not show such degradation in performance. I'm about to dig through
 the commit logs to find out more, but that's gonna take a while and I hope
 someone from Clojure/Core can shed some light instead.

 Proposals for workarounds are appreciated too (apart from avoiding
 destructuring)... Moving  reducing destructuring in the inner (let)
 improves it somewhat, but not much and makes the code less legible:

 (defn foo2 [t p]
   (let [[d r x2] (t 3)
 xx (- (d 0) (p 0)) yy (- (d 0) (p 0))]
 ( (+ (* xx xx) (* yy yy)) r)))

 1.4.0

 user= (bench 100 (dotimes [i 10] (foo2 t [i i])))
 {:median 17.122, :max 108.78, :min 14.293, :avg 19.7231707}

 1.5.0-master-SNAPSHOT

 user= (bench 100 (dotimes [i 10] (foo2 t [i i])))
 {:median 17.146, :max 93.476999, :min 13.777, :avg
 18.9884803}

 Many thanks!

 K.

 --
 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.lang.Keyword.hashCode is a hotspot in my app

2012-09-25 Thread Ben Smith-Mannschott
On Tue, Sep 25, 2012 at 1:53 AM, James Hess james.hes...@gmail.com wrote:
 Hi experienced clojure gurus,
 According to VisualVM 24% of my time is spent in
 clojure.lang.Keyword.hashCode. I'm sure I am doing something wrong (i.e. I'm
 not blaming clojure's implementation).  Is this an indication that I'm using
 keywords too much or something like that?  Have other people ran into this
 problem before, and if so what were you doing that was causing such high
 usage and how did you fix it?

 Thanks in advance,
 Jimbo

Well, you can eliminate the implementation of Keyword.hashCode() as an
explanation for what you're seeing:

public final int hashCode(){
return hash;
}

So, that leaves two possibilities: (1) You're doing something very
unusual in your code, which we can't say since you haven't showed us
any actual code. (2) You're misusing visualvm or misinterpreting the
results.

I'm guessing 2.

// 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: Map-destructuring a non-associative structure, non documented behavior?

2012-09-24 Thread Ben Smith-Mannschott
On Tue, Sep 25, 2012 at 5:10 AM, Nahuel Greco ngr...@gmail.com wrote:
 I can't find the documentation for this behaviour:

 (let [{x :b :as y} '(:a 1 :b 2)] [x y])

 ;= [2 {:a 1, :b 2}]

 It seems as if the list in the init-expr is converted first to an
 associative structure and then destructured.
 But that behaviour doesn't seems to be documented, the map destructuring
 documentation only talks
 about destructuring of associative structures, and also there is nothing
 about binding the :as expression
 to the resultant associative structure instead of the initial init-expr.

 Is this documented somewhere? Is an intended behaviour assured to be present
 in the future Clojure
 versions?

TL;DR: Intentional. Since 1.2.0.

This behavior was added in Clojure 1.2.0, the changes.txt for that release says:

== 2.3 Destructuring Enhanced ==

If you associatively destructure a seq, it will be poured
into a map first:

  (defn foo [ {:keys [a b c]}]
[a b c])

  (foo :c 3 :b 2)
  = [nil 2 3]

But, I didn't see a reference to this behavior on the page on
clojure.org where special forms and destructuring are discussed [1].

[1]: http://clojure.org/special_forms#Special Forms--(let [bindings* ] exprs*)

// 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: ANN edn-java

2012-09-23 Thread Ben Smith-Mannschott
On Sun, Sep 23, 2012 at 3:59 AM, Mikera mike.r.anderson...@gmail.com wrote:
 Looks cool - going to try it out in a couple of my projects, thanks!

 Question - assuming this is pretty lightweight and efficient, would it also
 make sense to use it from Clojure in circumstances where you just want edn
 and don't need the full Clojure reader?

I suppose it might, if you really need the performance. I've compared
the performance slurping in large (10+ MB) files containing a long
series of maps and found edn-java to be about twice as fast as
Clojure's LispReader. (I can only speculate as to why.)

On the other hand, using clojure.core/read is far more idiomatic when
calling from Clojure and doesn't require an additional dependency.

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


I've had some success using edn

2012-09-19 Thread Ben Smith-Mannschott
I've had some success using edn on one of my little projects.

First a little background:

We're running a code generator written in Clojure which consumes
homogenous collections of Clojure maps and producing a Java enum for
each such collection. (The input data is basically 'edn' except that
all values are strings since the Excel macro exporting the input data
it too stupid to do anything more sophisticated.)

These generated enums are more than just an identity, they also carry
additional (immutable) scalar attributes. Some enums are so large in
number of members or number of attributes that we were bursting the
64KB method-size limit on the static initializer of the generated
Enum class.

To solve this problem, these additional attributes were moved out into
a separate file, from which the data was retrieved to initialize the
each enum's attributes at class loading time.

The initial solution:

The initial solution used Java serialization for this attribute
data. This had two unfortunate properties:

 1. Serialized data is not diff/merge friendly.

 2. It proved useful to repeat all the attributes and their values as
a giant comment in the generated source code. (This made the enum
less opaque for the programmer using it.)

Using EDN:

I've now completed initial work on a feature branch which uses edn for
data storage in place of serialization. I'm pleased with the results.

The 'edn' data is over twice as large as the serialized data it's
replacing, but after compression the difference is less than
50%. Initializing the enums from the approximately 6 MB of edn data
takes about twice as long as from the serialized data (0.8 versus
0.4s).

Yes, it's bigger and slower than what it's replacing, but in our case
it's sufficiently small and sufficiently fast while at the same time
addressing points 1 and 2 above. That's a win.

I'm using 0.1-SNAPSHOT of my github.com/bpms/edn-java to do the
parsing. edn-java has also benefited from seeing some real
use. Still lots more to do on that front though.


  // 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: Nested functions on #() reader

2012-09-17 Thread Ben Smith-Mannschott
On Sun, Sep 16, 2012 at 6:16 AM, vhsmaia v...@viclib.com wrote:
 Hello. I'm new here, so, not sure if those were already posted. But why is
 this not used? An example would be:
 #(%a %%b %%%c) would be the same as (fn [a] (fn [b] (fn [c] (a b c)))

My eyes! The goggles to nothing!

-- 
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: Map literal with keys generated by function cause Duplicate key exception

2012-09-12 Thread Ben Smith-Mannschott
On Thu, Sep 13, 2012 at 12:02 AM, Matthew O.  Smith m0sm...@gmail.com wrote:

 On Wednesday, September 12, 2012 8:03:58 AM UTC-6, jarppe wrote:

 I have a function that generatwed unique ID's, something like this:

   (def k (atom 0))
   (defn generate-id [] (swap! k inc))

  and I try to use it like this:

{(generate-id) foo
 (generate-id) bar}

 How ever, I get

IllegalArgumentException Duplicate key: (generate-id)
 clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)


 This works as expected.

   (let [id1 (generate-id)
 id2 (generate-id)]
 {id1 foo id2 bar})

 Should I be able to call generate-id in map literal?

 --
 -jarppe


 This also fails:

  {  (gensym) foo
 (gensym) bar }

 From the stack trace I get it looks like the reader macro that handles map
 literals is only looking at the function call, not the result of the
 function call.  This makes sense as it is the reader, not the evaluator.

Figuring out what is and what isn't a compile time constant is tricky,
huh? *headdesk*...

But, what's really going on is that you're running into a consequence
of how Clojure and other lisps work. The first thing they do is
'read', which means
converting the text of the program into data structures. Then it
evaluates those data structures as a program. Then it prints the
result. (REPL)

So, here it's building a map which contains the key a list containing
the symbol gensym twice. Clearly, that can't work.

It's only *after* the reader has done its work, and returned the map
that compilation/evaluation take place.

Consider a simpler example with a vector, which doesn't produce an
error since it's allowed to have duplicates:

(def k (atom 0))
(defn generate-id [] (swap! k inc))

Now when the reader reads this:

[(generate-id) (generate-id)]

It returns a vector containing two lists, each of which contains the
symbol generate-id.

It's only when this data structure is evaluated, that the functions
generate-id get called. In some order. I wouldn't rely on getting [1
2] and not [2 1].

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


ANN edn-java

2012-09-11 Thread Ben Smith-Mannschott
I've posted a first rough cut of an edn parser written in plain Java
here: https://github.com/bpsm/edn-java

The parser itself is Wirthian, which is to say it's a hand-written
LL(2) scanner coupled with a hand-written LL(1) recursive decent
parser. This is easy enough to do for edn's uncomplicated grammar.

The parser can be configured with custom tag handlers. Handlers from
#uuid and #inst are provided. (The handler for #inst, however, is the
kind of code no one can love and has no unit tests.) There are hooks
available to control which collections are created by [], (), #{} and
{}.

The design, package structure, naming, public interfaces -- everything
-- is still subject to change. There are probably some bugs.
Clarification of some of the open issues on
https://github.com/edn-format/edn may bring tweaks to the parser.
Javadocs are currently MIA. I'll wait with that until I'm more
confident that I've found a design I like.

Feedback welcome. Tell me what sucks about it so that I can make it better.

// 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: edn

2012-09-10 Thread Ben Smith-Mannschott
On Mon, Sep 10, 2012 at 2:15 PM, Marko Topolnik
marko.topol...@gmail.com wrote:
 Java has arrays, lists, maps and sets, so does Ruby and Erlang.

 If they were redundancies in these structures, can't see why these three
 still
 maintain this distinction. It's probably a safe bet to say that we need to
 convey these
 nuances in edn somehow.


 Let's keep this in perspective: this is not about conveying and not
 conveying. If edn had only vectors, the nuance could still be conveyed
 through a tag. This is ONLY about what gets baked in and what is left over
 to extensions.

 Take a similar example from Java: there are no list/set/map literals in it.
 Sure, you can write an API call that mimics it, but it's nowhere near as
 convenient as a native construct. So, do we want edn to support the
 list/vector distinction only through extensions? Have our data files riddled
 with #list annotations? This is a strong argument in favor of the feature
 from the Clojure folks' perspective, while on the opposite side we have a
 quite weak motivation to make the format a tiny bit simpler to parse.

Having written (most of) a recursive decent parser for edn over the
weekend, I submit that the difference in complexity introduced by
supporting both [ ] and ( ) as opposed to supporting only one of them
is not worth worrying about.

// 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: edn

2012-09-10 Thread Ben Smith-Mannschott
On Mon, Sep 10, 2012 at 5:38 PM, Rich Hickey richhic...@gmail.com wrote:
 Would you mind taking specific requests for clarification to the issues page, 
 so I don't lose track of them?

 https://github.com/richhickey/edn/issues

 Thanks,

 Rich

sure thing
// 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: edn

2012-09-09 Thread Ben Smith-Mannschott
On Fri, Sep 7, 2012 at 3:01 AM, Rich Hickey richhic...@gmail.com wrote:
 I've started to document a subset of Clojure's data format in an effort to 
 get it more widely used as a data exchange format, e.g. as an alternative to 
 JSON.

 Please have a look:

 https://github.com/richhickey/edn

 Rich

The proposed grammar for floating point numbers does not allow: 1M
since at least a frac or exp part is required following the int part.
Clojure does allow this. Is this deliberate?

// 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: edn

2012-09-09 Thread Ben Smith-Mannschott
On Fri, Sep 7, 2012 at 3:01 AM, Rich Hickey richhic...@gmail.com wrote:
 I've started to document a subset of Clojure's data format in an effort to 
 get it more widely used as a data exchange format, e.g. as an alternative to 
 JSON.

 Please have a look:

 https://github.com/richhickey/edn

 Rich

I assume that character literals are intended to be like those in
Clojure, however these are legal in Clojure:

\an actual space
\an actual newline
\an actual return
\an actual tab

I don't think it would be a good idea to support these in edn as they
are hard for a human to read unambiguously. I'd suggest requiring:

\space
\newline
\return
\tab
...

and disallowing whitespace immediately following the \ introducing a
character literal.

// 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: edn

2012-09-08 Thread Ben Smith-Mannschott
On Fri, Sep 7, 2012 at 3:01 AM, Rich Hickey richhic...@gmail.com wrote:
 I've started to document a subset of Clojure's data format in an effort to 
 get it more widely used as a data exchange format, e.g. as an alternative to 
 JSON.

 Please have a look:

 https://github.com/richhickey/edn


If - or . are the first character, the second character must be
non-numeric. Additionally, : # are allowed as constituent characters
in symbols but not as the first character.

So, is foo/-4bar allowed or not? It would seem allowed, but this has
the unfortunate property that the we're left with an unreadable symbol
if we strip the prefix: -4bar.

I follow forbidding -4bar since that means potentially unbounded
look-ahead to distinguish numbers from non-numbers.

Presumably forbidding .4bar is for the same reason, though .01
doesn't appear to be a valid numeric literal. (Numeric literals all
start with a digit.)

// 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: edn

2012-09-07 Thread Ben Smith-Mannschott
On Fri, Sep 7, 2012 at 3:01 AM, Rich Hickey richhic...@gmail.com wrote:
 I've started to document a subset of Clojure's data format in an effort to 
 get it more widely used as a data exchange format, e.g. as an alternative to 
 JSON.

 Please have a look:

 https://github.com/richhickey/edn

 Rich

A few questions or things I'm unclear on:

- The expected result of parsing { 1.0 :a, 1 :b, 1.0M :c } is unclear
to me. Since we're gonna have maps, some more information on expected
equality semantics of edn values is needed.

- nil is not a symbol. A parser seeing «(nil)» is expected to produce
a list of length one containing a single reference to nothing. The
collections used to represent the result of the parse must support
null elements (Google Guava's, for example, generally do not).

- edn is described as a textual format (sequence of characters). A
word on the expected encoding of serialized representations (sequence
of bytes) would be good. Mandate UTF-8?

- Are \u style Unicode escapes supported? In strings? elsewhere?

- Comments appear not to be supported. I know a deliberate choice was
made not to support comments as part of JSON. For use in configuration
files edited by humans, however, this is an inconvenience. Thoughts?

// 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: Found bug in contains? used with vectors.

2012-09-04 Thread Ben Smith-Mannschott
The naming of contains? is one of Clojure's small warts. Almost
everyone seems to stumble over it when they're starting out. I know I
did. Naming it contains-key? would have prevented a great deal of
confusion, but I guess that ship has sailed... *shrug*

// ben

On Tue, Sep 4, 2012 at 1:35 PM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 personally I've gotten used to it but it seems that every couple of weeks
 someone else will be confused and try to use contains? as it would be used
 in Java...the docs are clear but unfortunately not everyone consults the
 docs beforehand! at least not for such a semantically clear name as
 contains?...

 Jim


 On 04/09/12 10:01, Marcus Lindner wrote:

 I think this is not a bad idea. ;)
 At all, a method/function name should describe what it does. And if
 'contains?' only looks for keys, then 'contains-key?' would be a better
 descriptor for it.

 Am 03.09.2012 13:29, schrieb Jim - FooBar();:

 this is probably the single most confusing name in clojure! :-)
 why can't we make it contains-key? ?

 Jim

 On 03/09/12 12:14, Goldritter wrote:

 Ah ok. So I need to transform a vector and/or a list into a set first.

 Thanks.

 Am Montag, 3. September 2012 13:05:52 UTC+2 schrieb Ambrose
 Bonnaire-Sergeant:

 'contains?' tests if a key is in a collection.

 Vector is an associative data structure, with keys being indexes.
 A vector of length 3 has the key 2, but not key 3.

 Thanks,
 Ambrose

 On Mon, Sep 3, 2012 at 7:03 PM, Goldritter
 marcus.goldr...@googlemail.com wrote:

 I use Clojure 1.4.0 and wanted to use 'contains?' on a vector and get
 following results:

 = (contains? [1 2 3] 3)
 false
 = (contains? [1 2 3] 2)
 true

 As it seems 'contains?' does not check for the last entry in the vector.

 And an other question.
 Why does contains? returns everytime 'false' when used on a list?
 = (contains? (list 1 2 3) 1)
 false
 = (contains? (list 1 2 3) 2)
 false
 = (contains? (list 1 2 3) 3)
 false

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clo...@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+u...@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


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


 --
 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: screencast corruption

2012-09-02 Thread Ben Smith-Mannschott
I can't fix the version posted on blip.tv, but I downloaded it over a
year ago when it was still working.

It's a 107 MB quicktime file encoded using H.264. Running time is 1
hour 14 minutes.

I could make it available somewhere, if that would help.

// Ben

On Sun, Sep 2, 2012 at 12:37 PM, Mayank Jain firesof...@gmail.com wrote:
 Confirmed. The video is indeed broken.


 On Sun, Sep 2, 2012 at 3:34 PM, Andrew Rafas andras.ra...@gmail.com wrote:

 Hi!

 I just wanted to watch this screencast (Clojure Sequences) as I really
 need that little table which compares C#, Java and Clojure sequences.
 However the video on this link seems to be like 5 seconds long instead of
 more than an hour. Can you fix it? Or do you have the slides somewhere?
 http://blip.tv/clojure/clojure-sequences-740581

 Thanks,
 Andrew

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

-- 
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: screencast corruption

2012-09-02 Thread Ben Smith-Mannschott
You should be able to download it from here for the next few days:

https://dl.dropbox.com/u/8238674/clojure-sequences.mov

// Ben

On Sun, Sep 2, 2012 at 6:56 PM, Andrew Rafas andras.ra...@gmail.com wrote:
 I would appreciate,
 Thank you very much,
 Andrew


 On Sunday, September 2, 2012 4:19:10 PM UTC+1, bsmith.occs wrote:

 I can't fix the version posted on blip.tv, but I downloaded it over a
 year ago when it was still working.

 It's a 107 MB quicktime file encoded using H.264. Running time is 1
 hour 14 minutes.

 I could make it available somewhere, if that would help.

 // Ben

 On Sun, Sep 2, 2012 at 12:37 PM, Mayank Jain fires...@gmail.com wrote:
  Confirmed. The video is indeed broken.
 
 
  On Sun, Sep 2, 2012 at 3:34 PM, Andrew Rafas andras...@gmail.com
  wrote:
 
  Hi!
 
  I just wanted to watch this screencast (Clojure Sequences) as I really
  need that little table which compares C#, Java and Clojure sequences.
  However the video on this link seems to be like 5 seconds long instead
  of
  more than an hour. Can you fix it? Or do you have the slides somewhere?
  http://blip.tv/clojure/clojure-sequences-740581
 
  Thanks,
  Andrew
 
  --
  You received this message because you are subscribed to the Google
  Groups Clojure group.
  To post to this group, send email to clo...@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+u...@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 clo...@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+u...@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

-- 
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: Lazily extract lines from large file

2012-08-18 Thread Ben Smith-Mannschott
On Fri, Aug 17, 2012 at 10:53 PM, David Jacobs da...@wit.io wrote:
 Okay that's great. Thanks, you guys. Was read-lines only holding onto
 the head of the line seq because I bound it in the let statement?

Yea... I think so... I don't know if that's a case that the compiler's
locals clearing handles. In any event, that's why I chose to pass
the lazy sequence directly to the called function without binding it
in a let first.

// Ben

 On Fri, Aug 17, 2012 at 11:09 AM, Ben Smith-Mannschott
 bsmith.o...@gmail.com wrote:
 On Thu, Aug 16, 2012 at 11:47 PM, David Jacobs da...@wit.io wrote:
 I'm trying to grab 5 lines by their line numbers from a large ( 1GB) file
 with Clojure.

 So far I've got:

 (defn multi-nth [values indices]
   (map (partial nth values) indices))

 (defn read-lines [file indices]
   (with-open [rdr (clojure.java.io/reader file)]
 (let [lines (line-seq rdr)]
   (multi-nth lines indices

 Now, (read-lines my-file [0]) works without a problem. However, passing in
 [0 1] gives me the following error: java.lang.RuntimeException:
 java.io.IOException: Stream closed

 It seems that the stream is being closed before I can read the second line
 from the file. Interestingly, if I manually pull out a line from the file
 with something like `(nth lines 200)`, the `multi-nth` call works for all
 values = 200.

 Any idea what's going on?

 PS This question is on SO if someone wants points:
 http://stackoverflow.com/questions/11995807/lazily-extract-lines-from-large-file

 The lazyness of map is biting you. The result of read-lines will not
 have been fully realized before the file is closed.  Also, calling nth
 repeatedly is not going to do wonders for efficiency. Try this on for
 size:


 (ns nthlines.core
   (:require [clojure.java.io :as io]))

 (defn multi-nth [values indices]
   (let [matches-index? (set indices)]
 (keep-indexed #(when (matches-index? %1) %2) values)))

 (defn read-lines [file indices]
   (with-open [r (io/reader file)]
 (doall (multi-nth (line-seq r) indices

 (comment

   (def words /Users/bsmith/w/nthlines/words.txt)
   (def nlines 84918960) ;; 856MB with one word per line

   (time (read-lines words [0 1 2 (- nlines 2) (- nlines 1)]))

   ;;= Elapsed time: 18778.904 msecs
   ;;   (A a aa Zyzomys Zyzzogeton)

 )

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

-- 
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: Lazily extract lines from large file

2012-08-17 Thread Ben Smith-Mannschott
On Thu, Aug 16, 2012 at 11:47 PM, David Jacobs da...@wit.io wrote:
 I'm trying to grab 5 lines by their line numbers from a large ( 1GB) file
 with Clojure.

 So far I've got:

 (defn multi-nth [values indices]
   (map (partial nth values) indices))

 (defn read-lines [file indices]
   (with-open [rdr (clojure.java.io/reader file)]
 (let [lines (line-seq rdr)]
   (multi-nth lines indices

 Now, (read-lines my-file [0]) works without a problem. However, passing in
 [0 1] gives me the following error: java.lang.RuntimeException:
 java.io.IOException: Stream closed

 It seems that the stream is being closed before I can read the second line
 from the file. Interestingly, if I manually pull out a line from the file
 with something like `(nth lines 200)`, the `multi-nth` call works for all
 values = 200.

 Any idea what's going on?

 PS This question is on SO if someone wants points:
 http://stackoverflow.com/questions/11995807/lazily-extract-lines-from-large-file

The lazyness of map is biting you. The result of read-lines will not
have been fully realized before the file is closed.  Also, calling nth
repeatedly is not going to do wonders for efficiency. Try this on for
size:


(ns nthlines.core
  (:require [clojure.java.io :as io]))

(defn multi-nth [values indices]
  (let [matches-index? (set indices)]
(keep-indexed #(when (matches-index? %1) %2) values)))

(defn read-lines [file indices]
  (with-open [r (io/reader file)]
(doall (multi-nth (line-seq r) indices

(comment

  (def words /Users/bsmith/w/nthlines/words.txt)
  (def nlines 84918960) ;; 856MB with one word per line

  (time (read-lines words [0 1 2 (- nlines 2) (- nlines 1)]))

  ;;= Elapsed time: 18778.904 msecs
  ;;   (A a aa Zyzomys Zyzzogeton)

)

// 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: use pmap but ensure that original ordering is retained?

2012-08-11 Thread Ben Smith-Mannschott
Yes, pmap behaves as map with respect to the ordering of the elements
of the resulting sequence.

// ben

On Sat, Aug 11, 2012 at 9:29 PM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 Hi all,

 I was wondering what assumptions does pmap take with regards to the ordering
 of the resulting seq? Can I assume it retains the original ordering or does
 it just cons whatever future returns earlier? In other words can I do this
 and feel safe?
 ---

 (defn min-max [root? depth dir board]
 (if (zero? depth) (score b) ;reached bottom level - evaluate board
 (let [mapper (if root? 'pmap 'map) ;if at root-node create futures
   team   (filter #(= dir (:direction %)) board) ;all the team-mates
 (with same direction)
   successors (concat (map #(core/getMoves %) team)) ;concat all
 potential moves
   result (- successors
  (map core/try-move)  ;try them all (producing boards)
  (mapper (partial min-max false (dec depth) (- dir];pass the
 resulting boards back to recursion with direction inverted
 (get (vec successors)
   (.indexOf result (apply max result))

 (def search (partial min-max true))
 

 It seems to me like a very succinct and idiomatic way to implement the
 min-max algorithm, the only problem is this line:
 (get (vec successors)  (.indexOf result (apply max result)))

 It assumes that the initial ordering of moves ('successors') has been
 preserved  throughout the recursion and so I can use .indexOf to go from the
 score back to the move that started it all! Is this the case? I am
 suspecting not! any suggestions?

 Thanks in advance,


 Jim

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 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:

2012-07-30 Thread Ben Smith-Mannschott
On Sun, Jul 29, 2012 at 3:07 PM, John Holland jbholl...@gmail.com wrote:
 I'm doing some exercises in coding that are meant for Java but I'm doing
 them in Clojure. I'm stuck on this one. The goal is
 to return true if an array of ints contains two consecutive 2s. I figured
 I'd use Stuart Halloway's by-pairs function to turn the sequence
 into pairs of numbers and check for a pair that is 2,2.  This code in has22
 below works if pasted into the REPL and evaluated but as a
 function it always returns false. If anyone can explain my error to me it'd
 be great.







 (  defn by-pairs [coll] (let [take-pair (fn [c]
  (when (next c) (take 2 c)))]
 (when-let [pair (seq (take-pair coll))]

 (lazy-seq

 (cons pair (by-pairs (rest coll)))

 (defn has22 [a]   (if (some true? (map  #(= 2 (first %) (nth % 1)) (by-pairs
 [a]))) true false))



 user (some true? (map  #(= 2 (first %) (nth % 1)) (by-pairs [1 2 2 2 ])))
 true


 user (has22 [1 2 2 2])
 false


In an effort to increase the net amount of perversity in the universe,
I offer the following alternate solution:

(defn has22 [a]
  (- (concat [] (map str a) [])
   (interpose  )
   (apply str)
   (re-find # 2 2 )
   boolean))

;-)

// 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: Alternative to (or (:k1 m) (:k2 m))

2012-07-30 Thread Ben Smith-Mannschott
On Tue, Jul 31, 2012 at 1:08 AM, Aaron Cohen aa...@assonance.org wrote:
 On Mon, Jul 30, 2012 at 6:55 PM, Moritz Ulrich ulrich.mor...@gmail.com 
 wrote:
 (some identity ((juxt :k1 :k2) m)) is the first thing I can think of.

 For even more fun, try (some m [:k1 :k2]) :)

The flip side of this proposal is:

((some-fn :k1 :k2) m)

Which takes advantage of the fact that keywords can be called as
functions. That means it will only work for keyword keys, but the
upshot is that it will work for arbitrary functions (not just
keywords) and m need not be a map.

See also every-pred, which

-- 
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: Alternative to (or (:k1 m) (:k2 m))

2012-07-30 Thread Ben Smith-Mannschott
On Tue, Jul 31, 2012 at 7:00 AM, Ben Smith-Mannschott
bsmith.o...@gmail.com wrote:
 On Tue, Jul 31, 2012 at 1:08 AM, Aaron Cohen aa...@assonance.org wrote:
 On Mon, Jul 30, 2012 at 6:55 PM, Moritz Ulrich ulrich.mor...@gmail.com 
 wrote:
 (some identity ((juxt :k1 :k2) m)) is the first thing I can think of.

 For even more fun, try (some m [:k1 :k2]) :)

 The flip side of this proposal is:

 ((some-fn :k1 :k2) m)

 Which takes advantage of the fact that keywords can be called as
 functions. That means it will only work for keyword keys, but the
 upshot is that it will work for arbitrary functions (not just
 keywords) and m need not be a map.

 See also every-pred, which

((my new truly ergonomic keyboard is taking some getting used to -- this
is the second time I've mashed some keys and ended up sending a gmail
message earlier than intended.))

See also every-pred, which complements some-fn. Oh, and see complement
too. These three correspond to 'or', 'and' and 'not' respectively.

// 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: auxiliary methods like :before and :after for multimethods?

2012-07-28 Thread Ben Smith-Mannschott
On Fri, Jul 27, 2012 at 9:06 PM, Vinzent ru.vinz...@gmail.com wrote:
 robert-hooke actualy doesn't work with multimethods afaik. You can try my
 new library (https://github.com/dnaumov/hooks), but it's alpha (no docs yet,
 sorry).

(defmulti foo* (fn [args] ...) ...)
(defmethod foo* :x [args]...)
(defmethod foo* :y [args] ...)

(defn foo [args]
  (foo* args))

Only foo calls foo*. Everyone else calls foo. Apply hooks to foo.

http://en.wikipedia.org/wiki/Fundamental_theorem_of_software_engineering

;-)

// Ben

 Any suggestions about API is welcome.

-- 
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: seeking namespace-aware xml lib

2012-07-24 Thread Ben Smith-Mannschott
On Thu, Jul 19, 2012 at 11:00 PM, Ben Smith-Mannschott
bsmith.o...@gmail.com wrote:
 I am interested and I have a CA with Rich, but I'm currently exploring
 using XOM from Clojure. My first impression is that the API is very
 clean (as a Java API) and I appreciate its emphasis on correctness. I
 could see data.xml benefiting from some of the ideas in XOM, if only
 indirectly. In any event I need to suss out the problem space more
 thoroughly before it would make sense to hack on data.xml.

 // Ben

The first results of my experiments interfacing with XOM are on github now:

https://github.com/bpsm/xombie

It's on just started and very experimental, but there's enough there
to allow one to comfortably use core XOM functionality from Clojure.

So far, I'm quite impressed by XOM (XML Object Model). As Java APIs
go, it's quite clean and approachable. Just be aware that a XOM is
*not* persistent. It's a rampant nest of mutability, as one would
expect from any idiomatic Java API. ;-) That said, I'm convinced it's
possible to use it tastefully so as not to be unduly impacted by this.

// 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: seeking namespace-aware xml lib

2012-07-19 Thread Ben Smith-Mannschott
I am interested and I have a CA with Rich, but I'm currently exploring
using XOM from Clojure. My first impression is that the API is very
clean (as a Java API) and I appreciate its emphasis on correctness. I
could see data.xml benefiting from some of the ideas in XOM, if only
indirectly. In any event I need to suss out the problem space more
thoroughly before it would make sense to hack on data.xml.

// Ben

On Tue, Jul 17, 2012 at 4:03 PM, Ryan Senior senior.r...@gmail.com wrote:
 Solid namespace support is a much needed feature for data.xml.  There's a
 ticket for it here: http://dev.clojure.org/jira/browse/DXML-4 though
 unfortunately the patch attached to it came from someone who hadn't signed a
 CA, so I was not able to accept it.

 I am planning on tackling namespace support soon, but would welcome help if
 you're interested (and have signed a CA).

 -Ryan

 On Mon, Jul 16, 2012 at 2:53 PM, Ben Smith-Mannschott
 bsmith.o...@gmail.com wrote:

 TL;DR: I'm looking for a Clojure library that round trips XML+namespaces
 through Clojure data structures and back again.


 I'm hacking on a chewing-gum-and-bailing-wire solution publish my wife's
 novels as EPUB.  I've got most of a prototype of the core functionality
 working, but an stubbing my toe an a lack of what  would consider
 sufficient XML support in the Clojure universe.

 I'm consuming Apple Pages (heavily namespaced XML) and will need to
 produce XML Plist, XHTML, OPF and NCX, all of which are namespaced as
 well.

 My first prototype parser for Pages documents used clojure.xml and
 works, provided Apple never changes the prefixes they use for the
 various namespaces the crop up in a Pages document. This is because
 clojure.xml is absolutely namespace ignorant. Also, there doesn't seem
 to be a way to write clojure.xml out as literal XML.

 I'm in the process of switching to clojure.data.xml, but have discovered
 that it parses namespace aware by default, but only uses this in order
 to have a simple way to ignore namespace information without getting
 confused by spurious namespace prefixes.

 That would be fine for parsing the Pages document, but it's a
 non-starter for producing my output files since these require the use of
 namespaces.

 I've looked at hiccup, which would solve my HTML production problem,
 save for the fact that it produces XHTML 1.0 while my current
 half-manual publishing process uses XHTML 1.1. I expect either version
 would work, but that still leaves me without a solution for Plist, OPF
 and NCX.


 What are my best options? Am I overlooking a Clojure library that
 already does what I need? I could try to teach data.xml to support XML
 namespaces, but the current half-hearted hack which conflates Clojure
 namespaces with XML namespaces would have to go, I fear. I could instead
 put my time into extending hiccup to support XML more generally, or at
 least provide explicit support for NCX, OPF and PList. Should I just
 write my own library? Maybe I could build atop XOM so as not to reinvent
 the heavy lifting.

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

-- 
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: Much longer build time for Clojure on HDD vs. SSD (4 min vs 30s)

2012-07-16 Thread Ben Smith-Mannschott
On Mon, Jul 16, 2012 at 5:21 PM, Raju Bitter rajubit...@googlemail.com wrote:
 I've checked out the Clojure source code, and build the JAR using the
 Ant command. I'm seeing a strange effect, where the compile time on my
 normal hard disk takes almost 4 min (with most the time being spent in
 the compile-clojure task, and doing the same build process on my SSD
 taking 30-35s.

 I've never seen any similar behavior on my machine, normally build
 processes take 10% more when they run on the HDD vs. the SSD. Has
 anyone else experienced the same effect? How long does it take to run
 the ant build on your machines?

 Thanks,
 Raju

I believe this is related to an oddity of the clojure compiler: it
syncs every time it writes a class file to disk. This appears to be
necessary for reasons that escape me. (One might naively assume that a
simple flush() would be enough; but that was not so when I stumbled
across this myself a year or so ago.)

In any event, it does not surprise me in the least that a storm of
sync calls would cause a mechanical hard disk to grovel a bit, while
presenting

-- 
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: Much longer build time for Clojure on HDD vs. SSD (4 min vs 30s)

2012-07-16 Thread Ben Smith-Mannschott
On Mon, Jul 16, 2012 at 9:17 PM, Ben Smith-Mannschott
bsmith.o...@gmail.com wrote:
 On Mon, Jul 16, 2012 at 5:21 PM, Raju Bitter rajubit...@googlemail.com 
 wrote:
 I've checked out the Clojure source code, and build the JAR using the
 Ant command. I'm seeing a strange effect, where the compile time on my
 normal hard disk takes almost 4 min (with most the time being spent in
 the compile-clojure task, and doing the same build process on my SSD
 taking 30-35s.

 I've never seen any similar behavior on my machine, normally build
 processes take 10% more when they run on the HDD vs. the SSD. Has
 anyone else experienced the same effect? How long does it take to run
 the ant build on your machines?

 Thanks,
 Raju

 I believe this is related to an oddity of the clojure compiler: it
 syncs every time it writes a class file to disk. This appears to be
 necessary for reasons that escape me. (One might naively assume that a
 simple flush() would be enough; but that was not so when I stumbled
 across this myself a year or so ago.)

 In any event, it does not surprise me in the least that a storm of
 sync calls would cause a mechanical hard disk to grovel a bit, while
 presenting

(new keyboard, sorry)

... while presenting little difficulty for an SSD.


static public void writeClassFile(String internalName, byte[]
bytecode) throws IOException{

... skip a bit, brother ...

try
{
cfs.write(bytecode);
cfs.flush();
cfs.getFD().sync(); // --
}
finally
{
cfs.close();
}
}

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


seeking namespace-aware xml lib

2012-07-16 Thread Ben Smith-Mannschott
TL;DR: I'm looking for a Clojure library that round trips XML+namespaces
through Clojure data structures and back again.


I'm hacking on a chewing-gum-and-bailing-wire solution publish my wife's
novels as EPUB.  I've got most of a prototype of the core functionality
working, but an stubbing my toe an a lack of what  would consider
sufficient XML support in the Clojure universe.

I'm consuming Apple Pages (heavily namespaced XML) and will need to
produce XML Plist, XHTML, OPF and NCX, all of which are namespaced as
well.

My first prototype parser for Pages documents used clojure.xml and
works, provided Apple never changes the prefixes they use for the
various namespaces the crop up in a Pages document. This is because
clojure.xml is absolutely namespace ignorant. Also, there doesn't seem
to be a way to write clojure.xml out as literal XML.

I'm in the process of switching to clojure.data.xml, but have discovered
that it parses namespace aware by default, but only uses this in order
to have a simple way to ignore namespace information without getting
confused by spurious namespace prefixes.

That would be fine for parsing the Pages document, but it's a
non-starter for producing my output files since these require the use of
namespaces.

I've looked at hiccup, which would solve my HTML production problem,
save for the fact that it produces XHTML 1.0 while my current
half-manual publishing process uses XHTML 1.1. I expect either version
would work, but that still leaves me without a solution for Plist, OPF
and NCX.


What are my best options? Am I overlooking a Clojure library that
already does what I need? I could try to teach data.xml to support XML
namespaces, but the current half-hearted hack which conflates Clojure
namespaces with XML namespaces would have to go, I fear. I could instead
put my time into extending hiccup to support XML more generally, or at
least provide explicit support for NCX, OPF and PList. Should I just
write my own library? Maybe I could build atop XOM so as not to reinvent
the heavy lifting.

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


ANN Big Ivan 0.1.0: BIC/IBAN parser, validator and constructor

2012-07-01 Thread Ben Smith-Mannschott
Big Ivan teaches Clojure how to parse, validate and construct BIC
and IBAN strings. (BIC and IBAN are both structured identifiers used
in banking.)

http://github.com/bpsm/big-ivan
http://bpsm.github.com/big-ivan/index.html
https://clojars.org/org.clojars.bpsm/big-ivan

As libraries go, it's a tiny little thing. Hardly worth mentioning,
really. Any one of you could probably hack it together in a
weekend. But, now you don't have to.

It's distributed under the Eclipse Public License, the same as Clojure.

-- 
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: defpartial returns object instead of html string

2012-06-22 Thread Ben Smith-Mannschott
str

On Fri, Jun 22, 2012 at 11:58 AM, Murtaza Husain
murtaza.hus...@sevenolives.com wrote:

 Hi,

 I am using Chris Ganger's crate library to generate html on the client side.


     (defpartial html [] form)

     (def form
   [:div.form-horizontal
    [:fieldset
     [:legend Student Registeration]
     [:div.control-group
  [:label.control-label Hello World]]])

 When I execute the above function in clojurescript repl as - (html) - I get
 - #[object HTMLDivElement].

 However when I execute it as (.log js/console (html)), the proper generated
 html is logged into the browser's console.

 How do I get it to return a HTML string instead of an object?

 Thanks,
 Murtaza

 --
 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: fully type-hinted record still uses reflection!

2012-06-10 Thread Ben Smith-Mannschott
On Sun, Jun 10, 2012 at 7:04 PM, Jim - FooBar(); jimpil1...@gmail.com wrote:
 Hi again (busy day eh?),

 well this doesn't make any sense either! Why is a record with  type-hinted
 arguments still using reflection?
 I've got the following example record:
 --
 (defrecord CheckersPiece [^java.awt.Color color
                                           ^java.awt.Point position
                                              rank]
  Piece
  (update-position [this np] ;mutable state inside Point!
   (. position setLocation  ;can accept ints or doubles
     (first np) (second np))) ;np should be [x, y]

can accept ints or doubles

How is the Clojure compiler to know wether to compile a call to
Point.setLocation(double,double) or Point.setLocation(int,int)?

I think you need to tell the compiler the types of (first np) and
(second np), which means -- of course -- that you'll need to know
what they are statically.

I'm a little rusty on my type hinting, but have you tried something
like:

(.position setLocation ^double (first np) ^double (second np))
or
(.position setLocation ^int (first np) ^int (second np))

// ben

  (die     [this] (vary-meta this assoc :dead true)) ;communicate death
 through meta-data
  (promote [this] (make-checker color position :rank 'prince)) ; a checker is
 promoted to prince
  (getGridPosition [this] (vector (.getX position) (.getY position)))
  (getListPosition [this] (translate-position  (first  (.getGridPosition
 this))
                                              (second (.getGridPosition
 this)) board-mappings-checkers))
  (getPoint [this] position)
  (getMoves [this] nil) ;TODO
  Object
  (toString [this]
   (println Checker ( rank ) at position: (.getListPosition this)  -
 (.getGridPosition this))) )
 ---
 and whenever i call update-position it complains that setLocation cannot be
 resolved. setLocation is a method in java.awt.Point so i don't see why this
 happens!

 any suggestions?

 Jim

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 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: Clojurians in Austria

2012-05-29 Thread Ben Smith-Mannschott
I too am in Vienna. I use Clojure at work for a few small internal
tools, but not in production. I'd be glad to meet some other
Clojurists.

// Ben

On Tue, May 29, 2012 at 5:05 PM, Nuno Marques
nuno.filipe.marq...@gmail.com wrote:
 I'm in Vienna and I know a couple of more Clojure people here.
 I would be happy to help start a clojure group here.

 On May 29, 2012, at 4:40 PM, Florian Over wrote:

 Hi
 i met a nice guy (David from intermaps.com) from Vienna on EuroClojure.
 He mentioned that there are other Clojure-User in Vienna as well.
 But no UserGroup right now.

 Maybe you can start irc clojure-at ?

 Florian

 2012/5/29 Jozef Wagner jozef.wag...@gmail.com:
 Hi,

 Are there some Clojurians from Austria or is there an Austria Clojure
 group?

 I'm looking for a Clojure related job in Austria, and so far I haven't found
 any Austrian group on meetup.com nor on the google groups :(

 Best,
 Jozef

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

 --
 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: Converting project.clj to maven's pom.xml

2012-04-20 Thread Ben Smith-Mannschott
lein pom may not do all you need. It depends on what you are trying
to accomplish.

It will generate a pom.xml which identifies your project (artifactId,
groupId, version, packaging) and lists its dependencies. This pom is
suitable for publishing your artifacts to some Maven repository for
others to consume. (That appears to be stated purpose of 'lein pom':
Write a pom.xml file to disk for Maven interoperability.)

It does't configure clojure-maven-plugin, so executing 'mvn package'
with the resulting pom will not produce a useful result.

// ben

On Fri, Apr 20, 2012 at 21:19, Timothy Baldridge tbaldri...@gmail.com wrote:
 Try

 lein pom

 On Apr 20, 2012 1:29 PM, Murtaza Husain murtaza.hus...@sevenolives.com
 wrote:

 Hi,

 Is there any way to convert project.clj to pom.xml.

 I was looking at jelastic which is a cloud provider for java, and they
 allow deploying projects from git repos which are compatible with maven 3.
 It will download the code and build it based on the maven config.

 Anyway we can leverage that?

 Thanks,
 Murtaza

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

-- 
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: Alternate set literal syntax?

2012-03-25 Thread Ben Smith-Mannschott
On Sat, Mar 24, 2012 at 04:44, Cedric Greevey cgree...@gmail.com wrote:
 #{foo bar baz} is somewhat ugly. It occurs to me that one could modify
 the reader to additionally accept

 {{foo bar baz}}

 without breaking anything. It's not possible for it to be a valid map
 literal, because the outer {...} pair has only one object inside it
 and a map literal requires an even number of objects (zero, two, four
 ...), so right now {{foo bar baz}} will just throw a
 CompilerException, and so will {{foo bar baz quux}} even though the
 inner {...} pair then has an even number of objects. Making the reader
 treat that as a set literal is therefore a purely additive change.

 It's one character longer than #{foo bar baz} but it looks nicer, IMO,
 and still shows the cousin-ship between sets and maps by using the
 same choice among {}, [], ().

I'd encourage you to have a look at LispReader.java [1], paying
particular attention to how macros[] and dispatchMacros[] are used
internally. Basically, the reader dispatches to a specialized
sub-reader based on the first character of what it reads. This gives
the reader a nice modularity while also allowing the reader to convert
a characters to data in a single pass. This has real advantages, but
arbitrary syntax tricks like {{ foo bar }} don't fit well into this
world.

[1] 
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java

I guess what I'm saying is that there is a deeper mechanism behind
what may seem to you like arbitrary syntactic noise. #{...} #(...)
etc.  Your proposal is unlikely to garner much support if you're not
able to formulate an argument that appreciates the complexity
trade-offs it implies. (Say, a far more complex Reader.)

One of the nice things about Lisps is that their written
representation as data is uncomplicated to parse. Don't be too quick
to throw that away.

// 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: [beginner] library for java code generation

2012-03-23 Thread Ben Smith-Mannschott
On Fri, Mar 23, 2012 at 14:22, Alex Shabanov avshaba...@gmail.com wrote:
 Hi all,

 Is there any easy-to-use library for generating java code?
 I ended up writing simple function that takes strings and characters
 and prints them in formatted form (e.g. with tabs and newlines after
 braces).
 I really like compojure approach to build html page - is there any
 similar libraries exist for arbitrary code generation?

I've also looked for, but not found such a library.

I wrote a tool in Clojure which generates Java 5 enumerations from
data. The templating solution I settled on was to do this:

A template is a function which returns a template-result.
A template-result is a sequence of atoms and template-results.
An atom is a string, number, boolean, java.lang.Class, keyword, symbol or nil.

The result of running my code generator is thus a tree of atoms, which
I then flatten, remove the nils, and then convert the atoms:
- strings are just themselves
- keywords and symbols are their names
- java.lang.Class objects are the fully qualified name of the class
- booleans and numbers become java literals
Then concatenate the resulting strings.

It's odd, but it works, and has the advantage that templates
(functions) need not have side-effects and can be composed in
interesting ways.

e.g. (rough sketch):

(defn declare-field [name value]
  [public final  (unbox (class value))   name  =  value ;])

(defn declare-fields [name-val]
  (interpose \n
(map delare-field (keys name-val) (vals name-val

(template-result-string
  (declare-fields {:aNumber 1, :aBoolean false}))

Would produce something like:

  public final long aNumber = 1;
  public final boolean aBoolean = false;

This works OK for me, but it's really just a step up from raw printfs.
It doesn't understand anything about java syntax, so, handling
indentation -- for example -- is ad-hoc and brittle.

// 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: Creating map from string

2012-03-19 Thread Ben Smith-Mannschott
On Sun, Mar 18, 2012 at 21:04, Jimmy jimmy.co...@gmail.com wrote:
 Hi,

 I would like to generate a hashmap from a string. The key portions of
 the string  will have some a prefix such as @ to define that they are
 a key. So the following string

 @key1  this is a value  @another-key  and another value @test1 and
 other value

 would get converted to.

 { :@key1  this is a value,  :@another-key  and another
 value ,  :@test1 and other value}

 What's the best way to do this?
 Thanks,
 Jimmy

Things to think about when designing an ad-hoc format:

- How are you handling white space?

Your example seems to indicate that any amount of white space is
allowed and ignored between key and value or value and key, but white
space internal to the value is preserved. I suppose keys will never
contain white space since that's not expressible as the first bit of
white space following the key marks the transition to value.

- Values can't be empty, consist of, start with or end with white space.

- Values can't contain @ unless you provide some kind of escaping convention.

// 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: how to get font-lock to work in swank repl buffer

2012-01-20 Thread Ben Smith-Mannschott
On Fri, Jan 20, 2012 at 00:45, Jack Moffitt j...@metajack.im wrote:
 (add-hook 'slime-repl-mode-hook
               (lambda ()
                 (clojure-mode-font-lock-setup)
                 (font-lock-mode)
                 (font-lock-mode)))

Excellent! This worked for me.

Many thanks for the tip.

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


how to get font-lock to work in swank repl buffer

2012-01-19 Thread Ben Smith-Mannschott
I'm trying to get syntax highlighting (font-lock) to work in the
repl buffer provided by slime as described here:
https://github.com/technomancy/swank-clojure

(add-hook 'slime-repl-mode-hook
  (defun clojure-mode-slime-font-lock ()
(let (font-lock-mode)
  (clojure-mode-font-lock-setup

The results are not visibly different from having not added this
slime-repl-mode-hook.

Once the repl buffer is open, I can get font-lock to work by
doing this manually:

M-x clojure-mode-font-lock-setup
M-x font-lock-mode (turning it off)
M-x font-lock-mode (turning it back on)

What am I misunderstanding?

I'm running:

 - Emacs 24.0.91.1
 - clojure-mode 1.11.5
 - slime 20100404.1
 - slime-repl 20100404
 - clojure 1.3.0
 - clojure-maven-plugin 1.3.8
 - swank-clojure 1.3.4

Incidentally, what's with this strange form of let?

  (let (font-lock-mode) ;; - shouldn't this bind variables?
(clojure-mode-font-lock-setup))

// 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: Help! Migrating to 1.3.0

2012-01-15 Thread Ben Smith-Mannschott
On Sun, Jan 15, 2012 at 01:37, James Reeves jree...@weavejester.com wrote:
 On 14 January 2012 23:34, myriam abramson labwor...@gmail.com wrote:
 I couldn't find quite the equivalent to read-lines from duck-streams. I
 found read-line but it's not the same. Where is the equivalent read-lines
 outside of clojure.contrib?

 There's clojure.core/line-seq, but it doesn't close the reader when
 the seq finishes.

That's true; You're expected to scope this yourself:

(with-open [reader (something-that-produces-a-buffered-reader)]
(something-that-consumes-line-sequence (line-seq reader)))

If you can't structure the computation this way because you're not
sure when or if you'll be consuming the sequence produced by line-seq,
then this becomes a hard problem.

// 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: Help! Migrating to 1.3.0

2012-01-13 Thread Ben Smith-Mannschott
On Fri, Jan 13, 2012 at 17:47,  labwor...@gmail.com wrote:
 I have a few issues. What do the following warnings mean and what should I
 do about them?

Did you read them?

*default-encoding* not declared dynamic and thus is not dynamically rebindable

;; wont' work:
(binding [*default-encoding* some-value]
  (do-something-that-uses *default-encoding*))

but it's name suggests otherwise

*ear-muffs* are lisp convention for dynamically bindable
global variable names. Using that convention is misleading
if the variable isn't actually dynamically bindable.

Please either indicate ^:dynamic *buffer-size*

(def ^:dynamic *buffer-size ...)

Starting with Clojure 1.3, you need to declare when a variable should
be dynamically bindable. This is because performance is better for
vars that are not dynamically bindable, so you are encouraged to use
^:dynamic only where it's actually needed.

or change the name.

If you're not (binding [...]) the var in question rename it.

// 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: Destructuring syntax

2012-01-04 Thread Ben Smith-Mannschott
On Wed, Jan 4, 2012 at 07:36, Johnny Weng Luu johnny.weng@gmail.com wrote:
 One thing that seems weird is the way Clojure destructures a map

 I have this map: {:last-name Vinge :first-name Vernor} which is passed
 to this function: (defn greet-author-2 [{fname :first-name}] ... )

 Wouldn't it be better doing: (defn greet-author-2 [{:first-name fname}] ...
 )

 You first type the keyword, then followed by the parameter to bind to. It
 reads that the value is bound to the parameter in the same place.

 Feels more natural to me in a way.

 Thoughts?

Doesn't make sense that way around. Remember that in a map, the key is
unique, but the value need not be. Remember that in a Lisp this isn't
just a question of arbitrary syntax. The code you write is always also
a data structure.

With the current solution I can write this, which while not obviously
useful at least has an obvious meaning:

(let [{name1 :name name2 :name} {:name a}]
  (= name1 name2))

Your proposal would seem to allow this:

(let [{:first-name name :last-name name} {:last-name last
:first-name first}]
  (= name ???))

It's not clear what this would mean.

It would also make it impossible to bind the value for a given key to
more than one variable, since map keys must be unique:

(let [{:name name1 :name name2} {:name a}]
  ;; boom? )

// 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: Where is ltrim?

2012-01-03 Thread Ben Smith-Mannschott
On Tue, Jan 3, 2012 at 16:09, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 03.01.2012 um 12:16 schrieb Cedric Greevey:

 Breaking changes are bad enough without making some of them
 gratuitous. They could have just renamed the namespace without also
 renaming some of the individual functions. :)

 One could also argue the other way around: When we break things already, we 
 can break it really hard and also clean up inconsistent naming of functions 
 and such. Then you have the pain of a breaking change only once.

 That said: I don't know whether considerations like this were the case here.


I think you'll find that the trim/triml/trimr naming came from thread
review the clojure.string code from between 2010-05-30 and
2010-06-03. The trimr/triml/trim naming has the nice property of
clustering the three functions together in documentation (which tends
to be sorted by name).

// 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: why would this statement java -server ???

2011-12-15 Thread Ben Smith-Mannschott
On Fri, Dec 16, 2011 at 05:48, jayvandal s...@ida.net wrote:
 I was looking at the installation in Learning clojure and the batch
 file had this statement:

  java -server -cp .;%CLOJURE_JAR% clojure.main

     why is  the server in the line and what is it referencing???
 Thanks for any help

The Java virtual machine (JVM) can run either in client or server
mode. The server virtual machine's just in time (JIT) compiler
generates better performing machine code. The down side is that
startup is slower (generating better code is more work), but
performance after startup is better (better code runs faster). The
byte code Clojure translates to benefits considerably from the
optimizations offered by the server virtual machine.

Here's a picture:

Clojure source -(Clojure compiler)- JVM byte code -(JIT Compiler)-
Machine code

java -server makes -(JIT Compiler)- do more work to generate
better machine code.

// 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: Surprising behavior with clojure.core/int (and probably other primitive integer functions)

2011-12-07 Thread Ben Smith-Mannschott
Would it help to have a naming convention for Clojure to distinguish
compile-time flags from normal dynamic vars?  // ben

On Tue, Dec 6, 2011 at 17:05, David Nolen dnolen.li...@gmail.com wrote:
 *unchecked-math* is a compiler flag.

 On Tue, Dec 6, 2011 at 7:00 AM, Cedric Greevey cgree...@gmail.com wrote:

 user= (binding [*unchecked-math* true] (map int [33 77 0x]))
 #IllegalArgumentException java.lang.IllegalArgumentException: Value out
 of range for int: 4294967295

 The cause of this:

 (defn int
   Coerce to int
   {
    :inline (fn  [x] `(. clojure.lang.RT (~(if *unchecked-math*
 'uncheckedIntCast 'intCast) ~x)))
    :added 1.0}
   [x] (. clojure.lang.RT (intCast x)))

 The inline and non-inline version don't coincide -- the non-inline version
 lacks the check for *unchecked-math*.

 On top of that, the inline version sort-of doesn't work anyway --
 specifically, it doesn't work if you do the obvious:

 user= (binding [*unchecked-math* true] (int 0x))
 #IllegalArgumentException java.lang.IllegalArgumentException: Value out
 of range for int: 4294967295
 user= (defn foo [] (binding [*unchecked-math* true] (int 0x)))
 #'user/foo
 user= (foo)
 #IllegalArgumentException java.lang.IllegalArgumentException: Value out
 of range for int: 4294967295

 The problem there is apparently that it checks *unchecked-math* at
 macroexpansion time, and of course binding it at runtime to do some
 unchecked math therefore binds it too late to influence the int function.

 If this is intentional, to avoid expensive runtime checks of dynamic Vars,
 then there are two additional problems.

 First, there's the apparent lack of an unchecked-int function, or similar,
 that either is unchecked or checks *unchecked-math* at runtime, for those
 who want dynamic behavior even if there's a cost.

 Without this, there's no way to get unchecked int casts in map and other
 HOFs short of ugly hacks like #(int %) or #(clojure.lang.RT/uncheckedIntCast
 %).

 Another use case would be when using ints not for speed but because you
 want a 32-bit wraparound integer for some other purpose, such as talking to
 I/O devices or legacy file formats that want such things, or to implement
 certain algorithms that rely heavily on wraparound and bit arithmetic in a
 relatively speed-insensitive context, likely where I/O is the bottleneck.

 Furthermore, though (do (set! *unchecked-math* true) (println (int
 0x)) (set! *unchecked-math* false)) works, it is ugly as sin and
 set! is (usually) evil.

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

-- 
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-16 Thread Ben Smith-Mannschott
On Wed, Nov 16, 2011 at 17:28, Ben Mabey b...@benmabey.com 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

Here's an approach that may be of use: don't store the metadata in a
Map instead of decorating the Object with it. This map should use
object identity, not equality and should hold its keys weakly so that
it prevent collection of  objects that otherwise would be garbage.
Safe to use concurrently would also be a plus. Conveniently, Google's
Guava library provides such a thing. Here's a sketch:

== project.clj 

(defproject pojometa 0.0.1-SNAPSHOT
  :dependencies [[org.clojure/clojure 1.3.0]
 [com.google.guava/guava 10.0.1]])

== src/pojometa/core.clj ==

(ns pojometa.core
(:import [com.google.common.collect MapMaker]))

(def meta-map
(- (MapMaker.) .weakKeys .makeMap))

(defn meta* [o]
(if (instance? clojure.lang.IMeta o)
(clojure.core/meta o)
(.get meta-map o)))

(defn with-meta* [o m]
(if (instance? clojure.lang.IMeta o)
(clojure.core/with-meta o m)
(do (.put meta-map o m)
o)))

== usage ==

pojometa.core= (def o (Object.)) ;; arbitrary java object
pojometa.core= (meta* (with-meta* o {:foo true}))
{:foo true}

;; also does the right thing for Clojure types that
;; already know how to have metadata.

pojometa.core= (meta* (with-meta* {} {:bar 1}))
{:bar 1}

== END

Hope that helps,
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: adding metadata to java objects

2011-11-16 Thread Ben Smith-Mannschott
On Wed, Nov 16, 2011 at 22:32, Alan Malloy a...@malloys.org wrote:
 On Nov 16, 11:53 am, Ben Smith-Mannschott bsmith.o...@gmail.com
 wrote:
 On Wed, Nov 16, 2011 at 17:28, Ben Mabey b...@benmabey.com 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

 Here's an approach that may be of use: don't store the metadata in a
 Map instead of decorating the Object with it. This map should use
 object identity, not equality and should hold its keys weakly so that
 it prevent collection of  objects that otherwise would be garbage.
 Safe to use concurrently would also be a plus. Conveniently, Google's
 Guava library provides such a thing. Here's a sketch:

 == project.clj 

 (defproject pojometa 0.0.1-SNAPSHOT
   :dependencies [[org.clojure/clojure 1.3.0]
                  [com.google.guava/guava 10.0.1]])

 == src/pojometa/core.clj ==

 (ns pojometa.core
     (:import [com.google.common.collect MapMaker]))

 (def meta-map
     (- (MapMaker.) .weakKeys .makeMap))

 (defn meta* [o]
     (if (instance? clojure.lang.IMeta o)
         (clojure.core/meta o)
         (.get meta-map o)))

 (defn with-meta* [o m]
     (if (instance? clojure.lang.IMeta o)
         (clojure.core/with-meta o m)
         (do (.put meta-map o m)
             o)))

 == usage ==

 pojometa.core= (def o (Object.)) ;; arbitrary java object
 pojometa.core= (meta* (with-meta* o {:foo true}))
 {:foo true}

 ;; also does the right thing for Clojure types that
 ;; already know how to have metadata.

 pojometa.core= (meta* (with-meta* {} {:bar 1}))
 {:bar 1}

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

// 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: Non Dev Builds

2011-11-16 Thread Ben Smith-Mannschott
== FILE ==
(def x 1) NEWLINE
; my comment
==

(str '( (slurp FILE) ) )

produces:

==
'((def x 1) NEWLINE
; my comment)
==

oops.


On Thu, Nov 17, 2011 at 05:32, Andres Gomez and...@fractalmedia.mx wrote:
 Thanks for the robustness tip, Meikel.

 Just a question, i dont understand what you state, i dont think it
 needs to end in a newline in order to work.

 On Nov 16, 5:17 pm, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 16.11.2011 um 17:17 schrieb Andres Gomez:

  It is very simple, its most important function is: (defn read-file
  [name] (eval (read-string (str '( (slurp name) )

 As a minor nitpick to promote robust code… Please use something like this 
 for reading:

 (let [eof (Object.)] (take-while (complement #{eof}) (repeatedly #(read 
 file-reader false eof

 (str ( ...) is so ugly and fragile. There are many files which do not end 
 in a newline. And if the last line is a comment…

 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


-- 
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-15 Thread Ben Smith-Mannschott
On Wed, Nov 16, 2011 at 02:16, thenwithexpandedwingshesteershisflight
mathn...@gmail.com 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-15 Thread Ben Smith-Mannschott
On Wed, Nov 16, 2011 at 02:16, thenwithexpandedwingshesteershisflight
mathn...@gmail.com wrote:
 Can we please get bored of saying idiomatic and in particular
 please ?

It's quite useful to be able to talk about
the-way-of-expressing-this-concept-most-in-keeping-with-established-practice
(idiomatic), particularly when a language still sees plenty of
newcomers.

The Python community, found a way around the problem you seem to be
having by inventing their own word: pythonic. Do I hear any votes for
clojuresque?

Ok, I think I've spent my smart-a$$ quota for the day,

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: Can't dynamically bind non-dynamic var

2011-11-12 Thread Ben Smith-Mannschott
On Sat, Nov 12, 2011 at 18:37, Kevin Albrecht onlya...@gmail.com wrote:
 I was experimenting with dynamic binding of vars with Clojure 1.3, as
 described on  http://clojure.org/vars and got this error:
 user= (def x 1)
 user= (binding [x 2] x)
 IllegalStateException Can't dynamically bind non-dynamic var: clojure.core/x
 clojure.lang.Var.pushThreadBindings
 I figured out the solution to this on a blog
 entry: http://blog.japila.pl/2011/03/cant-dynamically-bind-non-dynamic-var-in-clojure-1-3/ (use
 ^:dynamic when defining x)
 Is this new feature documented anywhere in the official documentation?

You'll find it here:

https://github.com/clojure/clojure/blob/master/changes.md

under the heading Earmuffed Vars Are No Longer Automatically
Considered Dynamic

// 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: Access to unzipped assets within jars

2011-11-05 Thread Ben Smith-Mannschott
On Sat, Nov 5, 2011 at 14:42, Sam Aaron samaa...@gmail.com wrote:
 Hi there,

 consider there exists foo.jar on Clojars which contains a bunch of asset 
 files i.e. png images. If I were to declare foo as one of my project's 
 dependencies, is it possible to get access to those asset files? I 
 essentially want a path to a non-zipped version of each asset.

These kinds of assets are known as resources in java parlance. A
resource is named by a path relative to an entry in the classpath.
Declaring foo as a dependency will place it in the classpath. The name
of the resource will therefore be the path of the asset within
foo.jar.

Give clojure.java.io/resource [1] that name, and it will return a URL.

Pass that URL to clojure.java.io/input-stream [2] to open the resource
for reading.

[1] 
http://clojure.github.com/clojure/clojure.java.io-api.html#clojure.java.io/resource

[2] 
http://clojure.github.com/clojure/clojure.java.io-api.html#clojure.java.io/input-stream

hth,
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: Any reason interleave needs 2 or more collections?

2011-11-03 Thread Ben Smith-Mannschott
On Thu, Nov 3, 2011 at 03:14, Alex Baranosky
alexander.barano...@gmail.com wrote:
 What a coincidence. My instinct would be to make (interleave) return an
 empty seq, instead of nil. I wonder the trade-offs between the two?

There is no such thing as an empty seq. Or put another way, the empty
seq *is* nil. You're probably thinking of an empty list.

;the empty list
user (list)
()

;the empty seq
user (seq (list))
nil

Returning nil has the advantage that nil is false in a boolean context.

(when-let [s (apply interleave ...)] ... )

// 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: Any reason interleave needs 2 or more collections?

2011-11-03 Thread Ben Smith-Mannschott
On Thu, Nov 3, 2011 at 13:13, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 03.11.2011 um 12:18 schrieb Ben Smith-Mannschott:

 There is no such thing as an empty seq. Or put another way, the empty
 seq *is* nil. You're probably thinking of an empty list.

 while this is true, the following is dangerous

 Returning nil has the advantage that nil is false in a boolean context.

 (when-let [s (apply interleave ...)] ... )

 The input sequences to interleave might be all nil. Since interleave is also 
 lazy, you have to put a seq around the apply when you use it in a when-let.

You're quite right. I'd overlooked that.

 Whether (interleave) returns nil or () is not really important, since you 
 have to call seq on it anyway. I'd probably prefer nil. My general approach 
 is to be as lazy as possible, but only if necessary. (interleave) can judge 
 immediately that it will never ever need laziness, because there are no 
 inputs. So it can return nil immediately. Maybe a matter of taste.

 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

-- 
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.core/max and NaN

2011-11-01 Thread Ben Smith-Mannschott
I've opened http://dev.clojure.org/jira/browse/CLJ-868

The min and max functions in clojure.core behave unpredictably when
one or more of their arguments is Float/NaN or Double/NaN. This is
because the current implementation assumes that  provides a total
ordering, but this is not the case when NaN is added to the mix. This
is an unfortunate fact of life when dealing with IEEE floating point
numbers.

It seems to me that there are four approaches one might take to
address this.

1. Document the current undefined behavior of min and max in the
   presence of NaN.
2. Define that min and max will return NaN if any argument is NaN.
3. Define that min and max will ignore any NaN arguments.
4. Define that min and max will throw an exception if any argument is NaN.

1 Document current behavior as undefined


This requires no changes in the implementation, but it doesn't strike
me as a desirable resolution. Why unnecessarily codify clearly
confusing behavior?

2 Make NaN contagious
-

Define min and max to return NaN if and only if at least one of their
arguments is NaN. This seems most in keeping with the (admittedly
perverse) behavior of NaN as specified.

See JLS 4.2.4 Floating Point Operations:

# An operation that overflows produces a signed infinity, an operation
# that underflows produces a denormalized value or a signed zero, and
# an operation that has no mathematically definite result produces
# NaN. All numeric operations with NaN as an operand produce NaN as a
# result. As has already been described, NaN is unordered, so a
# numeric comparison operation involving one or two NaNs returns false
# and any != comparison involving NaN returns true, including x!=x
# when x is NaN.

3 Let min and max ignore NaN arguments
--

This means that (min a NaN b) would be exactly equivalent to (min a
b). It would further imply that (min NaN) would be equivalent to
(min), which currently throws an exception.

4 Let NaN cause min and max to throw an exception
-

Currently min and max throw an exception if given arguments that are
not Numeric. One might plausibly argue that NaN is not numeric.

--

I've attached a patch with test and implementation for variant 2 to
the issue.

// 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: clojure.core/max and NaN

2011-11-01 Thread Ben Smith-Mannschott
On Tue, Nov 1, 2011 at 21:00, Michael michael.campb...@gmail.com wrote:


 On Nov 1, 12:14 pm, Ben Smith-Mannschott bsmith.o...@gmail.com
 wrote:
 3. Define that min and max will ignore any NaN arguments.

 What is:

 (min NaN NaN)

 in this situation;  ()?

The part of the message you didn't quote implies that it would behave
as (min): throw an exception. The other option would be to return NaN.
When I sat down to actually write the patch to implement this variant,
I found that the latter behavior fell out of the implementation
naturally, so I went with that.

// 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: clojure.core/max and NaN

2011-10-30 Thread Ben Smith-Mannschott
On Sun, Oct 30, 2011 at 10:02, bOR_ boris.sch...@gmail.com wrote:
 Hi all,
 Ran into something unexpected with max.
 user (sd-age-female 13)


 [10 NaN 0.746555245613119]


 user (apply max (sd-age-female 13))

 0.746555245613119

TL;DR: Don't expect sensible answers when NaN is involved.

The implementation of max in Clojure core assumes that it's possible
to compare the things it is given and get consistent results.

clojure.core:
#
#   (defn max
# Returns the greatest of the nums.
# {:added 1.0
#  :inline-arities 1?
#  :inline (nary-inline 'max)}
# ([x] x)
# ([x y] (. clojure.lang.Numbers (max x y)))
# ([x y  more]
#  (reduce1 max (max x y) more)))

clojure.lang.Numbers:
#
#   static public double max(double x, double y){
#   if(x  y){
#   return x;
#   } else {
#   return y;
#   }
#   }

This doesn't turn out to be the case with IEEE floating point numbers
because of the behavior of NaN, as mandated by the standard.

For every number that is not NaN, the world works as we expect:

a  b  b  c implies a  c
a  b implies !(a = b)
a  b implies b  a
a == b implies b == a

But, adding NaN to the mix changes all that. NaN is like a great big
black hole for truth. All of these are false:

(NaN == NaN)
(NaN  b)
(NaN = b)
...

http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2.4
#
# An operation that overflows produces a signed infinity, an operation
# that underflows produces a denormalized value or a signed zero, and an
# operation that has no mathematically definite result produces NaN. All
# numeric operations with NaN as an operand produce NaN as a result. As
# has already been described, NaN is unordered, so a numeric comparison
# operation involving one or two NaNs returns false and any !=
# comparison involving NaN returns true, including x!=x when x is NaN.

So, in your example (max [10 NaN 0.74]) what happens is this:

  - (max 10 NaN) discovers that (10  NaN) - false, therefore
NaN is chosen as the max of the first two is NaN.

  - (max NaN 0.74) discovers that (NaN  0.74) - false, therefore
0.74 is the maximum.

// 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: (dir *ns*) doesn't work??

2011-10-27 Thread Ben Smith-Mannschott
dir is a macro. It doesn't evaluate its arguments. So when you say
(dir *ns*), Clojure sees: show me what's in the namespace named
*ns*, and there is no such namespace because *ns* is the name of a
variable which contains the name of the current namespace.

Dir is this way because for interactive use, it's convenient not to
have to quote the symbol naming the namespace.  So (dir user) and (dir
clojure.core) should work.

In your situation you'll want to call dir-fn, which is a function that
will evaluate its arguments, so:

if we assume (= *ns* 'user) (i.e. you're currently in the namespace user)
(dir-fn *ns*)
is equivalent to
(dir-fn 'user)
and
(dir user)

HTH
// Ben


On Thu, Oct 27, 2011 at 10:57, jaime xiejianm...@gmail.com wrote:
 Hi there, when I tried to execute (dir *ns*) in REPL, I found it
 doesn't work -- with exception of:
          Exception No namespace: *ns* found  clojure.core/the-ns
 (core.clj:3689)
 I'm not sure if I used it the right way. Following are my execution
 tries:
 =
 Clojure 1.3.0
 user= (doc dir)
 -
 clojure.repl/dir
 ([nsname])
 Macro
  Prints a sorted directory of public vars in a namespace
 nil
 user= (dir *ns*)
 Exception No namespace: *ns* found  clojure.core/the-ns (core.clj:
 3689)
 user= *ns*
 #Namespace user
 user= (the-ns *ns*)
 #Namespace user
 user= (the-ns 'user)
 #Namespace user
 user=
 =
 Any 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

-- 
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: Pattern matching for map content

2011-10-25 Thread Ben Smith-Mannschott
On Tue, Oct 25, 2011 at 11:20, Michael Jaaka
michael.ja...@googlemail.com wrote:
 Hi!
 Pattern matching is fine for sequence or vector destruction.
 Is is possible to destruct map and make pattern machting?
 For example I would like to make constraint for to some query service.
 It would be done as map for example:  { :name Tom :surname Jakarta
 :birthDate (Date.) } or { :personalId 12312312132 }
 Then I would like to dispatch this Value Object:
 (defn service
   ([ {:keys [name surname]} ] (println searching by personal data))
  ([{:keys [personalId]} ] (println searching by id)))

 Why using map instead of specific type of VO?
 Because I don't want to decleare types of VO which doesn't bring any value
 to domain problem.
 Maybe matchure or other lib already implements it?

Clojure provides only destructuring, not pattern matching. (It's my
impression that Rich is not a fan of mixing destructuring with control
flow implied by pattern matching.)

If you want pattern matching, matchure seems like just what you need.
For your particular example, take a look at matchure's defn-match.

https://github.com/dcolthorp/matchure

// 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: Pattern matching for map content

2011-10-25 Thread Ben Smith-Mannschott
On Tue, Oct 25, 2011 at 15:33, Alex Ott alex...@gmail.com wrote:
 it's better to use https://github.com/clojure/core.match

Thanks, I'd forgotten about core.match.

// ben

 On Tue, Oct 25, 2011 at 11:32 AM, Ben Smith-Mannschott
 bsmith.o...@gmail.com wrote:
 On Tue, Oct 25, 2011 at 11:20, Michael Jaaka
 michael.ja...@googlemail.com wrote:
 Hi!
 Pattern matching is fine for sequence or vector destruction.
 Is is possible to destruct map and make pattern machting?
 For example I would like to make constraint for to some query service.
 It would be done as map for example:  { :name Tom :surname Jakarta
 :birthDate (Date.) } or { :personalId 12312312132 }
 Then I would like to dispatch this Value Object:
 (defn service
   ([ {:keys [name surname]} ] (println searching by personal data))
  ([{:keys [personalId]} ] (println searching by id)))

 Why using map instead of specific type of VO?
 Because I don't want to decleare types of VO which doesn't bring any value
 to domain problem.
 Maybe matchure or other lib already implements it?

 Clojure provides only destructuring, not pattern matching. (It's my
 impression that Rich is not a fan of mixing destructuring with control
 flow implied by pattern matching.)

 If you want pattern matching, matchure seems like just what you need.
 For your particular example, take a look at matchure's defn-match.

 https://github.com/dcolthorp/matchure

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



 --
 With best wishes,                    Alex Ott
 http://alexott.net/
 Tiwtter: alexott_en (English), alexott (Russian)
 Skype: alex.ott

 --
 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: java.lang.ClassFormatError: Invalid method Code length

2011-10-25 Thread Ben Smith-Mannschott
On Tue, Oct 25, 2011 at 22:28, Sergey Didenko sergey.dide...@gmail.com wrote:
 I get the subject error when trying to deserialize a big map (70kb)
 using load-file.

 Is this by design?

 There was an advice in the old thread to use smaller methods. But
 while small methods are good, breaking continuous data into smaller
 pieces looks like a hack.

 Should I use some other function for deserializing data?

 Currently I use pr-str to serialize and try load-file, load-string,
 eval read-string to deserialize.


load-file will compile what you've given it and then run the resulting
code. A data literal results in a method being emitted by the
compiler, which when run will produce the desired data structure. A
large data literal may cause the method to exceed the 64KB method size
limit of the class file format.

If it's really just data (not containing function or macro calls you
are expecting to be evaluated), just use (read ...). That will parse
the file, returning a Clojure data structure without evaluating it.

// 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: Is there a String protocol?

2011-10-25 Thread Ben Smith-Mannschott
On Tue, Oct 25, 2011 at 14:45, Sean Devlin francoisdev...@gmail.com wrote:
 I was wondering if there was a common protocol to get a string
 representation of an object yet.  Also, are there common protocols for
 ints, doubles, chars, etc?  Having just spent a lot of time writing
 Python, having an int function that worked on both Strings and Ints
 was great.  I'd love to be able to use a protocol for this.


What do you need the string for? Just for presentation (like __str__),
or are you hoping to be able to parse it back in again (like
__repr__)?

(pr-str x) will produce a string representation of x which you can
convert back to Clojure data using (read-string s) provided x was
composed only of things that are representable as Clojure literals
(lists, vectors, maps, sets, keywords, strings, symbols, numbers,
chars).

The behavior of pr and friends is not defined in a protocol, as such,
but rather by the multimethods print-method and print-dup. I suppose
one could add behavior for ones own types, but this would be of
limited utility since read and friends won't know how to read these
representations back in.

(str x) produces a string for presentation. This is not necessarily
something that can be read back in.

This is not defined by a protocol, as such, but rather by overriding
the toString(), which all Java classes provide.

// 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: partial, but instead of args + additional, get additional + args

2011-10-23 Thread Ben Smith-Mannschott
On Sun, Oct 23, 2011 at 21:25, Meikel Brandmeyer m...@kotka.de wrote:
 Hi,

 Am 22.10.2011 um 20:49 schrieb Sean Corfield:

 I'm
 starting to think there's a nice, idiomatic solution lurking somewhere
 that wouldn't require an extra function...

 The idiomatic solution is #(f % a1 a2 a3). I'm failing to see the issue with 
 “nice” and “expressive”, but that is most likely just me.

I find myself reaching for partial when I could be using #(), I even
often find myself rejiggering the argument order of my own functions
to make them more useful in combination with partial.

But, honestly, I'm not quite sure why I have this preference. The
#(...) is arguably more readable since we're shown explicitly where
the argument goes, and yet I still find myself reaching for partial
and comp when I can make them fit. I mean, I like the fact that
partial and comp don't cause yet-another-tiny-class to be generated
every time they appear in code. But that doesn't seem like reason
enough. Am I just being too clever?

// Ben

 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

-- 
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: partial, but instead of args + additional, get additional + args

2011-10-23 Thread Ben Smith-Mannschott
On Sun, Oct 23, 2011 at 23:53, Sean Corfield seancorfi...@gmail.com wrote:
 On Sun, Oct 23, 2011 at 1:04 PM, Ben Smith-Mannschott
 bsmith.o...@gmail.com wrote:
 On Sun, Oct 23, 2011 at 21:25, Meikel Brandmeyer m...@kotka.de wrote:
 The idiomatic solution is #(f % a1 a2 a3). I'm failing to see the issue 
 with “nice” and “expressive”, but that is most likely just me.
 I find myself reaching for partial when I could be using #()

 I was using #() and (fn..) extensively in my code until I noticed just
 how many anonymous classes were being generated (we had a scenario
 where we were repeatedly reloading the Clojure code - deliberately -
 and of course ended up with thousands of these classes loaded!).
 Understood it's fine in load-once-and-run scenarios.

 When I brought this up on IRC, several folks said they felt the comp /
 partial approach was nicer because it was point-free - as well as not
 generating new classes (new instances, yes, new classes, no - right?).
 Since then, I've almost eliminated the use of #() and (fn..) in our
 code and, whilst more verbose initially in some cases, I'm actually
 really liking the point-free style and it's letting me see new
 opportunities for refactoring and simplification that I hadn't seen
 previously (often triggered by encouraging me to pay more attention to
 argument ordering so that my functions are more composable).

 Given Meikel's 2009 blog post, I can understand why he might not
 agree, but given that we have both - and -, it does seem like we
 have a 'hole' - comp/partial and - go together but there's no
 comp/??? to go with - and we have to resort to #(f % a1 a2 a3)...

I propose partail ;-) While partial fills up the arguments from the
front, partail fills up the arguments from the back (the *tail*).
Plus, the spellings are so similar that it would cause no end of
confusion, particularly for people like me that swap letters every
once in a while, even when we don't mean to.

Ok, Cute name, but not a good name. Anyone got a better one?

// Ben


 --
 Sean A Corfield -- (904) 302-SEAN
 An Architect's View -- http://corfield.org/
 World Singles, LLC. -- http://worldsingles.com/
 Railo Technologies, Inc. -- http://www.getrailo.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

-- 
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: Reading special characters with slurp

2011-10-21 Thread Ben Smith-Mannschott
You need to tell slurp how the file is encoded.

(slurp path-to-my-file :encoding UTF-8)

That means that you'll need to know what encoding your file is using.
If you've never dealt with encoding before, I recommend reading this:
http://www.joelonsoftware.com/articles/Unicode.html

// Ben

On Fri, Oct 21, 2011 at 14:14, Jonathan Cardoso
jonathancar...@gmail.com wrote:
 when I read* a file

 --
 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: Is there a reader setting support BigDecimal by default?

2011-10-20 Thread Ben Smith-Mannschott
On Thu, Oct 20, 2011 at 11:17, Joel Gluth joel.gl...@gmail.com wrote:
 On Tue, Oct 18, 2011 at 3:47 PM, Tassilo Horn tass...@member.fsf.org wrote:
 Scott Hickey jscotthic...@gmail.com writes:
 And usually, you should refrain from using floating points at all, no
 matter if BigDecimal or Double.

 I thought BigDecimal with was not a floating point in the traditional
 sense (ie., subject to all of the usual rounding horror, unless you
 ask it to be)? That is, you can do decimal calculations exactly using
 it.

The term floating point is used to distingiush from fixed-point
schemes, such as deciding that We're going to store money as a 64 bit
integer representing the number of 100ths of a cent. Effectively,
fixing the decimal point thus: $1000..

BigDecimal is an arbitrary precision integer and a scale factor (think
of the scale factor as multiplying or dividing by a power of ten.) So,
in that sense the (decimal) point floats.

Unlike floating point in the IEEE754 sense, BigDecimal is decimal,
not binary, (so e.g. 0.1 has a terminating representation) and
arbitrary precision, so you can avoid rounding effects unless you're
dividing where you might have to round to truncate a non-terminating
representation.

// 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: Is there a reader setting support BigDecimal by default?

2011-10-20 Thread Ben Smith-Mannschott
On Thu, Oct 20, 2011 at 22:50, Stuart Halloway
stuart.hallo...@gmail.com wrote:
 It appears that the answer to the original question is no, there is no way 
 to configure the reader to default numbers with a decimal point to be 
 BigDecimal instead of Double.

 Scott Hickey

 Reading a double implies that somebody upstream of you was using doubles, 
 which violates the guarantees you want from BigDecimals.

 Why is the upstream provider using doubles?

I don't follow. The OP has text, which Clojure is reading as doubles.
This only implies that upstream (which need not have been written in
Clojure) is producing numbers matching #[-]?[1-9][0-9]*[.][0-9]*|0,
because LispReader interprets that as Double. Whatever internal
representation this text was produced form may or may not have been
(binary) floating point initially.

It doesn't seem reasonable to assume that the OP's 'business'
applications I've built over the last 25 years could have known that
Clojure would come along later and expect to find M on the end of
every decimal number.

// Ben

// 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: Is there a reader setting support BigDecimal by default?

2011-10-20 Thread Ben Smith-Mannschott
On Thu, Oct 20, 2011 at 23:16, Stuart Halloway
stuart.hallo...@gmail.com wrote:
 It appears that the answer to the original question is no, there is no 
 way to configure the reader to default numbers with a decimal point to be 
 BigDecimal instead of Double.

 Scott Hickey

 Reading a double implies that somebody upstream of you was using doubles, 
 which violates the guarantees you want from BigDecimals.

 Why is the upstream provider using doubles?

 I don't follow. The OP has text, which Clojure is reading as doubles.
 This only implies that upstream (which need not have been written in
 Clojure) is producing numbers matching #[-]?[1-9][0-9]*[.][0-9]*|0,
 because LispReader interprets that as Double. Whatever internal
 representation this text was produced form may or may not have been
 (binary) floating point initially.

 It doesn't seem reasonable to assume that the OP's 'business'
 applications I've built over the last 25 years could have known that
 Clojure would come along later and expect to find M on the end of
 every decimal number.

 // Ben

 Hmm, highly apropos discussion since Rich's talk on simplicity posted today.

 The reader does one thing: read Clojure data. Sometimes you need something 
 else: read data written in another format. You might accomplish that by (1) 
 making the reader able to do two things, adding a flag to deal with a 
 specific format, or (2) by using a different reader for that job.

 (2) is hands-down the right answer.

No argument there. The Clojure reader's job is to read Clojure. If
your have some data that happens to be syntactically compatible, fine,
but if not the Clojure reader  isn't the right tool.

One obvious approach would be a to use a regular expression to
identify the numbers in the text to be parsed and #(BigDecimal.
^String %) to do the actual conversion.

// 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: About metadat and #^ macro.

2011-10-19 Thread Ben Smith-Mannschott
The current syntax is just ^

(defn filenames-in-jar [^JarFile jar-file] ...)

On Thu, Oct 20, 2011 at 07:03, mmwaikar mmwai...@gmail.com wrote:
 Hi,

 I read in Clojure in Action book by Amit Rathore, that #^ associates
 metadata for the next form. He also mentions that it is deprecated. So what
 is the current way of doing it?

 Also, in code like this -

 (defn filenames-in-jar
 Returns a sequence of Strings naming the non-directory entries in the JAR
 file.
 [#^JarFile jar-file]

 is it specifying that the type of the jar-file argument should be JarFile?

 Where can I find some more documentation and or examples about it?

 Thanks,
 Manoj.

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


  1   2   >