Re: pre-conditions on !

2014-01-22 Thread t x
Consider the following attempt: for some reason, after the assertion fails, the main repl thread seems to lock up Line 1 Line 2 // after this, no more is printed Question: what is causing the problem -- and how do I fix it? Thanks! === code === (ns test (:require #+clj

Re: pre-conditions on !

2014-01-22 Thread t x
With apologies for spamming: in case anyone else wanted a solution to this problem: I believe the right layer is to wrap at the Channel layer, rather than the Buffer layer: for example: (ns test (:require #+clj [clojure.core.async.impl.protocols :as impl] #+cljs

Re: pre-conditions on !

2014-01-22 Thread Jozef Wagner
use filter user= (def c (chan 10)) #'user/c user= (def cf (filter #(if (even? %) % (throw (IllegalArgumentException.))) c)) #'user/cf user= (!! cf 2) nil user= (!! cf 1) IllegalArgumentException user/fn--4294 (form-init9067455327434905636.clj:1) user= (!! cf 4) nil user= (!! cf) 2 user= (!! cf)

Re: core.async question - canceling thread

2014-01-22 Thread Mark Engelberg
So far, this is the only way I've figured out that works: (defn try-fib [n] (let [ch (timeout 1000) th (Thread. #(!! ch (fib n))) _ (.start th) answer (!! ch)] (if answer answer (do (.stop th) nil But there are a couple bazillion sources that say you

Re: core.async question - canceling thread

2014-01-22 Thread Jozef Wagner
You can put the computation into a future, and cancel the future after the timeout. BTW is it idiomatic to write to the timeout channel? I thought one should use something like (alts!! [c (timeout 1000)]). JW On Wednesday, January 22, 2014 11:30:23 AM UTC+1, puzzler wrote: So far, this is

Re: Security implications of code is data/data is code

2014-01-22 Thread mynomoto
Sorry Luc P., you are right. I meant that people wouldn't do that without a good reason, but it was not what I wrote. On Wednesday, January 22, 2014 3:10:27 AM UTC-2, Luc wrote: Your last statement is incomplete. It all depends on trust. We do eval at runtime of code and data w/o edn

(go (loop [ ..] (try ... (catch ..)))) won't compile

2014-01-22 Thread László Török
Hi, I have a processing loop in a go block and I wanted to make sure that the processing continue with the next iteration if an exception is thrown. The following code doesn't seem to be accepted by the go macro: (go (loop [xs (range 10)] (when-let [x (first xs)] (try (println

Re: MyType cannot be cast to MyType?

2014-01-22 Thread Jonathan Barnard
Thank you for that. I've found that the code works correctly if I just copy it into the repl and run it; it's only when I load it in Eclipse (with Counterclockwise) using ctrl-alt-s that it displays the error. Is there some way to reset the repl to a blank state (remove all previous class

Re: (go (loop [ ..] (try ... (catch ..)))) won't compile

2014-01-22 Thread László Török
Sorry, too eager too soon. (loop (try ..) ) obviously doesn't work :) 2014/1/22 László Török ltoro...@gmail.com Hi, I have a processing loop in a go block and I wanted to make sure that the processing continue with the next iteration if an exception is thrown. The following code doesn't

Simple Macros

2014-01-22 Thread Alejandro Ciniglio
Hi, I've been using clojure for a few months now, but I've tried to avoid writing my own macros in production code, because of the general warnings I've heard about misusing their power and the challenges I've run into with debugging them. I was looking through the core.async code, and I

Re: (go (loop [ ..] (try ... (catch ..)))) won't compile

2014-01-22 Thread James Reeves
Just pull the exception out of the loop logic: (go (loop [xs (range 10)] (if-let [x (first xs)] (if (= ::error (try (println x) (catch Throwable t ::error))) (recur (rest x)) - James On 22 January 2014 11:05, László Török ltoro...@gmail.com wrote: Hi, I have a

tools.cli and required arguments

2014-01-22 Thread Alf Kristian Støyle
Hi all! Trying to use clojure.tools.cli to help us parse command line arguments. However we are having trouble understanding how to specify required arguments. The following example taken from the documentation ( https://github.com/clojure/tools.cli#quick-start) should give a required argument

random thought on #_

2014-01-22 Thread Dave Sann
I like #_, it's very useful I had a thought I'd like to have #__ - two _ to comment 2 expressions - specifically for commenting in maps Then I thought #_n where n is an integer - to comment as many as you need. end of my thought. Dave -- -- You received this message because you are

Re: tools.cli and required arguments

2014-01-22 Thread guns
On Wed 22 Jan 2014 at 01:48:22PM +0100, Alf Kristian Støyle wrote: From the documentation it seems that specifying the second part of the long option should be enough to make an argument required. So this minimal example should also produce errors: (def cli-options-simplified [[-p --port

Re: Simple Macros

2014-01-22 Thread guns
On Tue 21 Jan 2014 at 07:33:43PM -0800, Alejandro Ciniglio wrote: I was wondering if people had advice on when to write these sorts of macros vs. when to just use the trivial expansion in the code? (Or alternatively, what am I missing in this macro definition?) (defmacro go-loop Like (go

Re: tools.cli and required arguments

2014-01-22 Thread Alf Kristian Støyle
Thanks! That does explain it :) Would be nice to be able to specify that an option must be specified in every invocation though. I think it would lead to better error messages, e.g. if several mandatory options are forgotten, they will be shown at once. That is a bit of a hassle when doing it

Re: random thought on #_

2014-01-22 Thread Christophe Grand
#_ nests nicely: #_#_ comments out the next two expressions. Christophe On Wed, Jan 22, 2014 at 2:03 PM, Dave Sann daves...@gmail.com wrote: I like #_, it's very useful I had a thought I'd like to have #__ - two _ to comment 2 expressions - specifically for commenting in maps Then I

Re: random thought on #_

2014-01-22 Thread Dave Sann
another little gem. Just what I wanted. It didn't occur to me that it would work this way - but now it seems obvious Thanks Christophe Dave On Thursday, 23 January 2014 00:21:53 UTC+11, Christophe Grand wrote: #_ nests nicely: #_#_ comments out the next two expressions. Christophe

Re: Simple Macros

2014-01-22 Thread Moritz Ulrich
guns writes: On Tue 21 Jan 2014 at 07:33:43PM -0800, Alejandro Ciniglio wrote: I was wondering if people had advice on when to write these sorts of macros vs. when to just use the trivial expansion in the code? (Or alternatively, what am I missing in this macro definition?) (defmacro

Re: tools.cli and required arguments

2014-01-22 Thread Ray Miller
On 22 January 2014 13:21, Alf Kristian Støyle alf.krist...@gmail.com wrote: Thanks! That does explain it :) Would be nice to be able to specify that an option must be specified in every invocation though. I think it would lead to better error messages, e.g. if several mandatory options are

Re: ClojureScript integration with Emacs/Cider ?

2014-01-22 Thread Bozhidar Batsov
Sorry about the late response, Gary. Would you mind taking the discussion over to cider’s issue tracker? (I tend to miss emails, but I don’t miss issues :-) ). The second change seems totally reasonable. I guess ritz’s complete middleware returns the completion candidates in some odd format.

Re: random thought on #_

2014-01-22 Thread Jim - FooBar();
On 22/01/14 13:21, Christophe Grand wrote: #_ nests nicely: #_#_ comments out the next two expressions. Christophe WHAT?!!! I had no idea.I guess you do learn something new every day :) Jim -- -- You received this message because you are subscribed to the Google Groups Clojure group. To

Re: MyType cannot be cast to MyType?

2014-01-22 Thread Mauricio Aldazosa
Take a look at Stuart's tools.namespace ( https://github.com/clojure/tools.namespace), although be wary of the protocol issue as it is something that is pointed out in the warnings section of that project. Mauricio -- -- You received this message because you are subscribed to the Google Groups

Re: tools.cli and required arguments

2014-01-22 Thread guns
On Wed 22 Jan 2014 at 02:21:51PM +0100, Alf Kristian Støyle wrote: Would be nice to be able to specify that an option must be specified in every invocation though. I think it would lead to better error messages, e.g. if several mandatory options are forgotten, they will be shown at once. That

Re: tools.cli and required arguments

2014-01-22 Thread Alf Kristian Støyle
Ok, thanks for the reply guys :) Cheers, Alf On 22 January 2014 16:04, guns s...@sungpae.com wrote: On Wed 22 Jan 2014 at 02:21:51PM +0100, Alf Kristian Støyle wrote: Would be nice to be able to specify that an option must be specified in every invocation though. I think it would lead to

Re: Security implications of code is data/data is code

2014-01-22 Thread Luc Prefontaine
Just joking :) There are a bunch of golden rules that violate on a regular basis for good reasons. With some satisfaction I have to confess. When you have a muti purpose tool in your hands that you can bend to almost any use it's hard to be restrained by taboos :) Luc P. Sorry Luc P.,

Re: avoiding repetition in ns declarations

2014-01-22 Thread Stuart Sierra
There's nothing built in to Clojure that does this, but you can easily define a function in one namespace that calls `require` for your other namespaces. Note that this may reduce readability of your source code if you forget exactly which namespaces that special function loads. -S -- --

Re: avoiding repetition in ns declarations

2014-01-22 Thread Phillip Lord
t x txrev...@gmail.com writes: (ns foo.bar ... ... ... ) There's basically 10 lines of require that I want as part of nearly _every_ ns I declare is there a way to define some soft of alias / abbrevraviation that is used in namespaces at will? For example: ## somewhere, in a

Re: avoiding repetition in ns declarations

2014-01-22 Thread Michał Marczyk
Not addressing the main problem, but require takes multiple libspecs, so you can write (ns foo (:require [foo.bar :as bar] [foo.quux :as quux])) to avoid repeating the keyword, at least. :require in ns expands to a call to require-the-function, so the latter supports multiple

Re: [ANN] clj.jdbc 0.1.0-beta5

2014-01-22 Thread david
Looks nice. Thanks for sharing. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe

Re: core.async question - canceling thread

2014-01-22 Thread Mark Engelberg
On Wed, Jan 22, 2014 at 2:51 AM, Jozef Wagner jozef.wag...@gmail.comwrote: You can put the computation into a future, and cancel the future after the timeout. I experimented with that, but it didn't seem to work. I suspect that canceling a future doesn't really do what I think it should do.

Re: (go (loop [ ..] (try ... (catch ..)))) won't compile

2014-01-22 Thread László Török
hi, that's what I ended up doing :) 2014/1/22 James Reeves ja...@booleanknot.com Just pull the exception out of the loop logic: (go (loop [xs (range 10)] (if-let [x (first xs)] (if (= ::error (try (println x) (catch Throwable t ::error))) (recur (rest x)) - James

Re: core.async question - canceling thread

2014-01-22 Thread Praki Prakash
What is the task doing? If it is in a tight loop, it must check explicitly whether the interrupt flag is set and abort. If it is waiting on some resource, it will receive InterruptedException. Regards, Praki Prakash On Wed, Jan 22, 2014 at 11:20 AM, Mark Engelberg mark.engelb...@gmail.comwrote:

Re: core.async question - canceling thread

2014-01-22 Thread Mark Engelberg
I think the fib example is a good one in the sense that you are dealing with an already function that takes a long time, and isn't written as a loop. But in general, I want to solve the problem for an arbitrary long-running computation, for example, a call into a library that you don't control.

Re: pre-conditions on !

2014-01-22 Thread t x
Jozef: (let [] (def c (async/chan 10)) (def cf (async/filter #(if (even? %) % (assert false)) c)) (async/!! cf 2) (try (async/!! cf 1) (catch Exception e (println caught exception))) ) I believe filter causes

Re: avoiding repetition in ns declarations

2014-01-22 Thread t x
Staurt, Phillip: Correct me if I'm wrong, the main idea recommended is: (1) don't try to do it via (:require ...) inside of (ns ... ) (2) define a function, which calls (require ... ) [i.e. the function, outside of (ns ... )] Thus, the end solution ends up being: magic.cljx (defn

Re: core.async question - canceling thread

2014-01-22 Thread Jozef Wagner
If you want to be able to control an arbitrary long-running function, a safe way is to run it in a separate process. That way you can safely terminate it anytime you want. Of course this opens up a lot of other issues :) On Wed, Jan 22, 2014 at 9:15 PM, Mark Engelberg

Re: pre-conditions on !

2014-01-22 Thread Jozef Wagner
no, in the same thread. your code is wrong, assert never throws an exception. On Wed, Jan 22, 2014 at 9:17 PM, t x txrev...@gmail.com wrote: Jozef: (let [] (def c (async/chan 10)) (def cf (async/filter #(if (even? %) % (assert false))

Re: pre-conditions on !

2014-01-22 Thread t x
Damn it, you're right. :-) (try (async/!! cf 1) (catch Throwable e (println caught exception))) catches it. On Wed, Jan 22, 2014 at 12:30 PM, Jozef Wagner jozef.wag...@gmail.comwrote: no, in the same thread. your code is wrong, assert never throws an exception. On Wed,

Reminder: Clojure/West CFP closes Friday!

2014-01-22 Thread Alex Miller
If you're interested in submitting a talk to Clojure/West in San Francisco, March 24-26, time is running out! CFP: https://cognitect.wufoo.com/forms/clojurewest-2014-call-for-presentations/ Other useful links: Site: http://clojurewest.org Registration:

Re: core.async question - canceling thread

2014-01-22 Thread Mark Engelberg
Is there a convenient way within Clojure to launch a Clojure function or Java call in a separate process as opposed to a separate thread? Only way I know of is to literally shell out to the command prompt and launch a new executable. On Wed, Jan 22, 2014 at 12:19 PM, Jozef Wagner

Re: avoiding repetition in ns declarations

2014-01-22 Thread Stuart Sierra
On Wed, Jan 22, 2014 at 3:19 PM, t x txrev...@gmail.com wrote: (defn load-standard-requires [] (require ... ) (require ... )) ... Can either of you confirm this is the main plan of attack you have suggested? I don't actually *recommend* doing this. But it will work. My

Re: core.async question - canceling thread

2014-01-22 Thread Shantanu Kumar
On Thursday, 23 January 2014 02:37:43 UTC+5:30, puzzler wrote: Is there a convenient way within Clojure to launch a Clojure function or Java call in a separate process as opposed to a separate thread? Only way I know of is to literally shell out to the command prompt and launch a new

Re: core.async question - canceling thread

2014-01-22 Thread Mark Engelberg
So I guess this gets back to my earlier question: when is it safe to terminate a thread? I know that I often hit Ctrl-C in the REPL to terminate a long running function, and I've never really worried about it screwing things up. On Wed, Jan 22, 2014 at 1:29 PM, Shantanu Kumar

Re: core.async question - canceling thread

2014-01-22 Thread Cedric Greevey
It's not safe if the thread is holding any locks. It *may* also leak native resources if the thread is holding those, but native resources held by a heap-allocated Java object are supposed to be cleaned up by the finalizer if the object is GC'd, and I think Thread.stop properly removes that

Re: Profiling, VisualVM random-pause

2014-01-22 Thread John D. Hume
On Tue, Jan 21, 2014 at 1:50 PM, Yves Parès limestr...@gmail.com wrote: 2) All my methods listed in the profiler are suffixed by .invoke. Is it normal or is pathological of something (I haven't aot-compiled anything, I don't know if it may have an impact here), like unnecessary reflection

Re: core.async question - canceling thread

2014-01-22 Thread Jozef Wagner
For processes, there is a https://github.com/Raynes/conch but I haven't used it yet so I don't know how mature it is. On Wed, Jan 22, 2014 at 10:45 PM, Cedric Greevey cgree...@gmail.com wrote: It's not safe if the thread is holding any locks. It *may* also leak native resources if the thread

Re: avoiding repetition in ns declarations

2014-01-22 Thread Cedric Greevey
Maybe there should be a way to export stuff for transitive inclusion: (ns common-includes (:require [foo.core :refer [fooify] :export true]) ...) ... (ns my-ns (:require [common-includes :as c])) (defn bar [x] (c/fooify x 42)) On Wed, Jan 22, 2014 at 4:22 PM, Stuart Sierra

Re: [ANN] Jig

2014-01-22 Thread Joachim De Beule
Very impressive work! I was thinking of letting components not only implement the Lifecycle protocol but also a protocol that defines the functionality of the component. To give a simple example, there could be a jdbc component that establishes a connection on init etc., and which also

Re: core.async question - canceling thread

2014-01-22 Thread Stephen Cagle
I took a stab at it in pure core.async, unfortunately, it does not work; I would be curious if anyone could explain why. (use '[clojure.core.async :only [timeout ! go !! alts!]]) (defn fib [n tmout] (let [res (go (if ( n 2) n (let [r1 (! (fib (- n 1)

Re: [ANN] Jig

2014-01-22 Thread Joachim De Beule
(follow up) I just realized that another approach would be to hold the jdbc connection type implementing the JDBCProtocol in system under [:jdbc-component :db] or something, and then call the clojure.java.jdbc/query like functions on that. Anyway, I would be very happy to hear your comments on

Re: Clojure development laptop battery usage

2014-01-22 Thread John Chijioke
Not true. More RAM, more power. If it hits swap, even more power. That has been my personal observation. On Monday, January 20, 2014 6:53:14 AM UTC+1, g vim wrote: On 20/01/2014 05:43, john walker wrote: The JVM hasn't been receiving the love it deserves lately! Fortunately, percent

cljs error handling

2014-01-22 Thread t x
In clj, I can do something like: (defn exception-error [exception] {:tag :error :object (ex-data exception) :message (.getMessage exception) :stack-trace (= ** (.getStackTrace exception) (filter #(.endsWith (.getFileName %) clj) **)

ANN Langohr 2.3.2 is released

2014-01-22 Thread Michael Klishin
Langohr [1] is a minimalistic, feature complete Clojure client for RabbitMQ. Release notes: http://blog.clojurewerkz.org/blog/2014/01/22/langohr-2-dot-3-2-is-released/ 1. http://clojurerabbitmq.info -- MK http://github.com/michaelklishin http://twitter.com/michaelklishin -- -- You received

core.async over websocket + cljs + clojure

2014-01-22 Thread t x
Hi, I apologize for my vague question. Does anyone have a good example / blog / library for using the core.async abstraction across a websocket. * one side of the channel is in clojure land * other side of the channel is in cljs land * I promise that all messages can be encoded via

Re: core.async over websocket + cljs + clojure

2014-01-22 Thread Sean Corfield
Ah, what good timing! David Pollak's project Plugh does this, essentially as an implementation detail. I spent some time with him today discussing this, as I want to use exactly this functionality in a project I'm building. The plan is for me to create a standalone project, based on the kernel