core.async question - canceling thread

2014-01-21 Thread Mark Engelberg
Consider the really slow fib function: (defn fib [n] (if (< n 2) n (+ (fib (dec n)) (fib (- n 2) Now, let's say I want to compute the fib of some number n and timeout and return nil if it takes longer than a second. (defn try-fib [n] (let [ch (timeout 1000)] (go (>! ch (fib n))) (

Re: pre-conditions on >!

2014-01-21 Thread Kelker Ryan
Can't you just test the value before placing a value in a channel?  22.01.2014, 16:27, "t x" :Hi,## Question:  For a channel, is it possible to put a pre-condition of sorts on a channel?  For example:  (let [chan (async/chan 100)]    (set-pre-condition! chan even?)    (put! chan 1) ;; exception thr

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

2014-01-21 Thread Devin Walters
I would go one step further and say that homoiconicity actually is an improvement. There are a dozen ways to shell out in ruby. The syntax is more complex on a number of fronts. Cleansing user input in Clojure is simpler. Clojure's regularity makes it much simpler to cleanse. In addition: the j

Re: avoiding repetition in ns declarations

2014-01-21 Thread guns
On Tue 21 Jan 2014 at 11:15:50PM -0800, t x wrote: > Hi, > > I have the following problem: > > (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

pre-conditions on >!

2014-01-21 Thread t x
Hi, ## Question: For a channel, is it possible to put a pre-condition of sorts on a channel? For example: (let [chan (async/chan 100)] (set-pre-condition! chan even?) (put! chan 1) ;; exception thrown (>!! chan 3) ;; exception thrown ) ## Asides It's important that I wa

avoiding repetition in ns declarations

2014-01-21 Thread t x
Hi, I have the following problem: (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 magic f

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

2014-01-21 Thread John Wiseman
I don't think homoiconicity is the issue, except in a very indirect way. Note that Common Lisp does have a rather annoying, insecure default that did allow the kind of attack you're talking about: *read-eval* defaults to T , which enables the #. reader macro

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

2014-01-21 Thread Luc Prefontaine
Your last statement is incomplete. It all depends on trust. We do eval at runtime of code and data w/o edn but we know it comes from a secured source. Doing such thing from an unsecured alien source would "potentially" look insane. Lets not presume about the insanity of the designer w/o some dee

Re: Adding query customization to Ring-based REST APIs

2014-01-21 Thread Alexandr Kurilin
That's a great point of reference, thanks for the tip. I'm in the market mostly for bits and pieces that I can stitch onto my project, so something like service-hub-examples is a great way to see how it's used. I haven't used protocols much, your project seems like a pretty good fit for them. On

Re: clojure.java.shell/sh and expand wildcard

2014-01-21 Thread Michael Gardner
Try (sh “bash” “-c” “ls *.txt”). On Jan 21, 2014, at 21:51 , John Gabriele wrote: > I'd like to do something like: > > user=> (require '[clojure.java.shell :as sh]) > user=> (sh/sh "ls" "*.txt") > > but get: > > {:exit 2, :out "", :err "ls: cannot access *.txt: No such file or >

clojure.java.shell/sh and expand wildcard

2014-01-21 Thread John Gabriele
I'd like to do something like: user=> (require '[clojure.java.shell :as sh]) user=> (sh/sh "ls" "*.txt") but get: {:exit 2, :out "", :err "ls: cannot access *.txt: No such file or directory\n"} even though there *are* a few .txt files present. That error message is the same one I'

Re: MyType cannot be cast to MyType?

2014-01-21 Thread Stuart Sierra
Hello Jonathan, In my experience, an error along the lines of "class Foo cannot be cast to Foo" is usually caused by re-evaluating class definitions, either by reloading files or by re-evaluating definitions in your REPL or IDE. Here is a smaller example that demonstrates the problem: (def

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

2014-01-21 Thread Daniel Compton
I've been thinking for a while about what the security implications are for a homoiconic language like Clojure where code is data and data is code. What protections do you have against malicious input being automatically evaluated by the reader? It seems like every user input would be a possible ca

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

2014-01-21 Thread Gary Trakhman
Not every input is through the reader. For instance, Integer.parse takes a string argument and returns a java object. So there's no security problem there, unless it's a problem with the Integer class itself. Another piece of the puzzle, Clojure needs a way to represent objects and code as data.

Re: Nginx-Clojure Let You Deploy Clojure Web App on Nginx Without Any Java Web Server

2014-01-21 Thread Sergey Didenko
I see, thanks. On Tue, Jan 21, 2014 at 4:17 PM, Xfeep Zhang wrote: > > On Tuesday, January 21, 2014 6:25:02 AM UTC+8, Sergey Didenko wrote: >> >> Hi Xfeep, >> >> What are the good ways to handle some heavy Clojure calculations when >> using nginx-clojure? >> > > Do you mean every request will c

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

2014-01-21 Thread mynomoto
Hi Daniel, I'm not an expert in security but AFAIK this is not a problem. Every user input is a string and you chose how to parse it. There is a edn reader that is safe, but you can use specific parsers depending on the input. Of course if you read and eval the string anything could happen, but

Re: The :type key is not printed in metadata.

2014-01-21 Thread eduardoejp
i know it's special, but I don't see why that has to affect printing/serializing. What if I typed a map using :type, then wanted to save it as text somewhere and get it again? After I've read it back, it's no longer typed and whatever code was expecting it no longer works. There's also my part

Profiling, VisualVM & random-pause

2014-01-21 Thread Yves Parès
Hi! I'm trying to profile my Clojure code with VisualVM, and I would have 3 questions: 1) The method that always take an awful amount of time is sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run. This is the profiler itself, right? It has nothing to do with REPL connection (I'm not usin

[ANN] clj.jdbc 0.1.0-beta5

2014-01-21 Thread Andrey Antukh
Alternative jdbc wrapper for Clojure! Released: 2014-01-21 This should be the last beta release. - Query functions (make-query, query and with-query) now accepts prepared statements. - Add ability to extend all behavior between some type is set as parameter to prepared statement and retrieved

Re: core.async count in a channel

2014-01-21 Thread Bob Hutchison
On Jan 21, 2014, at 11:56 AM, Paul Viola wrote: > I think this is all well and good for a particular use of channel. > > So perhaps I am misusing channels?? > > To repeat: in one case I have workers pulling from a channel of real work. > For various reasons this channel might get filled rat

Re: [ANN] Yesql 0.3.0 - Clojure & SQL queries rethought.

2014-01-21 Thread tonihe
This is amazing. Any hope for INSERTs and so on? Currently only possible using postgres RETURNING clause On Tuesday, January 7, 2014 4:57:55 PM UTC+1, Kris Jenkins wrote: > > Yesql is a simple library for blending SQL queries & Clojure together, > cleanly. Here's how it > works

Re: core.async count in a channel

2014-01-21 Thread Jan Herich
Hello Paul, Why not just adjust the number of workers based on actual workload instead of monitoring the source channel for average depth ? Have a look at this codefrom clojure

Re: core.async count in a channel

2014-01-21 Thread Jarrod Swart
I have not used core.async much but I did use Go a fair bit and I concur with what Aaron said. The missing piece for you Paul is that goblocks\channels are not just a way to do concurrent work, but also a control flow mechanism. What Aaron is saying is that by using channels to control various

Re: core.async count in a channel

2014-01-21 Thread Paul Viola
I think this is all well and good for a particular use of channel. So perhaps I am misusing channels?? To repeat: in one case I have workers pulling from a channel of *real work*. For various reasons this channel might get filled rather deeply. In this case I would want to add additional workers

[ANN] mod-lang-clojure (for Vert.x) 1.0.0.Beta1 released

2014-01-21 Thread Toby Crawley
mod-lang-clojure[0] 1.0.0.Beta1 is no available in Maven Central. With this release, the API should be complete, and we hope to get a 1.0.0.Final out in time to be included in bundled language implementation list in Vert.x 2.1.Final (due to be released in the next few weeks). So if you are intere

Re: [Large File Processing] What am I doing wrong?

2014-01-21 Thread Jarrod Swart
Jim, Thanks for the idioms, I appreciate it! And thanks everyone for the help! On Tuesday, January 21, 2014 8:43:40 AM UTC-5, Jim foo.bar wrote: > > On 21/01/14 13:11, Chris Perkins wrote: > > This part: (some #{hashed} already-seen) is doing a linear lookup in > > `already-seen`. Try (contain

Re: [Large File Processing] What am I doing wrong?

2014-01-21 Thread Jarrod Swart
Chris, Thanks this was in fact it. I had read that sets had a near O[1] lookup, but apparently I was not achieving this properly with (some). Thank you the execution time is about 25x faster now! Jarrod On Tuesday, January 21, 2014 8:11:09 AM UTC-5, Chris Perkins wrote: > > On Monday, Januar

Re: [ANN] play-clj, a game library

2014-01-21 Thread James Trunk
> Do you mean *playjure*? No, I did mean *playure* (pronounced player), though after re-reading my post I understand the confusion. And considering that the current *play-clj* name isn't at all confusing, it's probably a good reason to stick with it! :-) Cheers, James On Tuesday, January 21, 2

Re: [ANN] play-clj, a game library

2014-01-21 Thread fmjrey
On 21/01/14 09:50, James Trunk wrote: I like the conciseness of the project name, but I worry that it doesn't roll off the tongue all that well. I guess that /jure/ library names are considered passé by most, but in this case I actually thought that the name /playure/ seemed like a nice fit. I

Re: Nginx-Clojure Let You Deploy Clojure Web App on Nginx Without Any Java Web Server

2014-01-21 Thread Xfeep Zhang
On Tuesday, January 21, 2014 6:25:02 AM UTC+8, Sergey Didenko wrote: > > Hi Xfeep, > > What are the good ways to handle some heavy Clojure calculations when > using nginx-clojure? > Do you mean every request will cost too much time ? If time cost is mainly caused by IO blocking, java thread p

Re: [Large File Processing] What am I doing wrong?

2014-01-21 Thread Michael Gardner
On Jan 21, 2014, at 07:11 , Chris Perkins wrote: > This part: (some #{hashed} already-seen) is doing a linear lookup in > `already-seen`. Try (contains? already-seen hashed) instead. Or just (already-seen hashed), given that OP's not trying to store nil hashes. To OP: note that if you’re stori

Re: [Large File Processing] What am I doing wrong?

2014-01-21 Thread Jim - FooBar();
On 21/01/14 13:11, Chris Perkins wrote: This part: (some #{hashed} already-seen) is doing a linear lookup in `already-seen`. Try (contains? already-seen hashed) instead. +1 to that as it will become faster... I would also add the following not so related to performance: (drop1 (line-seqf)) =

Re: core.async count in a channel

2014-01-21 Thread Aaron France
On 21/01/14 14:09, Moritz Ulrich wrote: On Tue, Jan 21, 2014 at 9:43 AM, Aaron France wrote: Since channels yield nil when they are devoid of items, surely this is enough to know when the channel is empty? That's not correct. Take-Operations block on empty channels. They yield nil when they'r

Re: [Large File Processing] What am I doing wrong?

2014-01-21 Thread Chris Perkins
On Monday, January 20, 2014 11:55:00 PM UTC-7, Jarrod Swart wrote: > > I'm processing a large csv with Clojure, honestly not even that big (~18k > rows, 11mb). I have a list of exported data from a client and I am > de-duplicating URLs within the list. My final output is a series of > vectors:

Re: core.async count in a channel

2014-01-21 Thread Moritz Ulrich
On Tue, Jan 21, 2014 at 9:43 AM, Aaron France wrote: > Since channels yield nil when they are devoid of items, surely this is enough > to know when the channel is empty? That's not correct. Take-Operations block on empty channels. They yield nil when they're closed. You could add a timeout to th

Re: Best way to loop a map of maps

2014-01-21 Thread Ryan
Thank you for your input Thomas. All replies have definitely been very useful :) Cheers, Ryan On Tuesday, December 10, 2013 1:57:38 PM UTC+2, Thomas Heller wrote: > > Oh nvm, just saw that it was suggested before. > > But maybe this is new: > > (def m > {"outerKeyA" {:innerKeyA {"string id" {

Re: core.async count in a channel

2014-01-21 Thread Aaron France
Hi, Whilst I am pretty new to clojure. I am not to Go. The counting of items in a channel is usually regarded as an error and a race condition causing idea. Since channels yield nil when they are devoid of items, surely this is enough to know when the channel is empty? Aaron -- -- You recei

Re: [ANN] play-clj, a game library

2014-01-21 Thread James Trunk
Thanks for all your hard work on this - it looks awesome, and I can't wait to play around with it! I like the conciseness of the project name, but I worry that it doesn't roll off the tongue all that well. I guess that *jure* library names are considered passé by most, but in this case I actual

Re: let bindings

2014-01-21 Thread Andy Smith
Excellent post, thank you for that. -- -- 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 unsubscr

Re: [Large File Processing] What am I doing wrong?

2014-01-21 Thread Rudi Engelbrecht
Hi Jarrod I have had success with the clojure-csv [1] library and processing large files in a lazy way (as opposed to using slurp). [1] - clojure-csv - https://github.com/davidsantiago/clojure-csv Here is a copy of my source code (disclaimer - this is my first Clojure program - so some things