Unable to get a response from my server, after re-architecting to get away from global vars

2015-06-12 Thread Lawrence Krubner
When I first wrote a Clojure web app, I followed a lot of the basic 
tutorials out there, and those tend to create a lot of global vars. So, for 
instance, I used the "defroutes" macro from Compojure, which left me with a 
global "app-routes" var. 

But lately I wanted to switch to a style that would allow me to call a 
"start" function that would reboot my app, so that I could more easily 
re-start from the REPL, without shutting down the JVM and starting over 
again. 

So I moved all of my global var stuff inside my start function, like this: 

(defn start [map-of-config]
  (try
(let [port (if (nil? (:port map-of-config))
 34000
 (Integer/parseInt (:port map-of-config)))
  app-routes (routes 
 (ANY "/" [] homepage)
   (GET "/v0.2/token" [] token)
   (GET "/v0.2/errors" [] errors)
 (ANY "/v0.2/:token/:name-of-collection/object-id/:object-id" request 
query/fetch)
 (ANY "/v0.2/:token/:name-of-collection/:document-id" request 
query/fetch)
 (ANY "/v0.2/:token/:name-of-collection/" request query/fetch)
 (route/resources "/")
 (route/not-found "Page not found. Check the http verb that you used 
(GET, POST, PUT, DELETE) and make sure you put a collection name in the 
URL, and possibly also a document ID. Also, all requests should go to an 
URL that starts with /v0.2"))
  app (-> app-routes
  (wrap-json-response)
  (middleware/wrap-objectid-to-str)
  (middleware/wrap-prepare-message)
  (middleware/wrap-error-post-with-document-id)
  (middleware/wrap-malformed?)
  (middleware/wrap-check-content-type)
  (middleware/wrap-transaction-id)
  (middleware/wrap-token)
  (middleware/wrap-token-check)
  (middleware/wrap-cors-headers)
  (wrap-keyword-params)
  (wrap-multipart-params)
  (wrap-nested-params)
  (wrap-params)
  (wrap-json-body {:keywords? true})
  (wrap-content-type))
jetty (run-jetty app {:port port :join? false :max-threads 5000})]
  ;; we want to reboot this app from the REPL, so the start function 
needs to overwrite "server"
  (println (str "The port number we will listen to: " port))
  (timbre/log :trace (str "The port number we will listen to: " port))
  (swap! server (fn [old-value] jetty)))
(catch Exception e (println e

This does not throw an exception. And, once it is running, if I do this: 

netstat -ntlp | grep LISTEN

then I can see there is suddenly an app listening on port 34000: 

tcp0  0 127.0.0.1:27017 0.0.0.0:*   LISTEN 
 -   
tcp0  0 127.0.0.1:3306  0.0.0.0:*   LISTEN 
 -   
tcp0  0 0.0.0.0:22  0.0.0.0:*   LISTEN 
 -   
tcp0  0 127.0.0.1:5432  0.0.0.0:*   LISTEN 
 -   
tcp6   0  0 :::34000:::*LISTEN 
 12835/java  
tcp6   0  0 :::80   :::*LISTEN 
 -   
tcp6   0  0 :::22   :::*LISTEN 
 -   

But if I point my browser at this port, I get nothing. I do not get an 
exception, I also see nothing printed at the terminal.

I have gone through and added print statements to all of my middleware, but 
I can not see any of the print statements in the terminal. I am wondering 
if it is possible for a request to come in and get swallowed entirely, 
without even triggering the middleware? 




-- 
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: stuartsierra/component is oop, can clojure namespace self init to solve the dependencies?

2015-06-21 Thread Lawrence Krubner
There are ways to handle dependencies without going down the OOP route that 
Stuart Sierra took. However, there are a lot of good ideas in Stuart 
Sierra's Component library, and to the extent that you can borrow those 
ideas, you end up with code that resembles "best practice" in the Clojure 
community. 

For me, one "Big Idea" that I got from Stuart Sierra is that there should 
be a "start" method that can be called either from the REPL or from -main 
(for when you app runs as a daemon). The other "Big Idea" I got was that 
there should be functions for handling the lifecycle of all the components 
in your app, so you can easily start and stop and restart. So nowadays my 
"core.clj" tends to look like this: 

(ns salesslick.core
  (:gen-class)
  (:require
   [salesslick.start :as start]
   [salesslick.stop :as stop]))

;; what you would call from the REPL to re-initate the app
(defn start []
  (try
(start/start)
(catch Exception e (println e

(defn stop []
  (try
(stop/stop)
(catch Exception e (println e

;; Enable command-line invocation
(defn -main [& args]
  (.addShutdownHook (Runtime/getRuntime)
(Thread.
  #(do (println "Salesslick is shutting down")
(stop
  (start))

So I can call "start" and "stop" from the REPL, or, if the app is running 
as a daemon, "start" gets called by -main, and "stop" is registered as a 
shutDownHook. 

These are great ideas that I got from Stuart Sierra, however, I did not 
feel the need to go as far toward OOP as Stuart Sierra did. And some of 
things he has suggested as "best practice" really strike me as odd. To be 
honest, some of the things he said were astonishing and went against 
everything I have learned over the years. I'm thinking of what he says in 
these 2 videos: 

http://www.infoq.com/presentations/Clojure-Large-scale-patterns-techniques

https://www.youtube.com/watch?v=13cmHf_kt-Q

At one point he says that "Object Oriented code has the advantage that it 
is obvious where you configure your code." 

Wow!!! What can I say about that!!! 

I have lost entire days because I was dragged into stupid, tedious meetings 
whose subject was "How should we refactor these fat Rails models?" 

I've been dragged into incredibly boring meetings to discuss Rails versus 
Sinatra, where the main thing under discussion was really the issue of 
configuration. 

When I am on my deathbed, looking back, I will recall some days fondly, and 
other days I will recall as wasted, and the most sadly wasted days of all 
are the days I was forced to discuss Dependency Injection with my 
co-workers. 

None of my experiences allow me to agree with Stuart Sierra that OOP makes 
it obvious how to configure an app. 

Still, without a doubt, there are good ideas in Stuart Sierra's Component 
library, and it is worth digging into them to find the good ideas. 

The place where I diverge from Stuart Sierra is in his use of Records. His 
main concern seems to be making dependencies visible. It's the same issue 
that Alex Miller focuses on here: 

http://tech.puredanger.com/2014/01/03/clojure-dependency-injection/

My own preference for making dependancies obvious is to use :pre 
assertions. I'm looking at Typed Clojure as a possibility for going further 
down that road. 

There might be use cases where it is fundamentally imperative to use 
something like Stuart Sierra's pseudo-OOP style, but I have not met those 
use cases yet. Most of the work I do tends to be the kind of thing where I 
can spin up some internal "workers" and have them pull work off a queue. I 
can initiate the workers from my "start" function and stop them with the 
"stop" function. Typically, each worker will have its own connection to 1 
or more databases, and each worker takes responsibility for closing its 
database connections once the "stop" function has been called. 

All of this is easy to do within the Functional Paradigm. 

I think there is a fascinating sociological question that haunts the 
Clojure community, regarding OOP. Many of the best Clojure developers spent 
10 or 20 years doing OOP before they came to Clojure, so how much do they 
bring OOP with them because they feel its natural, and they feel it natural 
because they spent so many years with the OOP style? 













On Wednesday, June 17, 2015 at 10:15:21 PM UTC-4, Xiangtao Zhou wrote:
>
> hi guys,
>
> Constructing simple clojure project is trival, just make functions. if the 
> project grows large, with more datasources, message queue, and other 
> storages, dependencies problem is on the table. 
>
> One solution is stuartsierra/component,  using system to configure 
> dependencies graph, make component and dependencies resolution separate.
>
> If we make namespace must run with code block that init the namespace, 
> like the "start" method in component, is this a good way to solve the 
> dependencies?
>
> because when the namespace is required the first time, the init block 
> worked once.
>
> any suggestio

Re: stuartsierra/component is oop, can clojure namespace self init to solve the dependencies?

2015-06-21 Thread Lawrence Krubner

>
>
> > As it sounds a lot like your definition of OOP to me.
>
> For sure, this code relies on messages passing. It is "functional" in the 
> old sense that the messages are functions -- a usage of the word 
> "functional" that any Lisper would have understood for decades. But it is 
> not "functional" in the newer sense of "immutable". 
>
> However, I avoid the things I dislike most about OOP: instantiating 
> objects, and having an outside Dependency Injection system that decides 
> what the dependencies of this code should be. As much as possible, I try to 
> write "start" and "stop" functions that take responsibility for initiating 
> whatever needs to be initiated for this namespace. 
>
>
> So it sounds like you went and re-built component, but this time 
> around message passing, and mutable actors.

And without records, which was the thing I felt was unnecessary in 
Component. 


A slightly simplified example: 
>
> (ns mercury.message-queue
>   (:require
>[mercury.datastore :as datastore]
>[manifold.stream :as stream]
>[manifold.deferred :as deferred]
>[taoensso.timbre :as timbre]
>[clojure.test :as test]))
>
> (def ^:private message-stream (atom nil))
>
> (defn enqueue
>   [message eventual-result]
>   {:pre [
>(keyword? (:field-to-sort-by message))
>  (number? (:offset message))
>  (number? (:limit message))
>   ]}
>   (stream/put! @message-stream
> [
>  (fn [db-connection]
>  (try 
>   (datastore/execute message db-connection)
>   (catch Exception e (timbre/log :trace (str "The was an exception when we 
> tried to call the datastore layer: " e)
>  eventual-result
> ]))
>
> (defn- worker
>   [db-connection]
>   (loop [message-vector @(stream/take! @message-stream)]
>   (let [message-fn (first message-vector)
> eventual-result (second message-vector)]
> (deliver eventual-result (message-fn db-connection)))
> (if (= @message-stream ::stop)
>   (datastore/stop db-connection)
>   (recur @(stream/take! @message-stream)
>
> (defn start
>   [map-of-config-info]
>   (swap! message-stream (fn [old-stream] (stream/stream)))
>   (dotimes [_ 10]
> (future (worker (datastore/start map-of-config-info)
>
> (defn stop []
>   (swap! message-stream (fn [old-stream] ::stop)))
>   
>   
>
 
 

> The "start" method spins up some workers and makes sure they each have a 
> database connection. 
>

The "stop" function sets in motion events that cause each worker to shut 
down its own database connection. 

 

>
>
>
> On Sunday, June 21, 2015 at 7:10:42 PM UTC-4, tbc++ wrote:
> I'd like to see an example of this "functional worker" style you mention. 
> As it sounds a lot like your definition of OOP to me. Not to mention that 
> anything that talks to a queue is performing io and is therefore not 
> functionally pure. So it sounds like you went and re-built component, but 
> this time around message passing, and mutable actors.
>
> On Sunday, June 21, 2015, Lawrence Krubner  wrote:
> There are ways to handle dependencies without going down the OOP route 
> that Stuart Sierra took. However, there are a lot of good ideas in Stuart 
> Sierra's Component library, and to the extent that you can borrow those 
> ideas, you end up with code that resembles "best practice" in the Clojure 
> community. 
>
> For me, one "Big Idea" that I got from Stuart Sierra is that there should 
> be a "start" method that can be called either from the REPL or from -main 
> (for when you app runs as a daemon). The other "Big Idea" I got was that 
> there should be functions for handling the lifecycle of all the components 
> in your app, so you can easily start and stop and restart. So nowadays my 
> "core.clj" tends to look like this: 
>
> (ns salesslick.core
>   (:gen-class)
>   (:require
>[salesslick.start :as start]
>[salesslick.stop :as stop]))
>
> ;; what you would call from the REPL to re-initate the app
> (defn start []
>   (try
> (start/start)
> (catch Exception e (println e
>
> (defn stop []
>   (try
> (stop/stop)
> (catch Exception e (println e
>
> ;; Enable command-line invocation
> (defn -main [& args]
>   (.addShutdownHook (Runtime/getRuntime)
> (Thread.
>   #(do (println "Salesslick is shutting down")
> (stop
>   (start))
>
> So I can call "start" and "stop" from the REPL, or, if the app is running 
> as a daemon, "start

How to share the large files that can not fit in Github?

2015-06-22 Thread Lawrence Krubner

This is more of Java eco-system/development question, but I am curious what 
folks in the Clojure community might regard as "best practice". Up till now 
most of the projects that I've worked on we've been able to share resources 
informally via "scp" and email, or via Github, but on the current project 
we are dealing with a lot of massive files, over 100 megs, many over a gig. 
These are things such as Natural Language Processing 
classifiers/dictionaries, many of which are huge. We need to have them 
available on our machines so we can do development work. We're trying to 
figure a way such that when we add new paths or new files we can tell each 
other, or find a way that they can do something similar to "git fetch 
origin" and see what changes have happened. 

How do others handle 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
--- 
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.


Using Hystrix comes at a cost?

2015-07-24 Thread Lawrence Krubner
I find this very interesting: 

http://blog.josephwilk.net/clojure/building-clojure-services-at-scale.html

"[Using Hystrix comes at a cost:] We cannot use Clojure’s concurrency 
primitives (futures/promises/agents)."

That is fascinating to think that at some point Clojure's concurrency 
primitives are not enough, and so we need to give up on them and move to a 
Java library. I am aware that Netflix is dealing with unusual scale, but 
what is the point of Clojure if it doesn't automate exactly these issues? I 
don't mean this as an attack on Clojure, but rather, I'm curious why issues 
of thread pool management and circuit breakers don't get baked in to a 
deeper level of Clojure? After all, that is the reason why people use 
Clojure, yes? The argument for Clojure is exactly that it automates so much 
of the work of dealing with concurrency, right? 

Am I being stupid? 




-- 
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: Using Hystrix comes at a cost?

2015-07-24 Thread Lawrence Krubner
Thank you, Stuart. This is a useful rule that I'll try to remember: 

"Clojure makes it easier to write programs which manage their state 
correctly. Hystrix makes it easier to write programs which manage 
side-effect-heavy libraries correctly."

 

On Friday, July 24, 2015 at 2:36:28 PM UTC-4, Stuart Sierra wrote:
>
> Hi Lawrence,
>
> I think Clojure's concurrency primitives are more narrowly scoped than 
> that.
>
> Clojure's most significant concurrency features (Atoms, Refs, Vars, 
> Agents) are mostly about managing changes to *shared, mutable state* via 
> pure functions. Hystrix is about managing code with unpredictable behavior 
> and timing, e.g. client libraries which do blocking I/O and other side 
> effects.
>
> When I do presentations or workshops about Clojure, I always make a point 
> to say that Clojure does not try to solve **all** problems related to 
> concurrency and parallelism. You still need things like Java thread pools. 
> Clojure was designed as a hosted language precisely so that it can take 
> advantage of the rich set of concurrency tools available on the JVM 
> platform, including frameworks like Hystrix.
>
> Clojure makes it easier to write programs which manage their state 
> correctly. Hystrix makes it easier to write programs which manage 
> side-effect-heavy libraries correctly. Together, they make a pretty good 
> combination.
>
> –S
>
>
> On Friday, July 24, 2015 at 1:10:10 PM UTC-4, Lawrence Krubner wrote:
>>
>> I find this very interesting: 
>>
>> http://blog.josephwilk.net/clojure/building-clojure-services-at-scale.html
>>
>> "[Using Hystrix comes at a cost:] We cannot use Clojure’s concurrency 
>> primitives (futures/promises/agents)."
>>
>> That is fascinating to think that at some point Clojure's concurrency 
>> primitives are not enough, and so we need to give up on them and move to a 
>> Java library. I am aware that Netflix is dealing with unusual scale, but 
>> what is the point of Clojure if it doesn't automate exactly these issues? I 
>> don't mean this as an attack on Clojure, but rather, I'm curious why issues 
>> of thread pool management and circuit breakers don't get baked in to a 
>> deeper level of Clojure? After all, that is the reason why people use 
>> Clojure, yes? The argument for Clojure is exactly that it automates so much 
>> of the work of dealing with concurrency, right? 
>>
>> Am I being stupid? 
>>
>>
>>
>>
>>

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


a question about Chris Zheng's "Abstract Container Pattern"

2015-07-27 Thread Lawrence Krubner
I have a question about this: 

"Servers that are running on a particular port can be tracked and stopped. 
I have to say, this was the feature that I wanted the most, which motivated 
the framework's design. The annoying thing about development in emacs is 
that I have to be careful of not losing the reference to the server. Since 
there was no way of stopping it unless the repl is restarted. I wanted to 
implement a registery for references to running servers to be saved."

http://z.caudate.me/the-abstract-container-pattern/

I have the impression that he's going over the same territory as that 
covered by Stuart Sierra, though Zheng doesn't mention "Component" nor 
"Sierra". But he offers this as an example of what he's after: 

(defprotocol IRunnable (start! [system]) (stop! [system]) (restart! [system]
) (started? [system]) (stopped? [system]))

That much seems similar to Sierra's system. Zheng seems to add an 
additional layer by simulating an abstract class above his protocols. As he 
says: 


   - A single deftype acts as the *abstract container*, extending one or 
   more protocols
   - A set of methods defined through defmulti that is used within the 
   deftype form act as *abstract methods*
   - The *abstract methods* all dispatch on map keys (usually :type).


I am curious if others have found this useful? 

Most of the people who work with Clojure have backgrounds with Object 
Oriented Programming, so that paradigm sometimes seems natural, or at least 
familiar. I often think these designs are more verbose than they need to 
be, but I am curious how others feel. 









-- 
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: a question about Chris Zheng's "Abstract Container Pattern"

2015-07-27 Thread Lawrence Krubner



I guess I'm wondering why take Zheng's approach, versus something more 
direct? I'm especially reacting to this: 

One way to look at design using abstract classes (or any language feature 
for that matter) is that it is a programming contract that is strictly 
enforced by the language itself. When we inherit functionality from an 
abstract class, we make a binding contract with the compiler.

…Essentially, it mimics the structure of how abstract classes are defined 
and used in object orientated design through simple use of protocols and 
multimethods.

But why mimic such a contract? Why not just clearly write a contract, using 
a library that is meant to write contracts? I mean, why not use something 
like Typed Clojure? 






On Monday, July 27, 2015 at 1:37:41 PM UTC-4, Lawrence Krubner wrote:
>
> I have a question about this: 
>
> "Servers that are running on a particular port can be tracked and stopped. 
> I have to say, this was the feature that I wanted the most, which motivated 
> the framework's design. The annoying thing about development in emacs is 
> that I have to be careful of not losing the reference to the server. Since 
> there was no way of stopping it unless the repl is restarted. I wanted to 
> implement a registery for references to running servers to be saved."
>
> http://z.caudate.me/the-abstract-container-pattern/
>
> I have the impression that he's going over the same territory as that 
> covered by Stuart Sierra, though Zheng doesn't mention "Component" nor 
> "Sierra". But he offers this as an example of what he's after: 
>
> (defprotocol IRunnable (start! [system]) (stop! [system]) (restart! 
> [system]) (started? [system]) (stopped? [system]))
>
> That much seems similar to Sierra's system. Zheng seems to add an 
> additional layer by simulating an abstract class above his protocols. As he 
> says: 
>
>
>- A single deftype acts as the *abstract container*, extending one or 
>more protocols
>- A set of methods defined through defmulti that is used within the 
>deftype form act as *abstract methods*
>- The *abstract methods* all dispatch on map keys (usually :type).
>
>
> I am curious if others have found this useful? 
>
> Most of the people who work with Clojure have backgrounds with Object 
> Oriented Programming, so that paradigm sometimes seems natural, or at least 
> familiar. I often think these designs are more verbose than they need to 
> be, but I am curious how others feel. 
>
>
>
>
>
>
>
>
>
>

-- 
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] Clojure 1.8.0-alpha2

2015-07-27 Thread Lawrence Krubner
Off topic, but I wonder if there was ever any discussion of megarefs being 
added to Clojure?

https://github.com/cgrand/megaref


On Tuesday, July 21, 2015 at 3:30:46 PM UTC-4, Rangel Spasov wrote:
>
> Ok, I think someone already mentioned this - sorry. Got it to compile by 
> bumping to [potemkin "0.4.1"] - thanks Zach + all : ) 
>
> On Tuesday, July 21, 2015 at 12:24:43 PM UTC-7, Rangel Spasov wrote:
>>
>> Hey guys,
>>
>> Getting this error with 1.8.0-alpha2, I think related to aleph (using 
>> 0.4.0, latest version at the moment).
>>
>> #error {
>>
>>  :cause IllegalName: 
>> compile__stub.aleph.http.core.aleph.http.core/HeaderMap
>>
>>  :via
>>
>>  [{:type clojure.lang.Compiler$CompilerException
>>
>>:message java.lang.NoClassDefFoundError: IllegalName: 
>> compile__stub.aleph.http.core.aleph.http.core/HeaderMap, 
>> compiling:(aleph/http/core.clj:81:1)
>>
>>:at [clojure.lang.Compiler analyzeSeq Compiler.java 6798]}
>>
>>   {:type java.lang.NoClassDefFoundError
>>
>>:message IllegalName: 
>> compile__stub.aleph.http.core.aleph.http.core/HeaderMap
>>
>>:at [java.lang.ClassLoader preDefineClass ClassLoader.java 654]}]
>>
>>  :trace
>>
>>  [[java.lang.ClassLoader preDefineClass ClassLoader.java 654]
>>
>>   [java.lang.ClassLoader defineClass ClassLoader.java 758]
>>
>>   [java.lang.ClassLoader defineClass ClassLoader.java 642]
>>
>>   [clojure.lang.DynamicClassLoader defineClass DynamicClassLoader.java 46]
>>
>>   [clojure.lang.Compiler$NewInstanceExpr compileStub Compiler.java 7815]
>>
>>   [clojure.lang.Compiler$NewInstanceExpr build Compiler.java 7680]
>>
>>   [clojure.lang.Compiler$NewInstanceExpr$DeftypeParser parse 
>> Compiler.java 7590]
>>
>>   [clojure.lang.Compiler analyzeSeq Compiler.java 6791]
>>
>>   [clojure.lang.Compiler analyze Compiler.java 6592]
>>
>>   [clojure.lang.Compiler analyze Compiler.java 6553]
>>
>>   [clojure.lang.Compiler$BodyExpr$Parser parse Compiler.java 5929]
>>
>>   [clojure.lang.Compiler$LetExpr$Parser parse Compiler.java 6247]
>>
>>   [clojure.lang.Compiler analyzeSeq Compiler.java 6791]
>>
>>   [clojure.lang.Compiler analyze Compiler.java 6592]
>>
>>   [clojure.lang.Compiler analyze Compiler.java 6553]
>>
>>   [clojure.lang.Compiler$BodyExpr$Parser parse Compiler.java 5929]
>>
>>   [clojure.lang.Compiler$FnMethod parse Compiler.java 5359]
>>
>>   [clojure.lang.Compiler$FnExpr parse Compiler.java 3959]
>>
>>   [clojure.lang.Compiler analyzeSeq Compiler.java 6789]
>>
>>   [clojure.lang.Compiler analyze Compiler.java 6592]
>>
>>   [clojure.lang.Compiler eval Compiler.java 6847]
>>
>>   [clojure.lang.Compiler eval Compiler.java 6839]
>>
>>   [clojure.lang.Compiler load Compiler.java 7295]
>>
>>   [clojure.lang.RT loadResourceScript RT.java 372]
>>
>>   [clojure.lang.RT loadResourceScript RT.java 363]
>>
>>   [clojure.lang.RT load RT.java 453]
>>
>>   [clojure.lang.RT load RT.java 419]
>>
>>   [clojure.core$load$fn__5448 invoke core.clj 5866]
>>
>>   [clojure.core$load doInvoke core.clj 5865]
>>
>>   [clojure.lang.RestFn invoke RestFn.java 408]
>>
>>   [clojure.core$load_one invoke core.clj 5671]
>>
>>   [clojure.core$load_lib$fn__5397 invoke core.clj 5711]
>>
>>   [clojure.core$load_lib doInvoke core.clj 5710]
>>
>>   [clojure.lang.RestFn applyTo RestFn.java 142]
>>
>>   [clojure.core$apply invoke core.clj 632]
>>
>>   [clojure.core$load_libs doInvoke core.clj 5749]
>>
>>   [clojure.lang.RestFn applyTo RestFn.java 137]
>>
>>   [clojure.core$apply invoke core.clj 632]
>>
>>   [clojure.core$require doInvoke core.clj 5832]
>>
>>   [clojure.lang.RestFn invoke RestFn.java 551]
>>
>>   [aleph.http.server$eval9251$loading__5340__auto9252 invoke 
>> server.clj 1]
>>
>>   [aleph.http.server$eval9251 invoke server.clj 1]
>>
>>   [clojure.lang.Compiler eval Compiler.java 6850]
>>
>>   [clojure.lang.Compiler eval Compiler.java 6839]
>>
>>   [clojure.lang.Compiler load Compiler.java 7295]
>>
>>   [clojure.lang.RT loadResourceScript RT.java 372]
>>
>>   [clojure.lang.RT loadResourceScript RT.java 363]
>>
>>   [clojure.lang.RT load RT.java 453]
>>
>>   [clojure.lang.RT load RT.java 419]
>>
>>   [clojure.core$load$fn__5448 invoke core.clj 5866]
>>
>>   [clojure.core$load doInvoke core.clj 5865]
>>
>>   [clojure.lang.RestFn invoke RestFn.java 408]
>>
>>   [clojure.core$load_one invoke core.clj 5671]
>>
>>   [clojure.core$load_lib$fn__5397 invoke core.clj 5711]
>>
>>   [clojure.core$load_lib doInvoke core.clj 5710]
>>
>>   [clojure.lang.RestFn applyTo RestFn.java 142]
>>
>>   [clojure.core$apply invoke core.clj 632]
>>
>>   [clojure.core$load_libs doInvoke core.clj 5753]
>>
>>   [clojure.lang.RestFn applyTo RestFn.java 137]
>>
>>   [clojure.core$apply invoke core.clj 632]
>>
>>   [clojure.core$require doInvoke core.clj 5832]
>>
>>   [clojure.lang.RestFn invoke RestFn.java 457]
>>
>>   [aleph.http$eval1594$loading__5340__auto1595 invoke http.clj 1]
>>
>>   [aleph.http$eval1594 invoke http.clj 1]
>>
>>   [clojure.lang.Compiler eval Compiler.java 6850]
>>
>>   [clojur

Re: Advice on introducing a Java dev to Clojure

2015-07-28 Thread Lawrence Krubner
 

I wrote this for a blog post, but I think it is relevant here. After a long 
comparison of a bit of code, first in Javascript and then in Clojure, I 
wrote: 


 At this point, a Javascript developer might say, “You've shown that the 
Functional style has some advantage, but why should I care? I can write in 
the Functional style using Javascript. I don't need Clojure.” That is 
absolutely true, and we all know that developers tend to be fiercely loyal 
to their languages, up 'til the moment they are not. I myself was fiercely 
loyal to Ruby, up 'til the moment when I wasn't. True moments of conversion 
are rare and always depend on a person reaching some point of pain with 
their current path. I myself suddenly realized that I was working with 
languages that would not carry me into a future full of multi-CPU computers 
and massive concurrency ... at which point I began to explore what the 
future might hold ... at which point I discovered Clojure. 


 I would, however, counter the Javascript developer with my own set of 
questions. If you have realized that the Functional style is best, do you 
want to work in a language that undercuts that style, or supports it? Do 
you want to burden yourself with the extra discipline needed to pull off 
the Functional style in a highly mutable language, or do you want to work 
with a language that was designed from conception to make your life easier 
? Do you want to “navigate disappointment” or travel directly in the 
direction of success?  


In his talk, “Why Clojure is my favorite Ruby,” Steven Deobald refers to 
dealing with pain points in a language as “Navigating disappointment.”





On Thursday, July 23, 2015 at 9:04:42 AM UTC-4, Paul deGrandis wrote:
>
> I have had success here with a few approaches.
>
> For every company I work with that is new to Clojure, I provide them with 
> a "Quick Learn" document.  The document is split into 5-7 days, and every 
> day they skim/read an article, poke around a resource (like ClojureDocs), 
> and watch a talk.  Sometimes that "resource" item is an exercise or 
> something interactive.
>
> Your goal should never be to convince someone of Clojure - Clojure itself 
> is convincing enough.  Instead motivate someone to want to learn more - get 
> them curious and self-driven to dive in wherever their interests lay.  Get 
> them well adapted to the Clojure culture and the radical approach to 
> simplicity.  Get them questioning their own practices and technologies.  
> Entice them with the functional approach to system creation.
>
> Leon mentioned my talk, which claims, "Clojure manages risk better than 
> any other technology" - 
> http://www.infoq.com/presentations/Clojure-powered-Startups
> For well-established enterprise shops, I think my most recent Conj talk is 
> more convincing - https://www.youtube.com/watch?v=BNkYYYyfF48
>
> Consider the following talks by Rich:
>  * Clojure, Made Simple - https://www.youtube.com/watch?v=VSdnJDO-xdg
>  * Are we there yet? - 
> http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey
>  * Simple Made Easy - http://www.infoq.com/presentations/Simple-Made-Easy
>
> Nothing is more convincing than a working system.  If it's possible, 
> illustrate the virtues of Clojure and its approach to problem solving by 
> "walking the walk" on a small scale, where the stakes and risks are low.  
> Build a tool, prototype an idea in half the time it would normally take, 
> show the power of Protocols within your own existing system, etc.
>
> Regards,
> Paul
>
>

-- 
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: a question about Chris Zheng's "Abstract Container Pattern"

2015-07-29 Thread Lawrence Krubner
te that not all OO frameworks are equal. Java uses a class 
> inheritence approach whereas javascript uses a prototype model. The 
> `abstract container` pattern that I was describing is probably closer to 
> the JS model but to be honest, I don't really know what it is. Ultimately, 
> it adds a middle tier of functionality in systems that have a plugin type 
> mechanism. I'm sure there are equivalent functional contructs... but that 
> was not the point of the pattern. This pattern has been very useful for me; 
> clojure's protocols and multimethods were not enough to do what I needed to 
> do - but combination of the two works wonders =)
>
> Since the article, the pattern has been codified here:
>
> https://github.com/zcaudate/hara/blob/master/src/hara/extend/abstract.clj#L196
>
> Hope that helps in clarifying the motivation behind the article and the 
> pattern
>
>
> Chris
>
>
>
>
>
>
>
> On Monday, July 27, 2015 at 11:42:21 PM UTC+5:30, Colin Yates wrote:
>>
>> I think his last sentence gives you the answer:
>>
>> "A warm shoutout to Tushar, Lyndon, Dean, Alan, Hank, Derek, and all the 
>> guys at clj-melb that gave feedback and helped flesh out this rehash of *OO 
>> design*.” (my emphasis)
>>
>> He wanted an OO approach and has implemented one; specifically behaviour 
>> and state coupled together. I think neither Typed Clojure nor Contracts 
>> would have achieved this guy’s goal as they are about enforcing a contract 
>> (either the shape of data or effects of a fn) in the ‘functional’ paradigm; 
>> this guy clearly wanted something in the OO paradigm. 
>>
>> Is there a ‘functional’ implementation which gives the same benefits; 
>> sure, but that isn’t what he wanted. Are there a bunch of ‘upgrades’ that I 
>> am sure we could all apply; sure, but again it seems like he was setting 
>> out with a very specific goal in mind and has achieved that. 
>>
>> On 27 Jul 2015, at 18:37, Lawrence Krubner  
>> wrote:
>>
>> I have a question about this: 
>>
>> "Servers that are running on a particular port can be tracked and 
>> stopped. I have to say, this was the feature that I wanted the most, which 
>> motivated the framework's design. The annoying thing about development in 
>> emacs is that I have to be careful of not losing the reference to the 
>> server. Since there was no way of stopping it unless the repl is restarted. 
>> I wanted to implement a registery for references to running servers to be 
>> saved."
>>
>> http://z.caudate.me/the-abstract-container-pattern/
>>
>> I have the impression that he's going over the same territory as that 
>> covered by Stuart Sierra, though Zheng doesn't mention "Component" nor 
>> "Sierra". But he offers this as an example of what he's after: 
>>
>> (defprotocol IRunnable (start! [system]) (stop! [system]) (restart! 
>> [system]) (started? [system]) (stopped? [system]))
>>
>> That much seems similar to Sierra's system. Zheng seems to add an 
>> additional layer by simulating an abstract class above his protocols. As he 
>> says: 
>>
>>
>>- A single deftype acts as the *abstract container*, extending one or 
>>more protocols
>>- A set of methods defined through defmulti that is used within the 
>>deftype form act as *abstract methods*
>>- The *abstract methods* all dispatch on map keys (usually :type).
>>
>>
>> I am curious if others have found this useful? 
>>
>> Most of the people who work with Clojure have backgrounds with Object 
>> Oriented Programming, so that paradigm sometimes seems natural, or at least 
>> familiar. I often think these designs are more verbose than they need to 
>> be, but I am curious how others feel. 
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>

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


why does this file watcher keep triggering?

2015-08-08 Thread Lawrence Krubner
I feel stupid, but I have not been able to track this down. 

The background is that I have Jenkins running on the server, and when 
triggered it pulls code from Github, compiles it, and then moves the final 
uberjar to the directory where I keep all the uberjars that run on this 
server. Then I have an app that should kill all currently running 
instances. Then Supervisord should step in and restart the instances, using 
the new uberjars for the new instances. 

All of this works, but I have been doing one bit by hand: "kill all 
currently running instances". I log in as root and run a script that kills 
the old instances. But just today I wrote a quick Clojure app to automate 
this for me (the whole app is 50 lines of code, so this is a very small 
app). 

To trigger the main action, I thought the app should set a watcher on the 
final directory where Jenkins moves the uberjars to. When Jenkins moves a 
new uberjar to the directory, the watch would be triggered and then it 
could run the "kill all currently running instances" script. However, I 
assumed that the ""kill all currently running instances"" script would be 
triggered once each time the uberjar was updated, but instead it seems to 
be triggered infinitely. Does a JVM app, or a Clojure app, change the dir 
its in, on launch? Or is the problem in my own code? I'm using Chris 
Zheng's excellent Hara library for the Watch. This is the main function of 
my app, which is called on startup: 

(defn establish-watchers []
  "The config contains a hashmap which has a 'watchers' key, which contains 
a vector that holds hashmaps with 2 keys, one pointing to the directory 
that should be watched and the other pointing to the command that should be 
run when the watch is triggered."
  (let [config (read-string (slurp "/etc/fiit.edn"))
watchers (:watchers config)]
  (doseq [w watchers]
 (common-watch/add (clojure.java.io/file (:dir-to-watch w)) (keyword 
 (:dir-to-watch w))
   (fn [f k _ [cmd file]]
 (pprint/pprint (:out (sh/sh (:action-to-do w)
   {:types #{:create :modify}
:recursive false
:async false}

So if I log in as root and start the app like this:

/usr/bin/java -jar /home/jenkins/fiit/fiit-1-standalone.jar

Then at the terminal I see this, which I expect: 

[/home/jenkins/sarr]
[/home/jenkins/food_for_all]

Those are the 2 directories that it is watching. 

Then if I trigger Jenkins for the sarr app, Jenkins will pull the sarr code 
from Github, rebuild the sarr uberjar, and move the uberjar to 
/home/jenkins/sarr. 

All of that works just great. And then my app sees there has been a change 
in /home/jenkins/sarr, and so it calls the command to kill all existing 
instances of the sarr app. However, instead of doing this once, it starts 
doing so an infinite number of times. At the terminal I see: 

(sarr is a Java app, not a Clojure app)

"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \nroot 25593  0.0  0.1 5813460 19452 ?   
Sl   20:28   0:00 /usr/bin/java -cp /home/jenkins/sarr/sarr.jar 
com.candle.sarr.Main\nroot 25595  0.0  0.1 5813460 19564 ?   Sl   
20:28   0:00 /usr/bin/java -cp /home/jenkins/sarr/sarr.jar 
com.candle.sarr.Main\n25593\n25595\n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n25694\n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \nroot 26239  0.0  0.1 5813460 19452 ?   
Sl   20:28   0:00 /usr/bin/java -cp /home/jenkins/sarr/sarr.jar 
com.candle.sarr.Main\n26239\n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \nroot 26319  0.0  0.1 5811252 15484 ?   
Sl   20:28   0:00 /usr/bin/java -cp /home/jenkins/sarr/sarr.jar 
com.candle.sarr.Main\n26319\n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n"
"We will kill these processes: \n

What does Zach Tellman mean by "factored out for greater inlining joy"

2015-08-08 Thread Lawrence Krubner

I'm always interested in anything Zach Tellman does, though I don't always 
understand it. 

I see that he defines a function twice, via (let), of which he 
says  "factored out for greater inlining joy". Does anyone know what he 
means by that? Can anyone suggest a reason why this was more convenient 
that writing a macro? And what is the point of the repetition? I feel lost. 


https://github.com/ztellman/manifold/blob/4e1fff70c5380b33e9cc2f50f03ce16af6d393b4/src/manifold/deferred.clj#L705
(let [;; factored out for greater inlining joy subscribe (fn ([this d x] (
let [d (or d (deferred))] (on-realized x #(this d %) #(error! d %)) d)) 
([this d x f] (let [d (or d (deferred))] (on-realized x #(this d % f) #(
error! d %)) d)) ([this d x f g] (let [d (or d (deferred))] (on-realized x 
#(this d % f g) #(error! d %)) d)))]



https://github.com/ztellman/manifold/blob/4e1fff70c5380b33e9cc2f50f03ce16af6d393b4/src/manifold/deferred.clj#L799


(let [;; factored out for greater inlining joy
  subscribe (fn
  ([this d x]
 (let [d (or d (deferred))]
   (on-realized x
 #(this d %)
 #(error! d %))
   d))
  ([this d x f]
 (let [d (or d (deferred))]
   (on-realized x
 #(this d % f)
 #(error! d %))
   d))
  ([this d x f g]
 (let [d (or d (deferred))]
   (on-realized x
 #(this d % f g)
 #(error! d %))
   d)))]









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


Re: What does Zach Tellman mean by "factored out for greater inlining joy"

2015-08-09 Thread Lawrence Krubner

Reid, thank you. I think you answer half the question. You make a good 
point about giving the JVM a way to better optimize a hot path. I think you 
are right about that. But, given the large amount of repetition between 
"chain'-" and "chain-" I'm wondering why this wasn't done with a macro? 



On Sunday, August 9, 2015 at 2:08:47 AM UTC-4, Reid McKenzie wrote:
>
> -BEGIN PGP SIGNED MESSAGE- 
> Hash: SHA256 
>
> Lawrence, 
>
> This is just a theory, but in the interests of response time, the JVM 
> uses a large number of heuristics to determine what optimizations will 
> likely prove profitable. One of them is a budget for method size. I 
> would guess that lifting this code out into a separate fn made the JVM 
> see that it was optimizing a hot path between the main body and 
> several small but tightly related methods thus giving itself more 
> leeway to inline and optimize in ways that it would otherwise presume 
> are more expensive and not pursue. 
>
> Reid 
>

-- 
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: why does this file watcher keep triggering?

2015-08-09 Thread Lawrence Krubner

Let's assume for a moment that, for some strange reason, the "directory 
watching" strategy won't work here. Does anyone have any other suggestions? 
I am thinking there must be a simple way to setup Jenkins and Supervisord 
to run these apps, but what I'm doing keeps getting more and more complex, 
which is typically a warning sign that I'm on the wrong track. 




On Saturday, August 8, 2015 at 5:24:28 PM UTC-4, Lawrence Krubner wrote:
>
> I feel stupid, but I have not been able to track this down. 
>
> The background is that I have Jenkins running on the server, and when 
> triggered it pulls code from Github, compiles it, and then moves the final 
> uberjar to the directory where I keep all the uberjars that run on this 
> server. Then I have an app that should kill all currently running 
> instances. Then Supervisord should step in and restart the instances, using 
> the new uberjars for the new instances. 
>
> All of this works, but I have been doing one bit by hand: "kill all 
> currently running instances". I log in as root and run a script that kills 
> the old instances. But just today I wrote a quick Clojure app to automate 
> this for me (the whole app is 50 lines of code, so this is a very small 
> app). 
>
> To trigger the main action, I thought the app should set a watcher on the 
> final directory where Jenkins moves the uberjars to. When Jenkins moves a 
> new uberjar to the directory, the watch would be triggered and then it 
> could run the "kill all currently running instances" script. However, I 
> assumed that the ""kill all currently running instances"" script would be 
> triggered once each time the uberjar was updated, but instead it seems to 
> be triggered infinitely. Does a JVM app, or a Clojure app, change the dir 
> its in, on launch? Or is the problem in my own code? I'm using Chris 
> Zheng's excellent Hara library for the Watch. This is the main function of 
> my app, which is called on startup: 
>
> (defn establish-watchers []
>   "The config contains a hashmap which has a 'watchers' key, which 
> contains a vector that holds hashmaps with 2 keys, one pointing to the 
> directory that should be watched and the other pointing to the command that 
> should be run when the watch is triggered."
>   (let [config (read-string (slurp "/etc/fiit.edn"))
> watchers (:watchers config)]
>   (doseq [w watchers]
>  (common-watch/add (clojure.java.io/file (:dir-to-watch w)) (keyword 
>  (:dir-to-watch w))
>(fn [f k _ [cmd file]]
>  (pprint/pprint (:out (sh/sh (:action-to-do w)
>{:types #{:create :modify}
> :recursive false
> :async false}
>
> So if I log in as root and start the app like this:
>
> /usr/bin/java -jar /home/jenkins/fiit/fiit-1-standalone.jar
>
> Then at the terminal I see this, which I expect: 
>
> [/home/jenkins/sarr]
> [/home/jenkins/food_for_all]
>
> Those are the 2 directories that it is watching. 
>
> Then if I trigger Jenkins for the sarr app, Jenkins will pull the sarr 
> code from Github, rebuild the sarr uberjar, and move the uberjar to 
> /home/jenkins/sarr. 
>
> All of that works just great. And then my app sees there has been a change 
> in /home/jenkins/sarr, and so it calls the command to kill all existing 
> instances of the sarr app. However, instead of doing this once, it starts 
> doing so an infinite number of times. At the terminal I see: 
>
> (sarr is a Java app, not a Clojure app)
>
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \nroot 25593  0.0  0.1 5813460 19452 ? 
>   Sl   20:28   0:00 /usr/bin/java -cp /home/jenkins/sarr/sarr.jar 
> com.candle.sarr.Main\nroot 25595  0.0  0.1 5813460 19564 ?   Sl   
> 20:28   0:00 /usr/bin/java -cp /home/jenkins/sarr/sarr.jar 
> com.candle.sarr.Main\n25593\n25595\n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n25694\n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"
> "We will kill these processes: \n"

Re: why does this file watcher keep triggering?

2015-08-09 Thread Lawrence Krubner

Okay, I am an idiot. I had the "directory watch" setup to watch the 
directory where the uberjar was built, so of course it was triggered 
thousands of time while the uberjar was built, since I guess every new byte 
added to the uberjar triggers the change event. 

So I set my app to listen on the final directory, where the final uberjar 
is moved, just once, when the uberjar is complete, and now the app behaves 
the way I was expecting it to. 


On Sunday, August 9, 2015 at 1:13:56 PM UTC-4, Lawrence Krubner wrote:
>
>
> Let's assume for a moment that, for some strange reason, the "directory 
> watching" strategy won't work here. Does anyone have any other suggestions? 
> I am thinking there must be a simple way to setup Jenkins and Supervisord 
> to run these apps, but what I'm doing keeps getting more and more complex, 
> which is typically a warning sign that I'm on the wrong track. 
>
>
>
>
> On Saturday, August 8, 2015 at 5:24:28 PM UTC-4, Lawrence Krubner wrote:
>>
>> I feel stupid, but I have not been able to track this down. 
>>
>> The background is that I have Jenkins running on the server, and when 
>> triggered it pulls code from Github, compiles it, and then moves the final 
>> uberjar to the directory where I keep all the uberjars that run on this 
>> server. Then I have an app that should kill all currently running 
>> instances. Then Supervisord should step in and restart the instances, using 
>> the new uberjars for the new instances. 
>>
>> All of this works, but I have been doing one bit by hand: "kill all 
>> currently running instances". I log in as root and run a script that kills 
>> the old instances. But just today I wrote a quick Clojure app to automate 
>> this for me (the whole app is 50 lines of code, so this is a very small 
>> app). 
>>
>> To trigger the main action, I thought the app should set a watcher on the 
>> final directory where Jenkins moves the uberjars to. When Jenkins moves a 
>> new uberjar to the directory, the watch would be triggered and then it 
>> could run the "kill all currently running instances" script. However, I 
>> assumed that the ""kill all currently running instances"" script would be 
>> triggered once each time the uberjar was updated, but instead it seems to 
>> be triggered infinitely. Does a JVM app, or a Clojure app, change the dir 
>> its in, on launch? Or is the problem in my own code? I'm using Chris 
>> Zheng's excellent Hara library for the Watch. This is the main function of 
>> my app, which is called on startup: 
>>
>> (defn establish-watchers []
>>   "The config contains a hashmap which has a 'watchers' key, which 
>> contains a vector that holds hashmaps with 2 keys, one pointing to the 
>> directory that should be watched and the other pointing to the command that 
>> should be run when the watch is triggered."
>>   (let [config (read-string (slurp "/etc/fiit.edn"))
>> watchers (:watchers config)]
>>   (doseq [w watchers]
>>  (common-watch/add (clojure.java.io/file (:dir-to-watch w)) (keyword 
>>  (:dir-to-watch w))
>>(fn [f k _ [cmd file]]
>>  (pprint/pprint (:out (sh/sh (:action-to-do w)
>>{:types #{:create :modify}
>> :recursive false
>> :async false}
>>
>> So if I log in as root and start the app like this:
>>
>> /usr/bin/java -jar /home/jenkins/fiit/fiit-1-standalone.jar
>>
>> Then at the terminal I see this, which I expect: 
>>
>> [/home/jenkins/sarr]
>> [/home/jenkins/food_for_all]
>>
>> Those are the 2 directories that it is watching. 
>>
>> Then if I trigger Jenkins for the sarr app, Jenkins will pull the sarr 
>> code from Github, rebuild the sarr uberjar, and move the uberjar to 
>> /home/jenkins/sarr. 
>>
>> All of that works just great. And then my app sees there has been a 
>> change in /home/jenkins/sarr, and so it calls the command to kill all 
>> existing instances of the sarr app. However, instead of doing this once, it 
>> starts doing so an infinite number of times. At the terminal I see: 
>>
>> (sarr is a Java app, not a Clojure app)
>>
>> "We will kill these processes: \n"
>> "We will kill these processes: \n"
>> "We will kill these processes: \n"
>> "We will kill these processes: \n"
>> "We will kill these processes: \n"
>> "We will kill these processes: \n"
>> "We will kill these proce

when the body of the request is HttpInputOverHTTP, how do I get the string representation?

2015-08-19 Thread Lawrence Krubner
I know this has been asked before, but Google is interpreting 
"HttpInputOverHTTP" as "Http Input Over HTTP" which renders it useless for 
finding conversations that are specific to the HttpInputOverHTTP class. 
(off topic: I wish there was a good search engine for software terms).

I've a simple web app using Jetty and Ring and Compojure. The body of each 
request that comes in is: 

:body #

If I do: 

(str (:body request))

I simply get:

HttpInputOverHTTP@3aa0a4ac

Can someone remind how I get a string representation of what should be in 
the body? 









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


Why (memoize (fn [_#] (gensym "node")) in rhizome?

2015-09-11 Thread Lawrence Krubner
I'm always interested in the stuff Zach Tellman does, though I don't always 
understand it. I'm curious about this bit: 

(memoize (fn [_#] (gensym "node"))

How is that different than 

(gensym "node")

I only see with-gensyms called once, so I assume the goal is to have 
dynamic bindings set up for that block of code. 

(defmacro ^:private with-gensyms
  "Makes sure the mapping of node and clusters onto identifiers is 
consistent within its scope."
  [& body]
  `(binding [*node->id* (or *node->id* (memoize (fn [_#] (gensym "node"
 *cluster->id* (or *cluster->id* (memoize (fn [_#] (gensym 
"cluster"]
 ~@body))

https://github.com/ztellman/rhizome/blob/1bca773540a0bd244650293d76374b7f0472025e/src/rhizome/dot.clj

The "or" should ensure that the function is only called once, so why is the 
memoize needed? When would the function be called a second time, at which 
point the memoized response could be returned? 


-- 
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: Why (memoize (fn [_#] (gensym "node")) in rhizome?

2015-09-13 Thread Lawrence Krubner
> Memoize takes the ignored argument into account 
> when associating the inputs with outputs.

This is the answer I was looking for. I feel like this is the subtlety that 
I had missed. 




On Saturday, September 12, 2015 at 5:24:55 AM UTC-4, Moe Aboulkheir wrote:
>
>
>
> On Sat, Sep 12, 2015 at 1:58 AM, Sam Ritchie  > wrote:
>
>> Seems like a good use of “delay”, yeah? Slightly different calling 
>> semantics, of course, but still:
>>
>> user> (def f (delay (gensym "node")))
>> #'user/f
>> user> @f
>> node3330
>> user> @f
>> node3330
>>
>
> The original code wanted different behaviour - a distinct gensym for each 
> distinct input.  Memoize takes the ignored argument into account when 
> associating the inputs with outputs.
>
> user> (def mapped-gensym (memoize (fn [_] (gensym "alias"
>
> user> (mapped-gensym "HI")
> alias29367
> user> (mapped-gensym "HI")
> alias29367
> user> (mapped-gensym "NOT HI")
> alias29372
>
> Take care,
> Moe
>

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


is there a way I can use a co-worker's uberjar without unpacking it to ./.m2?

2015-09-13 Thread Lawrence Krubner
I am lazy so I was hoping to find a simple way to do this. My co-worker has 
written a complex app in Java which does natural language processing. He 
delivered it to me as an uberjar. My app is suppose to call his app as a 
library. 

The path to the file is: 

/Users/rollio/projects/rollio/nlp-housing/maven_repository/SSAM.jar

I was hoping I could do something like this in my project.clj:

[local/SSAM]

and: 

  :repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))}

but when I do: 

lein uberjar

I get: 
 
(Could not find artifact SSAM:SSAM:jar:jar in central 
(http://repo1.maven.org/maven2/))
(Could not find artifact SSAM:SSAM:jar:jar in clojars 
(https://clojars.org/repo/))
(Could not find artifact SSAM:SSAM:jar:jar in local 
(file:/Users/rollio/projects/rollio/nlp-housing/maven_repository/))

Is there a way I can simply consume that, or do I have to unpack it and 
install it to ./.m2 and all of that jazz? 







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


Re: is there a way I can use a co-worker's uberjar without unpacking it to ./.m2?

2015-09-14 Thread Lawrence Krubner
> lein-localrepo helps with installing jar files into the 
> local maven repository

But they give examples like this:

lein localrepo install foo-1.0.6.jar com.example/foo 1.0.6

If I had that info I probably would not need to ask any questions here. But 
more to the point, I'm asking if I can avoid putting stuff in ~/.m2



On Monday, September 14, 2015 at 3:56:23 AM UTC-4, Ralf Schmitt wrote:
>
> Alex Miller > writes: 
>
> > Something like this can work but you need to have the proper path in the 
> > local maven_repository. You have the repository named local. Inside the 
> > repo, every artifact has a groupID (the first part of the dependency), 
> the 
> > artifactID, and the version. If you had a dependency like: 
> > 
> > [SSAM "0.1.0"] 
> > 
> > the jar should be at: 
> > 
> > 
> /Users/rollio/projects/rollio/nlp-housing/maven_repository/SSAM/SSAM/0.1.0/SSAM-0.1.0.jar
>  
>
> > 
> > where under the repo, it's at groupID/artifactID/artifactID-version.jar 
> > 
> > You don't need to specify that SSAM is in local - Maven will check all 
> > repos for it and find it in local. 
> > 
> > I've gotten this to work before and it's definitely possible. I feel 
> like 
> > I'm forgetting some other detail though. I'm not sure if you need a 
> pom.xml 
> > or any of the other repo metadata in that directory structure. 
>
> lein-localrepo helps with installing jar files into the local maven 
> repository: 
>
> https://github.com/kumarshantanu/lein-localrepo 
>
> -- 
> Cheers 
> Ralf 
>

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


Re: is there a way I can use a co-worker's uberjar without unpacking it to ./.m2?

2015-09-14 Thread Lawrence Krubner
> I'm using lein localrepo to install a jar file with a completely made up 
> version and group id. you just need to use the same values in 
> project.clj. 

Fantastic! Thank you so much for this tip! This is exactly what I was 
looking for!


On Monday, September 14, 2015 at 4:48:24 AM UTC-4, Ralf Schmitt wrote:
>
> Lawrence Krubner > writes: 
>
> >> lein-localrepo helps with installing jar files into the 
> >> local maven repository 
> > 
> > But they give examples like this: 
> > 
> > lein localrepo install foo-1.0.6.jar com.example/foo 1.0.6 
> > 
> > If I had that info I probably would not need to ask any questions 
> > here. 
>
> I'm using lein localrepo to install a jar file with a completely made up 
> version and group id. you just need to use the same values in 
> project.clj. 
>
> -- 
> Cheers 
> Ralf 
>

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


Re: is there a way I can use a co-worker's uberjar without unpacking it to ./.m2?

2015-09-14 Thread Lawrence Krubner
James, thank you for this. I understood that the local repo was not in 
~/.m2, I was simply hoping for a way to avoid having to install into ~/.m2. 

I did not know that I could use fictitious names for artifactId. I am 
grateful for the example you have posted. 



On Monday, September 14, 2015 at 10:56:46 AM UTC-4, James Elliott wrote:
>
> To hopefully help address another aspect of your question:
>
> This local repo is *not* inside ~/.m2
>
> It is a directory that can be part of your project, and checked into git 
> along with it. You just tell Leiningen where to find it using something 
> like this:
>
> :repositories {"project" "file:repo"}
>
> And then Leiningen will look for artifacts in the directory "repo" at the 
> project root.
>
> So, you do not have to put things into your actual local Maven repository. 
> But you *do* have to put artifacts into a properly structured Maven 
> repository (even if it is entirely fictitious, using made up artifact names 
> and versions), to use them with Leiningen.
>
> I do this in my project afterglow-max, for example, to build against an 
> API that is provided by its vendor as a jar file but not as a Maven 
> artifact. You can find the full project here, if it helps:
>
> https://github.com/brunchboy/afterglow-max#afterglow-max
>
> I hope this helps!
>   -James
>
> On Monday, September 14, 2015 at 3:48:24 AM UTC-5, Ralf Schmitt wrote:
>>
>> Lawrence Krubner  writes: 
>>
>> >> lein-localrepo helps with installing jar files into the 
>> >> local maven repository 
>> > 
>> > But they give examples like this: 
>> > 
>> > lein localrepo install foo-1.0.6.jar com.example/foo 1.0.6 
>> > 
>> > If I had that info I probably would not need to ask any questions 
>> > here. 
>>
>> I'm using lein localrepo to install a jar file with a completely made up 
>> version and group id. you just need to use the same values in 
>> project.clj. 
>>
>> -- 
>> Cheers 
>> Ralf 
>>
>

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


Uberjar aborting because jar failed: error in opening zip file

2015-09-16 Thread Lawrence Krubner
My co-worker is building a library in Java. He sent it to me. I downloaded 
and installed it with the help of the Leiningen plugin "localrepo". But now 
if I do: 

lein uberjar

I get: 

Uberjar aborting because jar failed: error in opening zip file

I am not sure how I debug this. The error message doesn't tell me much 
about what the problem might be. 

It is a very large file: 655 megs. 

How can I dig deeper to find the problem? 

-- 
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: Uberjar aborting because jar failed: error in opening zip file

2015-09-16 Thread Lawrence Krubner
Nevermind. I downloaded a new copy and went through the whole process again 
and everything worked. 


On Wednesday, September 16, 2015 at 4:55:33 PM UTC-4, Lawrence Krubner 
wrote:
>
> My co-worker is building a library in Java. He sent it to me. I downloaded 
> and installed it with the help of the Leiningen plugin "localrepo". But now 
> if I do: 
>
> lein uberjar
>
> I get: 
>
> Uberjar aborting because jar failed: error in opening zip file
>
> I am not sure how I debug this. The error message doesn't tell me much 
> about what the problem might be. 
>
> It is a very large file: 655 megs. 
>
> How can I dig deeper to find the problem? 
>
>

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


can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner
For maximum flexibility I wanted to use a multimethod, defined like this: 


(defmulti intent
  (fn [& args]
(apply discern args)))

This is how discern is defined: 

(defn- discern
  
  ([this-users-conversation]
   {:pre [(map? this-users-conversation)]}
   (:intent this-users-conversation)) 

  ([this-users-conversation salesforce-object-name]
   {:pre [(map? this-users-conversation)
  (string? salesforce-object-name)]}
   (:intent this-users-conversation))

  ([this-users-conversation salesforce-object-name name-of-attribute]
   {:pre [(map? this-users-conversation)
  (string? salesforce-object-name)
  (string? name-of-attribute)]}
   (:intent this-users-conversation))

  ([this-users-conversation salesforce-object-name name-of-attribute 
name-of-intent]
   {:pre [(map? this-users-conversation)
  (string? salesforce-object-name)
  (keyword? name-of-attribute)
  (string? name-of-intent)]}
   name-of-intent))

but then I call the multimethod like this:

(intent this-users-conversation "Opportunity" :Name 
"query-salesforce-for-attribute")

and I get: 

:class clojure.lang.ArityException,
:message "Wrong number of args (4) passed to: query/fn--65",

Should I give up on this idea, or is there a way to make this work? 





-- 
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: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner
I guess I could get rid of the multimethod and instead do something like 
this: 

   ((symbol (:intent this-users-conversation)))

but that seems like a hack.


On Wednesday, September 30, 2015 at 8:33:36 PM UTC-4, Lawrence Krubner 
wrote:
>
> For maximum flexibility I wanted to use a multimethod, defined like this: 
>
>
> (defmulti intent
>   (fn [& args]
> (apply discern args)))
>
> This is how discern is defined: 
>
> (defn- discern
>   
>   ([this-users-conversation]
>{:pre [(map? this-users-conversation)]}
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name]
>{:pre [(map? this-users-conversation)
>   (string? salesforce-object-name)]}
>(:intent this-users-conversation))
>
>   ([this-users-conversation salesforce-object-name name-of-attribute]
>{:pre [(map? this-users-conversation)
>   (string? salesforce-object-name)
>   (string? name-of-attribute)]}
>(:intent this-users-conversation))
>
>   ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent]
>{:pre [(map? this-users-conversation)
>   (string? salesforce-object-name)
>   (keyword? name-of-attribute)
>   (string? name-of-intent)]}
>name-of-intent))
>
> but then I call the multimethod like this:
>
> (intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute")
>
> and I get: 
>
> :class clojure.lang.ArityException,
> :message "Wrong number of args (4) passed to: query/fn--65",
>
> Should I give up on this idea, or is there a way to make this work? 
>
>
>
>
>
>

-- 
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: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner

> It's impossible to redefine the dispatch function within
>  the definition of the multimethod after the first call to 'defmulti'. 

That is a funny way to word it. I think you are saying that there is no way 
to have the multiple arities? 




On Wednesday, September 30, 2015 at 8:45:25 PM UTC-4, Gary Trakhman wrote:
>
> It works for me, for '(intent {} "yes" :yes "WAT")'
>
> I get the error: IllegalArgumentException No method in multimethod 
> 'intent' for dispatch value: WAT  clojure.lang.MultiFn.getFn 
> (MultiFn.java:156)
>
> You're probably being bitten by a different issue.  It's impossible to 
> redefine the dispatch function within the definition of the multimethod 
> after the first call to 'defmulti'.  In order to do so, you would have to 
> first ns-unmap that var.
>
> An alternative for development is to use the dispatch function's Var as 
> the dispatch function:
> (defn intent-dispatch [& args]
> (apply discern args))
> (defmulti intent #'intent-dispatch)
>
>
> On Wed, Sep 30, 2015 at 8:33 PM Lawrence Krubner  > wrote:
>
>> For maximum flexibility I wanted to use a multimethod, defined like this: 
>>
>>
>> (defmulti intent
>>   (fn [& args]
>> (apply discern args)))
>>
>> This is how discern is defined: 
>>
>> (defn- discern
>>   
>>   ([this-users-conversation]
>>{:pre [(map? this-users-conversation)]}
>>(:intent this-users-conversation)) 
>>
>>   ([this-users-conversation salesforce-object-name]
>>{:pre [(map? this-users-conversation)
>>   (string? salesforce-object-name)]}
>>(:intent this-users-conversation))
>>
>>   ([this-users-conversation salesforce-object-name name-of-attribute]
>>{:pre [(map? this-users-conversation)
>>   (string? salesforce-object-name)
>>   (string? name-of-attribute)]}
>>(:intent this-users-conversation))
>>
>>   ([this-users-conversation salesforce-object-name name-of-attribute 
>> name-of-intent]
>>{:pre [(map? this-users-conversation)
>>   (string? salesforce-object-name)
>>   (keyword? name-of-attribute)
>>   (string? name-of-intent)]}
>>name-of-intent))
>>
>> but then I call the multimethod like this:
>>
>> (intent this-users-conversation "Opportunity" :Name 
>> "query-salesforce-for-attribute")
>>
>> and I get: 
>>
>> :class clojure.lang.ArityException,
>> :message "Wrong number of args (4) passed to: query/fn--65",
>>
>> Should I give up on this idea, or is there a way to make this work? 
>>
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

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


Re: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner
Sean,

Thank you. That saves me hours of mistakes. 



On Wednesday, September 30, 2015 at 9:38:09 PM UTC-4, Sean Corfield wrote:
>
> Your example works for me as follows: 
>
> user> (defn- discern 
>   
>
>   ([this-users-conversation] 
>{:pre [(map? this-users-conversation)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (string? name-of-attribute)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (keyword? name-of-attribute) 
>   (string? name-of-intent)]} 
>name-of-intent)) 
>
> #'user/discern 
>
> user> (defmulti intent 
>
>   (fn [& args] 
> (apply discern args))) 
>
> #'user/intent 
>
> user> (defmethod intent nil [& args] (str "I got nil plus " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent "query-salesforce-for-attribute" [& args] (str 
> "SQFFA " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent :default [& args] (str "WAT? " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (def this-users-conversation {}) 
>
> #'user/this-users-conversation 
>
> user> (intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
>
> "SQFFA ({} \"Opportunity\" :Name \"query-salesforce-for-attribute\")" 
>
> user> (intent this-users-conversation "Opportunity" "Name") 
>
> "I got nil plus ({} \"Opportunity\" \"Name\")" 
>
> user> (intent {:intent "do-something"} "Opportunity" "Name") 
>
> "WAT? ({:intent \"do-something\"} \"Opportunity\" \"Name\")" 
>
>
>
>
> Sean Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
>
> "If you're not annoying somebody, you're not really alive." 
> -- Margaret Atwood 
>
>
>
>
>
>
> From:  > on behalf of Lawrence 
> Krubner 
> Reply-To:  > 
> Date:  Wednesday, September 30, 2015 at 5:33 PM 
> To:  Clojure 
> Subject:  can I use varargs in a multimethod? 
>
>
> >For maximum flexibility I wanted to use a multimethod, defined like this: 
> > 
> > 
> >(defmulti intent 
> >  (fn [& args] 
> >(apply discern args))) 
> > 
> > 
> >This is how discern is defined: 
> > 
> >(defn- discern 
> >   
> >  ([this-users-conversation] 
> >   {:pre [(map? this-users-conversation)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (string? name-of-attribute)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (keyword? name-of-attribute) 
> >  (string? name-of-intent)]} 
> >   name-of-intent)) 
> > 
> > 
> >but then I call the multimethod like this: 
> > 
> >(intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
> > 
> > 
> >and I get: 
> > 
> >:class clojure.lang.ArityException, 
> >:message "Wrong number of args (4) passed to: query/fn--65", 
> > 
> > 
> >Should I give up on this idea, or is there a way to make this work? 
> > 
> > 
>
>

-- 
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: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner
In a let statement I can do this: 

(let [[this-users-conversation salesforce-object-name name-of-attribute] 
args]

I would like to do this destructuring in my defmethods, but if I do this: 

(defmethod discern "find-user-credentials"
  [[this-users-conversation salesforce-object-name name-of-attribute]]

or:

(defmethod discern "find-user-credentials"
  [this-users-conversation salesforce-object-name name-of-attribute]

I get: 

:class clojure.lang.ArityException,
 :message "Wrong number of args (2) passed to: intent/fn--64",

Is there any way to do the destructuring as part of the definition of 
defmethod, or do I have to do it in a let statement? 






On Wednesday, September 30, 2015 at 9:38:09 PM UTC-4, Sean Corfield wrote:
>
> Your example works for me as follows: 
>
> user> (defn- discern 
>   
>
>   ([this-users-conversation] 
>{:pre [(map? this-users-conversation)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (string? name-of-attribute)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (keyword? name-of-attribute) 
>   (string? name-of-intent)]} 
>name-of-intent)) 
>
> #'user/discern 
>
> user> (defmulti intent 
>
>   (fn [& args] 
> (apply discern args))) 
>
> #'user/intent 
>
> user> (defmethod intent nil [& args] (str "I got nil plus " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent "query-salesforce-for-attribute" [& args] (str 
> "SQFFA " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent :default [& args] (str "WAT? " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (def this-users-conversation {}) 
>
> #'user/this-users-conversation 
>
> user> (intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
>
> "SQFFA ({} \"Opportunity\" :Name \"query-salesforce-for-attribute\")" 
>
> user> (intent this-users-conversation "Opportunity" "Name") 
>
> "I got nil plus ({} \"Opportunity\" \"Name\")" 
>
> user> (intent {:intent "do-something"} "Opportunity" "Name") 
>
> "WAT? ({:intent \"do-something\"} \"Opportunity\" \"Name\")" 
>
>
>
>
> Sean Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
>
> "If you're not annoying somebody, you're not really alive." 
> -- Margaret Atwood 
>
>
>
>
>
>
> From:  > on behalf of Lawrence 
> Krubner 
> Reply-To:  > 
> Date:  Wednesday, September 30, 2015 at 5:33 PM 
> To:  Clojure 
> Subject:  can I use varargs in a multimethod? 
>
>
> >For maximum flexibility I wanted to use a multimethod, defined like this: 
> > 
> > 
> >(defmulti intent 
> >  (fn [& args] 
> >(apply discern args))) 
> > 
> > 
> >This is how discern is defined: 
> > 
> >(defn- discern 
> >   
> >  ([this-users-conversation] 
> >   {:pre [(map? this-users-conversation)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (string? name-of-attribute)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (keyword? name-of-attribute) 
&g

Re: can I use varargs in a multimethod?

2015-09-30 Thread Lawrence Krubner

Oh, never mind, I'm a total idiot. At some point I confused myself by using 
the ":keys" directive. I was able to take Sean's example, apply 
destructuring, and get defmethods like this: 

(defmethod discern "this-users-objects" 
  [{:keys [salesforce-credentials]} salesforce-object-name]
  (:records
   (salesforce/with-version 34.0 
 (salesforce/soql (str "Select Id, Name From " salesforce-object-name) 
salesforce-credentials

(defmethod discern "new-opportunity"
  [{:keys [salesforce-credentials parsed-fields]}]
  (salesforce/with-version 34.0
(salesforce/so->create "Opportunity" (fcm/opportunity-map 
parsed-fields) salesforce-credentials)))

Which works perfectly.





On Wednesday, September 30, 2015 at 9:38:09 PM UTC-4, Sean Corfield wrote:
>
> Your example works for me as follows: 
>
> user> (defn- discern 
>   
>
>   ([this-users-conversation] 
>{:pre [(map? this-users-conversation)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (string? name-of-attribute)]} 
>(:intent this-users-conversation)) 
>
>   ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
>{:pre [(map? this-users-conversation) 
>   (string? salesforce-object-name) 
>   (keyword? name-of-attribute) 
>   (string? name-of-intent)]} 
>name-of-intent)) 
>
> #'user/discern 
>
> user> (defmulti intent 
>
>   (fn [& args] 
> (apply discern args))) 
>
> #'user/intent 
>
> user> (defmethod intent nil [& args] (str "I got nil plus " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent "query-salesforce-for-attribute" [& args] (str 
> "SQFFA " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (defmethod intent :default [& args] (str "WAT? " args)) 
>
> #object[clojure.lang.MultiFn 0x40954538 "clojure.lang.MultiFn@40954538"] 
>
> user> (def this-users-conversation {}) 
>
> #'user/this-users-conversation 
>
> user> (intent this-users-conversation "Opportunity" :Name 
> "query-salesforce-for-attribute") 
>
> "SQFFA ({} \"Opportunity\" :Name \"query-salesforce-for-attribute\")" 
>
> user> (intent this-users-conversation "Opportunity" "Name") 
>
> "I got nil plus ({} \"Opportunity\" \"Name\")" 
>
> user> (intent {:intent "do-something"} "Opportunity" "Name") 
>
> "WAT? ({:intent \"do-something\"} \"Opportunity\" \"Name\")" 
>
>
>
>
> Sean Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
>
> "If you're not annoying somebody, you're not really alive." 
> -- Margaret Atwood 
>
>
>
>
>
>
> From:  > on behalf of Lawrence 
> Krubner 
> Reply-To:  > 
> Date:  Wednesday, September 30, 2015 at 5:33 PM 
> To:  Clojure 
> Subject:  can I use varargs in a multimethod? 
>
>
> >For maximum flexibility I wanted to use a multimethod, defined like this: 
> > 
> > 
> >(defmulti intent 
> >  (fn [& args] 
> >(apply discern args))) 
> > 
> > 
> >This is how discern is defined: 
> > 
> >(defn- discern 
> >   
> >  ([this-users-conversation] 
> >   {:pre [(map? this-users-conversation)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object-name) 
> >  (string? name-of-attribute)]} 
> >   (:intent this-users-conversation)) 
> > 
> >  ([this-users-conversation salesforce-object-name name-of-attribute 
> name-of-intent] 
> >   {:pre [(map? this-users-conversation) 
> >  (string? salesforce-object

what is the shortest series of casts needed to get

2015-10-04 Thread Lawrence Krubner
My co-worker wrote an app in Java, which I call as a library within my own 
app. His code is expecting an ArrayList, and up until now I've been handing 
in an empty one like this: 

accounts (java.util.ArrayList. 1000)
sentence-parse-response-map (.init instance-of-sentence-parser 
incoming-message accounts contacts required-fields)

In my own code, I fetch the accounts and store it in a Clojure vector. 
Imagine something like: 

["Lisa Hare" "Morgan Aung" "Ki Xi"]

If I do this: 

(ancestors (type accounts))

I see this:

#{clojure.lang.IPersistentStack java.lang.Comparable java.lang.Iterable 
clojure.lang.IMeta clojure.lang.IReduceInit clojure.lang.AFn 
clojure.lang.Associative clojure.lang.IReduce clojure.lang.ILookup 
clojure.lang.IHashEq clojure.lang.Counted java.util.Collection 
clojure.lang.Reversible clojure.lang.IEditableCollection 
clojure.lang.Seqable java.io.Serializable java.lang.Runnable 
clojure.lang.IPersistentVector java.util.concurrent.Callable 
clojure.lang.IObj java.util.RandomAccess clojure.lang.Indexed 
clojure.lang.Sequential java.util.List java.lang.Object clojure.lang.IFn 
clojure.lang.IPersistentCollection clojure.lang.APersistentVector}

This: 

(ancestors java.util.ArrayList)

gives me: 

#{java.lang.Iterable java.util.AbstractList java.util.Collection 
java.util.AbstractCollection java.io.Serializable java.util.RandomAccess 
java.util.List java.lang.Object java.lang.Cloneable}

So what is the shortest path (of casts) to go from what I have to what he 
expects? Should I cast to  java.util.List and then call .toArray()? 




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


How do I return the data I need from this Exception?

2015-10-07 Thread Lawrence Krubner
I'm thinking that I've misunderstood something about how to catch an 
Exception. I have these 2 functions: 

(defn catch-exceptions [e this-users-conversation]
  (try 
(timbre/log :trace (str  "in catch-exceptions our exception was: " e))
(let [error (:object (ex-data e))
  status (if (:status error)
   (:status error)
   500)
  body (if (:body error)
 (:body error)
 (str e))
  intent (if (:intent this-users-conversation)
   (:intent this-users-conversation)
   "api")
  reply {:message body :status status :intent intent}]
  reply)
(catch Exception e (println "in catch-exceptions we triggered this 
exception: " e

(defn pull-response-from-query [this-users-conversation function-to-call]
  "Formatting exceptions as Peter requested so the iPhone app only needs to 
check the top-level status."
  (try
(function-to-call this-users-conversation)
(catch Exception e (catch-exceptions e this-users-conversation


Testing in the terminal, and feeding in garbage in a deliberate attempt to 
trigger the exception, I see this line over and over again: 

(timbre/log :trace (str  "in catch-exceptions our exception was: " e))

but I never get this line: 

  (timbre/log :trace (str  "in catch-exceptions our reply was: " 
reply))

nor do I ever see: 

"in catch-exceptions we triggered this exception: "

What am I doing wrong? 




-- 
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: How do I return the data I need from this Exception?

2015-10-08 Thread Lawrence Krubner

That the second logging line did not print when the first one did will 
continue to baffle me. There is absolutely no reason why that should 
happen. When a println statement goes missing the cause is usually 1 of 2 
things: the println was on a background thread, or there was an uncaught 
exception. But neither apply in this case. I am absolutely baffled. 

But I suppose it does not matter. The JVM is complex and sometimes strange 
things happen. I worked around the immediate issue with (throw) and I built 
a separation execution path to handle the exceptions that are thrown, but I 
don't like having this separate execution path. I want to bring the 
exception back into the normal flow of the program. I know there are 
libraries out there such as Hara/Ribol and I assume they do something like 
what I want. I can give them a look. 


On Thursday, October 8, 2015 at 4:01:14 AM UTC-4, Di Xu wrote:
>
> Well, I think you just misunderstand exception and try..catch expression.
>
> catch subexpression (in your case println) will evaluated only when try 
> subexpression (in your case log & let) throws exception.
>
> Thanks,
> Di Xu
>
> 2015-10-08 14:35 GMT+08:00 Lawrence Krubner  >:
>
>> I'm thinking that I've misunderstood something about how to catch an 
>> Exception. I have these 2 functions: 
>>
>> (defn catch-exceptions [e this-users-conversation]
>>   (try 
>> (timbre/log :trace (str  "in catch-exceptions our exception was: " e))
>> (let [error (:object (ex-data e))
>>   status (if (:status error)
>>(:status error)
>>500)
>>   body (if (:body error)
>>  (:body error)
>>  (str e))
>>   intent (if (:intent this-users-conversation)
>>(:intent this-users-conversation)
>>"api")
>>   reply {:message body :status status :intent intent}]
>>   reply)
>> (catch Exception e (println "in catch-exceptions we triggered this 
>> exception: " e
>>
>> (defn pull-response-from-query [this-users-conversation function-to-call]
>>   "Formatting exceptions as Peter requested so the iPhone app only needs 
>> to check the top-level status."
>>   (try
>> (function-to-call this-users-conversation)
>> (catch Exception e (catch-exceptions e this-users-conversation
>>
>>
>> Testing in the terminal, and feeding in garbage in a deliberate attempt 
>> to trigger the exception, I see this line over and over again: 
>>
>> (timbre/log :trace (str  "in catch-exceptions our exception was: " e))
>>
>> but I never get this line: 
>>
>>   (timbre/log :trace (str  "in catch-exceptions our reply was: " 
>> reply))
>>
>> nor do I ever see: 
>>
>> "in catch-exceptions we triggered this exception: "
>>
>> What am I doing wrong? 
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


How does one print the stacktrace from slingshot?

2015-10-09 Thread Lawrence Krubner

I'm trying to use Slingshot. I would like to print the stacktrace. If I do: 

 (timbre/log :trace " the stack trace via slingshot-support " 
(slingshot-support/stack-trace))


I get: 

the stack trace via slingshot-support 
 [Ljava.lang.StackTraceElement;@72ee66cd

How do I get what is in StackTraceElement? 

I looked at these articles: 

http://www.tutorialspoint.com/java/lang/stacktraceelement_tostring.htm

http://www.javaworld.com/article/2072391/the-surprisingly-simple-stacktraceelement.html

but I could not figure out how to translate that to what I'm doing. 

I also tried: 

 (timbre/log :trace " the true stack trace: "(.getStackTrace 
(:throwable &throw-context)))

but that gives me: 

 the true stack trace:  [Ljava.lang.StackTraceElement;@3733df3

I can not figure out how to see what is in StackTraceElement. 

If I search on Google for "slingshot print stacktrace" I can not find any 
examples: 

https://www.google.com/search?q=slingshot+print+stacktrace&oq=slingshot+pr&aqs=chrome.0.69i59j0j69i57j0l3.3861j0j7&sourceid=chrome&es_sm=91&ie=UTF-8





-- 
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: How does one print the stacktrace from slingshot?

2015-10-09 Thread Lawrence Krubner
Ah, not enough sleep. I was catching it a lower level and re throwing it in 
a form that tripped me up. Got rid of low level catch and did: 

 (timbre/log :trace " the true stack trace: " 
(stack/parse-exception (:throwable &throw-context)))

using clj-stacktrace and all is good. 


On Friday, October 9, 2015 at 6:00:35 AM UTC-4, Lawrence Krubner wrote:
>
>
> I'm trying to use Slingshot. I would like to print the stacktrace. If I 
> do: 
>
>  (timbre/log :trace " the stack trace via slingshot-support " 
> (slingshot-support/stack-trace))
>
>
> I get: 
>
> the stack trace via slingshot-support 
>  [Ljava.lang.StackTraceElement;@72ee66cd
>
> How do I get what is in StackTraceElement? 
>
> I looked at these articles: 
>
> http://www.tutorialspoint.com/java/lang/stacktraceelement_tostring.htm
>
>
> http://www.javaworld.com/article/2072391/the-surprisingly-simple-stacktraceelement.html
>
> but I could not figure out how to translate that to what I'm doing. 
>
> I also tried: 
>
>  (timbre/log :trace " the true stack trace: "(.getStackTrace 
> (:throwable &throw-context)))
>
> but that gives me: 
>
>  the true stack trace:  [Ljava.lang.StackTraceElement;@3733df3
>
> I can not figure out how to see what is in StackTraceElement. 
>
> If I search on Google for "slingshot print stacktrace" I can not find any 
> examples: 
>
>
> https://www.google.com/search?q=slingshot+print+stacktrace&oq=slingshot+pr&aqs=chrome.0.69i59j0j69i57j0l3.3861j0j7&sourceid=chrome&es_sm=91&ie=UTF-8
>
>
>
>
>
>

-- 
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: How does one print the stacktrace from slingshot?

2015-10-09 Thread Lawrence Krubner

Thank you.


On Friday, October 9, 2015 at 6:16:23 AM UTC-4, Marc O'Morain wrote:
>
> If you pass (:throwable &throw-context) as an arg before the string it 
> will print the stack trace:
>
> (timbre/log :trace (:throwable &throw-context)  "the true stack trace: ") 
>
>
>
>
> On Fri, Oct 9, 2015 at 11:00 AM, Lawrence Krubner  > wrote:
>
>>
>> I'm trying to use Slingshot. I would like to print the stacktrace. If I 
>> do: 
>>
>>  (timbre/log :trace " the stack trace via slingshot-support " 
>> (slingshot-support/stack-trace))
>>
>>
>> I get: 
>>
>> the stack trace via slingshot-support 
>>  [Ljava.lang.StackTraceElement;@72ee66cd
>>
>> How do I get what is in StackTraceElement? 
>>
>> I looked at these articles: 
>>
>> http://www.tutorialspoint.com/java/lang/stacktraceelement_tostring.htm
>>
>>
>> http://www.javaworld.com/article/2072391/the-surprisingly-simple-stacktraceelement.html
>>
>> but I could not figure out how to translate that to what I'm doing. 
>>
>> I also tried: 
>>
>>  (timbre/log :trace " the true stack trace: "(.getStackTrace 
>> (:throwable &throw-context)))
>>
>> but that gives me: 
>>
>>  the true stack trace:  [Ljava.lang.StackTraceElement;@3733df3
>>
>> I can not figure out how to see what is in StackTraceElement. 
>>
>> If I search on Google for "slingshot print stacktrace" I can not find any 
>> examples: 
>>
>>
>> https://www.google.com/search?q=slingshot+print+stacktrace&oq=slingshot+pr&aqs=chrome.0.69i59j0j69i57j0l3.3861j0j7&sourceid=chrome&es_sm=91&ie=UTF-8
>>
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: what is the shortest series of casts needed to get

2015-10-10 Thread Lawrence Krubner
Thank you. This was a good idea: 

> So if your coworkers code just needs something iterable (for example), 
you may 

> not need to do any casting at all: just give him the vector.




On Sunday, October 4, 2015 at 9:39:36 PM UTC-4, Francis Avila wrote:
>
> Does he actually need a real arraylist, or will something fulfilling a 
> collection interface (Collection, Iterable, or List for example) be ok? 
> Many clojure types do not require any casting at all as long as the java 
> code writes to a collection interface and doesn't expect to be able to 
> mutate the object. (Both of these are good Java idioms: write to interfaces 
> not classes, and copy defensively.)
>
> So if your coworkers code just needs something iterable (for example), you 
> may not need to do any casting at all: just give him the vector.
>
> If your coworker's code needs a real ArrayList and can accept no 
> substitutes, (java.util.ArrayList. your-vector) will make an ArrayList copy 
> of a vector's contents.
>
>

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


"get" returns nil even when "not-found" is supplied?

2015-10-16 Thread Lawrence Krubner
What am I doing wrong here? I want to call clojure.string/lower-case  on 
the :incoming-message of this-users-conversation. If there is no message, I 
return an empty string. 


(defn discern-current-state [this-users-conversation]
  (cond
(= (clojure.string/lower-case (get this-users-conversation 
:incoming-message "")) "yes") (assoc this-users-conversation :current-state 
:salesforce-write)


and yet the error points to the above line: 

java.lang.NullPointerException {:class java.lang.NullPointerException, 
:message nil, :trace-elems ({:anon-fn false, :fn "lower-case", :ns 
"clojure.string", :clojure true, :file "string.clj", :line 215} {:anon-fn 
false, :fn "discern-current-state", :ns "nlph.event-bus", :clojure true, 
:file "event_bus.clj", :line 92} 


but of course, at the REPL, everything works as I would expect: 

(def users {:message "hello"})
#'nlph.core/users

nlph.core=> (clojure.string/lower-case (get users :message))
"hello"

nlph.core=> (clojure.string/lower-case (get users :message ""))
"hello"

nlph.core=> (clojure.string/lower-case (get users :lisa))

NullPointerException   clojure.string/lower-case (string.clj:215)

nlph.core=> (clojure.string/lower-case (get users :lisa ""))
""

nlph.core=> (clojure.string/lower-case (get users :lisa))

NullPointerException   clojure.string/lower-case (string.clj:215)

-- 
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: "get" returns nil even when "not-found" is supplied?

2015-10-16 Thread Lawrence Krubner
> Is it possible that this-users-converstation *does* have 
> an :incoming-message key with a nil value?

Good catch! I feel like an idiot for not realizing that. 



On Friday, October 16, 2015 at 2:43:14 PM UTC-4, Francis Avila wrote:
>
> Not-found is not the same is not-nil. Is it possible that 
> this-users-converstation *does* have an :incoming-message key with a nil 
> value?
>
> See the difference between these two cases:
>
> (get {} :a :not-found)
> => :not-found
> (get {:a nil} :a :not-found)
> => nil
>
>
>
> Notice also that records always "have" keys that are defined on them even 
> if they are not set:
>
> (defrecord Rec [a])=> user.Rec
> (get (map->Rec {}) :a :not-found)
> => nil
>
>
>
> Perhaps you want to use or instead?
>
> (or (get this-users-conversation :incoming-message) "")
>
>
> Or figure out why nil is written and prevent it?
>
> On Friday, October 16, 2015 at 1:33:29 PM UTC-5, Lawrence Krubner wrote:
>>
>> What am I doing wrong here? I want to call clojure.string/lower-case  on 
>> the :incoming-message of this-users-conversation. If there is no message, I 
>> return an empty string. 
>>
>>
>> (defn discern-current-state [this-users-conversation]
>>   (cond
>> (= (clojure.string/lower-case (get this-users-conversation 
>> :incoming-message "")) "yes") (assoc this-users-conversation :current-state 
>> :salesforce-write)
>>
>>
>> and yet the error points to the above line: 
>>
>> java.lang.NullPointerException {:class java.lang.NullPointerException, 
>> :message nil, :trace-elems ({:anon-fn false, :fn "lower-case", :ns 
>> "clojure.string", :clojure true, :file "string.clj", :line 215} {:anon-fn 
>> false, :fn "discern-current-state", :ns "nlph.event-bus", :clojure true, 
>> :file "event_bus.clj", :line 92} 
>>
>>
>> but of course, at the REPL, everything works as I would expect: 
>>
>> (def users {:message "hello"})
>> #'nlph.core/users
>>
>> nlph.core=> (clojure.string/lower-case (get users :message))
>> "hello"
>>
>> nlph.core=> (clojure.string/lower-case (get users :message ""))
>> "hello"
>>
>> nlph.core=> (clojure.string/lower-case (get users :lisa))
>>
>> NullPointerException   clojure.string/lower-case (string.clj:215)
>>
>> nlph.core=> (clojure.string/lower-case (get users :lisa ""))
>> ""
>>
>> nlph.core=> (clojure.string/lower-case (get users :lisa))
>>
>> NullPointerException   clojure.string/lower-case (string.clj:215)
>>
>

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


is there a community "best practice" for including your co-workers libraries?

2015-10-16 Thread Lawrence Krubner
I know this question has been asked before, but when I went searching I 
mostly found old entries that were on a somewhat different topic, such as 
"How to add a java library (that is not in maven) as a dependency for a 
clojure library?"

I wrote a Clojure app and my co-worker wrote a Java app. I have another 
co-worker who is working on an app that would include the first 2 apps as 
libraries. 

I have been able to get the combination working using the Leiningen plugin 
"localrepo" but my co-worker wants me to make the other 2 libraries 
available from some central repo that Leiningen can download from. How is 
this usually done? Do I set up a Maven repo on one of the company servers? 








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


If a Java function seems to never return, how do I test?

2015-10-30 Thread Lawrence Krubner

I am trying to figure out where this code might die, and why we don't se 
the Exception, if there is an Exception. 

Inside of a try/catch block, we have this, when calls a library written in 
Java: 


(timbre/log :trace " in parse-sentence fields-and-labels is: " 
fields-and-labels)

(let [
  instance-of-sentence-parser @nlp-engine
  sentence-parse-response-map (.init instance-of-sentence-parser
 (:incoming-message 
this-users-conversation)
 organization
 accounts
 contacts
 required-fields
 fields-and-labels)
  ]

(timbre/log :trace " in parse-sentence sentence-parse-response-map is: " 
sentence-parse-response-map)


We get to the first of these log statements, but not the second. The Java 
function we call looks like this: 


public HashMap init(String debrief,String companyName, 
Collection contacts, Collection accounts, Collection requiredFields, Map 
fieldLabelMap) {
try {
System.out.println("The house is inside the nlp init.");
ArrayList ct = new 
ArrayList(Arrays.asList(contacts.toArray(new String[0])));
ArrayList ac = new 
ArrayList(Arrays.asList(accounts.toArray(new String[0])));
ArrayList rq = new 
ArrayList(Arrays.asList(requiredFields.toArray(new String[0])));
HashMap flMap = new HashMap<>(fieldLabelMap);
System.out.println("init method has ended.");
return transformer.transform(debrief, companyName, 
tecClassifier, rollioClassifier, caseClassifier, caselessClassifier, 
customClassifier, pipeline, parser, props, firstNames, lastNames, ac, ct, 
rq, flMap);
} catch (Exception e) {
System.out.println("Top level Exception in Main::main" + 
e.getMessage());
e.printStackTrace();
}
return null;
}


And it gets as far as :

System.out.println("init method has ended.");

The transform function looks like: 

public HashMap transform(String debrief, String 
companyName, AbstractSequenceClassifier tecClassifier, 
AbstractSequenceClassifier 
amaranClassifier,AbstractSequenceClassifier 
caseClassifier,AbstractSequenceClassifier caselessClassifier, 
AbstractSequenceClassifier customClassifier,StanfordCoreNLP 
pipeline, Parser parser, Properties props,String[] firstNames, String[] 
lastNames, ArrayList acctMp, ArrayList contactMap, 
ArrayList requiredFields, HashMap fieldLabelMap) {
try {
if (companyName.equals("Amaran")) {
AmaranSFInfoExtractor sfInfoExtractor = new 
AmaranSFInfoExtractor(debrief, pipeline, parser, amaranClassifier, 
caseClassifier, caselessClassifier, customClassifier, props, firstNames, 
lastNames, acctMp, contactMap, requiredFields, fieldLabelMap);
sfInfoExtractor.extract();
return deNestMap(sfInfoExtractor.tagMap);
} if (companyName.equals("TEC")) {
TECSFInfoExtractor sfInfoExtractor = new 
TECSFInfoExtractor(debrief, pipeline, parser, tecClassifier, 
caseClassifier, caselessClassifier, customClassifier, props, firstNames, 
lastNames, acctMp, contactMap, requiredFields, fieldLabelMap);
sfInfoExtractor.extract();
return deNestMap(sfInfoExtractor.tecTagMap);
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return new HashMap<>();
}


Where does this die? And why don't we see the Exception? 

What could we do to make the Exception visible, assuming there is one? 





-- 
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: If a Java function seems to never return, how do I test?

2015-11-01 Thread Lawrence Krubner
So, we eventually fixed this. There were 2 bugs that worked together to 
make this a mystery. I had to guess at what the problems were, and fix them 
blind, since I could not see the Exceptions. I am curious about why I was 
not able to see the Exceptions. 

About this:

> Exceptions are ALWAYS visible, the only way they get lost is 
> the try/catch blocks you added in your code which effectively 
> swallow and ignore them.

But the Exceptions I dealt with were invisible. We have the Clojure app set 
up to run via Supervisord and the conf has these lines:

stderr_logfile=/var/log/nlph_stderr.log
stdout_logfile=/var/log/nlph_stdout.log

So in 2 terminal windows I would:

cd /var/log

tail -f nlph_stdout.log

And the same for nlph_stderr.log.

So I was looking at the output in my terminal window. And I could see all 
of our logging statements appear. And the code clearly got to the line 
where the exception happens, but then the Exception never appeared in the 
terminal. It was invisible. I assume the output of this: 

System.out.println(e.getMessage());

would appear in one of the files that I was tailing. But it never did. 

So I am wondering why the Exceptions were invisible? Why didn't the print 
statements make it to the terminal? 




On Saturday, October 31, 2015 at 6:56:23 AM UTC-4, Thomas Heller wrote:
>
>
>> What could we do to make the Exception visible, assuming there is one? 
>>
>>
> Exceptions are ALWAYS visible, the only way they get lost is the try/catch 
> blocks you added in your code which effectively swallow and ignore them. 
> The JVM will not randomly lose an Exception, it is always code you write 
> that decided to handle them in some way. If you do not know how to handle 
> an exception do not catch it, printing its stacktrace and ignoring it is 
> never a good idea.
>
> In your case since you say that the function never returns I'd put my 
> guess on an infinite loop. There is no exception that gets lost, your code 
> is just still running. If your JVM is running locally you can attach to it 
> via jvisualvm [1] and get a quick overview of what the JVM is doing. If you 
> look at the thread information you'll see if something is still running or 
> dead-locked somehow.
>
> You can also use a debugger and step through the java code step by step.
>
> Also, consider coding against interfaces in java (eg. java.util.List and 
> java.util.Map instead of java.util.Collection), it will save you tons of 
> conversion calls.
>
> HTH
> /thomas
>
> [1] https://visualvm.java.net/
>

-- 
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: If a Java function seems to never return, how do I test?

2015-11-02 Thread Lawrence Krubner

Now there is a new error. 

Somehow, when the exception happens in our Java library, even though we, in 
theory, write to System.out.println(), I never see the Exception in the 
logs. 

All I can think is that somewhere in the Java library there is an exception 
that we catch but we forget to do System.out.println(). Can anyone think of 
another explanation? 




On Sunday, November 1, 2015 at 5:10:19 PM UTC-5, Lawrence Krubner wrote:
>
> So, we eventually fixed this. There were 2 bugs that worked together to 
> make this a mystery. I had to guess at what the problems were, and fix them 
> blind, since I could not see the Exceptions. I am curious about why I was 
> not able to see the Exceptions. 
>
> About this:
>
> > Exceptions are ALWAYS visible, the only way they get lost is 
> > the try/catch blocks you added in your code which effectively 
> > swallow and ignore them.
>
> But the Exceptions I dealt with were invisible. We have the Clojure app 
> set up to run via Supervisord and the conf has these lines:
>
> stderr_logfile=/var/log/nlph_stderr.log
> stdout_logfile=/var/log/nlph_stdout.log
>
> So in 2 terminal windows I would:
>
> cd /var/log
>
> tail -f nlph_stdout.log
>
> And the same for nlph_stderr.log.
>
> So I was looking at the output in my terminal window. And I could see all 
> of our logging statements appear. And the code clearly got to the line 
> where the exception happens, but then the Exception never appeared in the 
> terminal. It was invisible. I assume the output of this: 
>
> System.out.println(e.getMessage());
>
> would appear in one of the files that I was tailing. But it never did. 
>
> So I am wondering why the Exceptions were invisible? Why didn't the print 
> statements make it to the terminal? 
>
>
>
>
> On Saturday, October 31, 2015 at 6:56:23 AM UTC-4, Thomas Heller wrote:
>>
>>
>>> What could we do to make the Exception visible, assuming there is one? 
>>>
>>>
>> Exceptions are ALWAYS visible, the only way they get lost is the 
>> try/catch blocks you added in your code which effectively swallow and 
>> ignore them. The JVM will not randomly lose an Exception, it is always code 
>> you write that decided to handle them in some way. If you do not know how 
>> to handle an exception do not catch it, printing its stacktrace and 
>> ignoring it is never a good idea.
>>
>> In your case since you say that the function never returns I'd put my 
>> guess on an infinite loop. There is no exception that gets lost, your code 
>> is just still running. If your JVM is running locally you can attach to it 
>> via jvisualvm [1] and get a quick overview of what the JVM is doing. If you 
>> look at the thread information you'll see if something is still running or 
>> dead-locked somehow.
>>
>> You can also use a debugger and step through the java code step by step.
>>
>> Also, consider coding against interfaces in java (eg. java.util.List and 
>> java.util.Map instead of java.util.Collection), it will save you tons of 
>> conversion calls.
>>
>> HTH
>> /thomas
>>
>> [1] https://visualvm.java.net/
>>
>

-- 
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: If a Java function seems to never return, how do I test?

2015-11-04 Thread Lawrence Krubner

> flush twice, oracle is far far away? 

Are you saying this is so obvious I should be able to easily look it up? It 
might be obvious to you, but it is not obvious to me. That's why I'm asking.






On Monday, November 2, 2015 at 3:25:36 PM UTC-5, raould wrote:
>
> flush twice, oracle is far far away? 
>

-- 
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: If a Java function seems to never return, how do I test?

2015-11-04 Thread Lawrence Krubner

> It is possible to rebind System.out to something else inside Java, so the 
> library could be redirecting it from your view. Not saying that's 
> happening, but it's possible. 

Thanks for this. Now that you mention it, I recall some conversation about 
this over the summer. I will investigate this. 






On Monday, November 2, 2015 at 3:26:15 PM UTC-5, Alex Miller wrote:
>
> It is possible to rebind System.out to something else inside Java, so the 
> library could be redirecting it from your view. Not saying that's 
> happening, but it's possible. 
>
> If you you can connect with a debugger, you can set breakpoints based on 
> any thrown exception.
>
> On Monday, November 2, 2015 at 2:22:30 PM UTC-6, Lawrence Krubner wrote:
>>
>>
>> Now there is a new error. 
>>
>> Somehow, when the exception happens in our Java library, even though we, 
>> in theory, write to System.out.println(), I never see the Exception in the 
>> logs. 
>>
>> All I can think is that somewhere in the Java library there is an 
>> exception that we catch but we forget to do System.out.println(). Can 
>> anyone think of another explanation? 
>>
>>
>>
>>
>> On Sunday, November 1, 2015 at 5:10:19 PM UTC-5, Lawrence Krubner wrote:
>>>
>>> So, we eventually fixed this. There were 2 bugs that worked together to 
>>> make this a mystery. I had to guess at what the problems were, and fix them 
>>> blind, since I could not see the Exceptions. I am curious about why I was 
>>> not able to see the Exceptions. 
>>>
>>> About this:
>>>
>>> > Exceptions are ALWAYS visible, the only way they get lost is 
>>> > the try/catch blocks you added in your code which effectively 
>>> > swallow and ignore them.
>>>
>>> But the Exceptions I dealt with were invisible. We have the Clojure app 
>>> set up to run via Supervisord and the conf has these lines:
>>>
>>> stderr_logfile=/var/log/nlph_stderr.log
>>> stdout_logfile=/var/log/nlph_stdout.log
>>>
>>> So in 2 terminal windows I would:
>>>
>>> cd /var/log
>>>
>>> tail -f nlph_stdout.log
>>>
>>> And the same for nlph_stderr.log.
>>>
>>> So I was looking at the output in my terminal window. And I could see 
>>> all of our logging statements appear. And the code clearly got to the line 
>>> where the exception happens, but then the Exception never appeared in the 
>>> terminal. It was invisible. I assume the output of this: 
>>>
>>> System.out.println(e.getMessage());
>>>
>>> would appear in one of the files that I was tailing. But it never did. 
>>>
>>> So I am wondering why the Exceptions were invisible? Why didn't the 
>>> print statements make it to the terminal? 
>>>
>>>
>>>
>>>
>>> On Saturday, October 31, 2015 at 6:56:23 AM UTC-4, Thomas Heller wrote:
>>>>
>>>>
>>>>> What could we do to make the Exception visible, assuming there is one? 
>>>>>
>>>>>
>>>> Exceptions are ALWAYS visible, the only way they get lost is the 
>>>> try/catch blocks you added in your code which effectively swallow and 
>>>> ignore them. The JVM will not randomly lose an Exception, it is always 
>>>> code 
>>>> you write that decided to handle them in some way. If you do not know how 
>>>> to handle an exception do not catch it, printing its stacktrace and 
>>>> ignoring it is never a good idea.
>>>>
>>>> In your case since you say that the function never returns I'd put my 
>>>> guess on an infinite loop. There is no exception that gets lost, your code 
>>>> is just still running. If your JVM is running locally you can attach to it 
>>>> via jvisualvm [1] and get a quick overview of what the JVM is doing. If 
>>>> you 
>>>> look at the thread information you'll see if something is still running or 
>>>> dead-locked somehow.
>>>>
>>>> You can also use a debugger and step through the java code step by step.
>>>>
>>>> Also, consider coding against interfaces in java (eg. java.util.List 
>>>> and java.util.Map instead of java.util.Collection), it will save you tons 
>>>> of conversion calls.
>>>>
>>>> HTH
>>>> /thomas
>>>>
>>>> [1] https://visualvm.java.net/
>>>>
>>>

-- 
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: If a Java function seems to never return, how do I test?

2015-11-04 Thread Lawrence Krubner

Possible. I have not dug into the Java app, but I will look for that. 


On Monday, November 2, 2015 at 4:48:38 PM UTC-5, Rob Lally wrote:
>
> Is it possible that the exception is being thrown in a different thread? 
> If that’s the case, you can use:
>
>
> https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.UncaughtExceptionHandler.html
>
> to capture it.
>
>
> Rob.
>
>
> On 2 Nov 2015, at 12:22, Lawrence Krubner  > wrote:
>
>
> Now there is a new error. 
>
> Somehow, when the exception happens in our Java library, even though we, 
> in theory, write to System.out.println(), I never see the Exception in the 
> logs. 
>
> All I can think is that somewhere in the Java library there is an 
> exception that we catch but we forget to do System.out.println(). Can 
> anyone think of another explanation? 
>
>
>
>
> On Sunday, November 1, 2015 at 5:10:19 PM UTC-5, Lawrence Krubner wrote:
>>
>> So, we eventually fixed this. There were 2 bugs that worked together to 
>> make this a mystery. I had to guess at what the problems were, and fix them 
>> blind, since I could not see the Exceptions. I am curious about why I was 
>> not able to see the Exceptions. 
>>
>> About this:
>>
>> > Exceptions are ALWAYS visible, the only way they get lost is 
>> > the try/catch blocks you added in your code which effectively 
>> > swallow and ignore them.
>>
>> But the Exceptions I dealt with were invisible. We have the Clojure app 
>> set up to run via Supervisord and the conf has these lines:
>>
>> stderr_logfile=/var/log/nlph_stderr.log
>> stdout_logfile=/var/log/nlph_stdout.log
>>
>> So in 2 terminal windows I would:
>>
>> cd /var/log
>>
>> tail -f nlph_stdout.log
>>
>> And the same for nlph_stderr.log.
>>
>> So I was looking at the output in my terminal window. And I could see all 
>> of our logging statements appear. And the code clearly got to the line 
>> where the exception happens, but then the Exception never appeared in the 
>> terminal. It was invisible. I assume the output of this: 
>>
>> System.out.println(e.getMessage());
>>
>> would appear in one of the files that I was tailing. But it never did. 
>>
>> So I am wondering why the Exceptions were invisible? Why didn't the print 
>> statements make it to the terminal? 
>>
>>
>>
>>
>> On Saturday, October 31, 2015 at 6:56:23 AM UTC-4, Thomas Heller wrote:
>>>
>>>
>>>> What could we do to make the Exception visible, assuming there is one? 
>>>>
>>>>
>>> Exceptions are ALWAYS visible, the only way they get lost is the 
>>> try/catch blocks you added in your code which effectively swallow and 
>>> ignore them. The JVM will not randomly lose an Exception, it is always code 
>>> you write that decided to handle them in some way. If you do not know how 
>>> to handle an exception do not catch it, printing its stacktrace and 
>>> ignoring it is never a good idea.
>>>
>>> In your case since you say that the function never returns I'd put my 
>>> guess on an infinite loop. There is no exception that gets lost, your code 
>>> is just still running. If your JVM is running locally you can attach to it 
>>> via jvisualvm [1] and get a quick overview of what the JVM is doing. If you 
>>> look at the thread information you'll see if something is still running or 
>>> dead-locked somehow.
>>>
>>> You can also use a debugger and step through the java code step by step.
>>>
>>> Also, consider coding against interfaces in java (eg. java.util.List and 
>>> java.util.Map instead of java.util.Collection), it will save you tons of 
>>> conversion calls.
>>>
>>> HTH
>>> /thomas
>>>
>>> [1] https://visualvm.java.net/
>>>
>>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com 
> Note that posts from new members are moderated - please be patient with 
> your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+u...@googlegroups.com .
> 

Re: Ensure more concurrency

2017-03-07 Thread lawrence . krubner


https://clojuredocs.org/clojure.core/ensure

Must be called in a transaction. Protects the ref from modification
by other transactions.  Returns the in-transaction-value of
ref. Allows for more concurrency than (ref-set ref @ref)



This can be read in two contradictory ways. Protecting a ref during a 
transaction sounds like it increases contention and slows the app down. 
"Allows for more concurrency" can be read as "Allows you to use a huge 
number of refs while still ensuring consistency." In other words, it sounds 
like it offers safety at the cost of speed. 




On Monday, March 6, 2017 at 6:06:46 AM UTC-5, bertschi wrote:
>
> For a lecture I have implemented the write-skew example from Mark 
> Volkmann's article:
>
> (defn write-skew []
>   (let [cats (ref 1)
> dogs (ref 1)
>
> john (future
>(dosync
>  (when (< (+ @cats @dogs) 3)
>(alter cats inc
> mary (future
>(dosync
>  (when (< (+ @cats @dogs) 3)
>(alter dogs inc]
> (do @john @mary)
> (dosync
>  (> (+ @cats @dogs) 3
>
> (defn write-skew-demo []
>   (let [count-write-skews (atom 0)]
> (doseq [_ (range 25)]
>   (when (write-skew)
> (swap! count-write-skews inc)))
> @count-write-skews))
>
> (write-skew-demo)
>
> When I try to fix this program using ensure, i.e. using (ensure dogs) in 
> john and (ensure cats) in mary, I find that it sometimes runs very slow.
>
> From the docs it says "Allows for more concurrency than (ref-set ref 
> @ref)". I would read that as "runs at least as fast as (ref-set ref @ref)", 
> but using (ref-set dogs @dogs) instead of (ensure dogs) and the same with 
> cats, does not exhibit these occasional runtime spikes.
>
> Am I misunderstanding something or is it a bug in ensure?
>
>
> Nils
>

-- 
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: Application silently shuts down by itself after running for some hours

2017-03-07 Thread lawrence . krubner
To catch OutOfMemoryError s: 

catch(OutOfMemoryError e)




On Tuesday, March 7, 2017 at 5:18:44 PM UTC-5, JokkeB wrote:
>
> I'm under the impression that setDefaultExceptionHandler still catches OOM 
> errors. Some googling suggests this too. If not, how should I try to catch 
> it?
>
> I am running the app on a virtual server with 512mb ram. free -m is 
> showing 30mb free. Lack of memory can be the issue. What would be the best 
> way to confirm this if I'm not able to log the error?
>
> Sent from my iPhone
>
> On 7 Mar 2017, at 23.25, piast...@gmail.com  wrote:
>
> I asked the same question a year ago. The problem was that I was getting 
> an OutOfMemoryError. This is an Error but it is not an Exception. If you 
> catch all Exceptions, you will still not catch the OutOfMemoryError. You 
> have to catch that too. 
>
>
>
> On Tuesday, March 7, 2017 at 2:54:26 PM UTC-5, Kevin Corcoran wrote:
>>
>> On Mon, Mar 6, 2017 at 11:56 PM, JokkeB  wrote:
>>
>>> After adding this, I still can't see an exception before the app dies.
>>>
>>
>> I've encountered this before when the Linux "OOM killer" kicks in, which 
>> is especially likely if you are running your application on a 
>> resource-constrained system (say, a VM with a low RAM allocation) or your 
>> application is competing with other programs for memory.
>>
>> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com 
> Note that posts from new members are moderated - please be patient with 
> your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to a topic in the 
> Google Groups "Clojure" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/clojure/zhdcNMC7fQ8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> clojure+u...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>

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


Re: [ANN] meet postagga, a new lib for natural language processing

2017-03-27 Thread lawrence . krubner

Thank you for this. I am excited to give this a try. 


On Monday, March 13, 2017 at 9:24:36 AM UTC-4, Rafik NACCACHE wrote:
>
> Hey guys,
> I am pleased to share my new lib, capable of training models that help 
> parse natural language !
> My french-speaking friends will find it extremely useful as I did some 
> work to provide some french models!
> Besides, it is pure clojure, no open-nlp whatsoover, so it will happily 
> run on clojure and clojurescript!
> I would be glad if you can give it a shot here: 
> https://github.com/turbopape/postagga
> Cheers !
>
> -- 
>   
>
> [image: --] 
>   
> Rafik Naccache
> [image: https://]about.me/rafik_naccache
>
> 
>  
>

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


error in nrepl

2017-06-23 Thread lawrence . krubner
I'm using Emacs on my Mac. I ran "nrepl-jack-in" to load up the repl. I'm 
iterating over a dataset from mysql. My code is very simple, I'm just 
trying to count the words: 

(reduce 

(fn [map-of-word-count next-name] 
(let [
words (clojure.string/split next-name #"\s") 
map-of-names-words-with-count (frequencies words)
] 
(println map-of-names-words-with-count)
(merge-with + map-of-word-count map-of-names-words-with-count)
)
) 
{} 
names)

I keep getting this message:


error in process filter: nrepl-bdecode-buffer: Cannot decode object: 1
error in process filter: Cannot decode object: 1
Error running timer `jit-lock-stealth-fontify': (error "Variable binding 
depth exceeds max-specpdl-size")
timer-relative-time: Variable binding depth exceeds max-specpdl-size


Does anyone know what this means? 

-- 
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: error in nrepl

2017-06-23 Thread lawrence . krubner

Yes, sadly, I've never gotten Cider to work with Emacs. I keep thinking 
someday I'll take a weekend and work through all the errors and get it 
working, but I never seem to find the time. So I keep working with an old 
version of nrepl. But I take it, from your answer, you think this error 
would vanish if I upgraded to Cider? 




On Friday, June 23, 2017 at 5:15:09 PM UTC-4, James Reeves wrote:
>
> nrepl-jack-in? Do you mean cider-jack-in? AFAIK nrepl-jack-in is from a 
> very old version of Cider.
>
> On 23 June 2017 at 21:29, > wrote:
>
>> I'm using Emacs on my Mac. I ran "nrepl-jack-in" to load up the repl. I'm 
>> iterating over a dataset from mysql. My code is very simple, I'm just 
>> trying to count the words: 
>>
>> (reduce 
>>
>> (fn [map-of-word-count next-name] 
>> (let [
>> words (clojure.string/split next-name #"\s") 
>> map-of-names-words-with-count (frequencies words)
>> ] 
>> (println map-of-names-words-with-count)
>> (merge-with + map-of-word-count map-of-names-words-with-count)
>> )
>> ) 
>> {} 
>> names)
>>
>> I keep getting this message:
>>
>>
>> error in process filter: nrepl-bdecode-buffer: Cannot decode object: 1
>> error in process filter: Cannot decode object: 1
>> Error running timer `jit-lock-stealth-fontify': (error "Variable binding 
>> depth exceeds max-specpdl-size")
>> timer-relative-time: Variable binding depth exceeds max-specpdl-size
>>
>>
>> Does anyone know what this means? 
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> James Reeves
> booleanknot.com
>

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

2017-06-23 Thread lawrence . krubner


On Friday, June 23, 2017 at 4:29:24 PM UTC-4, lawrence...@gmail.com wrote:
>
> I'm using Emacs on my Mac. I ran "nrepl-jack-in" to load up the repl. I'm 
> iterating over a dataset from mysql. My code is very simple, I'm just 
> trying to count the words: 
>
> (reduce 
>
> (fn [map-of-word-count next-name] 
> (let [
> words (clojure.string/split next-name #"\s") 
> map-of-names-words-with-count (frequencies words)
> ] 
> (println map-of-names-words-with-count)
> (merge-with + map-of-word-count map-of-names-words-with-count)
> )
> ) 
> {} 
> names)
>
> I keep getting this message:
>
>
> error in process filter: nrepl-bdecode-buffer: Cannot decode object: 1
> error in process filter: Cannot decode object: 1
> Error running timer `jit-lock-stealth-fontify': (error "Variable binding 
> depth exceeds max-specpdl-size")
> timer-relative-time: Variable binding depth exceeds max-specpdl-size
>
>
> Does anyone know what this means? 
>
>

-- 
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: error in nrepl

2017-06-23 Thread lawrence . krubner

Thank you. Maybe I can find some time to upgrade my whole Emacs setup next 
weekend. It is a bit out of date. 

I'm curious if folks think it is easier to work with Emacs on a Linux 
machine, or on a Mac? 



On Friday, June 23, 2017 at 5:39:42 PM UTC-4, Kevin Baldor wrote:
>
> Have you tried following the instructions at 
> http://www.braveclojure.com/basic-emacs/ ?
>
> It's a bit heavy-handed (replacing your entire .emacs directory), but it 
> might give you a starting point to figure out how to integrate it into your 
> emacs setup.
>
> On Fri, Jun 23, 2017 at 4:36 PM, > 
> wrote:
>
>>
>> Yes, sadly, I've never gotten Cider to work with Emacs. I keep thinking 
>> someday I'll take a weekend and work through all the errors and get it 
>> working, but I never seem to find the time. So I keep working with an old 
>> version of nrepl. But I take it, from your answer, you think this error 
>> would vanish if I upgraded to Cider? 
>>
>>
>>
>>
>> On Friday, June 23, 2017 at 5:15:09 PM UTC-4, James Reeves wrote:
>>>
>>> nrepl-jack-in? Do you mean cider-jack-in? AFAIK nrepl-jack-in is from a 
>>> very old version of Cider.
>>>
>>> On 23 June 2017 at 21:29,  wrote:
>>>
 I'm using Emacs on my Mac. I ran "nrepl-jack-in" to load up the repl. 
 I'm iterating over a dataset from mysql. My code is very simple, I'm just 
 trying to count the words: 

 (reduce 

 (fn [map-of-word-count next-name] 
 (let [
 words (clojure.string/split next-name #"\s") 
 map-of-names-words-with-count (frequencies words)
 ] 
 (println map-of-names-words-with-count)
 (merge-with + map-of-word-count map-of-names-words-with-count)
 )
 ) 
 {} 
 names)

 I keep getting this message:


 error in process filter: nrepl-bdecode-buffer: Cannot decode object: 1
 error in process filter: Cannot decode object: 1
 Error running timer `jit-lock-stealth-fontify': (error "Variable 
 binding depth exceeds max-specpdl-size")
 timer-relative-time: Variable binding depth exceeds max-specpdl-size


 Does anyone know what this means? 

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

>>>
>>>
>>>
>>> -- 
>>> James Reeves
>>> booleanknot.com
>>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: error in nrepl

2017-06-29 Thread lawrence . krubner


Thank you for everyone's reply. Both Spacemacs and ProtoRepl sound very 
interesting. I am torn and am unsure which path to take. I suppose I'll 
give Spacemacs a try and see if that works out.

I am very pleased to see progress being made regarding at least the DE of 
IDE for Clojure. That's always been a pain point. 



On Monday, June 26, 2017 at 12:44:45 PM UTC-4, Bozhidar Batsov wrote:
>
> Newer versions of CIDER are much easier to setup than the older ones (e.g. 
> they auto-inject their dependencies, so you don't have to fiddle with 
> profiles.clj). You should try the latest stable or dev release. That said 
> you can also check Monroe (https://github.com/sanel/monroe) which is a 
> fork of a very old version of CIDER (from around the time it was named 
> nrepl.el) or inf-clojure (https://github.com/clojure-emacs/inf-clojure) - 
> a completely 0-setup Clojure(Script) REPL with support for connecting to a 
> REPL socket server. 
>
> On 24 June 2017 at 00:36, > wrote:
>
>>
>> Yes, sadly, I've never gotten Cider to work with Emacs. I keep thinking 
>> someday I'll take a weekend and work through all the errors and get it 
>> working, but I never seem to find the time. So I keep working with an old 
>> version of nrepl. But I take it, from your answer, you think this error 
>> would vanish if I upgraded to Cider? 
>>
>>
>>
>>
>> On Friday, June 23, 2017 at 5:15:09 PM UTC-4, James Reeves wrote:
>>>
>>> nrepl-jack-in? Do you mean cider-jack-in? AFAIK nrepl-jack-in is from a 
>>> very old version of Cider.
>>>
>>> On 23 June 2017 at 21:29,  wrote:
>>>
 I'm using Emacs on my Mac. I ran "nrepl-jack-in" to load up the repl. 
 I'm iterating over a dataset from mysql. My code is very simple, I'm just 
 trying to count the words: 

 (reduce 

 (fn [map-of-word-count next-name] 
 (let [
 words (clojure.string/split next-name #"\s") 
 map-of-names-words-with-count (frequencies words)
 ] 
 (println map-of-names-words-with-count)
 (merge-with + map-of-word-count map-of-names-words-with-count)
 )
 ) 
 {} 
 names)

 I keep getting this message:


 error in process filter: nrepl-bdecode-buffer: Cannot decode object: 1
 error in process filter: Cannot decode object: 1
 Error running timer `jit-lock-stealth-fontify': (error "Variable 
 binding depth exceeds max-specpdl-size")
 timer-relative-time: Variable binding depth exceeds max-specpdl-size


 Does anyone know what this means? 

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

>>>
>>>
>>>
>>> -- 
>>> James Reeves
>>> booleanknot.com
>>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: Clojure versions used by java.jdbc users

2017-07-06 Thread lawrence . krubner

I have some old projects that ran Clojure 1.5 and jbcd. I wrote them before 
the era of Cider. Cider only supports Clojure => 1.7. I do have to now use 
those old projects, but I was planning on upgrading them anyway, so I could 
work on them in Cider. 




On Monday, July 3, 2017 at 7:12:19 PM UTC-4, Sean Corfield wrote:
>
> I ran a short survey for java.jdbc users to gauge feeling about dropping 
> support for Clojure versions prior to 1.7 (so I could add reducible queries 
> without worrying about CollReduce vs IReduceInit vs IReduce).
>
>  
>
> So far, 68 people have taken the survey and the results are overwhelmingly 
> in favor of only supporting Clojure 1.7+ -- so I thought I’d share the 
> results with a larger audience, just for information:
>
>  
>
> https://www.surveymonkey.com/results/SM-CJY2YMHP/
>
>  
>
> Of 68 respondents, only one is still on Clojure 1.7, none are on earlier 
> versions. I was expecting a few more 1.7 responses – and I was not 
> expecting 35% already on Clojure 1.9 alpha builds!
>
>  
>
> If you use java.jdbc and haven’t already taken the survey and want your 
> voice heard:
>
>  
>
> https://www.surveymonkey.com/r/MR2HRFD
>
>  
>
> Sean Corfield -- (904) 302-SEAN -- (970) FOR-SEAN
>
> An Architect's View -- http://corfield.org/
>
>  
>
> "Perfection is the enemy of the good."
>
> -- Gustave Flaubert, French realist novelist (1821-1880)
>
>  
>
>  
>

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

2017-07-06 Thread lawrence . krubner
Thank you, Didier, but I'll wait till ProtoRepl is more stable. Also I'm 
not sure that I'm ready to step away from Emacs. 

I did try Spacemacs but I felt it was too much influenced by Vim. So now 
I'm using Prelude. 





On Thursday, June 29, 2017 at 1:46:11 PM UTC-4, Didier wrote:
>
> If you're no fan on emacs or vim, ProtoRepl is great. I also recommend 
> cursive, but if you're no fan of intelliJ autosave, counterclockwise 
> eclipse os surprisingly great. 

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


java.lang.ClassNotFoundException: clojure.lang.Var

2017-07-09 Thread lawrence . krubner
I was trying to knock out a quick project today, and most of it was 
copy-and-paste of another project that I have. This isn't really a big 
project, despite the long list of dependencies (which I could trim 
somewhat). 

Anyway, if I run "lein clean" and then "lein uberjar" it seems to compile 
just fine. 

But then I do this: 

 java -jar target/scan-database-find-similar-items.jar 

and get this: 

Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Var
at scan_database_find_similar_items.core.(Unknown Source)
Caused by: java.lang.ClassNotFoundException: clojure.lang.Var
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more

What would cause this?

Below is my project.clj file


(defproject scan-database-find-similar-items "1.0"
  :description "scan-database-find-similar-items compares items in the 
database to other items in the database, in the hopes of finding fake 
profiles that are duplicates. "
  :url "https://github.com/jazz/scan-database-find-similar-items";
  :license {:name "Copyright Sameday.com 2017"
:url "http://www.sameday.com/"}
  :dependencies [
 [org.clojure/clojure "1.8.0"]
 [org.clojure/test.check "0.9.0"]
 [org.clojure/java.jdbc "0.7.0-alpha1"]
 [org.clojure/data.json "0.2.5"]
 [org.clojure/tools.namespace "0.2.4"]
 [org.clojure/core.incubator "0.1.3"]
 [org.clojure/core.match "0.3.0-alpha4"]
 
 [clj-stacktrace "0.2.7"]
 [clj-time "0.6.0"]
 
 [joda-time/joda-time "2.9.4"]

 [com.taoensso/timbre "4.3.1"]
 [defun "0.3.0-RC1"]
 [slingshot "0.12.2"]
 [manifold "0.1.2"]
 [me.raynes/fs "1.4.4"]
 [overtone/at-at "1.2.0"]
 [mysql/mysql-connector-java "6.0.5"]
 [com.novemberain/monger "3.1.0"]
 [cheshire "5.3.1"]
 
 ;; TODO: remove one of these. both are in use
 [clj-http "2.3.0"]
 [http-kit "2.2.0"]
 ]

  :plugins [
[lein-localrepo "0.5.3"] ;; install java artifacts locally, 
even using fake artifactId
[lein-cprint "1.0.0"] ;; the same as lein-pprint but with colors
[lein-exec "0.3.5"] ;; execute text as Clojure code
[lein-nevam "0.1.2"] ;; convert a Maven pom to a project.clj
[lein-vanity "0.2.0"] ;; lines of code for vanity's sake
[lein-expectations "0.0.8"] ;; run expectations tests
[lein-collisions "0.1.4"] ;; find classpath collisions
]

  :aot :all  
  :source-paths  ["src/clojure"]
  :java-source-paths ["src/java"]
  :resource-paths ["src/main/resource"] ; Non-code files included in 
classpath/jar.

  ;; Name of the jar file produced. Will be placed inside :target-path.
  ;; Including %s will splice the project version into the filename.
  :jar-name "scan-database-find-similar-items.jar"
  ;; As above, but for uberjar.
  :uberjar-name "scan-database-find-similar-items-standalone.jar"
  
  ;; What to do in the case of version issues. Defaults to :ranges, which
  ;; warns when version ranges are present anywhere in the dependency tree,
  ;; but can be set to true to warn for both ranges and overrides, or :abort
  ;; to exit in the case of ranges or overrides.
  ;;  :pedantic? :abort
  

  :disable-implicit-clean true
  :warn-on-reflection true
  :main scan-database-find-similar-items.core
  :jvm-opts ["-Xms100m" "-Xmx1000m" "-XX:-UseCompressedOops"])



-- 
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: java.lang.ClassNotFoundException: clojure.lang.Var

2017-07-09 Thread lawrence . krubner
Sorry, that was dumb. Obviously I meant to call with classpath. It works 
fine with standalone. 



On Monday, July 10, 2017 at 1:27:53 AM UTC-4, lawrence...@gmail.com wrote:
>
> I was trying to knock out a quick project today, and most of it was 
> copy-and-paste of another project that I have. This isn't really a big 
> project, despite the long list of dependencies (which I could trim 
> somewhat). 
>
> Anyway, if I run "lein clean" and then "lein uberjar" it seems to compile 
> just fine. 
>
> But then I do this: 
>
>  java -jar target/scan-database-find-similar-items.jar 
>
> and get this: 
>
> Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Var
> at scan_database_find_similar_items.core.(Unknown Source)
> Caused by: java.lang.ClassNotFoundException: clojure.lang.Var
> at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
> ... 1 more
>
> What would cause this?
>
> Below is my project.clj file
>
>
> (defproject scan-database-find-similar-items "1.0"
>   :description "scan-database-find-similar-items compares items in the 
> database to other items in the database, in the hopes of finding fake 
> profiles that are duplicates. "
>   :url "https://github.com/jazz/scan-database-find-similar-items";
>   :license {:name "Copyright Sameday.com 2017"
> :url "http://www.sameday.com/"}
>   :dependencies [
>  [org.clojure/clojure "1.8.0"]
>  [org.clojure/test.check "0.9.0"]
>  [org.clojure/java.jdbc "0.7.0-alpha1"]
>  [org.clojure/data.json "0.2.5"]
>  [org.clojure/tools.namespace "0.2.4"]
>  [org.clojure/core.incubator "0.1.3"]
>  [org.clojure/core.match "0.3.0-alpha4"]
>  
>  [clj-stacktrace "0.2.7"]
>  [clj-time "0.6.0"]
>  
>  [joda-time/joda-time "2.9.4"]
>
>  [com.taoensso/timbre "4.3.1"]
>  [defun "0.3.0-RC1"]
>  [slingshot "0.12.2"]
>  [manifold "0.1.2"]
>  [me.raynes/fs "1.4.4"]
>  [overtone/at-at "1.2.0"]
>  [mysql/mysql-connector-java "6.0.5"]
>  [com.novemberain/monger "3.1.0"]
>  [cheshire "5.3.1"]
>  
>  ;; TODO: remove one of these. both are in use
>  [clj-http "2.3.0"]
>  [http-kit "2.2.0"]
>  ]
>
>   :plugins [
> [lein-localrepo "0.5.3"] ;; install java artifacts locally, 
> even using fake artifactId
> [lein-cprint "1.0.0"] ;; the same as lein-pprint but with 
> colors
> [lein-exec "0.3.5"] ;; execute text as Clojure code
> [lein-nevam "0.1.2"] ;; convert a Maven pom to a project.clj
> [lein-vanity "0.2.0"] ;; lines of code for vanity's sake
> [lein-expectations "0.0.8"] ;; run expectations tests
> [lein-collisions "0.1.4"] ;; find classpath collisions
> ]
>
>   :aot :all  
>   :source-paths  ["src/clojure"]
>   :java-source-paths ["src/java"]
>   :resource-paths ["src/main/resource"] ; Non-code files included in 
> classpath/jar.
>
>   ;; Name of the jar file produced. Will be placed inside :target-path.
>   ;; Including %s will splice the project version into the filename.
>   :jar-name "scan-database-find-similar-items.jar"
>   ;; As above, but for uberjar.
>   :uberjar-name "scan-database-find-similar-items-standalone.jar"
>   
>   ;; What to do in the case of version issues. Defaults to :ranges, which
>   ;; warns when version ranges are present anywhere in the dependency tree,
>   ;; but can be set to true to warn for both ranges and overrides, or 
> :abort
>   ;; to exit in the case of ranges or overrides.
>   ;;  :pedantic? :abort
>   
>
>   :disable-implicit-clean true
>   :warn-on-reflection true
>   :main scan-database-find-similar-items.core
>   :jvm-opts ["-Xms100m" "-Xmx1000m" "-XX:-UseCompressedOops"])
>
>
>
>

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

I can only get the first item of a lazyseq via a Manifold stream, and I can't get/find an Exception

2017-07-10 Thread lawrence . krubner
I'm using Zach Tellman's excellent Manifold library, though I admit I don't 
fully understand it. 

My code queries a MySQL database and then needs to do some processing on 
each row retrieved. I copy-and-pasted some code from the documentation for 
Manifold: 


;; 2017-07-10 -- we want a thread pool. I'm arbitrarily choosing 200 
threads.
;; query_database/start will pull data from the database and dump it onto a
;; stream below, at which point each row should be assigned to one of the 
rows
;; on our thread pool. 
(def executor (me/fixed-thread-executor 200))


(defn enqueue
  [sequence-from-database]
  (slingshot/try+
   (println "the type of the object from the database: " (type 
sequence-from-database))
   (->> (ms/->source sequence-from-database)
(ms/onto executor)
(ms/map api/query))
   (catch Object o
 (println " message queue is not happy about the message we were given")
 (errors/error o "" " we tried to put something on the message queue, 
but we got an error "

The line where I print out the type assures that I'm dealing with a LazySeq.

The code prints out the type and the first row: 


the type of the object from the database:  clojure.lang.LazySeq
 
in query_api/query  {:profile_id 2, :profile_name Mike Shaw Automotive 
Group, :headquarters_addr1 90 Madison St., :headquarters_city Denver, 
:headquarters_state_code CO, :headquarters_country_code US, :url 
mikeshawauto.com}

and then it stops. I assume there must be an Exception or Error happening, 
but I can't find it. I've added as many general Catch clauses as I could: 


(defn query
  [row & args]

  (println " in query_api/query " row)
  
  (let [config (if args
 (first args))
]
;; 2017-03-30 -- the API is overwhelmed and all I get is Socket Timeout 
errors
(Thread/sleep 300)

(slingshot/try+
 (call-api row)
 (catch Object o
   (println " error : " o)
   
   ;;(errors/error o row " we tried to call-api, but we got this error 
")


   )

 (catch Error e
   (println " there Error: " e))
 )))

So if I do: 

java  -jar scan-database-find-similar-items-standalone.jar 


The code runs till it prints out the first row from the database, and then 
it stops. Nothing else happens. There are no error messages. 

What did I miss? 







-- 
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: I can only get the first item of a lazyseq via a Manifold stream, and I can't get/find an Exception

2017-07-10 Thread lawrence . krubner
By the way, this code works fine if I go into a (doseq) a level above 
enqueue, and then put each individual row onto the stream. Then the code 
loops over all of the rows. But that seems to defeat the whole point of 
using something like Manifold. I want to be able to put the whole lazy-seq 
on the stream. That is supposed to work, yes? 


On Monday, July 10, 2017 at 8:18:07 PM UTC-4, lawrence...@gmail.com wrote:
>
> I'm using Zach Tellman's excellent Manifold library, though I admit I 
> don't fully understand it. 
>
> My code queries a MySQL database and then needs to do some processing on 
> each row retrieved. I copy-and-pasted some code from the documentation for 
> Manifold: 
>
>
> ;; 2017-07-10 -- we want a thread pool. I'm arbitrarily choosing 200 
> threads.
> ;; query_database/start will pull data from the database and dump it onto a
> ;; stream below, at which point each row should be assigned to one of the 
> rows
> ;; on our thread pool. 
> (def executor (me/fixed-thread-executor 200))
>
>
> (defn enqueue
>   [sequence-from-database]
>   (slingshot/try+
>(println "the type of the object from the database: " (type 
> sequence-from-database))
>(->> (ms/->source sequence-from-database)
> (ms/onto executor)
> (ms/map api/query))
>(catch Object o
>  (println " message queue is not happy about the message we were 
> given")
>  (errors/error o "" " we tried to put something on the message queue, 
> but we got an error "
>
> The line where I print out the type assures that I'm dealing with a 
> LazySeq.
>
> The code prints out the type and the first row: 
>
>
> the type of the object from the database:  clojure.lang.LazySeq
>  
> in query_api/query  {:profile_id 2, :profile_name Mike Shaw Automotive 
> Group, :headquarters_addr1 90 Madison St., :headquarters_city Denver, 
> :headquarters_state_code CO, :headquarters_country_code US, :url 
> mikeshawauto.com}
>
> and then it stops. I assume there must be an Exception or Error happening, 
> but I can't find it. I've added as many general Catch clauses as I could: 
>
>
> (defn query
>   [row & args]
>
>   (println " in query_api/query " row)
>   
>   (let [config (if args
>  (first args))
> ]
> ;; 2017-03-30 -- the API is overwhelmed and all I get is Socket 
> Timeout errors
> (Thread/sleep 300)
> 
> (slingshot/try+
>  (call-api row)
>  (catch Object o
>(println " error : " o)
>
>;;(errors/error o row " we tried to call-api, but we got this error 
> ")
>
>
>)
>
>  (catch Error e
>(println " there Error: " e))
>  )))
>
> So if I do: 
>
> java  -jar scan-database-find-similar-items-standalone.jar 
>
>
> The code runs till it prints out the first row from the database, and then 
> it stops. Nothing else happens. There are no error messages. 
>
> What did I miss? 
>
>
>
>
>
>
>
>

-- 
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: I can only get the first item of a lazyseq via a Manifold stream, and I can't get/find an Exception

2017-07-10 Thread lawrence . krubner

Once again, my lack of knowledge of Java trips me up. Manifold relies on 
Dirigiste, which relies on Java's Executor Service. I see a bit here:

http://www.nurkiewicz.com/2014/11/executorservice-10-tips-and-tricks.html

Nurkiewicz writes:
"I got bitten by that too many times: it won't print *anything*. No sign of 
java.lang.ArithmeticException: 
/ by zero, nothing. Thread pool just swallows this exception, as if it 
never happened. If it was a good'ol java.lang.Thread created from scratch, 
UncaughtExceptionHandler 

 could 
work. "

I suspect I'm facing something like that. 



On Monday, July 10, 2017 at 8:28:03 PM UTC-4, lawrence...@gmail.com wrote:
>
> By the way, this code works fine if I go into a (doseq) a level above 
> enqueue, and then put each individual row onto the stream. Then the code 
> loops over all of the rows. But that seems to defeat the whole point of 
> using something like Manifold. I want to be able to put the whole lazy-seq 
> on the stream. That is supposed to work, yes? 
>
>
> On Monday, July 10, 2017 at 8:18:07 PM UTC-4, lawrence...@gmail.com wrote:
>>
>> I'm using Zach Tellman's excellent Manifold library, though I admit I 
>> don't fully understand it. 
>>
>> My code queries a MySQL database and then needs to do some processing on 
>> each row retrieved. I copy-and-pasted some code from the documentation for 
>> Manifold: 
>>
>>
>> ;; 2017-07-10 -- we want a thread pool. I'm arbitrarily choosing 200 
>> threads.
>> ;; query_database/start will pull data from the database and dump it onto 
>> a
>> ;; stream below, at which point each row should be assigned to one of the 
>> rows
>> ;; on our thread pool. 
>> (def executor (me/fixed-thread-executor 200))
>>
>>
>> (defn enqueue
>>   [sequence-from-database]
>>   (slingshot/try+
>>(println "the type of the object from the database: " (type 
>> sequence-from-database))
>>(->> (ms/->source sequence-from-database)
>> (ms/onto executor)
>> (ms/map api/query))
>>(catch Object o
>>  (println " message queue is not happy about the message we were 
>> given")
>>  (errors/error o "" " we tried to put something on the message queue, 
>> but we got an error "
>>
>> The line where I print out the type assures that I'm dealing with a 
>> LazySeq.
>>
>> The code prints out the type and the first row: 
>>
>>
>> the type of the object from the database:  clojure.lang.LazySeq
>>  
>> in query_api/query  {:profile_id 2, :profile_name Mike Shaw Automotive 
>> Group, :headquarters_addr1 90 Madison St., :headquarters_city Denver, 
>> :headquarters_state_code CO, :headquarters_country_code US, :url 
>> mikeshawauto.com}
>>
>> and then it stops. I assume there must be an Exception or Error 
>> happening, but I can't find it. I've added as many general Catch clauses as 
>> I could: 
>>
>>
>> (defn query
>>   [row & args]
>>
>>   (println " in query_api/query " row)
>>   
>>   (let [config (if args
>>  (first args))
>> ]
>> ;; 2017-03-30 -- the API is overwhelmed and all I get is Socket 
>> Timeout errors
>> (Thread/sleep 300)
>> 
>> (slingshot/try+
>>  (call-api row)
>>  (catch Object o
>>(println " error : " o)
>>
>>;;(errors/error o row " we tried to call-api, but we got this 
>> error ")
>>
>>
>>)
>>
>>  (catch Error e
>>(println " there Error: " e))
>>  )))
>>
>> So if I do: 
>>
>> java  -jar scan-database-find-similar-items-standalone.jar 
>>
>>
>> The code runs till it prints out the first row from the database, and 
>> then it stops. Nothing else happens. There are no error messages. 
>>
>> What did I miss? 
>>
>>
>>
>>
>>
>>
>>
>>

-- 
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: I can only get the first item of a lazyseq via a Manifold stream, and I can't get/find an Exception

2017-07-10 Thread lawrence . krubner
Okay, that was a deadend. After going through line by line, I could pretty 
well rule out any kind of Exception or Error. The first row from the 
database seems to go through all of the functions perfectly, without any 
errors. But the second row never gets called. 

Which takes me back to where I started. Why can't I give a lazy-seq to a 
Manifold Stream and simply have a function map over the stream? 


On Monday, July 10, 2017 at 11:25:43 PM UTC-4, lawrence...@gmail.com wrote:
>
>
> Once again, my lack of knowledge of Java trips me up. Manifold relies on 
> Dirigiste, which relies on Java's Executor Service. I see a bit here:
>
> http://www.nurkiewicz.com/2014/11/executorservice-10-tips-and-tricks.html
>
> Nurkiewicz writes:
> "I got bitten by that too many times: it won't print *anything*. No sign 
> of java.lang.ArithmeticException: / by zero, nothing. Thread pool just 
> swallows this exception, as if it never happened. If it was a good'ol 
> java.lang.Thread created from scratch, UncaughtExceptionHandler 
> 
>  could 
> work. "
>
> I suspect I'm facing something like that. 
>
>
>
> On Monday, July 10, 2017 at 8:28:03 PM UTC-4, lawrence...@gmail.com wrote:
>>
>> By the way, this code works fine if I go into a (doseq) a level above 
>> enqueue, and then put each individual row onto the stream. Then the code 
>> loops over all of the rows. But that seems to defeat the whole point of 
>> using something like Manifold. I want to be able to put the whole lazy-seq 
>> on the stream. That is supposed to work, yes? 
>>
>>
>> On Monday, July 10, 2017 at 8:18:07 PM UTC-4, lawrence...@gmail.com 
>> wrote:
>>>
>>> I'm using Zach Tellman's excellent Manifold library, though I admit I 
>>> don't fully understand it. 
>>>
>>> My code queries a MySQL database and then needs to do some processing on 
>>> each row retrieved. I copy-and-pasted some code from the documentation for 
>>> Manifold: 
>>>
>>>
>>> ;; 2017-07-10 -- we want a thread pool. I'm arbitrarily choosing 200 
>>> threads.
>>> ;; query_database/start will pull data from the database and dump it 
>>> onto a
>>> ;; stream below, at which point each row should be assigned to one of 
>>> the rows
>>> ;; on our thread pool. 
>>> (def executor (me/fixed-thread-executor 200))
>>>
>>>
>>> (defn enqueue
>>>   [sequence-from-database]
>>>   (slingshot/try+
>>>(println "the type of the object from the database: " (type 
>>> sequence-from-database))
>>>(->> (ms/->source sequence-from-database)
>>> (ms/onto executor)
>>> (ms/map api/query))
>>>(catch Object o
>>>  (println " message queue is not happy about the message we were 
>>> given")
>>>  (errors/error o "" " we tried to put something on the message 
>>> queue, but we got an error "
>>>
>>> The line where I print out the type assures that I'm dealing with a 
>>> LazySeq.
>>>
>>> The code prints out the type and the first row: 
>>>
>>>
>>> the type of the object from the database:  clojure.lang.LazySeq
>>>  
>>> in query_api/query  {:profile_id 2, :profile_name Mike Shaw Automotive 
>>> Group, :headquarters_addr1 90 Madison St., :headquarters_city Denver, 
>>> :headquarters_state_code CO, :headquarters_country_code US, :url 
>>> mikeshawauto.com}
>>>
>>> and then it stops. I assume there must be an Exception or Error 
>>> happening, but I can't find it. I've added as many general Catch clauses as 
>>> I could: 
>>>
>>>
>>> (defn query
>>>   [row & args]
>>>
>>>   (println " in query_api/query " row)
>>>   
>>>   (let [config (if args
>>>  (first args))
>>> ]
>>> ;; 2017-03-30 -- the API is overwhelmed and all I get is Socket 
>>> Timeout errors
>>> (Thread/sleep 300)
>>> 
>>> (slingshot/try+
>>>  (call-api row)
>>>  (catch Object o
>>>(println " error : " o)
>>>
>>>;;(errors/error o row " we tried to call-api, but we got this 
>>> error ")
>>>
>>>
>>>)
>>>
>>>  (catch Error e
>>>(println " there Error: " e))
>>>  )))
>>>
>>> So if I do: 
>>>
>>> java  -jar scan-database-find-similar-items-standalone.jar 
>>>
>>>
>>> The code runs till it prints out the first row from the database, and 
>>> then it stops. Nothing else happens. There are no error messages. 
>>>
>>> What did I miss? 
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>

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

Re: I can only get the first item of a lazyseq via a Manifold stream, and I can't get/find an Exception

2017-07-11 Thread lawrence . krubner
Justin, thanks. I'd like to ask a follow up question. To be clear, if I go 
into (doseq) then this works fine: 

(defn start []
  (let [
config (get-config)
mysql-db {
  :dbtype "mysql"
  :dbname (get-in  config [:database :config :connection 
:database])
  :user (get-in  config [:database :config :connection 
:user] )
  :password (get-in  config [:database :config :connection 
:password] )
  :host (get-in  config [:database :config :connection 
:host])
  }
data (fetch mysql-db)
]
(slingshot/try+
 (doseq [row data]
   (queue/enqueue row))
 (catch Object o
   (errors/error o ""  "error in query_database/start: ")


but if I do this instead:

;;;  (doseq [row data]
   (queue/enqueue data))
   
and then enqueue does this: 

   (->> (ms/->source data)
(ms/onto executor)
(ms/map api/query))


The first row comes through fine, but then the second row is never 
processed. 

So are you suggesting that simply passing "data" from one function to the 
next is enough to lose the database context? But only after the first row 
has been pulled? 






On Tuesday, July 11, 2017 at 1:44:15 PM UTC-4, Justin Smith wrote:
>
> My first suspicion would be that by the time you access the second 
> element, you have exited the context of your database transaction, so 
> there's no data stream available to get it from. Lazyness doesn't tend to 
> mix well with stateful resources and contexts.
>
> On Mon, Jul 10, 2017 at 9:45 PM > 
> wrote:
>
>> Okay, that was a deadend. After going through line by line, I could 
>> pretty well rule out any kind of Exception or Error. The first row from the 
>> database seems to go through all of the functions perfectly, without any 
>> errors. But the second row never gets called. 
>>
>> Which takes me back to where I started. Why can't I give a lazy-seq to a 
>> Manifold Stream and simply have a function map over the stream? 
>>
>>
>> On Monday, July 10, 2017 at 11:25:43 PM UTC-4, lawrence...@gmail.com 
>> wrote:
>>>
>>>
>>> Once again, my lack of knowledge of Java trips me up. Manifold relies on 
>>> Dirigiste, which relies on Java's Executor Service. I see a bit here:
>>>
>>> http://www.nurkiewicz.com/2014/11/executorservice-10-tips-and-tricks.html
>>>
>>> Nurkiewicz writes:
>>> "I got bitten by that too many times: it won't print *anything*. No 
>>> sign of java.lang.ArithmeticException: / by zero, nothing. Thread pool 
>>> just swallows this exception, as if it never happened. If it was a good'ol 
>>> java.lang.Thread created from scratch, UncaughtExceptionHandler 
>>> 
>>>  could 
>>> work. "
>>>
>>> I suspect I'm facing something like that. 
>>>
>>>
>>>
>>> On Monday, July 10, 2017 at 8:28:03 PM UTC-4, lawrence...@gmail.com 
>>> wrote:

 By the way, this code works fine if I go into a (doseq) a level above 
 enqueue, and then put each individual row onto the stream. Then the code 
 loops over all of the rows. But that seems to defeat the whole point of 
 using something like Manifold. I want to be able to put the whole lazy-seq 
 on the stream. That is supposed to work, yes? 


 On Monday, July 10, 2017 at 8:18:07 PM UTC-4, lawrence...@gmail.com 
 wrote:
>
> I'm using Zach Tellman's excellent Manifold library, though I admit I 
> don't fully understand it. 
>
> My code queries a MySQL database and then needs to do some processing 
> on each row retrieved. I copy-and-pasted some code from the documentation 
> for Manifold: 
>
>
> ;; 2017-07-10 -- we want a thread pool. I'm arbitrarily choosing 200 
> threads.
> ;; query_database/start will pull data from the database and dump it 
> onto a
> ;; stream below, at which point each row should be assigned to one of 
> the rows
> ;; on our thread pool. 
> (def executor (me/fixed-thread-executor 200))
>
>
> (defn enqueue
>   [sequence-from-database]
>   (slingshot/try+
>(println "the type of the object from the database: " (type 
> sequence-from-database))
>(->> (ms/->source sequence-from-database)
> (ms/onto executor)
> (ms/map api/query))
>(catch Object o
>  (println " message queue is not happy about the message we were 
> given")
>  (errors/error o "" " we tried to put something on the message 
> queue, but we got an error "
>
> The line where I print out the type assures that I'm dealing with a 
> LazySeq.
>
> The code prints out the type and the first row: 
>
>
> the type of the object from the database:  clojure.lang.LazySeq
>  
> in query_api/query  {:profile_id 2, :profile_name Mike Shaw Automotive 
> Group, :headquarters_addr1 90 

Re: I can only get the first item of a lazyseq via a Manifold stream, and I can't get/find an Exception

2017-07-11 Thread lawrence . krubner
Sean, thanks for asking. The function is so basic that I didn't include it, 
but here it is:


(defn fetch [mysql-db]
  (slingshot/try+
   (jdbc/query mysql-db
   ["  SELECT p.id as profile_id,  p.name as profile_name, 
p.headquarters_addr1,  p.headquarters_city,  p.headquarters_state_code, 
headquarters_country_code, cw.url  FROM  company_profile p LEFT JOIN 
company_website cw ON p.id = cw.company_profile_id WHERE p.name is not null 
and p.name != ''  "])
   (catch Object o
 (errors/error o ""  " query to database had a problem "




On Wednesday, July 12, 2017 at 2:09:32 AM UTC-4, Sean Corfield wrote:
>
> What is the ‘fetch’ function here?
>
>  
>
> Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood
>
>  
>
> *From: *lawrence...@gmail.com 
> *Sent: *Tuesday, July 11, 2017 1:18 PM
> *To: *Clojure 
> *Subject: *Re: I can only get the first item of a lazyseq via a Manifold 
> stream, and I can't get/find an Exception
>
>  
>
> Justin, thanks. I'd like to ask a follow up question. To be clear, if I go 
> into (doseq) then this works fine:  
>
>  
>
> (defn start []
>
>   (let [
>
> config (get-config)
>
> mysql-db {
>
>   :dbtype "mysql"
>
>   :dbname (get-in  config [:database :config :connection 
> :database])
>
>   :user (get-in  config [:database :config :connection 
> :user] )
>
>   :password (get-in  config [:database :config :connection 
> :password] )
>
>   :host (get-in  config [:database :config :connection 
> :host])
>
>   }
>
> data (fetch mysql-db)
>
> ]
>
> (slingshot/try+
>
>  (doseq [row data]
>
>(queue/enqueue row))
>
>  (catch Object o
>
>(errors/error o ""  "error in query_database/start: ")
>
>  
>
>  
>
> but if I do this instead:
>
>  
>
> ;;;  (doseq [row data]
>
>(queue/enqueue data))
>
>
>
> and then enqueue does this: 
>
>  
>
>(->> (ms/->source data)
>
> (ms/onto executor)
>
> (ms/map api/query))
>
>  
>
>  
>
> The first row comes through fine, but then the second row is never 
> processed. 
>
>  
>
> So are you suggesting that simply passing "data" from one function to the 
> next is enough to lose the database context? But only after the first row 
> has been pulled? 
>
>  
>
>  
>
>  
>
>  
>
>  
>
>
> On Tuesday, July 11, 2017 at 1:44:15 PM UTC-4, Justin Smith wrote: 
>
> My first suspicion would be that by the time you access the second 
> element, you have exited the context of your database transaction, so 
> there's no data stream available to get it from. Lazyness doesn't tend to 
> mix well with stateful resources and contexts.
>
>  
>
> On Mon, Jul 10, 2017 at 9:45 PM  wrote:
>
> Okay, that was a deadend. After going through line by line, I could pretty 
> well rule out any kind of Exception or Error. The first row from the 
> database seems to go through all of the functions perfectly, without any 
> errors. But the second row never gets called.  
>
>  
>
> Which takes me back to where I started. Why can't I give a lazy-seq to a 
> Manifold Stream and simply have a function map over the stream? 
>
>
>
> On Monday, July 10, 2017 at 11:25:43 PM UTC-4, lawrence...@gmail.com 
> wrote: 
>
>  
>
> Once again, my lack of knowledge of Java trips me up. Manifold relies on 
> Dirigiste, which relies on Java's Executor Service. I see a bit here:
>
>  
>
> http://www.nurkiewicz.com/2014/11/executorservice-10-tips-and-tricks.html
>
>  
>
> Nurkiewicz writes:
>
> "I got bitten by that too many times: it won't print *anything*. No sign 
> of java.lang.ArithmeticException: / by zero, nothing. Thread pool just 
> swallows this exception, as if it never happened. If it was a good'ol 
> java.lang.Thread created from scratch, UncaughtExceptionHandler 
> 
>  could 
> work. "
>
>  
>
> I suspect I'm facing something like that. 
>
>  
>
>
>
> On Monday, July 10, 2017 at 8:28:03 PM UTC-4, lawrence...@gmail.com 
> wrote: 
>
> By the way, this code works fine if I go into a (doseq) a level above 
> enqueue, and then put each individual row onto the stream. Then the code 
> loops over all of the rows. But that seems to defeat the whole point of 
> using something like Manifold. I want to be able to put the whole lazy-seq 
> on the stream. That is supposed to work, yes?  
>
>
>
> On Monday, July 10, 2017 at 8:18:07 PM UTC-4, lawrence...@gmail.com 
> wrote: 
>
> I'm using Zach Tellman's excellent Manifold library, though I admit I 
> don't fully understand it.  
>
>  
>
> My code queries a MySQL database and then needs to do some processing on 
> each row retrieved. I copy-and-pasted some code from the documentation for 
> Manifold: 
>
>  
>
>  
>
> ;; 2017-07-10 -- we

What is juxt really doing?

2017-07-15 Thread lawrence . krubner
If I do this: 

((juxt :who :what :when) {:who 1 :when 2} {:who 4 :what 99}) 

I get: 

[1 {:who 4, :what 99} 2]

Why does a map come back instead of a number? 

Does anyone use juxt in the real world, or is mostly for examples? 


-- 
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: What is juxt really doing?

2017-07-16 Thread lawrence . krubner
Thank you for all the responses. The examples of using juxt to sort among 
results that are otherwise the same is a good example. 


On Sunday, July 16, 2017 at 3:18:07 AM UTC-4, Boris V. Schmid wrote:
>
> I don't use juxt much, but the example that I did pick up is where juxt is 
> used for sorting on one function first, and in the case of a tie, on the 
> second function. That is quite useful to me.
>
> > 
> (sort-by (juxt first second) (map vector (repeatedly 10 #(rand-int 3)) 
> (shuffle (range 10
> ([0 1] [0 4] [0 5] [0 6] [0 7] [0 8] [1 2] [1 3] [2 0] [2 9])
>
> On Sunday, July 16, 2017 at 5:52:44 AM UTC+2, lawrence...@gmail.com wrote:
>>
>>
>>
>> Does anyone use juxt in the real world, or is mostly for examples? 
>>
>>
>>
>  
>

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


how to be notified when a Future is realized?

2017-08-02 Thread lawrence . krubner
I stumbled across this old post by Tomasz Nurkiewicz:

http://www.nurkiewicz.com/2013/03/promises-and-futures-in-clojure.html

He writes: 

"And here is where the greatest disappointment arrives: neither future 
 nor promise 
 in Clojure 
supports listening for completion/failure asynchronously. The API is pretty 
much equivalent to very limited java.util.concurrent.Future 
. 
We can create future, cancel it 
, check 
whether it is realized? (resolved) 
 and block 
waiting for a value. Just like Future in Java, as a matter of fact the 
result of future function even implements java.util.concurrent.Future. 
As much as I love Clojure concurrency primitives like STM and agents, 
futures feel a bit underdeveloped. Lack of event-driven, asynchronous 
callbacks that are invoked whenever futures completes (notice that add-watch 
 doesn't work 
futures - and is still in alpha) greatly reduces the usefulness of a future 
object. "

That was written in 2013. I think since then the community has found other 
ways to achieve the same goals? I'm curious what patterns have become 
common? Would it be correct to say that for most of the use cases where one 
would otherwise want a notification of completion on a Future, people 
nowadays instead use something like core.async or a library such as 
Manifold? 








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


does each class need its own file when I include Java files?

2017-09-19 Thread lawrence . krubner
I need to add something very much like this to my Clojure app:

https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java

I currently have source paths set up as: 

src/
 clojure/
 java/

I believe I can copy-and-paste most of this code in the Java folder. Do I 
need to put each class in its own file? 



 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To 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: does each class need its own file when I include Java files?

2017-09-20 Thread lawrence . krubner
Sorry, I totally misread it. Thank you so much. 


On Wednesday, September 20, 2017 at 3:55:40 AM UTC-4, Juraj Martinka wrote:
>
>
> > I believe I can copy-and-paste most of this code in the Java folder. Do 
> I need to put each class in its own file? 
>
> I'm not sure what you mean by "each class in its own file".
> In the example, there's one inner class. If you put this to java folder 
> everything should work.
> If you use leiningen, you can just specify `:java-source-paths 
> ["src/java"]` in your project.clj.
>
> I tested your example and it works pretty well - see here: 
> https://github.com/jumarko/clojure-repl-experiments/blob/master/src/clojure_repl_experiments/experiments.clj#L252
>
>
>
>
> On Tuesday, 19 September 2017 17:59:10 UTC+2, lawrence...@gmail.com wrote:
>>
>> I need to add something very much like this to my Clojure app:
>>
>>
>> https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
>>
>> I currently have source paths set up as: 
>>
>> src/
>>  clojure/
>>  java/
>>
>>
>>
>>
>>
>>  
>>
>

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


When does .getThreadCpuTime return nil?

2017-09-22 Thread lawrence . krubner
I've been using this code for years. I copy and pasted it from someone else 
on this group, someone much smarter than I am. I have never seen an error 
from this code. Now suddenly I get a null pointer exception at the last 
line of this code: 

(ns denormalize_mysql_to_mongodb.monitoring
  (:import
   java.lang.management.ManagementFactory)
  (:require [clojure.string :as st]))


(defn thread-top
  "Return a seq of threads sorted by their total userland CPU usage."
  []
  (let [mgr (ManagementFactory/getThreadMXBean)
cpu-times (map (fn [t]
 [(.getThreadCpuTime mgr (.getId t)) t])
(threads))]
(map
  (fn [[cpu t]] [cpu (.getName t) (.getId t) t])
  (reverse (sort-by first cpu-times)

This error is thrown at startup. I don't know much about ThreadMXBean. Can 
anyone give me a clue why any of this would be nil? 





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

2017-09-23 Thread lawrence . krubner

Thanks for the answer. I am surprised because I used this code for years 
without ever seeing that error. I'm trying to imagine what I did 
differently this one time. I've added error detection, we'll see if it 
happens again. 



On Friday, September 22, 2017 at 7:34:49 PM UTC-4, Neil Okamoto wrote:
>
>
> Maybe it's because you attempted method invocation via reflection but the 
> object is nil. So for example if (threads) returns a list containing nils, 
> then calling (.getId t) or (.getName t) would probably throw a null pointer 
> exception. I'm not sure it's possible for 
> (ManagementFactory/getThreadMXBean) to return nil, but if it does then 
> (.getThreadCpuTime mgr ...) would similarly fail.
>
> So best guess is, take a look at the implementation of "threads".
>
>
>
>
> On Friday, September 22, 2017 at 1:37:04 PM UTC-7, lawrence...@gmail.com 
> wrote:
>>
>> I've been using this code for years. I copy and pasted it from someone 
>> else on this group, someone much smarter than I am. I have never seen an 
>> error from this code. Now suddenly I get a null pointer exception at the 
>> last line of this code: 
>>
>> (ns denormalize_mysql_to_mongodb.monitoring
>>   (:import
>>java.lang.management.ManagementFactory)
>>   (:require [clojure.string :as st]))
>>
>>
>> (defn thread-top
>>   "Return a seq of threads sorted by their total userland CPU usage."
>>   []
>>   (let [mgr (ManagementFactory/getThreadMXBean)
>> cpu-times (map (fn [t]
>>  [(.getThreadCpuTime mgr (.getId t)) t])
>> (threads))]
>> (map
>>   (fn [[cpu t]] [cpu (.getName t) (.getId t) t])
>>   (reverse (sort-by first cpu-times)
>>
>> This error is thrown at startup. I don't know much about ThreadMXBean. 
>> Can anyone give me a clue why any of this would be nil? 
>>
>>
>>
>>
>>
>>

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


How to get an error message from Elastisch?

2017-10-03 Thread lawrence . krubner
This is probably a stupid question, but is there an obvious way to get an 
error message out of Elastisch? I had an app that was working with MongoDB 
and I was then told I had to use ElasticSearch instead (something about 
only using AWS for everything) so now I'm trying to get an error message, 
because my code doesn't seem to work. I read through here without seeing 
anything obvious: 

http://clojureelasticsearch.info/articles/getting_started.htm

I rewrote my MongoDB function, so it should work with Elastisch: 

(defn push-item-to-persistence
  [item db]
  (let [
denormalized-id (get-in item [:denormalized-id] :no-id)
item (assoc item :updated-at (temporal/current-time-as-datetime))
item (assoc item :permanent-holding-id-for-item-instances 
(java.util.UUID/randomUUID))
item (assoc item :instance-id-for-this-one-item 
(java.util.UUID/randomUUID))
item (assoc item :item-type :deduplication)
]
(if (= denormalized-id :no-id)
  (slingshot/throw+ {
 :type 
::no-denormalized-id-in-push-item-into-database
 :item item
 })
  (slingshot/try+
   (put conn index mapping-type id document)
   (esd/put db "facts-over-time" "deduplicaton" (str denormalized-id) 
item)
   (println " done with put in push-item-to-persistence ")
   (catch Object o
 (slingshot/throw+ {
:type ::push-item-to-persistence
:error o
:item item
:db db
}
   ))


It doesn't seem that any documents are getting into ElasticSearch. I was 
hoping to the (throw) would reveal to me some useful debugging information, 
but that doesn't seem to happen. 

The connection appears to be valid, as I can do this:

 (let [conn (persistence/multi-thread-start config)
   res  (esd/search conn "facts-over-time" 
"deduplication" :query {:match_all {}})
   n(esrsp/total-hits res)
   hits (esrsp/hits-from res)]
   (clojure.pprint/pprint res))

and I get: 

{:took 1,
 :timed_out false,
 :_shards {:total 5, :successful 5, :failed 0},
 :hits {:total 0, :max_score nil, :hits []}}

So the connection is there. But no records are. 


-- 
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: How to get an error message from Elastisch?

2017-10-05 Thread lawrence . krubner
This problem has become much stranger. Really, I thought I was developing 
some intuitions about how to write Clojure code, but everything about this 
seems counter-intuitive. 

When the app starts, it seems to be broken, doing one write per second to 
ElasticSearch (on AWS). Then I get an error, and the error seems to fix the 
app, which then starts to make about 15,000 writes a minute to 
ElasticSearch. The error is a retry attempt reported from either Apache 
Commons HTTP or from Elastish, which is the library I'm using to connect to 
ElasticSearch.

I am not sure that anyone can help me with this, but I'll share some 
details in case anyone has run into this before. 

I'm moving 1.2 million records from MySQL to ElasticSearch (it's actually 4 
million documents that aggregate down to 1.2 million). I'm using 
DurableQueue to move the records from one transformation to another, 
denormalizing the data into the format that the frontend needs. I use 3 
queues to move through our 3 transformations. I've also a function that 
runs in the background and every 30 seconds it prints out some facts about 
my app, to give me a rough idea of what is going on. I use the (stats) 
function provided by DurableQueue to see how the 3 queues are doing.  So 
after 4 or 5 minutes, I see this block of information: 

Resource usage:  Memory in use (percentage/used/max-heap): ("87%" "3131M" 
"3568M")

CPU usage (how-many-cpu's/load-average):  [4 3.88]

Free memory in jvm: [74424])

Stats about from-mysql-to-tables-queue:  {message {:num-slabs 1, 
:num-active-slabs 1, :enqueued 236358, :retried 0, :completed 236358, 
:in-progress -1}})
}

Stats about from-tables-to-topics-queue: {:num-slabs 1, :num-active-slabs 
1, :enqueued 45731, :retried  0, :completed 45729, :in-progress 1}}
 
Stats about the from-topics-to-persistence-queue:  {message {:num-slabs 1, 
:num-active-slabs 1, :enqueued 766, :retried 0, :completed 737, 
:in-progress 20}})

This final queue is moving at a glacial speed until I get these errors: 


Oct 04, 2017 10:27:35 PM org.apache.http.impl.client.DefaultHttpClient 
tryConnect
INFO: Retrying connect to 
{s}->https://search-samedayes01-ntsdht7rqwesdu.us-east-1.es.amazonaws.com:443

Oct 04, 2017 10:27:35 PM org.apache.http.impl.client.DefaultHttpClient 
tryConnect
INFO: I/O exception (java.net.SocketException) caught when connecting to 
{s}->https://search-samedayes01-ntsdht7rqwesdu.us-east-1.es.amazonaws.com:443: 
Broken pipe (Write failed)

Oct 04, 2017 10:27:35 PM org.apache.http.impl.client.DefaultHttpClient 
tryConnect
INFO: Retrying connect to 
{s}->https://search-samedayes01-ntsdht7rqwesdu.us-east-1.es.amazonaws.com:443

Strangely, these errors seem to fix my app. After I get these errors, the 
app starts writing to ElasticSearch at about 15,000 records per minute. 

A minute or two later I see:

Resource usage:  Memory in use (percentage/used/max-heap): ("62%" "2245M" 
"3568M")

CPU usage (how-many-cpu's/load-average):  [4 1.32]

Free memory in jvm: [611550400])

Stats about from-mysql-to-tables-queue:  {message {:num-slabs 1, 
:num-active-slabs 1, :enqueued 1156526, :retried 0, :completed 1156526, 
:in-progress 0}})

Stats about from-tables-to-topics-queue:  {message {:num-slabs 1, 
:num-active-slabs 1, :enqueued 59928, :retried 0, :completed 59928, 
:in-progress 0}})

Stats about the from-topics-to-persistence-queue:  {message {:num-slabs 1, 
:num-active-slabs 1, :enqueued 53222, :retried 0, :completed 53192, 
:in-progress 20}})


So memory use declines and the speed increases. 

It is possible that the java.net.SocketException is a red herring. It is 
possible that it shows up just when the app is done with most of the 
transformations, so of course memory use would go down and speed would go 
up. But I've run this several times and java.net.SocketException always 
shows up at the same time as the big increase in speed. 

I did some research about this error and ElasticSearch and I discovered 
this:

https://stackoverflow.com/questions/28908835/ssl-peer-shut-down-incorrectly-in-java

So I added this to the -main function that starts the app:

   (System/setProperty "https.protocols" "TLSv1.1")
   
This didn't seem to have any effect. 

Going out on a limb, it does seem that all the threads that write to 
ElasticSearch initially end up blocked, and then they timeout, and when 
they retry then things go well, so the app doesn't perform well until those 
threads writing to ElasticSearch have timedout and retried. But why the 
timeout should be necessary, and why the retry works so well (repeatedly, 
every time I do this) is beyond me. 

The code that spins up the worker threads that write to ElasticSearch looks 
like this: 

(defn advance
  [message db]
  {:pre [
 (= (type message) durable_queue.Task)
 ]}
  (persistence/push-item-to-persistence @message db)
  (durable/complete! message))


(defn worker
  [from-topics-to-persistence-queue db]
  (slingshot/try+
   (loop [message (durable

Re: How to get an error message from Elastisch?

2017-10-05 Thread lawrence . krubner
One last thing, I should mention, if I go through and add " LIMIT 100 " to 
all the SQL queries, everything works great. That is, when dealing with a 
few hundred documents, the app seems to work perfectly, and there are no 
errors. It's only when I try to work with a few million documents that 
things fall apart. I suspect some kind of contention arises... somewhere. 
Possibly in several locations. But I'm not yet sure what the problem is. 



On Wednesday, October 4, 2017 at 12:49:12 AM UTC-4, lawrence...@gmail.com 
wrote:
>
> This is probably a stupid question, but is there an obvious way to get an 
> error message out of Elastisch? I had an app that was working with MongoDB 
> and I was then told I had to use ElasticSearch instead (something about 
> only using AWS for everything) so now I'm trying to get an error message, 
> because my code doesn't seem to work. I read through here without seeing 
> anything obvious: 
>
> http://clojureelasticsearch.info/articles/getting_started.htm
>
> I rewrote my MongoDB function, so it should work with Elastisch: 
>
> (defn push-item-to-persistence
>   [item db]
>   (let [
> denormalized-id (get-in item [:denormalized-id] :no-id)
> item (assoc item :updated-at (temporal/current-time-as-datetime))
> item (assoc item :permanent-holding-id-for-item-instances 
> (java.util.UUID/randomUUID))
> item (assoc item :instance-id-for-this-one-item 
> (java.util.UUID/randomUUID))
> item (assoc item :item-type :deduplication)
> ]
> (if (= denormalized-id :no-id)
>   (slingshot/throw+ {
>  :type 
> ::no-denormalized-id-in-push-item-into-database
>  :item item
>  })
>   (slingshot/try+
>(put conn index mapping-type id document)
>(esd/put db "facts-over-time" "deduplicaton" (str denormalized-id) 
> item)
>(println " done with put in push-item-to-persistence ")
>(catch Object o
>  (slingshot/throw+ {
> :type ::push-item-to-persistence
> :error o
> :item item
> :db db
> }
>))
>
>
> It doesn't seem that any documents are getting into ElasticSearch. I was 
> hoping to the (throw) would reveal to me some useful debugging information, 
> but that doesn't seem to happen. 
>
> The connection appears to be valid, as I can do this:
>
>  (let [conn (persistence/multi-thread-start config)
>res  (esd/search conn "facts-over-time" 
> "deduplication" :query {:match_all {}})
>n(esrsp/total-hits res)
>hits (esrsp/hits-from res)]
>(clojure.pprint/pprint res))
>
> and I get: 
>
> {:took 1,
>  :timed_out false,
>  :_shards {:total 5, :successful 5, :failed 0},
>  :hits {:total 0, :max_score nil, :hits []}}
>
> So the connection is there. But no records are. 
>
>
>

-- 
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: How to get an error message from Elastisch?

2017-10-05 Thread lawrence . krubner
Obviously I'm brain-dead, since I forgot to retry the write on failure. So 
I fixed this now:
 
(defn advance
  [message db]
  {:pre [
 (= (type message) durable_queue.Task)
 ]}
  (let [
;; 2017-10-05 -- if this is successful, then the return will look 
like this:
;; {:_index facts-over-time, :_type deduplicaton, :_id 
investor-6757, :_version 1, :result created, :_shards {:total 2, 
:successful 1, :failed 0}, :created true}
success-or-failure (persistence/push-item-to-persistence @message 
db)
]
(if (= (get-in success-or-failure [:_shards :successful]) 1) 
  (durable/complete! message)
  (durable/retry! message))

But my question remains: why would the app crawl at a glacial speed, till I 
get those SocketConnection errors, and then it goes fast? 

I'm not sure if this is a Clojure question or an ElasticSearch AWS 
question. I'm also researching what sort of rate limits AWS imposes, so I 
can figure out why I would get SocketConnection errors at first. 

If I got zero writes at first, then I could believe that all 20 of my 
threads were blocking, and then they all timeout, then they all start going 
fast. I know AWS load balancing has an algorithm that only slowly adapts to 
spikes in demand. I have trouble believing they would apply that kind of 
load balancing to their ElasticSearch service, but that would explain what 
I'm seeing. I have not been able to find a single article online that 
suggests this. 




On Thursday, October 5, 2017 at 12:32:11 PM UTC-4, lawrence...@gmail.com 
wrote:
>
> One last thing, I should mention, if I go through and add " LIMIT 100 " to 
> all the SQL queries, everything works great. That is, when dealing with a 
> few hundred documents, the app seems to work perfectly, and there are no 
> errors. It's only when I try to work with a few million documents that 
> things fall apart. I suspect some kind of contention arises... somewhere. 
> Possibly in several locations. But I'm not yet sure what the problem is. 
>
>
>
> On Wednesday, October 4, 2017 at 12:49:12 AM UTC-4, lawrence...@gmail.com 
> wrote:
>>
>> This is probably a stupid question, but is there an obvious way to get an 
>> error message out of Elastisch? I had an app that was working with MongoDB 
>> and I was then told I had to use ElasticSearch instead (something about 
>> only using AWS for everything) so now I'm trying to get an error message, 
>> because my code doesn't seem to work. I read through here without seeing 
>> anything obvious: 
>>
>> http://clojureelasticsearch.info/articles/getting_started.htm
>>
>> I rewrote my MongoDB function, so it should work with Elastisch: 
>>
>> (defn push-item-to-persistence
>>   [item db]
>>   (let [
>> denormalized-id (get-in item [:denormalized-id] :no-id)
>> item (assoc item :updated-at (temporal/current-time-as-datetime))
>> item (assoc item :permanent-holding-id-for-item-instances 
>> (java.util.UUID/randomUUID))
>> item (assoc item :instance-id-for-this-one-item 
>> (java.util.UUID/randomUUID))
>> item (assoc item :item-type :deduplication)
>> ]
>> (if (= denormalized-id :no-id)
>>   (slingshot/throw+ {
>>  :type 
>> ::no-denormalized-id-in-push-item-into-database
>>  :item item
>>  })
>>   (slingshot/try+
>>(put conn index mapping-type id document)
>>(esd/put db "facts-over-time" "deduplicaton" (str denormalized-id) 
>> item)
>>(println " done with put in push-item-to-persistence ")
>>(catch Object o
>>  (slingshot/throw+ {
>> :type ::push-item-to-persistence
>> :error o
>> :item item
>> :db db
>> }
>>))
>>
>>
>> It doesn't seem that any documents are getting into ElasticSearch. I was 
>> hoping to the (throw) would reveal to me some useful debugging information, 
>> but that doesn't seem to happen. 
>>
>> The connection appears to be valid, as I can do this:
>>
>>  (let [conn (persistence/multi-thread-start config)
>>res  (esd/search conn "facts-over-time" 
>> "deduplication" :query {:match_all {}})
>>n(esrsp/total-hits res)
>>hits (esrsp/hits-from res)]
>>(clojure.pprint/pprint res))
>>
>> and I get: 
>>
>> {:took 1,
>>  :timed_out false,
>>  :_shards {:total 5, :successful 5, :failed 0},
>>  :hits {:total 0, :max_score nil, :hits []}}
>>
>> So the connection is there. But no records are. 
>>
>>
>>

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

Re: How to get an error message from Elastisch?

2017-10-05 Thread lawrence . krubner
Konstantinov, yes, perhaps, though I can't think where. This is a small 
app, about 950 lines of code. There is a limited number of places where I 
can make such a mistake. I do aggregate a lot of data into an atom, and I'm 
sure there is a lot of contention around the atom, but the Socket timeout 
errors are surely some weird AWS or ElasticSearch thing. 



On Thursday, October 5, 2017 at 2:12:42 PM UTC-4, Lubomir Konstantinov 
wrote:
>
> Holding to a head somewhere perhaps?
>
> On Thursday, 5 October 2017 19:32:11 UTC+3, lawrence...@gmail.com wrote:
>>
>> One last thing, I should mention, if I go through and add " LIMIT 100 " 
>> to all the SQL queries, everything works great. That is, when dealing with 
>> a few hundred documents, the app seems to work perfectly, and there are no 
>> errors. It's only when I try to work with a few million documents that 
>> things fall apart. I suspect some kind of contention arises... somewhere. 
>> Possibly in several locations. But I'm not yet sure what the problem is. 
>>
>>
>>
>> On Wednesday, October 4, 2017 at 12:49:12 AM UTC-4, lawrence...@gmail.com 
>> wrote:
>>>
>>> This is probably a stupid question, but is there an obvious way to get 
>>> an error message out of Elastisch? I had an app that was working with 
>>> MongoDB and I was then told I had to use ElasticSearch instead (something 
>>> about only using AWS for everything) so now I'm trying to get an error 
>>> message, because my code doesn't seem to work. I read through here without 
>>> seeing anything obvious: 
>>>
>>> http://clojureelasticsearch.info/articles/getting_started.htm
>>>
>>> I rewrote my MongoDB function, so it should work with Elastisch: 
>>>
>>> (defn push-item-to-persistence
>>>   [item db]
>>>   (let [
>>> denormalized-id (get-in item [:denormalized-id] :no-id)
>>> item (assoc item :updated-at (temporal/current-time-as-datetime))
>>> item (assoc item :permanent-holding-id-for-item-instances 
>>> (java.util.UUID/randomUUID))
>>> item (assoc item :instance-id-for-this-one-item 
>>> (java.util.UUID/randomUUID))
>>> item (assoc item :item-type :deduplication)
>>> ]
>>> (if (= denormalized-id :no-id)
>>>   (slingshot/throw+ {
>>>  :type 
>>> ::no-denormalized-id-in-push-item-into-database
>>>  :item item
>>>  })
>>>   (slingshot/try+
>>>(put conn index mapping-type id document)
>>>(esd/put db "facts-over-time" "deduplicaton" (str 
>>> denormalized-id) item)
>>>(println " done with put in push-item-to-persistence ")
>>>(catch Object o
>>>  (slingshot/throw+ {
>>> :type ::push-item-to-persistence
>>> :error o
>>> :item item
>>> :db db
>>> }
>>>))
>>>
>>>
>>> It doesn't seem that any documents are getting into ElasticSearch. I was 
>>> hoping to the (throw) would reveal to me some useful debugging information, 
>>> but that doesn't seem to happen. 
>>>
>>> The connection appears to be valid, as I can do this:
>>>
>>>  (let [conn (persistence/multi-thread-start config)
>>>res  (esd/search conn "facts-over-time" 
>>> "deduplication" :query {:match_all {}})
>>>n(esrsp/total-hits res)
>>>hits (esrsp/hits-from res)]
>>>(clojure.pprint/pprint res))
>>>
>>> and I get: 
>>>
>>> {:took 1,
>>>  :timed_out false,
>>>  :_shards {:total 5, :successful 5, :failed 0},
>>>  :hits {:total 0, :max_score nil, :hits []}}
>>>
>>> So the connection is there. But no records are. 
>>>
>>>
>>>

-- 
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: How to get an error message from Elastisch?

2017-10-05 Thread lawrence . krubner
I did find this:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSPerformance.html

"Your performance can also be impacted if your application isn’t sending 
enough I/O requests. This can be monitored by looking at your volume’s 
queue length and I/O size. The queue length is the number of pending I/O 
requests from your application to your volume. For maximum consistency, 
HDD-backed volumes must maintain a queue length (rounded to the nearest 
whole number) of 4 or more when performing 1 MiB sequential I/O. "

So, at least for now, I'll assume I'm dealing with some weird kind of AWS 
thing. But if anyone has seen this pattern (slow until you get a Socket 
timeout, then fast) because of something you did in your Clojure code, I 
would love to hear about it. 




On Thursday, October 5, 2017 at 2:31:10 PM UTC-4, lawrence...@gmail.com 
wrote:
>
> Konstantinov, yes, perhaps, though I can't think where. This is a small 
> app, about 950 lines of code. There is a limited number of places where I 
> can make such a mistake. I do aggregate a lot of data into an atom, and I'm 
> sure there is a lot of contention around the atom, but the Socket timeout 
> errors are surely some weird AWS or ElasticSearch thing. 
>
>
>
> On Thursday, October 5, 2017 at 2:12:42 PM UTC-4, Lubomir Konstantinov 
> wrote:
>>
>> Holding to a head somewhere perhaps?
>>
>> On Thursday, 5 October 2017 19:32:11 UTC+3, lawrence...@gmail.com wrote:
>>>
>>> One last thing, I should mention, if I go through and add " LIMIT 100 " 
>>> to all the SQL queries, everything works great. That is, when dealing with 
>>> a few hundred documents, the app seems to work perfectly, and there are no 
>>> errors. It's only when I try to work with a few million documents that 
>>> things fall apart. I suspect some kind of contention arises... somewhere. 
>>> Possibly in several locations. But I'm not yet sure what the problem is. 
>>>
>>>
>>>
>>> On Wednesday, October 4, 2017 at 12:49:12 AM UTC-4, 
>>> lawrence...@gmail.com wrote:

 This is probably a stupid question, but is there an obvious way to get 
 an error message out of Elastisch? I had an app that was working with 
 MongoDB and I was then told I had to use ElasticSearch instead (something 
 about only using AWS for everything) so now I'm trying to get an error 
 message, because my code doesn't seem to work. I read through here without 
 seeing anything obvious: 

 http://clojureelasticsearch.info/articles/getting_started.htm

 I rewrote my MongoDB function, so it should work with Elastisch: 

 (defn push-item-to-persistence
   [item db]
   (let [
 denormalized-id (get-in item [:denormalized-id] :no-id)
 item (assoc item :updated-at 
 (temporal/current-time-as-datetime))
 item (assoc item :permanent-holding-id-for-item-instances 
 (java.util.UUID/randomUUID))
 item (assoc item :instance-id-for-this-one-item 
 (java.util.UUID/randomUUID))
 item (assoc item :item-type :deduplication)
 ]
 (if (= denormalized-id :no-id)
   (slingshot/throw+ {
  :type 
 ::no-denormalized-id-in-push-item-into-database
  :item item
  })
   (slingshot/try+
(put conn index mapping-type id document)
(esd/put db "facts-over-time" "deduplicaton" (str 
 denormalized-id) item)
(println " done with put in push-item-to-persistence ")
(catch Object o
  (slingshot/throw+ {
 :type ::push-item-to-persistence
 :error o
 :item item
 :db db
 }
))


 It doesn't seem that any documents are getting into ElasticSearch. I 
 was hoping to the (throw) would reveal to me some useful debugging 
 information, but that doesn't seem to happen. 

 The connection appears to be valid, as I can do this:

  (let [conn (persistence/multi-thread-start config)
res  (esd/search conn "facts-over-time" 
 "deduplication" :query {:match_all {}})
n(esrsp/total-hits res)
hits (esrsp/hits-from res)]
(clojure.pprint/pprint res))

 and I get: 

 {:took 1,
  :timed_out false,
  :_shards {:total 5, :successful 5, :failed 0},
  :hits {:total 0, :max_score nil, :hits []}}

 So the connection is there. But no records are. 




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

Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
I'm trying to use a Zach Tellman's durable-queue to pass information from 
one part of my app to another. I have 3 queues. I also have a function that 
runs every 30 seconds, that is suppose to report some statistics for me: 

  (fn []
(future
  (slingshot/try+
   (errors/log "Resource usage: "
  
 (monitoring/show-stats-regarding-resources-used-by-this-app))
   (errors/log "Stats about from-mysql-to-tables-queue: " 
(durable/stats from-mysql-to-tables-queue))
   (errors/log "Stats about from-tables-to-topics-queue: " 
(durable/stats from-tables-to-topics-queue))
   (errors/log "Stats about the 
from-topics-to-persistence-queue: " (durable/stats 
from-topics-to-persistence-queue))
   (catch Object o
 (slingshot/throw+ {
:type ::cycle-resource-usage-report
:error o
}
   )

I think there is an error here, because I see the first (errors/log) but 
typically not anything after that. Can I rely on the fact that this should 
catch anything: 

   (catch Object o

Because it doesn't seem to work. Instead, the app runs for 8 minutes, then 
prints data about the queues just once, then never again. Assuming an error 
is occuring, why can't I see the error? 


{:timestamp "17-10-09 01:27:45", :level :trace, :hostname "ip-172-31-4-54", 
:message ("STARTING")}

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver 
class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered 
via the SPI and manual loading of the driver class is generally unnecessary.


{:timestamp "17-10-09 01:28:16", :level :trace, :hostname "ip-172-31-4-54", 
:message ("\n\n\n\n\nResource usage: " "Memory in use 
(percentage/used/max-heap): (\"67%\" \"2414M\" \"3568M\")\n\nCPU usage 
(how-many-cpu's/load-average):  [4 1.56]\n\nFree memory in jvm: 
[1201758848]")}


{:timestamp "17-10-09 01:28:49", :level :trace, :hostname "ip-172-31-4-54", 
:message ("\n\n\n\n\nResource usage: " "Memory in use 
(percentage/used/max-heap): (\"81%\" \"2900M\" \"3568M\")\n\nCPU usage 
(how-many-cpu's/load-average):  [4 2.64]\n\nFree memory in jvm: 
[699798216]")}

;; removing redundant entries

{:timestamp "17-10-09 01:34:48", :level :trace, :hostname "UnknownHost", 
:message ("\n\n\n\n\nResource usage: " "Memory in use 
(percentage/used/max-heap): (\"87%\" \"3118M\" \"3568M\")\n\nCPU usage 
(how-many-cpu's/load-average):  [4 3.77]\n\nFree memory in jvm: 
[471249616]")}


{:timestamp "17-10-09 01:35:17", :level :trace, :hostname "ip-172-31-4-54", 
:message ("\n\n\n\n\nResource usage: " "Memory in use 
(percentage/used/max-heap): (\"87%\" \"3120M\" \"3568M\")\n\nCPU usage 
(how-many-cpu's/load-average):  [4 3.79]\n\nFree memory in jvm: 
[468602192]")}


{:timestamp "17-10-09 01:35:35", :level :trace, :hostname "ip-172-31-4-54", 
:message ("\nStats about from-mysql-to-tables-queue: " {"message" 
{:num-slabs 1, :num-active-slabs 1, :enqueued 306671, :retried 0, 
:completed 306660, :in-progress 8}})}


{:timestamp "17-10-09 01:35:50", :level :trace, :hostname "ip-172-31-4-54", 
:message ("\nStats about from-tables-to-topics-queue: " {})}


{:timestamp "17-10-09 01:35:50", :level :trace, :hostname "ip-172-31-4-54", 
:message ("\nStats about the from-topics-to-persistence-queue: " {})}


{:timestamp "17-10-09 01:36:15", :level :trace, :hostname "ip-172-31-4-54", 
:message ("\n\n\n\n\nResource usage: " "Memory in use 
(percentage/used/max-heap): (\"28%\" \"1007M\" \"3568M\")\n\nCPU usage 
(how-many-cpu's/load-average):  [4 4.14]\n\nFree memory in jvm: 
[1868654000]")}





So 8 minutes after the app starts, it print the lines with stats about the 
queues, just this one time, and then never again. I think an error must 
occur inside of the function that is suppose to report the queues. What 
would I have to do to see that error?

My core/main function looks like this:

(defn -main [& args]

  (slingshot/try+

   ;; 2017-10-04 -- see this:
   ;; 
https://stackoverflow.com/questions/28908835/ssl-peer-shut-down-incorrectly-in-java
   (System/setProperty "https.protocols" "TLSv1.1")
   
   (.addShutdownHook (Runtime/getRuntime)
 (Thread.
  #(do (println "addShutdownHook triggered. This app is 
shutting down.")
   (stop

   ;; 2017-07-12 -- stealing code from here:
   ;; https://stuartsierra.com/2015/05/27/clojure-uncaught-exceptions
   ;; Assuming require [clojure.tools.logging :as log]
   (Thread/setDefaultUncaughtExceptionHandler
(reify Thread$UncaughtExceptionHandler
  (uncaughtException [_ thread ex]
(println ex "Uncaught background exception on thread " (.getName 
thread) " Caught by Thread/setDefaultUncaughtExcept

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
(errors/log) simply writes to the Timbre logging library. I thought perhaps 
there was an error in my Timbre configuration, so I wrapped those functions 
in try/catch, but I still don't see anything. I'm trying this as my Timbre 
config:




(defn- set-timbre-level []
  (timbre/set-config!
   {:level :trace ; e/o #{:trace :debug :info :warn :error :fatal :report}
:output-fn (fn [data]
 (slingshot/try+
   (clojure.string/join "\n" data)
   (catch Object o
 (slingshot/throw+ {
:type ::output-fn-of-timbre
:error o
}
 
:appenders {
;; Appender id
:for-stdout {
 :enabled?   true
 :async? false
 :min-level  nil
 :rate-limit [[1 250] [10 5000]] ; 1/250ms, 
10/5s
 :output-fn  :inherit
 ;; Appender's fn
 :fn (fn
   [{:keys [vargs_ hostname_ timestamp_ 
level output-fn] :as args}]
   (slingshot/try+
 (let [
   messages (map (fn [msg] { 
:timestamp @timestamp_
:level 
level

:hostname  @hostname_

:message   msg })
 @vargs_)
   ]
   (println (str 
(temporal/current-time-as-string) "\n" (output-fn messages
 (catch Object o
   (slingshot/throw+ {
  :type 
::for-stdout-fn-of-timbre
  :error o
  }
 }}}))

On Sunday, October 8, 2017 at 11:13:10 PM UTC-4, lawrence...@gmail.com 
wrote:
>
> I'm trying to use a Zach Tellman's durable-queue to pass information from 
> one part of my app to another. I have 3 queues. I also have a function that 
> runs every 30 seconds, that is suppose to report some statistics for me: 
>
>   (fn []
> (future
>   (slingshot/try+
>(errors/log "Resource usage: "
>   
>  (monitoring/show-stats-regarding-resources-used-by-this-app))
>(errors/log "Stats about from-mysql-to-tables-queue: " 
> (durable/stats from-mysql-to-tables-queue))
>(errors/log "Stats about from-tables-to-topics-queue: " 
> (durable/stats from-tables-to-topics-queue))
>(errors/log "Stats about the 
> from-topics-to-persistence-queue: " (durable/stats 
> from-topics-to-persistence-queue))
>(catch Object o
>  (slingshot/throw+ {
> :type ::cycle-resource-usage-report
> :error o
> }
>)
>
> I think there is an error here, because I see the first (errors/log) but 
> typically not anything after that. Can I rely on the fact that this should 
> catch anything: 
>
>(catch Object o
>
> Because it doesn't seem to work. Instead, the app runs for 8 minutes, then 
> prints data about the queues just once, then never again. Assuming an error 
> is occuring, why can't I see the error? 
>
>
> {:timestamp "17-10-09 01:27:45", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("STARTING")}
>
> Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver 
> class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered 
> via the SPI and manual loading of the driver class is generally unnecessary.
>
>
> {:timestamp "17-10-09 01:28:16", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"67%\" \"2414M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 1.56]\n\nFree memory in jvm: 
> [1201758848]")}
>
>
> {:timestamp "17-10-09 01:28:49", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"81%\" \"2900M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 2.64]\n\nFree memory in jvm: 
> [699798216]")}
>
> ;; removing redundant entries
>
> {:timestamp "17

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
More generally, I'm having trouble seeing any kind of logging messages. 
Even when I delete this Timbre config, and simply go with Timbre defaults, 
and set the level to "trace", I only erratically see anything printed to 
the logs. I assume there are messages dying in background threads, but I 
have a bit of code, which I stole from a blog post by Stuart Sierra, and 
which I put in my core/main function, which should, I assumed, reveal to me 
errors thrown from background threads. 


On Sunday, October 8, 2017 at 11:13:10 PM UTC-4, lawrence...@gmail.com 
wrote:
>
> I'm trying to use a Zach Tellman's durable-queue to pass information from 
> one part of my app to another. I have 3 queues. I also have a function that 
> runs every 30 seconds, that is suppose to report some statistics for me: 
>
>   (fn []
> (future
>   (slingshot/try+
>(errors/log "Resource usage: "
>   
>  (monitoring/show-stats-regarding-resources-used-by-this-app))
>(errors/log "Stats about from-mysql-to-tables-queue: " 
> (durable/stats from-mysql-to-tables-queue))
>(errors/log "Stats about from-tables-to-topics-queue: " 
> (durable/stats from-tables-to-topics-queue))
>(errors/log "Stats about the 
> from-topics-to-persistence-queue: " (durable/stats 
> from-topics-to-persistence-queue))
>(catch Object o
>  (slingshot/throw+ {
> :type ::cycle-resource-usage-report
> :error o
> }
>)
>
> I think there is an error here, because I see the first (errors/log) but 
> typically not anything after that. Can I rely on the fact that this should 
> catch anything: 
>
>(catch Object o
>
> Because it doesn't seem to work. Instead, the app runs for 8 minutes, then 
> prints data about the queues just once, then never again. Assuming an error 
> is occuring, why can't I see the error? 
>
>
> {:timestamp "17-10-09 01:27:45", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("STARTING")}
>
> Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver 
> class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered 
> via the SPI and manual loading of the driver class is generally unnecessary.
>
>
> {:timestamp "17-10-09 01:28:16", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"67%\" \"2414M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 1.56]\n\nFree memory in jvm: 
> [1201758848]")}
>
>
> {:timestamp "17-10-09 01:28:49", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"81%\" \"2900M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 2.64]\n\nFree memory in jvm: 
> [699798216]")}
>
> ;; removing redundant entries
>
> {:timestamp "17-10-09 01:34:48", :level :trace, :hostname "UnknownHost", 
> :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"87%\" \"3118M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 3.77]\n\nFree memory in jvm: 
> [471249616]")}
>
>
> {:timestamp "17-10-09 01:35:17", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"87%\" \"3120M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 3.79]\n\nFree memory in jvm: 
> [468602192]")}
>
>
> {:timestamp "17-10-09 01:35:35", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\nStats about from-mysql-to-tables-queue: " 
> {"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 306671, :retried 
> 0, :completed 306660, :in-progress 8}})}
>
>
> {:timestamp "17-10-09 01:35:50", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\nStats about from-tables-to-topics-queue: " 
> {})}
>
>
> {:timestamp "17-10-09 01:35:50", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\nStats about the 
> from-topics-to-persistence-queue: " {})}
>
>
> {:timestamp "17-10-09 01:36:15", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"28%\" \"1007M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 4.14]\n\nFree memory in jvm: 
> [1868654000]")}
>
>
>
>
>
> So 8 minutes after the app starts, it print the lines with stats about the 
> queues, just this one time, and then never again. I think an error must 
> occur inside of the function that is suppose to report the queues. What 
> would I have to do to see that error?
>
> My core/main function looks like this:
>
> (defn -main [& args]
>
>   (slingshot/try+
>
>;; 2017-10-04 -- see this:
>;; 
> ht

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
Using spit to an append to a log file, I end up seeing much more than what 
I can see from Timbre. The app writes a few lines, then dies: 

("\n\n\n\n\nResource usage: " "Memory in use (percentage/used/max-heap): 
(\"3%\" \"133M\" \"3568M\")\n\nCPU usage (how-many-cpu's/load-average):  [4 
0.0]\n\nFree memory in jvm: [252719920]") 

("\nStats about from-mysql-to-tables-queue: " {"message" {:num-slabs 1, 
:num-active-slabs 1, :enqueued 389, :retried 10, :completed 378, 
:in-progress 1}}) 

("\nStats about from-tables-to-topics-queue: " {}) 

("\nStats about the from-topics-to-persistence-queue: " {}) 

("\n\n\n\n\nResource usage: " "Memory in use (percentage/used/max-heap): 
(\"3%\" \"134M\" \"3568M\")\n\nCPU usage (how-many-cpu's/load-average):  [4 
0.0]\n\nFree memory in jvm: [251769008]") 

("\nStats about from-mysql-to-tables-queue: " {"message" {:num-slabs 1, 
:num-active-slabs 1, :enqueued 389, :retried 10, :completed 378, 
:in-progress 1}}) 

("\nStats about from-tables-to-topics-queue: " {}) 

("\nStats about the from-topics-to-persistence-queue: " {}) 

Still, I feel like I've got everything wrapped in slingshot/try+ and catch 
and throw, yet I don't see the error that is killing the app. Is that 
because of (catch Object) doesn't catch all the errors that I should be 
checking for, or is that because my logging functions just don't write 
them? 


On Sunday, October 8, 2017 at 11:13:10 PM UTC-4, lawrence...@gmail.com 
wrote:
>
> I'm trying to use a Zach Tellman's durable-queue to pass information from 
> one part of my app to another. I have 3 queues. I also have a function that 
> runs every 30 seconds, that is suppose to report some statistics for me: 
>
>   (fn []
> (future
>   (slingshot/try+
>(errors/log "Resource usage: "
>   
>  (monitoring/show-stats-regarding-resources-used-by-this-app))
>(errors/log "Stats about from-mysql-to-tables-queue: " 
> (durable/stats from-mysql-to-tables-queue))
>(errors/log "Stats about from-tables-to-topics-queue: " 
> (durable/stats from-tables-to-topics-queue))
>(errors/log "Stats about the 
> from-topics-to-persistence-queue: " (durable/stats 
> from-topics-to-persistence-queue))
>(catch Object o
>  (slingshot/throw+ {
> :type ::cycle-resource-usage-report
> :error o
> }
>)
>
> I think there is an error here, because I see the first (errors/log) but 
> typically not anything after that. Can I rely on the fact that this should 
> catch anything: 
>
>(catch Object o
>
> Because it doesn't seem to work. Instead, the app runs for 8 minutes, then 
> prints data about the queues just once, then never again. Assuming an error 
> is occuring, why can't I see the error? 
>
>
> {:timestamp "17-10-09 01:27:45", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("STARTING")}
>
> Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver 
> class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered 
> via the SPI and manual loading of the driver class is generally unnecessary.
>
>
> {:timestamp "17-10-09 01:28:16", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"67%\" \"2414M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 1.56]\n\nFree memory in jvm: 
> [1201758848]")}
>
>
> {:timestamp "17-10-09 01:28:49", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"81%\" \"2900M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 2.64]\n\nFree memory in jvm: 
> [699798216]")}
>
> ;; removing redundant entries
>
> {:timestamp "17-10-09 01:34:48", :level :trace, :hostname "UnknownHost", 
> :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"87%\" \"3118M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 3.77]\n\nFree memory in jvm: 
> [471249616]")}
>
>
> {:timestamp "17-10-09 01:35:17", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"87%\" \"3120M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 3.79]\n\nFree memory in jvm: 
> [468602192]")}
>
>
> {:timestamp "17-10-09 01:35:35", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\nStats about from-mysql-to-tables-queue: " 
> {"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 306671, :retried 
> 0, :completed 306660, :in-progress 8}})}
>
>
> {:timestamp "17-10-09 01:35:50", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\nStats about from-tables-to-topics-

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
So, for instance, this says that 10 documents were retried:

{"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 389, :retried 10, 
:completed 378, :in-progress 1}}

The only place that I call retry! is in this catch block (this function 
runs in a background thread):

(defn advance
  [message]
  {:pre [
 (= (type message) durable_queue.Task)
 ]}
  (slingshot/try+
   (doseq [[k v] @message]
 (when-not (or
(= :how-many-rows-and-fields-from-database k)
(= :database-table k)
(= :denormalized-id k)
(= :topic k))
   (transform
(get @message :denormalized-id :missing-denormalized-id)
k
v
(get @message :topic :missing-topic)
(get @message :how-many-rows-and-fields-from-database 
:missing-how-many-rows-and-fields-from-database
   
   (durable/complete! message)
   (catch Object o
 (durable/retry! message)
 (slingshot/throw+ {
:type ::advance
:error o
}
   

So clearly, the code has a problem with some of the documents, and so an 
error is thrown, and it is caught by the catch block. I would love to see 
the error. I can not. If I put println in the catch block, the message 
never shows up in the terminal. Likewise if I use Timbre. 

I would love to see the error object. My inability to see the error objects 
has crippled my productivity. 

Can anyone tell me what I need to do to see these errors? 





On Sunday, October 8, 2017 at 11:13:10 PM UTC-4, lawrence...@gmail.com 
wrote:
>
> I'm trying to use a Zach Tellman's durable-queue to pass information from 
> one part of my app to another. I have 3 queues. I also have a function that 
> runs every 30 seconds, that is suppose to report some statistics for me: 
>
>   (fn []
> (future
>   (slingshot/try+
>(errors/log "Resource usage: "
>   
>  (monitoring/show-stats-regarding-resources-used-by-this-app))
>(errors/log "Stats about from-mysql-to-tables-queue: " 
> (durable/stats from-mysql-to-tables-queue))
>(errors/log "Stats about from-tables-to-topics-queue: " 
> (durable/stats from-tables-to-topics-queue))
>(errors/log "Stats about the 
> from-topics-to-persistence-queue: " (durable/stats 
> from-topics-to-persistence-queue))
>(catch Object o
>  (slingshot/throw+ {
> :type ::cycle-resource-usage-report
> :error o
> }
>)
>
> I think there is an error here, because I see the first (errors/log) but 
> typically not anything after that. Can I rely on the fact that this should 
> catch anything: 
>
>(catch Object o
>
> Because it doesn't seem to work. Instead, the app runs for 8 minutes, then 
> prints data about the queues just once, then never again. Assuming an error 
> is occuring, why can't I see the error? 
>
>
> {:timestamp "17-10-09 01:27:45", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("STARTING")}
>
> Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver 
> class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered 
> via the SPI and manual loading of the driver class is generally unnecessary.
>
>
> {:timestamp "17-10-09 01:28:16", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"67%\" \"2414M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 1.56]\n\nFree memory in jvm: 
> [1201758848]")}
>
>
> {:timestamp "17-10-09 01:28:49", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"81%\" \"2900M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 2.64]\n\nFree memory in jvm: 
> [699798216]")}
>
> ;; removing redundant entries
>
> {:timestamp "17-10-09 01:34:48", :level :trace, :hostname "UnknownHost", 
> :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"87%\" \"3118M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 3.77]\n\nFree memory in jvm: 
> [471249616]")}
>
>
> {:timestamp "17-10-09 01:35:17", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
> (percentage/used/max-heap): (\"87%\" \"3120M\" \"3568M\")\n\nCPU usage 
> (how-many-cpu's/load-average):  [4 3.79]\n\nFree memory in jvm: 
> [468602192]")}
>
>
> {:timestamp "17-10-09 01:35:35", :level :trace, :hostname 
> "ip-172-31-4-54", :message ("\nStats about from-mysql-to-tables-queue: " 
> {"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 306671, :retrie

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
Well, the people behind Slingshot have suggested it as the Slingshot 
version of catch Exception, but I like your idea and I'll try it. 

Having said that, as I said in my last post, the only place I call (retry!) 
is inside the catch block, so the code does end up inside of that catch 
block. But I never see any results of printing or throwing from inside the 
catch block. 


On Sunday, October 8, 2017 at 11:46:26 PM UTC-4, tbc++ wrote:
>
> I don't think you can catch an Object on the JVM can you? What happens if 
> you catch Throwable?
>
> On Sun, Oct 8, 2017 at 9:43 PM, > 
> wrote:
>
>> So, for instance, this says that 10 documents were retried:
>>
>> {"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 389, :retried 
>> 10, :completed 378, :in-progress 1}}
>>
>> The only place that I call retry! is in this catch block (this function 
>> runs in a background thread):
>>
>> (defn advance
>>   [message]
>>   {:pre [
>>  (= (type message) durable_queue.Task)
>>  ]}
>>   (slingshot/try+
>>(doseq [[k v] @message]
>>  (when-not (or
>> (= :how-many-rows-and-fields-from-database k)
>> (= :database-table k)
>> (= :denormalized-id k)
>> (= :topic k))
>>(transform
>> (get @message :denormalized-id :missing-denormalized-id)
>> k
>> v
>> (get @message :topic :missing-topic)
>> (get @message :how-many-rows-and-fields-from-database 
>> :missing-how-many-rows-and-fields-from-database
>>
>>(durable/complete! message)
>>(catch Object o
>>  (durable/retry! message)
>>  (slingshot/throw+ {
>> :type ::advance
>> :error o
>> }
>>
>>
>> So clearly, the code has a problem with some of the documents, and so an 
>> error is thrown, and it is caught by the catch block. I would love to see 
>> the error. I can not. If I put println in the catch block, the message 
>> never shows up in the terminal. Likewise if I use Timbre. 
>>
>> I would love to see the error object. My inability to see the error 
>> objects has crippled my productivity. 
>>
>> Can anyone tell me what I need to do to see these errors? 
>>
>>
>>
>>
>>
>> On Sunday, October 8, 2017 at 11:13:10 PM UTC-4, lawrence...@gmail.com 
>> wrote:
>>
>>> I'm trying to use a Zach Tellman's durable-queue to pass information 
>>> from one part of my app to another. I have 3 queues. I also have a function 
>>> that runs every 30 seconds, that is suppose to report some statistics for 
>>> me: 
>>>
>>>   (fn []
>>> (future
>>>   (slingshot/try+
>>>(errors/log "Resource usage: "
>>>   
>>>  (monitoring/show-stats-regarding-resources-used-by-this-app))
>>>(errors/log "Stats about from-mysql-to-tables-queue: 
>>> " (durable/stats from-mysql-to-tables-queue))
>>>(errors/log "Stats about from-tables-to-topics-queue: 
>>> " (durable/stats from-tables-to-topics-queue))
>>>(errors/log "Stats about the 
>>> from-topics-to-persistence-queue: " (durable/stats 
>>> from-topics-to-persistence-queue))
>>>(catch Object o
>>>  (slingshot/throw+ {
>>> :type 
>>> ::cycle-resource-usage-report
>>> :error o
>>> }
>>>)
>>>
>>> I think there is an error here, because I see the first (errors/log) but 
>>> typically not anything after that. Can I rely on the fact that this should 
>>> catch anything: 
>>>
>>>(catch Object o
>>>
>>> Because it doesn't seem to work. Instead, the app runs for 8 minutes, 
>>> then prints data about the queues just once, then never again. Assuming an 
>>> error is occuring, why can't I see the error? 
>>>
>>>
>>> {:timestamp "17-10-09 01:27:45", :level :trace, :hostname 
>>> "ip-172-31-4-54", :message ("STARTING")}
>>>
>>> Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new 
>>> driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically 
>>> registered via the SPI and manual loading of the driver class is generally 
>>> unnecessary.
>>>
>>>
>>> {:timestamp "17-10-09 01:28:16", :level :trace, :hostname 
>>> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
>>> (percentage/used/max-heap): (\"67%\" \"2414M\" \"3568M\")\n\nCPU usage 
>>> (how-many-cpu's/load-average):  [4 1.56]\n\nFree memory in jvm: 
>>> [1201758848]")}
>>>
>>>
>>> {:timestamp "17-10-09 01:28:49", :level :trace, :hostname 
>>> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
>>> (percentage/used/max-heap): (\"81%\" \"2900M\" \"3568M\")\n\nCPU usage 
>>> (how-many-cpu's/load-average):  [4 2.64]\n\nFree memory 

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
It's a bit absurd, but at the end of core/main I'm now catching Exceptions, 
Throwable and Object. But this doesn't seem to help me see what is 
happening on background threads.


(defn -main [& args]

  (slingshot/try+

   ;; 2017-10-04 -- see this:
   ;; 
https://stackoverflow.com/questions/28908835/ssl-peer-shut-down-incorrectly-in-java
   (System/setProperty "https.protocols" "TLSv1.1")
   
   (.addShutdownHook (Runtime/getRuntime)
 (Thread.
  #(do (println "addShutdownHook triggered. This app is 
shutting down.")
   (stop

   ;; 2017-07-12 -- stealing code from here:
   ;; https://stuartsierra.com/2015/05/27/clojure-uncaught-exceptions
   ;; Assuming require [clojure.tools.logging :as log]
   (Thread/setDefaultUncaughtExceptionHandler
(reify Thread$UncaughtExceptionHandler
  (uncaughtException [_ thread ex]
(println ex "Uncaught background exception on thread " (.getName 
thread) " Caught by Thread/setDefaultUncaughtExceptionHandler in 
core/main.")
(throw (ex-info "/setDefaultUncaughtExceptionHandler. The app has 
died!")

   (start)
   (catch Exception e
 (println e)
 (stack/parse-exception e)
 (throw (ex-info "The app has died!")))
   (catch Throwable t
 (println t)
 (throw (ex-info "The app has died!")))
   (catch Object o
 (println o)
 (throw (ex-info "The app has died!")


On Sunday, October 8, 2017 at 11:46:26 PM UTC-4, tbc++ wrote:
>
> I don't think you can catch an Object on the JVM can you? What happens if 
> you catch Throwable?
>
> On Sun, Oct 8, 2017 at 9:43 PM, > 
> wrote:
>
>> So, for instance, this says that 10 documents were retried:
>>
>> {"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 389, :retried 
>> 10, :completed 378, :in-progress 1}}
>>
>> The only place that I call retry! is in this catch block (this function 
>> runs in a background thread):
>>
>> (defn advance
>>   [message]
>>   {:pre [
>>  (= (type message) durable_queue.Task)
>>  ]}
>>   (slingshot/try+
>>(doseq [[k v] @message]
>>  (when-not (or
>> (= :how-many-rows-and-fields-from-database k)
>> (= :database-table k)
>> (= :denormalized-id k)
>> (= :topic k))
>>(transform
>> (get @message :denormalized-id :missing-denormalized-id)
>> k
>> v
>> (get @message :topic :missing-topic)
>> (get @message :how-many-rows-and-fields-from-database 
>> :missing-how-many-rows-and-fields-from-database
>>
>>(durable/complete! message)
>>(catch Object o
>>  (durable/retry! message)
>>  (slingshot/throw+ {
>> :type ::advance
>> :error o
>> }
>>
>>
>> So clearly, the code has a problem with some of the documents, and so an 
>> error is thrown, and it is caught by the catch block. I would love to see 
>> the error. I can not. If I put println in the catch block, the message 
>> never shows up in the terminal. Likewise if I use Timbre. 
>>
>> I would love to see the error object. My inability to see the error 
>> objects has crippled my productivity. 
>>
>> Can anyone tell me what I need to do to see these errors? 
>>
>>
>>
>>
>>
>> On Sunday, October 8, 2017 at 11:13:10 PM UTC-4, lawrence...@gmail.com 
>> wrote:
>>
>>> I'm trying to use a Zach Tellman's durable-queue to pass information 
>>> from one part of my app to another. I have 3 queues. I also have a function 
>>> that runs every 30 seconds, that is suppose to report some statistics for 
>>> me: 
>>>
>>>   (fn []
>>> (future
>>>   (slingshot/try+
>>>(errors/log "Resource usage: "
>>>   
>>>  (monitoring/show-stats-regarding-resources-used-by-this-app))
>>>(errors/log "Stats about from-mysql-to-tables-queue: 
>>> " (durable/stats from-mysql-to-tables-queue))
>>>(errors/log "Stats about from-tables-to-topics-queue: 
>>> " (durable/stats from-tables-to-topics-queue))
>>>(errors/log "Stats about the 
>>> from-topics-to-persistence-queue: " (durable/stats 
>>> from-topics-to-persistence-queue))
>>>(catch Object o
>>>  (slingshot/throw+ {
>>> :type 
>>> ::cycle-resource-usage-report
>>> :error o
>>> }
>>>)
>>>
>>> I think there is an error here, because I see the first (errors/log) but 
>>> typically not anything after that. Can I rely on the fact that this should 
>>> catch anything: 
>>>
>>>(catch Object o
>>>
>>> Because it doesn't seem to work. Instead, the app runs for 8 minutes, 
>>> then prints data about the queues just on

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
Possibly this is a complication arising from the use of Slingshot? It would 
take a 2 maybe hours to completely tear Slingshot out of this app, but I 
would do that if I thought I would then be able to see the error messages. 


On Sunday, October 8, 2017 at 11:46:26 PM UTC-4, tbc++ wrote:
>
> I don't think you can catch an Object on the JVM can you? What happens if 
> you catch Throwable?
>
> On Sun, Oct 8, 2017 at 9:43 PM, > 
> wrote:
>
>> So, for instance, this says that 10 documents were retried:
>>
>> {"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 389, :retried 
>> 10, :completed 378, :in-progress 1}}
>>
>> The only place that I call retry! is in this catch block (this function 
>> runs in a background thread):
>>
>> (defn advance
>>   [message]
>>   {:pre [
>>  (= (type message) durable_queue.Task)
>>  ]}
>>   (slingshot/try+
>>(doseq [[k v] @message]
>>  (when-not (or
>> (= :how-many-rows-and-fields-from-database k)
>> (= :database-table k)
>> (= :denormalized-id k)
>> (= :topic k))
>>(transform
>> (get @message :denormalized-id :missing-denormalized-id)
>> k
>> v
>> (get @message :topic :missing-topic)
>> (get @message :how-many-rows-and-fields-from-database 
>> :missing-how-many-rows-and-fields-from-database
>>
>>(durable/complete! message)
>>(catch Object o
>>  (durable/retry! message)
>>  (slingshot/throw+ {
>> :type ::advance
>> :error o
>> }
>>
>>
>> So clearly, the code has a problem with some of the documents, and so an 
>> error is thrown, and it is caught by the catch block. I would love to see 
>> the error. I can not. If I put println in the catch block, the message 
>> never shows up in the terminal. Likewise if I use Timbre. 
>>
>> I would love to see the error object. My inability to see the error 
>> objects has crippled my productivity. 
>>
>> Can anyone tell me what I need to do to see these errors? 
>>
>>
>>
>>
>>
>> On Sunday, October 8, 2017 at 11:13:10 PM UTC-4, lawrence...@gmail.com 
>> wrote:
>>
>>> I'm trying to use a Zach Tellman's durable-queue to pass information 
>>> from one part of my app to another. I have 3 queues. I also have a function 
>>> that runs every 30 seconds, that is suppose to report some statistics for 
>>> me: 
>>>
>>>   (fn []
>>> (future
>>>   (slingshot/try+
>>>(errors/log "Resource usage: "
>>>   
>>>  (monitoring/show-stats-regarding-resources-used-by-this-app))
>>>(errors/log "Stats about from-mysql-to-tables-queue: 
>>> " (durable/stats from-mysql-to-tables-queue))
>>>(errors/log "Stats about from-tables-to-topics-queue: 
>>> " (durable/stats from-tables-to-topics-queue))
>>>(errors/log "Stats about the 
>>> from-topics-to-persistence-queue: " (durable/stats 
>>> from-topics-to-persistence-queue))
>>>(catch Object o
>>>  (slingshot/throw+ {
>>> :type 
>>> ::cycle-resource-usage-report
>>> :error o
>>> }
>>>)
>>>
>>> I think there is an error here, because I see the first (errors/log) but 
>>> typically not anything after that. Can I rely on the fact that this should 
>>> catch anything: 
>>>
>>>(catch Object o
>>>
>>> Because it doesn't seem to work. Instead, the app runs for 8 minutes, 
>>> then prints data about the queues just once, then never again. Assuming an 
>>> error is occuring, why can't I see the error? 
>>>
>>>
>>> {:timestamp "17-10-09 01:27:45", :level :trace, :hostname 
>>> "ip-172-31-4-54", :message ("STARTING")}
>>>
>>> Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new 
>>> driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically 
>>> registered via the SPI and manual loading of the driver class is generally 
>>> unnecessary.
>>>
>>>
>>> {:timestamp "17-10-09 01:28:16", :level :trace, :hostname 
>>> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
>>> (percentage/used/max-heap): (\"67%\" \"2414M\" \"3568M\")\n\nCPU usage 
>>> (how-many-cpu's/load-average):  [4 1.56]\n\nFree memory in jvm: 
>>> [1201758848]")}
>>>
>>>
>>> {:timestamp "17-10-09 01:28:49", :level :trace, :hostname 
>>> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
>>> (percentage/used/max-heap): (\"81%\" \"2900M\" \"3568M\")\n\nCPU usage 
>>> (how-many-cpu's/load-average):  [4 2.64]\n\nFree memory in jvm: 
>>> [699798216]")}
>>>
>>> ;; removing redundant entries
>>>
>>> {:timestamp "17-10-09 01:34:48", :level :trace, :hostname "UnknownHost", 
>>>

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
I just re-wrote much of the code to run on the main thread. And so now I 
can see the error message (which was about a nil value in a place where I 
was certain there would be no nil values). Which is great. But since the 
app does a lot of I/O, I would like to for this app to be multi-threaded. 
But I need to figure out a way that I can see errors that happen in 
background threads. 


On Sunday, October 8, 2017 at 11:46:26 PM UTC-4, tbc++ wrote:
>
> I don't think you can catch an Object on the JVM can you? What happens if 
> you catch Throwable?
>
> On Sun, Oct 8, 2017 at 9:43 PM, > 
> wrote:
>
>> So, for instance, this says that 10 documents were retried:
>>
>> {"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 389, :retried 
>> 10, :completed 378, :in-progress 1}}
>>
>> The only place that I call retry! is in this catch block (this function 
>> runs in a background thread):
>>
>> (defn advance
>>   [message]
>>   {:pre [
>>  (= (type message) durable_queue.Task)
>>  ]}
>>   (slingshot/try+
>>(doseq [[k v] @message]
>>  (when-not (or
>> (= :how-many-rows-and-fields-from-database k)
>> (= :database-table k)
>> (= :denormalized-id k)
>> (= :topic k))
>>(transform
>> (get @message :denormalized-id :missing-denormalized-id)
>> k
>> v
>> (get @message :topic :missing-topic)
>> (get @message :how-many-rows-and-fields-from-database 
>> :missing-how-many-rows-and-fields-from-database
>>
>>(durable/complete! message)
>>(catch Object o
>>  (durable/retry! message)
>>  (slingshot/throw+ {
>> :type ::advance
>> :error o
>> }
>>
>>
>> So clearly, the code has a problem with some of the documents, and so an 
>> error is thrown, and it is caught by the catch block. I would love to see 
>> the error. I can not. If I put println in the catch block, the message 
>> never shows up in the terminal. Likewise if I use Timbre. 
>>
>> I would love to see the error object. My inability to see the error 
>> objects has crippled my productivity. 
>>
>> Can anyone tell me what I need to do to see these errors? 
>>
>>
>>
>>
>>
>> On Sunday, October 8, 2017 at 11:13:10 PM UTC-4, lawrence...@gmail.com 
>> wrote:
>>
>>> I'm trying to use a Zach Tellman's durable-queue to pass information 
>>> from one part of my app to another. I have 3 queues. I also have a function 
>>> that runs every 30 seconds, that is suppose to report some statistics for 
>>> me: 
>>>
>>>   (fn []
>>> (future
>>>   (slingshot/try+
>>>(errors/log "Resource usage: "
>>>   
>>>  (monitoring/show-stats-regarding-resources-used-by-this-app))
>>>(errors/log "Stats about from-mysql-to-tables-queue: 
>>> " (durable/stats from-mysql-to-tables-queue))
>>>(errors/log "Stats about from-tables-to-topics-queue: 
>>> " (durable/stats from-tables-to-topics-queue))
>>>(errors/log "Stats about the 
>>> from-topics-to-persistence-queue: " (durable/stats 
>>> from-topics-to-persistence-queue))
>>>(catch Object o
>>>  (slingshot/throw+ {
>>> :type 
>>> ::cycle-resource-usage-report
>>> :error o
>>> }
>>>)
>>>
>>> I think there is an error here, because I see the first (errors/log) but 
>>> typically not anything after that. Can I rely on the fact that this should 
>>> catch anything: 
>>>
>>>(catch Object o
>>>
>>> Because it doesn't seem to work. Instead, the app runs for 8 minutes, 
>>> then prints data about the queues just once, then never again. Assuming an 
>>> error is occuring, why can't I see the error? 
>>>
>>>
>>> {:timestamp "17-10-09 01:27:45", :level :trace, :hostname 
>>> "ip-172-31-4-54", :message ("STARTING")}
>>>
>>> Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new 
>>> driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically 
>>> registered via the SPI and manual loading of the driver class is generally 
>>> unnecessary.
>>>
>>>
>>> {:timestamp "17-10-09 01:28:16", :level :trace, :hostname 
>>> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
>>> (percentage/used/max-heap): (\"67%\" \"2414M\" \"3568M\")\n\nCPU usage 
>>> (how-many-cpu's/load-average):  [4 1.56]\n\nFree memory in jvm: 
>>> [1201758848]")}
>>>
>>>
>>> {:timestamp "17-10-09 01:28:49", :level :trace, :hostname 
>>> "ip-172-31-4-54", :message ("\n\n\n\n\nResource usage: " "Memory in use 
>>> (percentage/used/max-heap): (\"81%\" \"2900M\" \"3568M\")\n\nCPU usage 
>>> (how-many-cpu's/load-average):  [4 2.64]\n\nFr

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-08 Thread lawrence . krubner
I'm using Cider in Emacs, but the problems I face only occur when I've 
created an uberjar and I try to run the app on the server. In the REPL I 
only work with small amounts of data, whereas on the server I work with a 
few million. Not sure how to get around that as I'm working from my 
apartment and my client has AWS roles set up so that the database can only 
be reached from the server.

I'm fine with writing everything to a log file, if that would catch 
messages from background threads, though I'm curious what setups others 
use? I'm a bit surprised I can't get Timbre to work the way I want to, 
though I have not put much effort into configuring it to write to a log 
file. In the past I've been happy to have it write to stdout and then (in 
production) Supervisord would take the stdout and write it to a log file. 

I'm curious what others do for logging? 


On Monday, October 9, 2017 at 12:31:16 AM UTC-4, tbc++ wrote:
>
> What REPL are you using? A rather nasty side-effect of NRepl is that it 
> tends to send messages from non-main-threads to weird places. 
>
> On Sun, Oct 8, 2017 at 10:29 PM, > 
> wrote:
>
>> I just re-wrote much of the code to run on the main thread. And so now I 
>> can see the error message (which was about a nil value in a place where I 
>> was certain there would be no nil values). Which is great. But since the 
>> app does a lot of I/O, I would like to for this app to be multi-threaded. 
>> But I need to figure out a way that I can see errors that happen in 
>> background threads. 
>>
>>
>> On Sunday, October 8, 2017 at 11:46:26 PM UTC-4, tbc++ wrote:
>>>
>>> I don't think you can catch an Object on the JVM can you? What happens 
>>> if you catch Throwable?
>>>
>>> On Sun, Oct 8, 2017 at 9:43 PM,  wrote:
>>>
 So, for instance, this says that 10 documents were retried:

 {"message" {:num-slabs 1, :num-active-slabs 1, :enqueued 389, :retried 
 10, :completed 378, :in-progress 1}}

 The only place that I call retry! is in this catch block (this function 
 runs in a background thread):

 (defn advance
   [message]
   {:pre [
  (= (type message) durable_queue.Task)
  ]}
   (slingshot/try+
(doseq [[k v] @message]
  (when-not (or
 (= :how-many-rows-and-fields-from-database k)
 (= :database-table k)
 (= :denormalized-id k)
 (= :topic k))
(transform
 (get @message :denormalized-id :missing-denormalized-id)
 k
 v
 (get @message :topic :missing-topic)
 (get @message :how-many-rows-and-fields-from-database 
 :missing-how-many-rows-and-fields-from-database

(durable/complete! message)
(catch Object o
  (durable/retry! message)
  (slingshot/throw+ {
 :type ::advance
 :error o
 }


 So clearly, the code has a problem with some of the documents, and so 
 an error is thrown, and it is caught by the catch block. I would love to 
 see the error. I can not. If I put println in the catch block, the message 
 never shows up in the terminal. Likewise if I use Timbre. 

 I would love to see the error object. My inability to see the error 
 objects has crippled my productivity. 

 Can anyone tell me what I need to do to see these errors? 





 On Sunday, October 8, 2017 at 11:13:10 PM UTC-4, lawrence...@gmail.com 
 wrote:

> I'm trying to use a Zach Tellman's durable-queue to pass information 
> from one part of my app to another. I have 3 queues. I also have a 
> function 
> that runs every 30 seconds, that is suppose to report some statistics for 
> me: 
>
>   (fn []
> (future
>   (slingshot/try+
>(errors/log "Resource usage: "
>   
>  (monitoring/show-stats-regarding-resources-used-by-this-app))
>(errors/log "Stats about 
> from-mysql-to-tables-queue: " (durable/stats from-mysql-to-tables-queue))
>(errors/log "Stats about 
> from-tables-to-topics-queue: " (durable/stats 
> from-tables-to-topics-queue))
>(errors/log "Stats about the 
> from-topics-to-persistence-queue: " (durable/stats 
> from-topics-to-persistence-queue))
>(catch Object o
>  (slingshot/throw+ {
> :type 
> ::cycle-resource-usage-report
> :error o
> }
>)
>
> I think there is an error here, because I see

Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-09 Thread lawrence . krubner
Kumar,

Just so you know, on this page:

https://github.com/cambium-clojure/cambium.logback.core

you link to here:

https://cambium-clojure.github.io/

but I get a 404 when I go there. 



On Monday, October 9, 2017 at 2:56:24 AM UTC-4, Shantanu Kumar wrote:
>
>
>>
>> I'm curious what others do for logging? 
>>
>
> At Concur we using Cambium https://github.com/kumarshantanu/cambium 
> that's being moved (WIP) here: https://github.com/cambium-clojure
>
> Cambium wraps SLF4j and gives a Clojure API (which extends tools.logging) 
> to use it's MDC feature.
>
>
> Shantanu
>
>>

-- 
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: Can slingshot/try+ and then catch Object really catch any error?

2017-10-09 Thread lawrence . krubner
Shantanu Kumar, thanks for that, I might try it. I assume you've never had 
the problem I'm talking about, of messages on background threads that 
disappear?


On Monday, October 9, 2017 at 2:56:24 AM UTC-4, Shantanu Kumar wrote:
>
>
>>
>> I'm curious what others do for logging? 
>>
>
> At Concur we using Cambium https://github.com/kumarshantanu/cambium 
> that's being moved (WIP) here: https://github.com/cambium-clojure
>
> Cambium wraps SLF4j and gives a Clojure API (which extends tools.logging) 
> to use it's MDC feature.
>
>
> Shantanu
>
>>

-- 
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: Can slingshot/try+ and then catch Object really catch any error?

2017-10-09 Thread lawrence . krubner
MatchingSocks, thanks for that. I think the pattern I followed everywhere 
was:

(future
  (slingshot/try+
 ;;; some code
(catch Object o
   (println o

So I think I do catch everything inside of each future that I launch. But I 
will check again. Perhaps I missed one somewhere.


On Monday, October 9, 2017 at 8:12:33 AM UTC-4, Matching Socks wrote:
>
> The linked page 
> https://stuartsierra.com/2015/05/27/clojure-uncaught-exceptions also says 
> "Another wrinkle: exceptions inside a future are always caught by the 
> Future. The exception will not be thrown until something calls Future.get 
> (deref in Clojure)."  So you would need to review the pattern of "(try 
> (future (catch (throw".
>

-- 
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: Can slingshot/try+ and then catch Object really catch any error?

2017-10-09 Thread lawrence . krubner
Gary Verhaegen, thanks for that. The idea of buffers and threads dying is a 
good one and gives me something to look for. 


On Monday, October 9, 2017 at 2:23:05 PM UTC-4, lawrence...@gmail.com wrote:
>
> MatchingSocks, thanks for that. I think the pattern I followed everywhere 
> was:
>
> (future
>   (slingshot/try+
>  ;;; some code
> (catch Object o
>(println o
>
> So I think I do catch everything inside of each future that I launch. But 
> I will check again. Perhaps I missed one somewhere.
>
>
> On Monday, October 9, 2017 at 8:12:33 AM UTC-4, Matching Socks wrote:
>>
>> The linked page 
>> https://stuartsierra.com/2015/05/27/clojure-uncaught-exceptions also 
>> says "Another wrinkle: exceptions inside a future are always caught by the 
>> Future. The exception will not be thrown until something calls Future.get 
>> (deref in Clojure)."  So you would need to review the pattern of "(try 
>> (future (catch (throw".
>>
>

-- 
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: Can slingshot/try+ and then catch Object really catch any error?

2017-10-09 Thread lawrence . krubner
Sean Corfield, thank you, that is a great tip.


On Monday, October 9, 2017 at 2:59:35 PM UTC-4, Sean Corfield wrote:
>
> Timbre has a logged-future macro that you can use instead of future so 
> that exceptions are automatically logged.
>
>  
>
> Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood
>
>  
> --
> *From:* clo...@googlegroups.com   > on behalf of lawrence...@gmail.com  <
> lawrence...@gmail.com >
> *Sent:* Monday, October 9, 2017 11:23:05 AM
> *To:* Clojure
> *Subject:* Re: Can slingshot/try+ and then catch Object really catch any 
> error? 
>  
> MatchingSocks, thanks for that. I think the pattern I followed everywhere 
> was: 
>
> (future
>   (slingshot/try+
>  ;;; some code
> (catch Object o
>(println o
>
> So I think I do catch everything inside of each future that I launch. But 
> I will check again. Perhaps I missed one somewhere.
>
>
> On Monday, October 9, 2017 at 8:12:33 AM UTC-4, Matching Socks wrote: 
>>
>> The linked page 
>> https://stuartsierra.com/2015/05/27/clojure-uncaught-exceptions also 
>> says "Another wrinkle: exceptions inside a future are always caught by the 
>> Future. The exception will not be thrown until something calls Future.get 
>> (deref in Clojure)."  So you would need to review the pattern of "(try 
>> (future (catch (throw".
>>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com 
> Note that posts from new members are moderated - please be patient with 
> your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+u...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Can slingshot/try+ and then catch Object really catch any error?

2017-10-09 Thread lawrence . krubner
I figured a common reason for error messages to disappear is when there is 
another Exception inside of the catch block, so the catch block itself dies 
without doing anything. 

I had copy-and-pasted this from somewhere, without looking at it much:

   (catch Exception e
 (println e)
 (stack/parse-exception e)
 (throw (ex-info "The app has died!")))

It took me awhile before I saw this: 

:type clojure.lang.ArityException
   :message Wrong number of args (1) passed to: core/ex-info
   :at [clojure.lang.AFn throwArity AFn.java 429]}]

Looking here reveals that there is no one argument version of ex-info:

https://clojuredocs.org/clojure.core/ex-info

My fault, obviously, for being careless when mixing different kinds of 
error reporting. 


On Monday, October 9, 2017 at 2:59:35 PM UTC-4, Sean Corfield wrote:
>
> Timbre has a logged-future macro that you can use instead of future so 
> that exceptions are automatically logged.
>
>  
>
> Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood
>
>  
> --
> *From:* clo...@googlegroups.com   > on behalf of lawrence...@gmail.com  <
> lawrence...@gmail.com >
> *Sent:* Monday, October 9, 2017 11:23:05 AM
> *To:* Clojure
> *Subject:* Re: Can slingshot/try+ and then catch Object really catch any 
> error? 
>  
> MatchingSocks, thanks for that. I think the pattern I followed everywhere 
> was: 
>
> (future
>   (slingshot/try+
>  ;;; some code
> (catch Object o
>(println o
>
> So I think I do catch everything inside of each future that I launch. But 
> I will check again. Perhaps I missed one somewhere.
>
>
> On Monday, October 9, 2017 at 8:12:33 AM UTC-4, Matching Socks wrote: 
>>
>> The linked page 
>> https://stuartsierra.com/2015/05/27/clojure-uncaught-exceptions also 
>> says "Another wrinkle: exceptions inside a future are always caught by the 
>> Future. The exception will not be thrown until something calls Future.get 
>> (deref in Clojure)."  So you would need to review the pattern of "(try 
>> (future (catch (throw".
>>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com 
> Note that posts from new members are moderated - please be patient with 
> your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+u...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>

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


Does (into) ever combine 2 numbers into 1?

2017-10-11 Thread lawrence . krubner
I seem unable to figure out where I made a mistake, though this should be 
simple.

I have two SQL calls that bring back 5 fields:

 SELECT company_profile_id ,  reference_id,  reference_source   FROM   
company_reference_idlimit 1  ;

++--+--+
| company_profile_id | reference_id | reference_source |
++--+--+
|  2 | 331089191| EIN  |
++--+--+

 SELECT company_profile_id, urlFROM company_website limit 1 
  ;

++--+
| company_profile_id | url  |
++--+
|  2 | mikeshawauto.com |
++--+

This brings back a total of 5 values. I need to have a document that has 5 
values, though if values have the same field-name, then I want to 
consolidate them into one vector. There are 4 unique field names, so I 
expect to end up with 4 vectors, holding 5 values. Instead, I get this: 

({:company_profile_id ["2"], :topic :company, 
:how-many-rows-and-fields-from-database 13, :url ["mikeshawauto.com"], 
:reference_id ["331089191"], :reference_source ["ein"]})

I expect: 

{:company_profile_id ["2" "2"]

but I get: 

{:company_profile_id ["2"]

The documents are combined in a map in an atom, with this function: 


(def documents (atom {}))


(defn update-documents
  [denormalized-id field-name field-value 
how-many-rows-and-fields-from-database topic]
  {:pre [
 (not (nil? denormalized-id))
 (not (nil? field-name))
 (vector? field-value)
 ]}
  (swap! documents
 (fn [old-documents]
   (slingshot/try+
(let [
  document (get old-documents denormalized-id {})
  old-field-value (get old-documents field-name [])
  new-field-value (into old-field-value field-value)
  document (assoc document field-name new-field-value)

  previous-how-many-rows-and-fields-from-database (get 
document :how-many-rows-and-fields-from-database 0)
  new-how-many-rows-and-fields-from-database (+ 
previous-how-many-rows-and-fields-from-database 
how-many-rows-and-fields-from-database)
  document (assoc document :topic topic)
  document (assoc document 
:how-many-rows-and-fields-from-database 
new-how-many-rows-and-fields-from-database)
  new-documents (assoc old-documents denormalized-id 
document)
  ]
  new-documents)
(catch Object o
  (errors/log o) 
  (slingshot/throw+ {
 :type ::update-documents
 :error o
 }
))

Can I assume that this always gives me 2 values in a vector? 

  old-field-value (get old-documents field-name [])
  new-field-value (into old-field-value field-value)
  document (assoc document field-name new-field-value)

I'm going to guess that the bug is somewhere else in my code. But if anyone 
sees a flaw in this function, I'd be grateful if you could point it out to 
me. 



-- 
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: Does (into) ever combine 2 numbers into 1?

2017-10-11 Thread lawrence . krubner
Nevermind. Something about my reasoning is off on this one. I notice that 
even if I use conj, the same problem happens, I get 4 values in 4 vectors 
instead of 5 values in 4 vectors. So there must be some earlier step that 
I've gotten wrong. 


On Wednesday, October 11, 2017 at 11:44:40 AM UTC-4, lawrence...@gmail.com 
wrote:
>
> I seem unable to figure out where I made a mistake, though this should be 
> simple.
>
> I have two SQL calls that bring back 5 fields:
>
>  SELECT company_profile_id ,  reference_id,  reference_source   FROM   
> company_reference_idlimit 1  ;
>
> ++--+--+
> | company_profile_id | reference_id | reference_source |
> ++--+--+
> |  2 | 331089191| EIN  |
> ++--+--+
>
>  SELECT company_profile_id, urlFROM company_website limit 
> 1   ;
>
> ++--+
> | company_profile_id | url  |
> ++--+
> |  2 | mikeshawauto.com |
> ++--+
>
> This brings back a total of 5 values. I need to have a document that has 5 
> values, though if values have the same field-name, then I want to 
> consolidate them into one vector. There are 4 unique field names, so I 
> expect to end up with 4 vectors, holding 5 values. Instead, I get this: 
>
> ({:company_profile_id ["2"], :topic :company, 
> :how-many-rows-and-fields-from-database 13, :url ["mikeshawauto.com"], 
> :reference_id ["331089191"], :reference_source ["ein"]})
>
> I expect: 
>
> {:company_profile_id ["2" "2"]
>
> but I get: 
>
> {:company_profile_id ["2"]
>
> The documents are combined in a map in an atom, with this function: 
>
>
> (def documents (atom {}))
>
>
> (defn update-documents
>   [denormalized-id field-name field-value 
> how-many-rows-and-fields-from-database topic]
>   {:pre [
>  (not (nil? denormalized-id))
>  (not (nil? field-name))
>  (vector? field-value)
>  ]}
>   (swap! documents
>  (fn [old-documents]
>(slingshot/try+
> (let [
>   document (get old-documents denormalized-id {})
>   old-field-value (get old-documents field-name [])
>   new-field-value (into old-field-value field-value)
>   document (assoc document field-name new-field-value)
>
>   previous-how-many-rows-and-fields-from-database (get 
> document :how-many-rows-and-fields-from-database 0)
>   new-how-many-rows-and-fields-from-database (+ 
> previous-how-many-rows-and-fields-from-database 
> how-many-rows-and-fields-from-database)
>   document (assoc document :topic topic)
>   document (assoc document 
> :how-many-rows-and-fields-from-database 
> new-how-many-rows-and-fields-from-database)
>   new-documents (assoc old-documents denormalized-id 
> document)
>   ]
>   new-documents)
> (catch Object o
>   (errors/log o) 
>   (slingshot/throw+ {
>  :type ::update-documents
>  :error o
>  }
> ))
>
> Can I assume that this always gives me 2 values in a vector? 
>
>   old-field-value (get old-documents field-name [])
>   new-field-value (into old-field-value field-value)
>   document (assoc document field-name new-field-value)
>
> I'm going to guess that the bug is somewhere else in my code. But if 
> anyone sees a flaw in this function, I'd be grateful if you could point it 
> out to me. 
>
>
>
>

-- 
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: Does (into) ever combine 2 numbers into 1?

2017-10-11 Thread lawrence . krubner
Using conj instead of into, for no particular reason, except debugging. The 
document is slowly built-up: 

({:company_profile_id [["2"]], :topic :company, :url 
[["mikeshawauto.com"]]})

({:company_profile_id [["2"]], :topic :company, :url 
[["mikeshawauto.com"]]})

({:company_profile_id [["2"]], :topic :company, :url 
[["mikeshawauto.com"]], :reference_id [["331089191"]]})

In the transition from row 1 to row 2, I assume the field being added is 
company_profile_id. Why is there no change? Why isn't a new value added to 
the vector? I must be missing something obvious. 







On Wednesday, October 11, 2017 at 11:44:40 AM UTC-4, lawrence...@gmail.com 
wrote:
>
> I seem unable to figure out where I made a mistake, though this should be 
> simple.
>
> I have two SQL calls that bring back 5 fields:
>
>  SELECT company_profile_id ,  reference_id,  reference_source   FROM   
> company_reference_idlimit 1  ;
>
> ++--+--+
> | company_profile_id | reference_id | reference_source |
> ++--+--+
> |  2 | 331089191| EIN  |
> ++--+--+
>
>  SELECT company_profile_id, urlFROM company_website limit 
> 1   ;
>
> ++--+
> | company_profile_id | url  |
> ++--+
> |  2 | mikeshawauto.com |
> ++--+
>
> This brings back a total of 5 values. I need to have a document that has 5 
> values, though if values have the same field-name, then I want to 
> consolidate them into one vector. There are 4 unique field names, so I 
> expect to end up with 4 vectors, holding 5 values. Instead, I get this: 
>
> ({:company_profile_id ["2"], :topic :company, 
> :how-many-rows-and-fields-from-database 13, :url ["mikeshawauto.com"], 
> :reference_id ["331089191"], :reference_source ["ein"]})
>
> I expect: 
>
> {:company_profile_id ["2" "2"]
>
> but I get: 
>
> {:company_profile_id ["2"]
>
> The documents are combined in a map in an atom, with this function: 
>
>
> (def documents (atom {}))
>
>
> (defn update-documents
>   [denormalized-id field-name field-value 
> how-many-rows-and-fields-from-database topic]
>   {:pre [
>  (not (nil? denormalized-id))
>  (not (nil? field-name))
>  (vector? field-value)
>  ]}
>   (swap! documents
>  (fn [old-documents]
>(slingshot/try+
> (let [
>   document (get old-documents denormalized-id {})
>   old-field-value (get old-documents field-name [])
>   new-field-value (into old-field-value field-value)
>   document (assoc document field-name new-field-value)
>
>   previous-how-many-rows-and-fields-from-database (get 
> document :how-many-rows-and-fields-from-database 0)
>   new-how-many-rows-and-fields-from-database (+ 
> previous-how-many-rows-and-fields-from-database 
> how-many-rows-and-fields-from-database)
>   document (assoc document :topic topic)
>   document (assoc document 
> :how-many-rows-and-fields-from-database 
> new-how-many-rows-and-fields-from-database)
>   new-documents (assoc old-documents denormalized-id 
> document)
>   ]
>   new-documents)
> (catch Object o
>   (errors/log o) 
>   (slingshot/throw+ {
>  :type ::update-documents
>  :error o
>  }
> ))
>
> Can I assume that this always gives me 2 values in a vector? 
>
>   old-field-value (get old-documents field-name [])
>   new-field-value (into old-field-value field-value)
>   document (assoc document field-name new-field-value)
>
> I'm going to guess that the bug is somewhere else in my code. But if 
> anyone sees a flaw in this function, I'd be grateful if you could point it 
> out to me. 
>
>
>
>

-- 
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: Does (into) ever combine 2 numbers into 1?

2017-10-11 Thread lawrence . krubner
So I have this: 

({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]})

And then I get this field name and value: 

(:company_profile_id)

(["2"])

The next 3 lines of code are: 

  old-field-value (get old-documents field-name [])
  new-field-value (into old-field-value field-value)
  document (assoc document field-name new-field-value)

And when the function is next called, I end up with :

({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]})

I need: 

({:company_profile_id ["2", "2"], :topic :company, :url 
["mikeshawauto.com"]})

So perhaps I've misunderstood what (into) is for? How do I add another the 
values of these 2 vectors together? 





On Wednesday, October 11, 2017 at 12:20:55 PM UTC-4, lawrence...@gmail.com 
wrote:
>
> Using conj instead of into, for no particular reason, except debugging. 
> The document is slowly built-up: 
>
> ({:company_profile_id [["2"]], :topic :company, :url [["mikeshawauto.com
> "]]})
>
> ({:company_profile_id [["2"]], :topic :company, :url [["mikeshawauto.com
> "]]})
>
> ({:company_profile_id [["2"]], :topic :company, :url [["mikeshawauto.com"]], 
> :reference_id [["331089191"]]})
>
> In the transition from row 1 to row 2, I assume the field being added is 
> company_profile_id. Why is there no change? Why isn't a new value added to 
> the vector? I must be missing something obvious. 
>
>
>
>
>
>
>
> On Wednesday, October 11, 2017 at 11:44:40 AM UTC-4, lawrence...@gmail.com 
> wrote:
>>
>> I seem unable to figure out where I made a mistake, though this should be 
>> simple.
>>
>> I have two SQL calls that bring back 5 fields:
>>
>>  SELECT company_profile_id ,  reference_id,  reference_source   FROM   
>> company_reference_idlimit 1  ;
>>
>> ++--+--+
>> | company_profile_id | reference_id | reference_source |
>> ++--+--+
>> |  2 | 331089191| EIN  |
>> ++--+--+
>>
>>  SELECT company_profile_id, urlFROM company_website limit 
>> 1   ;
>>
>> ++--+
>> | company_profile_id | url  |
>> ++--+
>> |  2 | mikeshawauto.com |
>> ++--+
>>
>> This brings back a total of 5 values. I need to have a document that has 
>> 5 values, though if values have the same field-name, then I want to 
>> consolidate them into one vector. There are 4 unique field names, so I 
>> expect to end up with 4 vectors, holding 5 values. Instead, I get this: 
>>
>> ({:company_profile_id ["2"], :topic :company, 
>> :how-many-rows-and-fields-from-database 13, :url ["mikeshawauto.com"], 
>> :reference_id ["331089191"], :reference_source ["ein"]})
>>
>> I expect: 
>>
>> {:company_profile_id ["2" "2"]
>>
>> but I get: 
>>
>> {:company_profile_id ["2"]
>>
>> The documents are combined in a map in an atom, with this function: 
>>
>>
>> (def documents (atom {}))
>>
>>
>> (defn update-documents
>>   [denormalized-id field-name field-value 
>> how-many-rows-and-fields-from-database topic]
>>   {:pre [
>>  (not (nil? denormalized-id))
>>  (not (nil? field-name))
>>  (vector? field-value)
>>  ]}
>>   (swap! documents
>>  (fn [old-documents]
>>(slingshot/try+
>> (let [
>>   document (get old-documents denormalized-id {})
>>   old-field-value (get old-documents field-name [])
>>   new-field-value (into old-field-value field-value)
>>   document (assoc document field-name new-field-value)
>>
>>   previous-how-many-rows-and-fields-from-database (get 
>> document :how-many-rows-and-fields-from-database 0)
>>   new-how-many-rows-and-fields-from-database (+ 
>> previous-how-many-rows-and-fields-from-database 
>> how-many-rows-and-fields-from-database)
>>   document (assoc document :topic topic)
>>   document (assoc document 
>> :how-many-rows-and-fields-from-database 
>> new-how-many-rows-and-fields-from-database)
>>   new-documents (assoc old-documents denormalized-id 
>> document)
>>   ]
>>   new-documents)
>> (catch Object o
>>   (errors/log o) 
>>   (slingshot/throw+ {
>>  :type ::update-documents
>>  :error o
>>  }
>> ))
>>
>> Can I assume that this always gives me 2 values in a vector? 
>>
>>   old-field-value (get old-documents field-name [])
>>   new-field-value (into old-field-value field-value)
>>   document (assoc document field-name new-field-value)
>>

Re: Does (into) ever combine 2 numbers into 1?

2017-10-11 Thread lawrence . krubner
So I tried this:

  new-field-value (into [] (concat old-field-value 
field-value))

And I did not get what I expected. Maybe I am sleep deprived, but I don't 
see why I can't build up a vector with several values. This is in a map in 
an atom. This is the code: 

  (swap! documents
 (fn [old-documents]
(let [
  document (get old-documents denormalized-id {})

  _ (errors/log document)
  _ (errors/log field-name)
  _ (errors/log field-value)

  old-field-value (get old-documents field-name [])
  new-field-value (into [] (concat old-field-value 
field-value))
  document (assoc document field-name new-field-value)

  _ (errors/log "final document: " document)
  new-documents (assoc old-documents denormalized-id 
document)
  ]  
  new-documents)

Those log statements show me this for old-field-value:

({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]})

field-name: 
(:company_profile_id)

field-value:
(["2"])

but I in the final document I only get: 

("final document: " {:company_profile_id ["2"], :topic :company, :url 
["mikeshawauto.com"]})

I want: 

("final document: " {:company_profile_id ["2", "2"], :topic :company, :url 
["mikeshawauto.com"]})

What am I missing here? 




On Wednesday, October 11, 2017 at 12:28:59 PM UTC-4, lawrence...@gmail.com 
wrote:
>
> So I have this: 
>
> ({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]})
>
> And then I get this field name and value: 
>
> (:company_profile_id)
>
> (["2"])
>
> The next 3 lines of code are: 
>
>   old-field-value (get old-documents field-name [])
>   new-field-value (into old-field-value field-value)
>   document (assoc document field-name new-field-value)
>
> And when the function is next called, I end up with :
>
> ({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]})
>
> I need: 
>
> ({:company_profile_id ["2", "2"], :topic :company, :url ["mikeshawauto.com
> "]})
>
> So perhaps I've misunderstood what (into) is for? How do I add another the 
> values of these 2 vectors together? 
>
>
>
>
>
> On Wednesday, October 11, 2017 at 12:20:55 PM UTC-4, lawrence...@gmail.com 
> wrote:
>>
>> Using conj instead of into, for no particular reason, except debugging. 
>> The document is slowly built-up: 
>>
>> ({:company_profile_id [["2"]], :topic :company, :url [["mikeshawauto.com
>> "]]})
>>
>> ({:company_profile_id [["2"]], :topic :company, :url [["mikeshawauto.com
>> "]]})
>>
>> ({:company_profile_id [["2"]], :topic :company, :url [["mikeshawauto.com"]], 
>> :reference_id [["331089191"]]})
>>
>> In the transition from row 1 to row 2, I assume the field being added is 
>> company_profile_id. Why is there no change? Why isn't a new value added to 
>> the vector? I must be missing something obvious. 
>>
>>
>>
>>
>>
>>
>>
>> On Wednesday, October 11, 2017 at 11:44:40 AM UTC-4, 
>> lawrence...@gmail.com wrote:
>>>
>>> I seem unable to figure out where I made a mistake, though this should 
>>> be simple.
>>>
>>> I have two SQL calls that bring back 5 fields:
>>>
>>>  SELECT company_profile_id ,  reference_id,  reference_source   FROM   
>>> company_reference_idlimit 1  ;
>>>
>>> ++--+--+
>>> | company_profile_id | reference_id | reference_source |
>>> ++--+--+
>>> |  2 | 331089191| EIN  |
>>> ++--+--+
>>>
>>>  SELECT company_profile_id, urlFROM company_website 
>>> limit 1   ;
>>>
>>> ++--+
>>> | company_profile_id | url  |
>>> ++--+
>>> |  2 | mikeshawauto.com |
>>> ++--+
>>>
>>> This brings back a total of 5 values. I need to have a document that has 
>>> 5 values, though if values have the same field-name, then I want to 
>>> consolidate them into one vector. There are 4 unique field names, so I 
>>> expect to end up with 4 vectors, holding 5 values. Instead, I get this: 
>>>
>>> ({:company_profile_id ["2"], :topic :company, 
>>> :how-many-rows-and-fields-from-database 13, :url ["mikeshawauto.com"], 
>>> :reference_id ["331089191"], :reference_source ["ein"]})
>>>
>>> I expect: 
>>>
>>> {:company_profile_id ["2" "2"]
>>>
>>> but I get: 
>>>
>>> {:company_profile_id ["2"]
>>>
>>> The documents are combined in a map in an atom, with this function: 
>>>
>>>
>>> (def documents (atom {}))
>>>
>>>
>>> (defn update-documents
>>>   [denormalized-id field-name field-value 
>>> how-many-rows-and-fields-from-database topic]
>>>   {:pre [
>>>  (not (nil? denormalized-id))
>>>  (not (nil? field-name))

Re: Does (into) ever combine 2 numbers into 1?

2017-10-11 Thread lawrence . krubner
I should remove the parens before they confuse anyone. They are added by 
the log statement. Without the parens:



{:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]}

field-name: 
:company_profile_id

field-value:
["2"]

but I in the final document I only get: 

"final document: " {:company_profile_id ["2"], :topic :company, :url ["
mikeshawauto.com"]}

I want: 

"final document: " {:company_profile_id ["2" "2"], :topic :company, :url ["
mikeshawauto.com"]}



On Wednesday, October 11, 2017 at 1:42:12 PM UTC-4, lawrence...@gmail.com 
wrote:
>
> So I tried this:
>
>   new-field-value (into [] (concat old-field-value 
> field-value))
>
> And I did not get what I expected. Maybe I am sleep deprived, but I don't 
> see why I can't build up a vector with several values. This is in a map in 
> an atom. This is the code: 
>
>   (swap! documents
>  (fn [old-documents]
> (let [
>   document (get old-documents denormalized-id {})
>
>   _ (errors/log document)
>   _ (errors/log field-name)
>   _ (errors/log field-value)
>
>   old-field-value (get old-documents field-name [])
>   new-field-value (into [] (concat old-field-value 
> field-value))
>   document (assoc document field-name new-field-value)
>
>   _ (errors/log "final document: " document)
>   new-documents (assoc old-documents denormalized-id 
> document)
>   ]  
>   new-documents)
>
> Those log statements show me this for old-field-value:
>
> ({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]})
>
> field-name: 
> (:company_profile_id)
>
> field-value:
> (["2"])
>
> but I in the final document I only get: 
>
> ("final document: " {:company_profile_id ["2"], :topic :company, :url ["
> mikeshawauto.com"]})
>
> I want: 
>
> ("final document: " {:company_profile_id ["2", "2"], :topic :company, :url 
> ["mikeshawauto.com"]})
>
> What am I missing here? 
>
>
>
>
> On Wednesday, October 11, 2017 at 12:28:59 PM UTC-4, lawrence...@gmail.com 
> wrote:
>>
>> So I have this: 
>>
>> ({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]})
>>
>> And then I get this field name and value: 
>>
>> (:company_profile_id)
>>
>> (["2"])
>>
>> The next 3 lines of code are: 
>>
>>   old-field-value (get old-documents field-name [])
>>   new-field-value (into old-field-value field-value)
>>   document (assoc document field-name new-field-value)
>>
>> And when the function is next called, I end up with :
>>
>> ({:company_profile_id ["2"], :topic :company, :url ["mikeshawauto.com"]})
>>
>> I need: 
>>
>> ({:company_profile_id ["2", "2"], :topic :company, :url ["
>> mikeshawauto.com"]})
>>
>> So perhaps I've misunderstood what (into) is for? How do I add another 
>> the values of these 2 vectors together? 
>>
>>
>>
>>
>>
>> On Wednesday, October 11, 2017 at 12:20:55 PM UTC-4, 
>> lawrence...@gmail.com wrote:
>>>
>>> Using conj instead of into, for no particular reason, except debugging. 
>>> The document is slowly built-up: 
>>>
>>> ({:company_profile_id [["2"]], :topic :company, :url [["mikeshawauto.com
>>> "]]})
>>>
>>> ({:company_profile_id [["2"]], :topic :company, :url [["mikeshawauto.com
>>> "]]})
>>>
>>> ({:company_profile_id [["2"]], :topic :company, :url 
>>> [["mikeshawauto.com"]], 
>>> :reference_id [["331089191"]]})
>>>
>>> In the transition from row 1 to row 2, I assume the field being added is 
>>> company_profile_id. Why is there no change? Why isn't a new value added to 
>>> the vector? I must be missing something obvious. 
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Wednesday, October 11, 2017 at 11:44:40 AM UTC-4, 
>>> lawrence...@gmail.com wrote:

 I seem unable to figure out where I made a mistake, though this should 
 be simple.

 I have two SQL calls that bring back 5 fields:

  SELECT company_profile_id ,  reference_id,  reference_source   FROM   
 company_reference_idlimit 1  ;

 ++--+--+
 | company_profile_id | reference_id | reference_source |
 ++--+--+
 |  2 | 331089191| EIN  |
 ++--+--+

  SELECT company_profile_id, urlFROM company_website 
 limit 1   ;

 ++--+
 | company_profile_id | url  |
 ++--+
 |  2 | mikeshawauto.com |
 ++--+

 This brings back a total of 5 values. I need to have a document that 
 has 5 values, though if values have the same field-name, then I want to 
 consolidate them into one vector. Ther

  1   2   >