Re: problem with threading and sql lib

2009-09-20 Thread Roger Gilliar


 Nothing leaps out at me as a likely cause of a dropped message.

-
The only reason I can think of: It could be a problem when the loading  
of the JDBC driver is happening inside a thread.  At least that would  
explain why calling

(with-connection db
   nil
)

before the thread is started, solves the problem.


 OTOH, the loop/recur at the end is probably better changed to a doseq.


Thanks for this tip.

Regards
   Roger

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Metadata: something funny

2009-09-20 Thread David Nolen
Hmm, I also note that:
(def b #^{:b 2} (quote (1 2 3))) ; ^b - {:line 1}
(def b #^{:b 2} (list 1 2 3)) ; ^b - nil

On Sun, Sep 20, 2009 at 12:20 PM, samppi rbysam...@gmail.com wrote:


 I was messing with the REPL when I found this happens:

 Clojure 1.0.0-
 user= (def a #^{:a 5} [1 2 3])
 #'user/a
 user= ^a
 {:a 5}
 user= (def b #^{:b 2} '(1 2 3))
 #'user/b
 user= ^b
 {:line 3}
 user= (def c (with-meta '(1 2 3) {:c 0}))
 #'user/c
 user= ^c
 {:c 0}

 What's going on with that {:line 3}? Is it something that the REPL is
 doing? Where did {:b 2} go? And why does it happen with the reader
 macro #^ and not with-meta?
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Metadata: something funny

2009-09-20 Thread Wilson MacGyver

I just checked against the latest 1.1 snapshot. It
returns the same result as you outlined here.

On Sun, Sep 20, 2009 at 12:20 PM, samppi rbysam...@gmail.com wrote:

 I was messing with the REPL when I found this happens:

 Clojure 1.0.0-
 user= (def a #^{:a 5} [1 2 3])
 #'user/a
 user= ^a
 {:a 5}
 user= (def b #^{:b 2} '(1 2 3))
 #'user/b
 user= ^b
 {:line 3}
 user= (def c (with-meta '(1 2 3) {:c 0}))
 #'user/c
 user= ^c
 {:c 0}

 What's going on with that {:line 3}? Is it something that the REPL is
 doing? Where did {:b 2} go? And why does it happen with the reader
 macro #^ and not with-meta?
 




-- 
Omnem crede diem tibi diluxisse supremum.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Metadata: something funny

2009-09-20 Thread Christian Vest Hansen

On Sun, Sep 20, 2009 at 6:20 PM, samppi rbysam...@gmail.com wrote:

 I was messing with the REPL when I found this happens:

 Clojure 1.0.0-
 user= (def a #^{:a 5} [1 2 3])
 #'user/a
 user= ^a
 {:a 5}
 user= (def b #^{:b 2} '(1 2 3))

You have a quote symbol in there, so that line can also be written as:

(def b #^{:b 2} (quote (1 2 3)))


 #'user/b
 user= ^b
 {:line 3}
 user= (def c (with-meta '(1 2 3) {:c 0}))
 #'user/c
 user= ^c
 {:c 0}

 What's going on with that {:line 3}? Is it something that the REPL is
 doing? Where did {:b 2} go? And why does it happen with the reader
 macro #^ and not with-meta?
 




-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Metadata: something funny

2009-09-20 Thread Christian Vest Hansen

On Sun, Sep 20, 2009 at 7:25 PM, Christian Vest Hansen
karmazi...@gmail.com wrote:
 On Sun, Sep 20, 2009 at 6:20 PM, samppi rbysam...@gmail.com wrote:

 I was messing with the REPL when I found this happens:

 Clojure 1.0.0-
 user= (def a #^{:a 5} [1 2 3])
 #'user/a
 user= ^a
 {:a 5}
 user= (def b #^{:b 2} '(1 2 3))

 You have a quote symbol in there, so that line can also be written as:

 (def b #^{:b 2} (quote (1 2 3)))

... and #^{} applies read-time to the following *form* rather than the
value they evaluate to, so that is why neither (list ...) nor (quote
...) work.



 #'user/b
 user= ^b
 {:line 3}
 user= (def c (with-meta '(1 2 3) {:c 0}))
 #'user/c
 user= ^c
 {:c 0}

 What's going on with that {:line 3}? Is it something that the REPL is
 doing? Where did {:b 2} go? And why does it happen with the reader
 macro #^ and not with-meta?
 




 --
 Venlig hilsen / Kind regards,
 Christian Vest Hansen.




-- 
Venlig hilsen / Kind regards,
Christian Vest Hansen.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Silly Convention Question

2009-09-20 Thread Daniel Renfer

I think this further reinforces the need for a clj-lint of sorts. I  
know I have accidentally declared variables, fns, etc. in both def- 
derivative forms and in let-style forms that have shadowed a var that  
was in use somewhere else higher up. It would be handy to have a tool  
I could run over my source that would highlight instances such as this  
and many other instances of non-idiomatic code.

Just like any other lint program, you would probably end up ignoring  
the advice of the checker, but it's still nice to have it pointed out  
to you.


On Sep 18, 2009, at 7:06 PM, Sean Devlin wrote:


 For what it's worth, I try to follow the convention Rich uses in core

 f - for a function
 pred - for a predicate
 coll - for a collection
 body - for macro bodys
 name - symbol definition
 params - bindings

 Just my $.02

 Sean

 On Sep 18, 6:37 pm, CuppoJava patrickli_2...@hotmail.com wrote:
 John illustrates a common scenario in Clojure. Clojure's built-in
 functions are tersely and sensibly named. The problem is that there  
 is
 indeed a finite number of terse and sensible names... which bites you
 when you need some of those names. Hence why in my code I have  
 started
 to just capitalize variables.

 In my code: A function is something that is executed in its lexical
 scope.
   -Patrick
 


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



Q: How to convert a struct-map to xml and back (ignoring functions)?

2009-09-20 Thread MarkSwanson

I would like to encode/decode Clojure structures to/from a database.
Parsing XML is easy, but I can't seem to find a simple way to encode
Clojure structures to XML and back. Atm my structures are simple: just
simple key/value pairs where the key is always a string and the value
is always a string or a set of strings.

clojure.xml/emit and clojure.contrib.laxy_xml/emit both require
specially constructed structures which isn't useful to me. I was
hoping for a core or contrib function that was more generic that
dynamically and recursively determined the structure keys for element
names and strings for the element text data.

In my mind I was thinking something simple like what Sarissa provides
for JavaScript.
If nothing exists I'll take a stab at it. I just thought I'd ask
because the available Clojure libraries seem quite good and I feel
like I'm missing something obvious.

Cheers.

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



Re: If you wish to have a version for off-line use...

2009-09-20 Thread MarkSwanson

Personally, that's not what I want.

I want to download the clojure.org web page - one level deep so the
files api, special_forms, macros, etc. are all available on my laptop
offline.
I tried a couple of programs (wget and httrack) to get this but there
is some strange combobulation of redirects and cookie sessions going
on that prevented these from working (for me).

If anyone knows an easy way to get this documentation available
offline please contribute.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Q: How to convert a struct-map to xml and back (ignoring functions)?

2009-09-20 Thread Timothy Pratley

I've found clojure-contrib/prxml to be very useful
http://richhickey.github.com/clojure-contrib/prxml-api.html



On Sep 21, 8:32 am, MarkSwanson mark.swanson...@gmail.com wrote:
 I would like to encode/decode Clojure structures to/from a database.
 Parsing XML is easy, but I can't seem to find a simple way to encode
 Clojure structures to XML and back. Atm my structures are simple: just
 simple key/value pairs where the key is always a string and the value
 is always a string or a set of strings.

 clojure.xml/emit and clojure.contrib.laxy_xml/emit both require
 specially constructed structures which isn't useful to me. I was
 hoping for a core or contrib function that was more generic that
 dynamically and recursively determined the structure keys for element
 names and strings for the element text data.

 In my mind I was thinking something simple like what Sarissa provides
 for JavaScript.
 If nothing exists I'll take a stab at it. I just thought I'd ask
 because the available Clojure libraries seem quite good and I feel
 like I'm missing something obvious.

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



Re: Metadata: something funny

2009-09-20 Thread samppi

That's perfect. Thanks a lot, everyone.

On Sep 20, 11:35 am, Jarkko Oranen chous...@gmail.com wrote:
   (def b #^{:b 2} (quote (1 2 3)))

  ... and #^{} applies read-time to the following *form* rather than the
  value they evaluate to, so that is why neither (list ...) nor (quote
  ...) work.

 Yep. #^ is for read-time metadata. Note though that the following will
 work:
 (def b '#^{:b 2} (1 2 3)) ; read carefully :)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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 anyone here give a comparison between Clojure and Erlang on concurrent programming?

2009-09-20 Thread dongbo

A million thanks to you guys!

To ss: concise and clear. very helpful!
To Wojtek: very detailed, I'll bear your suggestion in my mind! Thanks
a lot
To Timothy: thanks for sharing!

-dongbo
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: If you wish to have a version for off-line use...

2009-09-20 Thread Adrian Cuthbertson

Generally I use the source code for clojure and contrib documentation.
I open an instance of Jedit on the source directory and use it's
search/grep facilities to find what I'm looking for. It also helps in
familiarising with the clojure and contrib implementations and
learning the techniques used. It's also always available. (I use
vim/vimclojure separately as my ide and jedit only for source/doc
browsing).

Rgds, Adrian.

On Mon, Sep 21, 2009 at 12:37 AM, MarkSwanson mark.swanson...@gmail.com wrote:

 Personally, that's not what I want.

 I want to download the clojure.org web page - one level deep so the
 files api, special_forms, macros, etc. are all available on my laptop
 offline.
 I tried a couple of programs (wget and httrack) to get this but there
 is some strange combobulation of redirects and cookie sessions going
 on that prevented these from working (for me).

 If anyone knows an easy way to get this documentation available
 offline please contribute.

 


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



exception: agents + swing

2009-09-20 Thread Raoul Duke

hi,

i don't have a repro case yet, but i've been trying to use agents to
be able to get swing's thread to draw things from my engine w/out
having to think hard about threading; using @agent in my swing-related
code to get the state of things to be drawn. but sometimes i get an
error on a source line that is doing @agent. for example, below is the
top of one such exception.

any ideas what might be going on to case this exception? i'm on
clojure 1.0.0, winxppro, java 1.6.0_15-b03.

user= Exception in thread AWT-EventQueue-0 java.lang.Exception:
Agent has errors
at clojure.lang.Agent.deref(Agent.java:129)
at clojure.core$deref__3725.invoke(core.clj:1285)

thanks.

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



Q: how to solve this concurrency problem ?

2009-09-20 Thread Roger Gilliar

Hi,

im not sure how to solve the following problem:

(defn parse [outstream-agent xml]
(let [content  (clojure.xml/parse (ByteArrayInputStream. (. xml  
getBytes)))
first-element   (:tag content) ]
(try
(if @*is-syncing*
(do
; iust continue f the agent is not 
running
(await *message-cache-agent* )
(if @*is-syncing*
(let [command (first-element 
*process-during-sync*)
  cache   (first-element 
*cache-during-sync*)
  ]
(if command
(command 
outstream-agent content)
(if cache

(cache-message content)
)
)
)
((first-element *messages*) 
outstream-agent content)
)
)
((first-element *messages*) outstream-agent 
content)
)
(catch Exception e
(do
(info (. e getMessage))
(fatal (str Unknown command: first-element))
false
)


The above code can be run by n threads. If the application is syncing  
certain messages are going to be cached. At some point the messages in  
the cache needed to be processed by a different thread (the *message- 
cache-agent* in this example). After that *is-syncing* is false. The  
problem with the above code is that messages could be added to the  
cache after the message-cache-agent is started so that is possible  
that some messages are not sent by the agent.

Right now I can only think of two solutions:

1.) the message-cache-agent checks for a certain amount of time if  
there are now new messages
2.)  I modify the code like this:

(if cache
(cache-message content)
(if (mesage-cache-agent-is-running)
(send-of *message-cache-agent* send-last-message-with 
content
)

The question  is.What would be the correct solution to this problem ?

Regards
   Roger

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