Re: REQUEST: Add seqable? to core

2009-07-30 Thread J. McConnell
On Wed, Jul 29, 2009 at 11:06 PM, John Harrop jharrop...@gmail.com wrote:

 How about defining seqable? in terms of whether seq works, using try catch?


I think this is the only DRY way to do it, but I know Rich has expressed in
the past the he does not approve of using exception handling as a form of
flow control.

Stephen Gilardi added a seqable? function to clojure.contrib.core here:

http://github.com/richhickey/clojure-contrib/commit/bc07de7c3b1058f4263bd7b1c424f771fb010005

Regards,

- J.

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



Bug? Definline arguments multiply evaluated.

2009-07-30 Thread John Harrop
user= (definline addsq [a b] `(+ (* ~a ~a) (* ~b ~b)))
#'hxr.clj.util/addsq
user= (addsq (do (println a evaluated) 1) 1)
a evaluated
a evaluated
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
-~--~~~~--~~--~--~---



Re: Exit delay from java when lazy?

2009-07-30 Thread mwillson

On Jul 29, 8:17 pm, Michael Wood esiot...@gmail.com wrote:
 2009/7/29 mwillson cdr@gmail.com:
 
  I was experimenting with Clojure and XML and stumbled upon a lengthy
  hang when exiting java which was tracked down to the use of
  clojure.contrib.lazy-xml.  Here's a toy example which exhibits the
  issue:

 I haven't looked at clojure.contrib.lazy-xml, but this sounds like
 what happens if you make use of agents.  Shutting down the agents with
 (shutdown-agents) should fix it if so.  Perhaps
 clojure.contrib.lazy-xml uses agents.

Michael,

Thanks for your reply.  You are quite right - adding (shutdown-agents)
does allow the script using lazy-xml to exit promptly.  From a cursory
scan of the lazy-xml/parse-seq code, it does use agents.

-mark

--~--~-~--~~~---~--~~
You 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 1.4 class files

2009-07-30 Thread Frank Koenig

Thank you Stuart and Daniel for the help. I think I have to step back
from the idea to use clojure on this Java 1.4 project :-(

Let's hope my next Java project addresses a less archaic Java version.

--~--~-~--~~~---~--~~
You 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: Bug? Definline arguments multiply evaluated.

2009-07-30 Thread Rich Hickey



On Jul 30, 1:29 am, John Harrop jharrop...@gmail.com wrote:
 user= (definline addsq [a b] `(+ (* ~a ~a) (* ~b ~b)))
 #'hxr.clj.util/addsq
 user= (addsq (do (println a evaluated) 1) 1)
 a evaluated
 a evaluated
 2

You write the expansion, so you are in control of multiple evaluation.

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



Bug? Primitives get boxed if passed out of let.

2009-07-30 Thread Rich Hickey

On Thu, Jul 30, 2009 at 1:28 AM, John Harropjharrop...@gmail.com wrote:
 user= (loop [i 0 j (double 1.0)]
   (if (= i 1) j (recur 1 (+ j j
 2.0
 user= (loop [i 0 j (double 1.0)]
   (if (= i 1) j (recur 1 (let [a j b j] (+ a b)
 #CompilerException java.lang.RuntimeException:
 java.lang.IllegalArgumentException: recur arg for primitive local: j must be
 matching primitive (NO_SOURCE_FILE:0)
 user= (loop [i 0 j (double 1.0)]
   (if (= i 1) j (let [a j b j] (recur 1 (+ a b)
 2.0
 So when j is a lowercase-d double, inside (let [a j b j] ... ) a and b are
 lowercase-d doubles, and (+ a b) is a lowercase-d double, but the type of
 the expression (let [a j b j] (+ a b)) is apparently capital-D Double.
 This seems like a bug to me, and could cripple performance in some
 conceivable cases. Primitives should not get boxed when not passed across
 function-call boundaries, and let is not a function.


Currently only host expressions and bindings to host expressions of
primitive types can have primitives type. let expressions etc cannot.

One reason is that let etc can have more than one 'type' by containing
conditionals or making calls to polymorphic functions:

;let might have type double or String
(let [j (double 42.0)] (if x j 42))

Currently there is no analysis to determine that potentially composite
expressions yield a uniform type, which would be required to let a
primitive flow out of a let. It would be a nice enhancement.

Rich

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

2009-07-30 Thread Rich Hickey



On Jul 29, 6:09 pm, Jason Wolfe jawo...@berkeley.edu wrote:
 Is this a bug?

 user (eval `(make-array ~Byte/TYPE 2))
 ; Evaluation aborted. (ExceptionInInitializerError)

 Compare:

 user (eval `(make-array ~Byte 2))
 #Byte[] [Ljava.lang.Byte;@26fcfd5c

 user (eval `(make-array Byte/TYPE 2))
 #byte[] [...@1f0feb6e

 user (make-array (eval Byte/TYPE) 2)
 #byte[] [...@7ce49289

 If not, can someone please help me understand what's going on here?


Yes, currently you cannot embed constants of primitive Class types.
This arises from an asymmetry in Java:

user= (.getName Byte)
java.lang.Byte

user= (Class/forName java.lang.Byte)
java.lang.Byte

user= (.getName Byte/TYPE)
byte

user= (Class/forName byte)
java.lang.ClassNotFoundException: byte (NO_SOURCE_FILE:0)

A patch to support reading, and embedded constants, of primitive Class
objects would be welcome. The current print-dup support won't do it.

If anyone is interested in contributing this patch please bring it up
on the clojure-dev group before proceeding and I can give you some
guidance as to what needs to be changed.

Thanks for the report,

Rich

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

2009-07-30 Thread Aaron Cohen
At my day job, we've always used a custom classloader to get around that
asymmetry.
-- Aaron


On Thu, Jul 30, 2009 at 9:51 AM, Rich Hickey richhic...@gmail.com wrote:




 On Jul 29, 6:09 pm, Jason Wolfe jawo...@berkeley.edu wrote:
  Is this a bug?
 
  user (eval `(make-array ~Byte/TYPE 2))
  ; Evaluation aborted. (ExceptionInInitializerError)
 
  Compare:
 
  user (eval `(make-array ~Byte 2))
  #Byte[] [Ljava.lang.Byte;@26fcfd5c
 
  user (eval `(make-array Byte/TYPE 2))
  #byte[] [...@1f0feb6e
 
  user (make-array (eval Byte/TYPE) 2)
  #byte[] [...@7ce49289
 
  If not, can someone please help me understand what's going on here?
 

 Yes, currently you cannot embed constants of primitive Class types.
 This arises from an asymmetry in Java:

 user= (.getName Byte)
 java.lang.Byte

 user= (Class/forName java.lang.Byte)
 java.lang.Byte

 user= (.getName Byte/TYPE)
 byte

 user= (Class/forName byte)
 java.lang.ClassNotFoundException: byte (NO_SOURCE_FILE:0)

 A patch to support reading, and embedded constants, of primitive Class
 objects would be welcome. The current print-dup support won't do it.

 If anyone is interested in contributing this patch please bring it up
 on the clojure-dev group before proceeding and I can give you some
 guidance as to what needs to be changed.

 Thanks for the report,

 Rich

 


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

2009-07-30 Thread Sean Devlin

This is slightly unrelated, but...

How much work would it be to run the old code on a Java 5/6 VM?  I
didn't get into Java until 5, so I'm not sure how much work is
actually involved w/ upgrading a JVM installation.

On Jul 30, 7:07 am, Frank Koenig frakoe.koe...@googlemail.com wrote:
 Thank you Stuart and Daniel for the help. I think I have to step back
 from the idea to use clojure on this Java 1.4 project :-(

 Let's hope my next Java project addresses a less archaic Java version.
--~--~-~--~~~---~--~~
You 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: Possible bug report

2009-07-30 Thread Jason Wolfe


On Jul 30, 2009, at 6:51 AM, Rich Hickey wrote:
 On Jul 29, 6:09 pm, Jason Wolfe jawo...@berkeley.edu wrote:
 Is this a bug?

 user (eval `(make-array ~Byte/TYPE 2))
 ; Evaluation aborted. (ExceptionInInitializerError)

 Compare:

 user (eval `(make-array ~Byte 2))
 #Byte[] [Ljava.lang.Byte;@26fcfd5c

 user (eval `(make-array Byte/TYPE 2))
 #byte[] [...@1f0feb6e

 user (make-array (eval Byte/TYPE) 2)
 #byte[] [...@7ce49289

 If not, can someone please help me understand what's going on here?


 Yes, currently you cannot embed constants of primitive Class types.
 This arises from an asymmetry in Java:

 user= (.getName Byte)
 java.lang.Byte

 user= (Class/forName java.lang.Byte)
 java.lang.Byte

 user= (.getName Byte/TYPE)
 byte

 user= (Class/forName byte)
 java.lang.ClassNotFoundException: byte (NO_SOURCE_FILE:0)

 A patch to support reading, and embedded constants, of primitive Class
 objects would be welcome. The current print-dup support won't do it.

 If anyone is interested in contributing this patch please bring it up
 on the clojure-dev group before proceeding and I can give you some
 guidance as to what needs to be changed.

 Thanks for the report,

 Rich

Thanks for the clear explanation.

-Jason

--~--~-~--~~~---~--~~
You 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: Bug? Definline arguments multiply evaluated.

2009-07-30 Thread Nicolas Oury

Hello,

I am not sure to agree.

If I get it right, definline is used to replace defn for function that
we want to be inlined.

So replacing defn by definline should have no impact on the semantic of
the program.


Best regards,


Nicolas.

On Thu, 2009-07-30 at 05:34 -0700, Rich Hickey wrote:
 
 
 On Jul 30, 1:29 am, John Harrop jharrop...@gmail.com wrote:
  user= (definline addsq [a b] `(+ (* ~a ~a) (* ~b ~b)))
  #'hxr.clj.util/addsq
  user= (addsq (do (println a evaluated) 1) 1)
  a evaluated
  a evaluated
  2
 
 You write the expansion, so you are in control of multiple evaluation.
 
 Rich
  


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

2009-07-30 Thread Rich Hickey

On Thu, Jul 30, 2009 at 1:26 PM, Nicolas Ourynicolas.o...@gmail.com wrote:

 Hello,

 I am not sure to agree.

 If I get it right, definline is used to replace defn for function that
 we want to be inlined.

 So replacing defn by definline should have no impact on the semantic of
 the program.


The docs for definline state it is expansion like macro expansion.

Rich


 On Thu, 2009-07-30 at 05:34 -0700, Rich Hickey wrote:


 On Jul 30, 1:29 am, John Harrop jharrop...@gmail.com wrote:
  user= (definline addsq [a b] `(+ (* ~a ~a) (* ~b ~b)))
  #'hxr.clj.util/addsq
  user= (addsq (do (println a evaluated) 1) 1)
  a evaluated
  a evaluated
  2

 You write the expansion, so you are in control of multiple evaluation.

 Rich
 


 


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

2009-07-30 Thread Laurent PETIT
BTW,

is definline still considered experimental (I know it is still mentioned in
the doc, just asking whether it's up to date or not) ?

2009/7/30 Stuart Halloway stuart.hallo...@gmail.com


 The documentation is explicit that definline observes defmacro-like
 semantics.

 A.K.A. What Rich said :-)

 Stu

  Hello,
 
  I am not sure to agree.
 
  If I get it right, definline is used to replace defn for function that
  we want to be inlined.
 
  So replacing defn by definline should have no impact on the semantic
  of
  the program.
 
 
  Best regards,
 
 
  Nicolas.
 
  On Thu, 2009-07-30 at 05:34 -0700, Rich Hickey wrote:
 
 
  On Jul 30, 1:29 am, John Harrop jharrop...@gmail.com wrote:
  user= (definline addsq [a b] `(+ (* ~a ~a) (* ~b ~b)))
  #'hxr.clj.util/addsq
  user= (addsq (do (println a evaluated) 1) 1)
  a evaluated
  a evaluated
  2
 
  You write the expansion, so you are in control of multiple
  evaluation.
 
  Rich
 
 
 
  


 


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



struct-map niggle

2009-07-30 Thread Richard Newman

I understand what's going on here (and I don't regard it as a bug that  
needs fixing) but I thought I'd share something that caught me off- 
guard, and perhaps should be mentioned in the docs for struct-maps.

Clojure 1.0.0-
user= (defstruct foo :bar :baz)
#'user/foo
user= (def foo-bar (accessor foo :bar))
#'user/foo-bar
user= (= (struct foo 1 2) (eval (struct foo 1 2)))
true
user= (foo-bar (struct foo 1 2))
1
user= (foo-bar (eval (struct foo 1 2)))
java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot  
be cast to clojure.lang.PersistentStructMap (NO_SOURCE_FILE:0)


i.e., struct-map-ness does not persist through evaluation.

Client code must either avoid accessors for data that might be  
evaluated, or post-process the result of calling eval. I have a  
defstruct* macro that defines a structure and its accessors, so it's  
straightforward for me to also define a map-foo function that  
rebuilds the struct from the resultant map.

-R

--~--~-~--~~~---~--~~
You 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: Bug? Definline arguments multiply evaluated.

2009-07-30 Thread Stuart Halloway

The documentation is explicit that definline observes defmacro-like  
semantics.

A.K.A. What Rich said :-)

Stu

 Hello,

 I am not sure to agree.

 If I get it right, definline is used to replace defn for function that
 we want to be inlined.

 So replacing defn by definline should have no impact on the semantic  
 of
 the program.


 Best regards,


 Nicolas.

 On Thu, 2009-07-30 at 05:34 -0700, Rich Hickey wrote:


 On Jul 30, 1:29 am, John Harrop jharrop...@gmail.com wrote:
 user= (definline addsq [a b] `(+ (* ~a ~a) (* ~b ~b)))
 #'hxr.clj.util/addsq
 user= (addsq (do (println a evaluated) 1) 1)
 a evaluated
 a evaluated
 2

 You write the expansion, so you are in control of multiple  
 evaluation.

 Rich



 


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

2009-07-30 Thread Chouser

On Thu, Jul 30, 2009 at 4:20 PM, Richard Newmanholyg...@gmail.com wrote:

 The scenario here, though, is different: given an *existing* struct-
 map (which prints as {:foo 1 :bar 2} -- not a form), one cannot print
 it in such a way that the struct-map-ness is preserved when it is re-
 read. You can discover that it's a struct-map (type =
 PersistentStructMap), but not what kind of struct-map it is.

 The same is true of sorted maps and sets, and assorted other data
 structures.

Are you aware of *print-dup* ?  It causes the printer to
preserve more of the specific type information than normal
printing:

user= (binding [*print-dup* true] (prn (hash-map :a 1, :b 2)))
{:a 1, :b 2}
nil
user= (binding [*print-dup* true] (prn (sorted-map :a 1, :b 2)))
#=(clojure.lang.PersistentTreeMap/create {:a 1, :b 2})
nil
user= (binding [*print-dup* true] (prn {:a 1, :b 2}))
#=(clojure.lang.PersistentArrayMap/create {:a 1, :b 2})
nil

The #=() is an intentionally under-documented reader macro
specifically to allow such preservation.

Having said that, it's important to note it doesn't help
your original scenario, because *print-dup* doesn't support
struct maps (yet):

(- (binding [*print-dup* true] (prn-str (struct foo 1 2)))
java.io.StringReader. java.io.PushbackReader. read class)
java.lang.IllegalArgumentException: No matching method found: create
(NO_SOURCE_FILE:0)

sorted-maps work, but lose any custom sort-by fn:

(- (binding [*print-dup* true] (prn-str (sorted-map :a 1, :b 2)))
java.io.StringReader. java.io.PushbackReader. read class)
clojure.lang.PersistentTreeMap

(- (binding [*print-dup* true]
  (prn-str (sorted-map-by #(compare %2 %1) :a 1, :b 2)))
java.io.StringReader. java.io.PushbackReader. read)
{:a 1, :b 2}

--Chouser

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



Idiomatic parsing of objects from several lines of a text file

2009-07-30 Thread David Plumpton

I'm trying to find an idiomatic way to read through a text file (e.g.
a Git history log) where an object will be represented by several
lines of text, and when we find a line that starts a new entry we
create the old entry and continue. For example here's my first clumsy
attempt. Can anybody advise on how to do this in a more functional
style?

(def *line-re* #[^\n]{1,})

(defstruct commit :id :parent :msg)

(defn parse-log [filename]
  (let [text (slurp filename)
lines (re-seq *line-re* text)]
(with-local-vars
  [commits {}
  commit-id 
  parent 
  msg ]
  (doseq [line lines]
(if (.startsWith line commit )
  (do
(if (not= @commit-id )
  (do
(var-set commits (conj @commits {...@commit-id (struct
commit @commit-id @parent @msg)}))
(var-set msg )
(var-set parent nil)))
(var-set commit-id (subs line 7
(if (.startsWith line parent )
  (var-set parent (subs line 7)))
(if (.startsWith line )
  (var-set msg (str @msg \n (subs line 4)
  (var-set commits (assoc @commits @commit-id (struct commit
@commit-id @parent @msg)))
  @commits)))



--~--~-~--~~~---~--~~
You 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: Idiomatic parsing of objects from several lines of a text file

2009-07-30 Thread Meikel Brandmeyer

Hi,

I would suggest to have a look at fnparse[1]. It's
really cool. A commit-log parser might look like
this:

(def linebreak
  (alt (conc (opt (lit \return)) (lit \newline))
   (lit \return)))

(def hex-digit
  (alt-lit-seq 0123456789abcdef))

(def checksum
  (semantics (rep+ hex-digit) #(apply str %)))

(def commit
  (complex [_ (conc-lit-seq commit )
commit-id checksum
_ linebreak
_ (conc-lit-seq parent )
parent-id checksum
_ (rep= 2 linebreak)
msg   (semantics (rep* (except anything
   (conc linebreak
 (conc-lit-seq  
commit 

 #(apply str %))]
{:id commit-id :parent parent-id :message msg}))

(def commit-log
  (rep* commit))

This should parse a log like:

commit a2b5927f24c
parent c726fe5211a

This is
the
message
commit 285abb36e12
parent 81f2e35bc61

Another
message.

The result would be:
[{:id a2b5927f24c :parent c726fe5211a :message This is\nthe\nmessage}
 {:id 285abb36e12 :parent 81f2e35bc61 :message Another\nmessage.}]

Note, the code is not tested, but should be close.

Hope this helps.

Sincerely
Meikel

[1]: http://github.com/joshua-choi/fnparse/tree/master




smime.p7s
Description: S/MIME cryptographic signature


Re: struct-map niggle

2009-07-30 Thread Richard Newman

 Are you aware of *print-dup* ?  It causes the printer to
 preserve more of the specific type information than normal
 printing:

It's one of those things that hasn't yet crept close enough on my  
radar for me to absorb. This is the impetus...

 Having said that, it's important to note it doesn't help
 your original scenario, because *print-dup* doesn't support
 struct maps (yet):

Ah, good and bad :)

I expect there are plenty of dangerous edge cases to handle -- e.g.,  
what to do if there is no struct by that name, or if it's a different  
struct with the same name.

I suspect that in my case the right approach is either to switch to  
pure maps (which round-trip perfectly), or to take more control over  
the upstream serialization, and produce a (struct foo ...) form  
instead of just prn-ing the struct-map. I started down the avenue of  
converting maps into struct-maps, though, so perhaps I'll see how that  
turns out. This data is accessed much more often than it's loaded, so  
the overhead is likely worthwhile.

Thanks for the discussion!

-R

--~--~-~--~~~---~--~~
You 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: Idiomatic parsing of objects from several lines of a text file

2009-07-30 Thread Richard Newman

On  30 Jul 2009, at 2:26 PM, David Plumpton wrote:

 I'm trying to find an idiomatic way to read through a text file (e.g.
 a Git history log)

Sidenote: I'm hacking on this:

http://github.com/rnewman/clj-git/tree/master

I haven't got to commit messages etc. yet -- I'm primarily using git  
as a backing store, not accessing existing repositories, so there are  
much more pressing things -- but there might be something useful there  
for you.

The usual caveats of hacky, bad, probably-buggy code apply :)

-R


--~--~-~--~~~---~--~~
You 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: Bug? Definline arguments multiply evaluated.

2009-07-30 Thread Rich Hickey

On Thu, Jul 30, 2009 at 2:52 PM, Laurent PETITlaurent.pe...@gmail.com wrote:
 BTW,

 is definline still considered experimental (I know it is still mentioned in
 the doc, just asking whether it's up to date or not) ?


Yes, still experimental.

Rich

 2009/7/30 Stuart Halloway stuart.hallo...@gmail.com

 The documentation is explicit that definline observes defmacro-like
 semantics.

 A.K.A. What Rich said :-)

 Stu

  Hello,
 
  I am not sure to agree.
 
  If I get it right, definline is used to replace defn for function that
  we want to be inlined.
 
  So replacing defn by definline should have no impact on the semantic
  of
  the program.
 
 
  Best regards,
 
 
  Nicolas.
 
  On Thu, 2009-07-30 at 05:34 -0700, Rich Hickey wrote:
 
 
  On Jul 30, 1:29 am, John Harrop jharrop...@gmail.com wrote:
  user= (definline addsq [a b] `(+ (* ~a ~a) (* ~b ~b)))
  #'hxr.clj.util/addsq
  user= (addsq (do (println a evaluated) 1) 1)
  a evaluated
  a evaluated
  2
 
  You write the expansion, so you are in control of multiple
  evaluation.
 
  Rich
 
 
 
  







 


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

2009-07-30 Thread Stuart Sierra

On Jul 30, 5:03 pm, Chouser chou...@gmail.com wrote:
 Are you aware of *print-dup* ?  It causes the printer to
 preserve more of the specific type information than normal
 printing:

 user= (binding [*print-dup* true] (prn (hash-map :a 1, :b 2)))
 {:a 1, :b 2}
 nil
 user= (binding [*print-dup* true] (prn (sorted-map :a 1, :b 2)))
 #=(clojure.lang.PersistentTreeMap/create {:a 1, :b 2})
 nil

This doesn't actually work for structs, which may be a bug.  That is,
you can prn a struct, but you can't read it back in.
-SS
--~--~-~--~~~---~--~~
You 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: Idiomatic parsing of objects from several lines of a text file

2009-07-30 Thread Aaron Cohen
What is this convention you are using with the - ?
Are you coming from a C or C++ background or is this something lispy I
haven't seen before?
-- Aaron


On Thu, Jul 30, 2009 at 7:56 PM, Richard Newman holyg...@gmail.com wrote:


 On  30 Jul 2009, at 2:26 PM, David Plumpton wrote:

  I'm trying to find an idiomatic way to read through a text file (e.g.
  a Git history log)

 Sidenote: I'm hacking on this:

 http://github.com/rnewman/clj-git/tree/master

 I haven't got to commit messages etc. yet -- I'm primarily using git
 as a backing store, not accessing existing repositories, so there are
 much more pressing things -- but there might be something useful there
 for you.

 The usual caveats of hacky, bad, probably-buggy code apply :)

 -R


 


--~--~-~--~~~---~--~~
You 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: Idiomatic parsing of objects from several lines of a text file

2009-07-30 Thread Richard Newman

 What is this convention you are using with the - ?

 Are you coming from a C or C++ background or is this something lispy  
 I haven't seen before?

A fair proportion of Common Lispers do that (though I've witnessed  
debates about its merit, usually in the context of low-level code  
where the symbols are already cluttered with [-_+] etc), exploiting  
the much richer options for symbol names than most languages. It's  
certainly not a dereferencing operation, which is the only context in  
which it would arise for a C/C++ user.

Usually it means to, either as a conversion or lookup.

(defn ref-commit [ref]
   ...)

thus means take this ref and give me the corresponding commit (in the  
context of this repo). Similarly,

(defn tree-entry-map [e]
   ...)

takes a Git tree entry string and returns a Clojure map that  
represents it. This is slightly less confusing than `tree-entry-map`,  
which could very well mean some mapping construct over a tree entry,  
or a map of multiple tree entries, or something else.

I haven't been entirely consistent, though -- witness `tree-entry- 
seq`, which should really be `tree-entry-seq`. I said it was a work  
in progress :)

I suppose in Clojure we could use a real arrow character, with UTF-8  
available in symbol names...

-R


--~--~-~--~~~---~--~~
You 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: Keyword not serializable

2009-07-30 Thread Chas Emerick

It turns out that a framework we've been using is able to serialize
*any* Java class, whether it implements Serializable or not -- so,
we've been happily serializing keywords without them explicitly
supporting it for some time.

However, making Keyword formally Serializable has other benefits,
specifically that a proper patch would ensure that deserialized
Keywords are interned as one would expect out.

So, I may make a run at this sooner rather than later...

- Chas

On Jul 24, 7:06 pm, Chris Kent cjk...@gmail.com wrote:
 Hi

 Are there any fundamental reasons why the Keyword class shouldn't be
 serializable?  I've been playing around with Clojure and Wicket and
 it's not possible to use maps containingKeywordsin Wicket page
 classes.  Wicket pages are serialized and stored in the session
 between requests and this fails if the page refers to anyKeywords.
 UsingKeywordsin maps is common in Clojure (and in clj-record in
 particular) and it would be a really useful change.

 I'd be happy to supply a (very small) patch if people think it's a
 good idea.

 Thanks
 Chris
--~--~-~--~~~---~--~~
You 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
-~--~~~~--~~--~--~---