Component question/advice

2019-09-16 Thread Don Jackson
Hello,

I'm writing an app/system that subscribes to a number of feeds, the number 
and configuration of the feeds is a configurable run-time thing.
Seems like I should have a Feed component, which is passed its config when 
instantiated.
But having a named slot in the system for each feed would be painful and 
kinda defeats the point of having a variable number of feeds that get 
configured.

How best to deal with this in Component?

One thought I had was to create a Feeds (note plural, trailing s) component.
The Feeds component would be instantiated with a collection of feed 
configs, and would have a single slot to hold the collection of 
instantiated feeds.
This Feeds component would instantiate a Feed component for each feed, and 
could start/stop them in its own start/stop methods.

I appreciate/understand that my individual Feed components would not be 
participating in the System dependency injection, but AFAICT they don't 
need to.

The above seems like it would work fine, but also seems like it is not 
idiomatic Component.

I would welcome any thoughts/advice as to how best to structure this with 
Component.

Thanks

Don



-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/0caae21e-b7c0-422f-a157-15c535c84022%40googlegroups.com.


Re: [ANN] Throttler: a library for rate limiting

2014-05-17 Thread Don Jackson

On May 16, 2014, at 11:11 PM, Bruno Vecchi vecch...@gmail.com wrote:

 As per having a random frequency between an interval, could you clarify a 
 bit? Do you want the time between requests to be drawn randomly from some 
 distribution each time? If that's the case, the best way I can think of would 
 require a change in the implementation of the bucket filling go thread. 
 Instead of doing:
 
 (timeout some-constant)
 
 it would have to do
 
 (timeout (sample distribution))
 
 Or maybe even more generally just
 
 (timeout (gen-timeout))
 
 where gen-timeout is just a function that returns a timeout value for the 
 next function call. For the common case it would have to be `(constantly 
 some-number)`.

I like gen-timeout the best.  It is the most general.  


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: [ANN] Throttler: a library for rate limiting

2014-05-16 Thread Don Jackson

On May 14, 2014, at 9:43 AM, Bruno Vecchi vecch...@gmail.com wrote:

 Throttler[1] is a little library I wrote out of need for one of my personal 
 projects. It lets you control the maximum rate of function calls or message 
 transmissions through core.async channels.

This is way cool, thanks for sharing it!

A while back I needed something like this to throttle http requests, and I 
cobbled something together that used Thread/sleep, 
it worked, but vastly inferior to your library, AFAICT. I intent to throw out 
my code out and use your library.

In my application, I would like to have a throttle-fn that was guaranteed not 
to occur faster than some number, but also want to add a (bounded) random 
number to that limit.
For example, let's say I wanted my http requests to be no more frequent than 
every 5 seconds, but some random number of seconds between 5 seconds and 15 
seconds.
Is there any way to add/modify throttler to handle a case like that?

In my application, I use clj-http to make http requests, and what I did was to 
create a wrap-throttle middleware and added that to the middleware stack for the
(customized) http client I used for rate-limited requests.  I am thinking that 
approach would work well with your throttle-fn

Best regards,

Don

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

2013-11-03 Thread Don Jackson

On Nov 2, 2013, at 9:27 AM, Mark Engelberg mark.engelb...@gmail.com wrote:

 I seem to be a relatively lone voice thinking it makes sense to preserve the 
 type of the map, and honestly, I'm not going to lose any sleep if this patch 
 is never actually implemented, but here's my two cents on the optimal 
 design for records.
 
 Earlier in the thread, I mentioned two mental models about how select-keys 
 works.  Even though the actual implementation involves starting from an empty 
 map and building back up, I think the behavior of select-keys should mimic 
 the mental model of discarding irrelevant keys.
 
 The two mental models predict somewhat differently what would happen when 
 working with records.  Records can hold additional keys.  So imagine someone 
 dumps a whole lot of additional keys, and then wants to recover the 
 original, true record, by calling select-keys with the original keys in the 
 record.  I think this is a use case worth supporting.  This corresponds to 
 the mental model of discarding unwanted keys.
 
 To implement this for records:
 If any of the original record keys do not appear in the selected keys, then, 
 as with dissoc, we must revert back to a map as there is no valid way to 
 represent this as a record.
 Otherwise, maintain the record type -- the core record contents are 
 preserved, and essentially you only need to call select-keys only on the 
 extended map of extra keys stored in the record.

I agree 100% with Mark’s comments above.
This is exactly the model I would expect select-keys to have.

Conceptually, this is how I imagine select-keys should work:

(defn select-keys++
  Returns a new map of the same (hashed/sorted) type,
  that contains only those entries whose key is in keyseq
  [map keyseq]
  (apply dissoc 
 map 
 (clojure.set/difference (set (keys map))
 (set keyseq

I am not saying that this would be the best , or even a good, implementation.

Like Mark, I am not going to lose any sleep about this either, but I was using 
Mark’s data.priority-maps the other day,
did a select-keys to winnow down my priority-map, and was surprised by the 
result.
Perhaps I should not have been surprised….
In preparing this email, I carefully re-read the doc strings for both dissoc 
and select keys:

(defn dissoc
  dissoc[iate]. Returns a new map of the same (hashed/sorted) type,
  that does not contain a mapping for key(s).”

(defn select-keys
  Returns a map containing only those entries in map whose key is in keys

Clearly dissoc makes the promise to return a map of the same type that 
select-keys doesn’t.
A potential non-code change to select-keys might be to emphasize that the 
return map will be
a hash-map, regardless of the kind/type of input map.

Don

 
 
 On Sat, Nov 2, 2013 at 8:49 AM, Andy Fingerhut andy.finger...@gmail.com 
 wrote:
 I attached another patch to the ticket.  It builds up the answer from the 
 empty map {} if the argument is a record (as the current select-keys does), 
 but from (empty map) if it is not a record, so it will preserve sortedness of 
 the argument.  Not sure if there are any other cases that are a problem, or 
 if it does what everyone would expect, but it should be closer.
 
 http://dev.clojure.org/jira/browse/CLJ-1287
 
 Andy
 
 
 On Sat, Nov 2, 2013 at 6:07 AM, Alex Miller a...@puredanger.com wrote:
  One other point:
  Sometimes people use sorted maps and array maps specifically for scenarios 
  in which the keys are not hashable and therefore hash maps would not apply. 
   Dumping the contents into a regular map in such cases doesn't make much 
  sense.
 
 Everything is hashable, not sure what a non-hashable key means. Array maps 
 use the hash of the key to determine the array bucket. If you get the hash 
 code of a sorted map, it will get the hash of all keys and values.
 
 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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
 

Potential improvement to select-keys ?

2013-10-31 Thread Don Jackson

select-keys currently returns a regular hash-map, regardless of the kind of map 
provided as the input argument.

Alternately, select-keys could call empty on it’s map argument to obtain the 
map it will return,  thereby preserving the type of map provided.

FYI, Mark Engelberg recently pushed a change to data.priority-map that ensures 
that the specific flavor of priority-map is preserved through calls to empty…


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


Can a protocol method have the same name as a clojure.core function?

2013-02-07 Thread Don Jackson

I'd like to name a protocol method to be the same name as a clojure.core 
function, for example, get.

Is this possible, and if so, how?

user= (ns ptest.protocol
(:refer-clojure :exclude [get]))
nil

ptest.protocol= (defprotocol TestProtocol
(get
   [_ key]
Returns the contents of field :key) )

TestProtocol

ptest.protocol= (ns ptest.core
  (:require [ptest.protocol :as testp])
  (:refer-clojure :exclude [get]))

ptest.core= (defrecord TF
 [a
 b
 ]
   testp/TestProtocol
   (get
[this key]
   Doesn't work!))

CompilerException java.lang.ClassFormatError: Duplicate method namesignature 
in class file ptest/core/TF, compiling:(NO_SOURCE_PATH:1) 


-- 
-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: Can a protocol method have the same name as a clojure.core function?

2013-02-07 Thread Don Jackson

That makes perfect sense, and I should have figured that out since defrecord is 
implementing
a bunch of useful protocols underneath….

Thanks for the quick response!

On Feb 7, 2013, at 9:38 PM, Ben Wolfson wolf...@gmail.com wrote:

 You just can't use defrecord, because defrecord macroexpands into a
 deftype that implements a *different* protocol with a function *also*
 named get.
 
 On Thu, Feb 7, 2013 at 9:24 PM, Don Jackson
 cloj...@clark-communications.com wrote:
 
 I'd like to name a protocol method to be the same name as a clojure.core
 function, for example, get.
 
 Is this possible, and if so, how?
 
 user= (ns ptest.protocol
(:refer-clojure :exclude [get]))
 nil
 
 ptest.protocol= (defprotocol TestProtocol
(get
   [_ key]
Returns the contents of field :key) )
 
 TestProtocol
 
 ptest.protocol= (ns ptest.core
  (:require [ptest.protocol :as testp])
  (:refer-clojure :exclude [get]))
 
 ptest.core= (defrecord TF
 [a
 b
 ]
   testp/TestProtocol
   (get
[this key]
   Doesn't work!))
 
 CompilerException java.lang.ClassFormatError: Duplicate method
 namesignature in class file ptest/core/TF, compiling:(NO_SOURCE_PATH:1)
 
 
 --
 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your
 first post.
 To unsubscribe from 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.
 
 
 
 
 
 -- 
 Ben Wolfson
 Human kind has used its intelligence to vary the flavour of drinks,
 which may be sweet, aromatic, fermented or spirit-based. ... Family
 and social life also offer numerous other occasions to consume drinks
 for pleasure. [Larousse, Drink entry]
 
 -- 
 -- 
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from 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: Why is there not much conversation on Spreadsheet like APIs in this group?

2013-02-03 Thread Don Jackson

John, 

Thanks for your email and the links, I'm interested in this topic and wasn't 
aware of the previous work you referenced.

I would't be surprised if the sentiments expressed by Stephen Compall in this 
thread, specially 
  my Clojure style seeks immutable solutions, and cells-ishs don't fit in that 
 category
 

might be shared by many in the Clojure community. 
Just something to keep in mind, and it is certainly possible that I'm wrong 
about this.

Important parts of the app I am currently working on definitely have a need to 
react to changes on dependent values

Right now, unfortunately, I am attempting to manage the dependency graph and 
the resulting
updates/propagations manually, which is tedious and prone to error.  
I'm actively looking for a solution that would automate some or all of this.

I'm wondering if this kind of thing might work well in conjunction with the 
graph library recently released by Prismatic, and there are
are similar work-alike libraries.

One idea I am currently mulling over is compiling a computation specified in 
the graph manner into a dynamically updatable
realization/implementation, somewhat similar to the way that Prismatic compiles 
their graphs into maps , lazy maps, 
or a map with each subcomputation spawned in parallel via futures.

I'm definitely interested in talking/working with others with similar 
interests/requirements….

Don

On Feb 3, 2013, at 1:39 AM, john john.vie...@gmail.com wrote:

 Hi,
 the library 
 https://github.com/straszheimjeffrey/dataflow
 and 
 http://richhickey.github.com/clojure-contrib/dataflow-api.html (1)
 
 or 
 https://github.com/gcv/dgraph 
 
 seems to me very cool for systems that need to react on changes on dependent 
 values. I very much like the API in (1)
 
 Actually my personal opinion is that this is a very substantial thing in 
 business applications.
 
 Am I wrong but nobody seems to bother about them? 
 (I am not well clojure connected so this assumption is totally based on 
 git-update-dates / clojure-user-group discussions / planet.clojure.in posts)

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




(into [] (take n v)) vs (subvec v 0 n)

2013-01-31 Thread Don Jackson

In the app I am working on, I have a number of  pre-computed,cached 
collections, 
and for each collection, I have an accessor function that returns either the 
entire collection or the first n elements.

Currently the underlying collection is a vector, so I had something like this:

(defn foo-accessor
  ([] foo-vector)
  ([n] (take n foo-vector)))

It occurred to me that take returns a list, and so the type returned by my 
accessor was dependent on how it was called,
I thought I would change that, and remembered subvec, so I substituted in 
subvec for take, like this:

([n] (subvec foo-vector 0 n))

That worked great until ( (count foo-vector) n), and I got an 
IndexOutOfBoundsException

So, then without thinking much, I wrote 

(defn  subvec-safe
  subvec fails if you specify an end that is greater than count.  This version 
checks that, and DoesTheRightThing!
  ([v start]
 (subvec v start))
  ([v start end]
 (if ( (count v)
end)
   (subvec v
   start
   end)
   (subvec v
   start
   (count v)

(Yes, it is safe ONLY for the end value…)

And
(defn takev
   take for a vector, returns a subvec or the vector itself. Uses subvec-safe 
so specifying a n longer than (count v) works
   [n vec]
   (subvec-safe vec
0
n))

Even before finishing takev, it occurred to me that

(defn- takev
  take for a vector
  [n vec]
  (into []
(take n
  vec)))

Might be easier/faster. 

subvec returns a clojure.lang.APersistentVector$SubVector

whereas (into [] (take …)) returns a vector.

Any thoughts on which of the above is better?

Thanks,

Don



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




Advice/recommendations for generating templated (non-Clojure) s-expressions?

2012-09-02 Thread Don Jackson
‎
Hello,

I want to generate non-Clojure s-expressions in Clojure code, with a nice 
templating format (like syntax-quote provides), BUT with the option of 
providing my own methods/functions for
resolving/processing symbols, and the ability to provide my own 
methods/functions for evaluating syntax-quote escapes, e.g. ~, @.

Is there anything out there I can use?

Here is some background:

I have been playing around with generating SUO-KIF from Clojure code.

ontolog.cim3.net/file/resource/reference/SIGMA-kee/suo-kif.pdf

Here is an example SUO-KIF form:

(=
  (instance ?COMPANY Coffeeshop)
  (exists  (?SERVICE ?BEVERAGE)
(and
  (instance  ?SERVICE   CommercialService)
  (agent ?SERVICE   ?COMPANY)
  (instance  ?SERVICE   Selling)
  (patient   ?SERVICE   ?BEVERAGE)
  (instance  ?BEVERAGE  Coffee
I'd like to generate the above via a Clojure macro/function that would be 
called like this:

(sells Coffeeshop Coffee)

By defining sells something like this:

(defmacro-like-thing sells [kind-of-store product]
`(=
(instance ?COMPANY ~kind-of-store)
(exists  (?SERVICE ?PRODUCT))
…
))

My initial thought was this was going to be completely trivial, and I'd be done 
in 30 minutes maximum
and it is easy to generate something right away, but I am not at all happy
with the result, especially what the Clojure code templates look like.

It would be really nice if the resulting template would look very close to the 
resulting output, so that users of this tool (Ontologists, not programmers)
could easily see/specify the templates.  

My first thought was that I would use Clojure macros and syntax-quote to 
generate the SUO-KIF  s-expressions.  
To my way of thinking, syntax-quote is a very nice s-exp templating tool, what 
could be easier?
I quickly re-learned that macros are a really about generating Clojure, at read 
time, that is then eval'ed.
Two issues with that:
1) symbols in my template specification are 
resolved/namespace-qualified by syntax-quote, which is not what I want at all.
2) I don't want the resulting s-expression to be eval'ed by Clojure.  I 
can work around that by having the the macro return (quote s-exp), I guess.

I then tried using syntax-quote within a Clojure function, but again, 
syntax-quote is resolving/namespace-qualifying the symbols, 
and of course, a function's arguments are always evaluated on the way in, which 
leads to tedious and unpleasant quoting of SUO-KIF symbols.

I'd welcome any thoughts/pointers about how best to approach this.

Don



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

tools.logging question

2012-02-17 Thread Don Jackson

I would like to conditionally generate log statements based on run-time checks 
of various application-specific info.

I note  the following:

Logging levels are specified by clojure keywords corresponding to the values 
used in log4j and commons-logging:
:trace, :debug, :info, :warn, :error, :fatal
log
macro
Usage: (log level message)
…
Evaluates and logs a message only if the specified level is enabled. 

So, it occurs to me that for the level argument to log, I could pass in a 
function that would figure out if I really wanted to log anything right then, 
or not.

In the case that I *do* want to log something, that function would return the 
log level, e.g. :info  (this part seems to work fine…)

But what could my function return if it didn't want anything to be logged at 
this point?

Any log level beneath the current level in effect would seem to work, but 
figuring that out feels hackish, and what if the lowest level of logging 
(:trace ?) is enabled, then what?
Nil and/or false did not work at all in my test!

Is there something like a :noop level, that would never be enabled, and could 
be returned by my function whenever it decided it did not want the log to 
happen?

Obviously/alternately I could wrap all my logging in

(when (log-decision args) (log :level message))

But right now I'd rather do all this with just the log call,and I'm hoping 
there is already a way to do what I ask above, or if not, willingness to add 
something like a :noop level 

Don









-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: No longer able to write a UUID to Postgres with ClojureQL

2011-12-06 Thread Don Jackson

On Dec 6, 2011, at 11:23 AM, Sean Corfield wrote:

 On Tue, Dec 6, 2011 at 6:12 AM, Herwig Hochleitner
 hhochleit...@gmail.com wrote:
 2011/12/6 Sean Corfield seancorfi...@gmail.com:
 So the question is probably: why is ClojureQL assuming all generated
 keys are integers?
 It shouldn't, and doesn't now:
 https://github.com/LauJensen/clojureql/commit/f7ffe88b166e6f60eccb3b4f46b7db5d69dbcc64
 Thanks for tracing this and taking the time to post it.

I have confirmed that this change/commit fixes my/the problem!

Thank you Herwig for the fix, and thank you Sean for narrowing the problem down!



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


No longer able to write a UUID to Postgres with ClojureQL

2011-12-05 Thread Don Jackson

For those of you following along at home, my spate of bad luck continues….

A week or so ago, I was happily writing and reading UUIDs into Postgres with 
ClojureQL.
Then, all of a sudden, it stopped working, and I can't figure out why.

Shame on me for not being more careful about documenting when it worked, and 
what changed.  
And a lot of stuff changed in the interim…

So I wrote small example project to demonstrate the problem:

I have verified that I can write UUIDs into Postgres with java.jdbc itself, so 
that is evidence that the issue is not with java.jdbc, the Postgres JDBC 
library, nor my Postgres server.

(def u1 (. UUID (randomUUID)))
(def u2 (. UUID (randomUUID)))

(defn write-uuid-jdbc
  [uid name]
  (sql/with-connection postgres-db
(sql/insert-values
 :testuuid
 [:uid :name]
 [uid name])))

(defn read-table-clojureql
  []
  @(table postgres-db :testuuid))

(defn write-uuid-clojureql
  [uid name]
  (conj! (table postgres-db :testuuid)
 {:uid uid :name name}))

This illustrates the problem:

(write-uuid-jdbc u1 jdbc) 

works.

(write-uuid-clojureql u2 clojureql) 

throws the following exception:

Bad value for type int : d812274a-a1ff-4ce5-962e-005f3c893459
  [Thrown class org.postgresql.util.PSQLException]

Restarts:
 0: [QUIT] Quit to the SLIME top level

Backtrace:
  0: 
org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.java:2759)
  1: 
org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2003)

Now write u2 with jdbc:

(write-uuid-jdbc u2 jdbc)

And read the entire table back out using ClojureQL:

(read-table-clojureql)

({:name jdbc, :uid #UUID 2896de2b-2c48-40ab-83a6-cee6c2be16cd} 
 {:name jdbc, :uid #UUID d812274a-a1ff-4ce5-962e-005f3c893459})

So ClojureQL can certainly read the table, and return the UUIDs, but can't 
write them…

Here is the relevant part of project.clj:

  :dependencies [[org.clojure/clojure 1.2.1]
 [postgresql/postgresql 9.1-901.jdbc4]
 [org.clojure/java.jdbc 0.1.1]
 [clojureql 1.1.0-SNAPSHOT]
 ])

I woud definitely appreciate/welcome any suggestions about why this is 
happening, or how it might be fixed….

I've pushed this example test case/project up to GitHub in case anyone wants to 
poke around:

dcj/postgres-uuid-test 

Don







-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: FYI: problem I had with namespace, defrecord, and import, or Hyphen characters in namespaces considered harmful

2011-12-04 Thread Don Jackson

On Dec 2, 2011, at 1:29 PM, Phil Hagelberg wrote:

 I was using defrecord for the first time, to create a type that I wanted to
 throw+ via slingshot to signal errors from a library.
 
 For what it's worth, the main point of slingshot is removing the
 necessity of creating custom classes for exceptions, so this shouldn't
 be necessary in the first place.

Would you elaborate on this a bit more?  I would greatly appreciate the 
education!

Let's say I am writing some code that uses three different libraries (actiona, 
actionb, and actionc) to accomplish its goals.
Each of these action libraries can generate an exception that indicates that 
things did not go well for the user/client.

I'd like to write my code so that the try+ clause is the everything works 
path, and that I then catch various errors that each of my actions may have 
generated.
Assume that I need to distinguish between the three possible action exceptions, 
and handle them completely differently.

If each of the (independently written) action libraries throws its own map, 
then how do I distinguish between these maps, especially if they happen to use 
identical keywords to report errors?

One reason I was/am attracted to the each action library should define its own 
error record type I mentioned originally is that it makes distinguishing 
between these different exceptions trivial:

(try+
 (- (actiona data)
 (actionb)
 (actionc))
 (catch actiona-error ...)
 (catch actionb-error ...)
 (catch actionc-error …))

Perhaps putting multiple exception generating actions into one try+ is not the 
recommended/idiomatic approach?
I guess I could be convinced of that, but at the moment, I really like 
concentrating first on implementing the functionality of my app,
and then catching and dealing with all the errors at the top level.  
I find code that for every call has to test or try/catch errors for every thing 
it does is more painful to follow/read, but maybe that is just my 
bias/limitation.

To take a random example, the library clj-http throws its normal response map 
when the http response code it receives is not unexceptional-status?
So how do I catch that?
By looking for a key of :status?
That seems quite ripe for key name collisions, if there are more than one 
action in the try block that could create an exception, and more than one 
action generates a map with the keyword :status
Here is what I am doing right now:

(defn http-response-map?
  [hrm]
  (get hrm :status false))

  (try+
   (client/get url)
   (catch http-response-map? {:keys [status headers body]} … ))

I had some confusion last night when I was not specific enough about the 
exceptions I was catching, 
and a catch of Object that I (in error) thought would only catch the last 
remaining exception caught everything, 
and something else that I didn't expect threw, and I didn't realize the problem 
for a while….totally my fault, 
but further motivation that catches be very specific about what they are 
catching, 
and I'd like to understand how best to do that without defining custom classes.

Best regards,

Don








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

FYI: problem I had with namespace, defrecord, and import, or Hyphen characters in namespaces considered harmful

2011-12-02 Thread Don Jackson

I was using defrecord for the first time, to create a type that I wanted to 
throw+ via slingshot to signal errors from a library.

I'd seen an example of this in another library, and I pretty much just cut and 
pasted it into my project.

I understood that I need to explicitly import the resulting class into clients 
that use my library, and attempted to do so.

When loading the client library that uses and imports, I got this:

foo-bar.core.foo-bar-error
  [Thrown class java.lang.ClassNotFoundException]

Restarts:
 0: [QUIT] Quit to the SLIME top level

Backtrace:
  0: java.net.URLClassLoader$1.run(URLClassLoader.java:202)
  1: java.security.AccessController.doPrivileged(Native Method)
  2: java.net.URLClassLoader.findClass(URLClassLoader.java:190)
  3: clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:61)
  4: java.lang.ClassLoader.loadClass(ClassLoader.java:306)
  5: java.lang.ClassLoader.loadClass(ClassLoader.java:247)
  6: java.lang.Class.forName0(Native Method)
  7: java.lang.Class.forName(Class.java:169)
  8: factmigrate.core$eval1645$loading__4414__auto1646.invoke(core.clj:1)
  9: factmigrate.core$eval1645.invoke(core.clj:1)
 --more--

After a LOT of time and experimentation, I finally realized that in my import 
statement, I need to replace the hyphen character in my namespace (let's call 
my namespace foo-bar.core)
to an underscore.

So in a client of my library, it needs to do something like this

(ns foobarclient.core
(:use foo-bar.core)
(:import foo_bar.core foo-bar-error))

Assuming that somewhere in the foo-bar.core namespace I had done something like 
this:

(defrecord foo-bar-error [blah1 blah2])

I am still recovering from this debugging session, but my current thought is 
that this was all my fault, and I just need to be smarter about Java interop 
and naming issues.
The hyphen/underscore issue is mentioned here:

http://clojure.org/libs

Lib Conventions
Clojure defines conventions for naming and structuring libs:
A lib name is a symbol that will typically contain two or more parts separated 
by periods.
A lib's container is a Java resource whose classpath-relative path is derived 
from the lib name:
The path is a string
Periods in the lib name are replaced by slashes in the path
Hyphens in the lib name are replaced by underscores in the path

But I did not find this right away, and even after I did find it, it was not 
immediately obvious to me what the implication was in an import statement.

So, I simply wanted to document this for the mailing list, in the hope of 
preventing others from stumbling into this, and maybe if they do, they will 
find this
explanation in their searches…

Don

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

2011-06-09 Thread Don Jackson

On Jun 9, 2011, at 11:49 AM, Laurent PETIT wrote:

 I've seen people coming from a java background quite happy to start
 discovering clojure via the 4clojure website.

Hey, I've got an idea:  Maybe we could get the 4clojure folks to hook their 
site up to Twitter to let us know how people solve these puzzles…

:-(

Don

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

2011-05-15 Thread Don Jackson

On May 15, 2011, at 1:34 AM, Thorsten Wilms wrote:

 * Wrapper around git or darcs for using them as storage backends

See:  

rnewman/clj-git - GitHub

for a start on this.

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

Re: Clojure ideas repository / todo list

2011-05-15 Thread Don Jackson

On May 14, 2011, at 2:17 PM, Islon Scherer wrote:

 Is there anyplace people post ideas of libraries/frameworks/functions
 that would be nice to be implemented in clojure?
 Sometimes I want to help the community but I don't know what to do (an
 idea), what's already done (yeah, I know one can search github or ask
 here but you can't be 100% sure it's not already implemented). Maybe a
 wiki or something like that would do the job.


Here is one idea:

At IO this week, Google announced their new API Discovery Service:

  It provides a lightweight, JSON-based API that exposes machine-readable 
metadata about Google APIs including:
A directory of supported APIs.
A machine-readable Discovery document for each of the supported APIs that 
includes:
A list of API resource schemas based on JSON Schema
A list of API methods and available parameters for each method.
A list of available OAuth 2.0 scopes.
Inline documentation of methods, parameters and available parameter values.

http://code.google.com/apis/discovery/

https://code.google.com/apis/discovery/v1/using.html

It would be great/cool to have a Clojure library that accessed the discovery 
service, and created Clojure libraries that implement the Google APIs described 
by this service.




-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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] emacs-nexus (Emacs client for Nexus Maven repository servers)

2011-02-15 Thread Don Jackson

On Feb 14, 2011, at 8:21 PM, Michael Ossareh wrote:
 
 Along with anything that is listed in :repositories in your project.clj ?

+1




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

Re: Clojure 1.3: Integrating clj-stacktrace?

2010-08-25 Thread Don Jackson

On Aug 24, 2010, at 9:55 PM, Phil Hagelberg wrote:
 
 Thoughts?

+1.

The existing stack traces are pretty horrible.  Phil's proposal, or something 
similar, would be a huge improvement.


-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from 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: clj-facebook, a Clojure client library for Facebook apps

2010-03-19 Thread Don Jackson

I'd like to announce the initial release of clj-facebook, a Facebook client 
library in Clojure.

The code can be found here:

http://github.com/rnewman/clj-facebook

We welcome comments and proposed code improvements.

Don

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


ANN: clj-facebook, a Clojure client library for Facebook apps

2010-03-19 Thread Don Jackson
I'd like to announce the initial release of clj-facebook, a Facebook client
library in Clojure.

The code can be found here:

http://github.com/rnewman/clj-facebook

We welcome comments and proposed code improvements.

Don

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.