Re: Problem filtering with definline'd function

2013-06-20 Thread Colin Fleming
So this has just happened to me again: Clojure 1.5.1 (plugin.psi/symbol? 2) => false (filter plugin.psi/symbol? [1 2 3]) => (1 2 3) ((var-get #'plugin.psi/symbol?) 2) => (clojure.core/instance? org.jetbrains.plugins.clojure.psi.api.symbols.ClSymbol 2) What that looks like to me is that the macro

representing clojure source code as data?

2013-06-20 Thread kovas boguta
What's the latest opinion on parsing and representing clojure code as data? I'm talking about representations suitable for code analysis; representing the definition of the program as specified by the programmer. As opposed to: 1. a representation of the program implied by the source code (aka

More on Object Behavior System and "the entire hierarchy is a nested data structure"

2013-06-20 Thread Leon Talbot
Hello! I am interested in knowing more about the Object Behavior system presented by Chris Granger at Conj 2012. I find it really clean and the idea of having objects combined with the fact that "the entire hierarchy is a nested data structure that is easy to reason about and modify at runtime

Re: Vector is only half associative?

2013-06-20 Thread Stephen Compall
On Fri, 2013-06-07 at 13:25 +0200, Robert Ewald wrote: > But merge-with and other functions don't work, even though I > think it is not unreasonable to expect that. What do you expect the results of these to be? (merge-with + [1 2]) (merge-with + [1 2 3] []) (merge-with + [] [1 2 3]) (merge-with

Re: Why does peek on a seq of vector fail?

2013-06-20 Thread Jason Gilman
I think I get the difference now between a sequence, list, and a vector. Thanks for the quick answers. On Jun 20, 2013, at 5:14 PM, "John D. Hume" wrote: > On Jun 20, 2013 3:11 PM, "Jason Gilman" wrote: > > > > (defn bar [my-list n] > > (if (= n 0) > > (peek my-list) > > (bar (r

Re: Why does peek on a seq of vector fail?

2013-06-20 Thread John D. Hume
On Jun 20, 2013 3:11 PM, "Jason Gilman" wrote: > > (defn bar [my-list n] > (if (= n 0) > (peek my-list) > (bar (rest my-list) (dec n > (bar [1 2 3] 1) > It seems likely you want either first and rest* (to work from the front of any seqable) or peek and pop (to work from the back

Re: try* macro to catch multiple exception classes with one body. feedback is needed.

2013-06-20 Thread Herwig Hochleitner
One thing to consider: try* is a compiler builtin form. Those are currently not even namespaced. That might lead to confusion for readers. 2013/6/20 Max Gonzih > I updated my macro to your solution, looks really simple and works like > before. I don't know why I overcomplicated my original solu

Re: Why does peek on a seq of vector fail?

2013-06-20 Thread László Török
Hi, I think it's by design. It only works with concrete data structure (list, vector, queue) types that implement clojure.lang.IPersistentStack Las 2013/6/20 Jason Gilman > Also, I really appreciate anyone who takes the time to answer. My company > is currently evaluating Clojure. I'm try

Re: Why does peek on a seq of vector fail?

2013-06-20 Thread David Nolen
Calling seq on vector returns a sequence which is no longer a vector. The docstring is pretty specific about which types it's supposed to work on. clojure.core/peek ([coll]) For a list or queue, same as first, for a vector, same as, but much more efficient than, last. If the collection is empt

Re: Why does peek on a seq of vector fail?

2013-06-20 Thread Jason Gilman
Also, I really appreciate anyone who takes the time to answer. My company is currently evaluating Clojure. I'm trying to determine if this is non-idiomatic use of the language or some other issue. Doing something like this can cause the bug to occur without directly calling seq on a vector: (de

Why does peek on a seq of vector fail?

2013-06-20 Thread Jason Gilman
Why does (peek (seq [1])) result in: ClassCastException clojure.lang.PersistentVector$ChunkedSeq cannot be cast to clojure.lang.IPersistentStack clojure.lang.RT.peek (RT.java:634) Peek documentation "For a list or queue, same as first, for a vector, same as, but much more efficient than, last.

Re: Project Euler problem in clojure

2013-06-20 Thread Alan Malloy
More importantly than any of these things, he is hanging onto the head of a very, very large sequence with (def lazytri (map triangle (range))). This will lead to serious memory pressure, and perhaps eventually a slowdown as this sequence takes up all the memory in his app and the GC strains to

Re: Heroku Clojure scheduled tasks versus worker threads

2013-06-20 Thread Phil Hagelberg
On Jun 18, 6:22 am, Jonathon McKitrick wrote: > So, the question then, is what would be the difference between a heroku > scheduled command (which I currently am running, wakes up, does some work, > etc) and a 'worker process' type?  Does the latter need a job queue set up? >  Does it run constant

Re: Project Euler problem in clojure

2013-06-20 Thread Meikel Brandmeyer (kotarak)
Hi, Am Donnerstag, 20. Juni 2013 15:19:40 UTC+2 schrieb John Holland: > > (defn triangle [n] (reduce + (range n))) > (def lazytri (lazy-seq (map triangle (range > > Some quick idea: here is a major difference in your clojure and your java implementation. You always recompute the whole sum f

Re: Namespace qualification of symbols

2013-06-20 Thread Michał Marczyk
On 20 June 2013 14:35, Phillip Lord wrote: > Oh yeah, how sneaky. In one case, you get a class, in the other, you get > a symbol. Backtick is doing quite a bit more than letting you unquote > and splice. You get a symbol in both cases, though with a different name: (import java.awt.image.Buffere

Re: Project Euler problem in clojure

2013-06-20 Thread John Holland
OK, with a coding improvement (defn factors-sqrt [n] (filter #(= 0 (mod n %)) (range 1 (+ 1 (Math/sqrt n ) (defn num-of-factors [n] (* 2 (count (factors-sqrt n it works for 499. (Idea being factors come in pairs, each factor > sqrt(x) corresponds to one > sqrt(x)) Was it just runnin

Project Euler problem in clojure

2013-06-20 Thread John Holland
I'm working on problems at projecteuler.net in Clojure. There is a particular problem that my code doesn't seem to work for. The problem is: == The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 +

Re: Namespace qualification of symbols

2013-06-20 Thread Ambrose Bonnaire-Sergeant
On Thu, Jun 20, 2013 at 8:50 PM, Phillip Lord wrote: > Thanks for the explanation. I was confused. Cheers, glad it helped. Ambrose -- -- 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 No

Re: Namespace qualification of symbols

2013-06-20 Thread Phillip Lord
"Jim - FooBar();" writes: > On 20/06/13 08:49, Phillip Lord wrote: >> Well, that doesn't answer the question. The backtick is useful in >> writing macros (although the situation this caused me grief, actually, I >> wasn't). So is quote. But then I do not understand why the behaviour is >> differen

Re: Namespace qualification of symbols

2013-06-20 Thread Phillip Lord
Oh yeah, how sneaky. In one case, you get a class, in the other, you get a symbol. Backtick is doing quite a bit more than letting you unquote and splice. Colin Fleming writes: > Thank you for this, you just fixed a bug for me :-) > > I was trying to do some tricky type hinting with definline us

Re: Namespace qualification of symbols

2013-06-20 Thread Phillip Lord
Ambrose Bonnaire-Sergeant writes: > It's a good question. > > Syntax quote is designed for generating code/syntax that is deterministic > and avoids accidental local name capture. > > 1. Automatic namespace qualification helps avoid accidental local name > capture in macros. > > user=> `(let [a# 1

Re: Problem filtering with definline'd function

2013-06-20 Thread Colin Fleming
ClSymbol is a Java class. I don't get the replacement warning because I've excluded that symbol explicitly in my ns declaration using :refer-clojure :exclude. I haven't done a 'lein clean' because I'm not using lein, but I have rebuilt various times. However, sometimes it will work and sometimes i

Re: Namespace qualification of symbols

2013-06-20 Thread Jim - FooBar();
On 20/06/13 08:49, Phillip Lord wrote: Well, that doesn't answer the question. The backtick is useful in writing macros (although the situation this caused me grief, actually, I wasn't). So is quote. But then I do not understand why the behaviour is different between the two. I thought the ques

Re: Problem filtering with definline'd function

2013-06-20 Thread Jim - FooBar();
On 20/06/13 10:59, Colin Fleming wrote: Because this tests for something different - that the element is an instance of ClSymbol. It's not testing the same thing as the core version. I qualify it (psi/symbol? in the examples above) to distinguish it from the core one. Basically, I'm trying to

Re: Problem filtering with definline'd function

2013-06-20 Thread Colin Fleming
Because this tests for something different - that the element is an instance of ClSymbol. It's not testing the same thing as the core version. I qualify it (psi/symbol? in the examples above) to distinguish it from the core one. Basically, I'm trying to use definline to allow me to have a more Clo

Re: Problem filtering with definline'd function

2013-06-20 Thread Jim - FooBar();
There is already a symbol? predicate in core. Why are you defining your own? Does your problem disappear when you use the one from core? What exactly are you trying to do? I use definline quite frequently and have never encountered such problems... Jim On 20/06/13 10:35, Colin Fleming wrote:

Problem filtering with definline'd function

2013-06-20 Thread Colin Fleming
Hi all, I'm having a problem where a definline'd function is not working when used as a predicate for filtering. It seems to work sporadically - occasionally it works, occasionally it doesn't. I'm thinking it's probably a compile problem since it seems to work or not work consistently for each com

Re: Namespace qualification of symbols

2013-06-20 Thread Ambrose Bonnaire-Sergeant
Hi Phil, It's a good question. Syntax quote is designed for generating code/syntax that is deterministic and avoids accidental local name capture. 1. Automatic namespace qualification helps avoid accidental local name capture in macros. user=> `(let [a# 1 b# a] a#) (cloj

Re: Namespace qualification of symbols

2013-06-20 Thread Phillip Lord
Jim writes: > On 19/06/13 09:46, Phillip Lord wrote: >> With the ' paul is not namespace qualified, while with the ` paul is. >> >> >> Turns out to be a bit of a pain, actually, although I have worked around >> it. But mostly I am surprised. Is this expected? > > Yes, this is very much expected! :

Re: Clojure generates unnecessary and slow type-checks

2013-06-20 Thread Jason Wolfe
On Saturday, June 15, 2013 4:37:06 AM UTC-7, Mikera wrote: > > On Friday, 14 June 2013 18:15:34 UTC+1, Jason Wolfe wrote: > >> Hey Mikera, >> >> I did look at core.matrix awhile ago, but I'll take another look. >> >> Right now, flop is just trying to make it easy to write *arbitrary* >> array

Re: try* macro to catch multiple exception classes with one body. feedback is needed.

2013-06-20 Thread Max Gonzih
I updated my macro to your solution, looks really simple and works like before. I don't know why I overcomplicated my original solution so much :). Thanks again! On Thursday, June 20, 2013 8:47:37 AM UTC+3, Meikel Brandmeyer (kotarak) wrote: > > Hi, > > Am Mittwoch, 19. Juni 2013 17:00:17 UTC+2