How to: reduce boolean operations?

2013-05-22 Thread Peter Mancini
OK long time lurker here. I've been growing in my Clojure strength for a while now. For the most part I think I get it and I have no problem getting programs to do what I want. However, sometimes I get stumped. I have one function that produces a list of booleans like '(false false true). It

Re: How to: reduce boolean operations?

2013-05-22 Thread Baishampayan Ghose
Using a lambda seems to be a sane approach - (reduce #(and %1 %2) '(false false true)) ;= false On Wed, May 22, 2013 at 5:36 AM, Peter Mancini pe...@cicayda.com wrote: OK long time lurker here. I've been growing in my Clojure strength for a while now. For the most part I think I get it and I

Re: How to: reduce boolean operations?

2013-05-22 Thread Mark Engelberg
Using eval should be a rarity. I'd use (every? identity [false false true]) to do a reduce-and, and I'd use (some identity [false false true]) to do a reduce-or (keeping in mind the latter actually returns nil rather than false). -- -- You received this message because you are subscribed to

ClassNotfound Exception while loading JAR files in Clojure 1.2

2013-05-22 Thread vcomandur
Hi, We have built a web application using grails framework and we use Groovy, Java and Clojure programming languages. We use Clojure 1.2. The clojure files include classes from HTMLUnit. Recently HTMLUnit released a new version of JAR file and we were trying to migrate the web app to

Re: How to: reduce boolean operations?

2013-05-22 Thread Chris Ford
The reason and is a macro is that it's designed to short-circuit - ie if the first result is false the rest shouldn't even be evaluated. Using it on raw booleans works, because booleans evaluate to themselves, but it's really designed to be given forms. The absence of a pure function for

Re: Design/structure for a game loop in clojure

2013-05-22 Thread Daniel P. Wright
Thanks everyone for your replies, in particular: Mikera: Glad to hear we're along the right lines, and thanks for the extra advice. I've found your blog series on Alchemy very helpful while considering this stuff. This game is a little different, and I'm mainly concerned with what's going on

Re: Design/structure for a game loop in clojure

2013-05-22 Thread Mikera
On Wednesday, 22 May 2013 16:46:54 UTC+8, Daniel Wright wrote: Thanks everyone for your replies, in particular: Mikera: Glad to hear we're along the right lines, and thanks for the extra advice. I've found your blog series on Alchemy very helpful while considering this stuff. This game

Re: confused on set!

2013-05-22 Thread Phillip Lord
Ah, okay, I see the idea. I'm not sure why it doesn't work. For now, I think, using an atom and reset! seems to do the job! Phil atkaaz atk...@gmail.com writes: The following idea came to me in the shower, sort of out of the blue, and I don't know why I didn't think of it before(I'm

Re: Design/structure for a game loop in clojure

2013-05-22 Thread atkaaz
concurrency-wise, you might find useful Rich Hickey's ants simulation https://github.com/juliangamble/clojure-ants-simulation/ the relevant video where he explains it: https://www.youtube.com/watch?v=dGVqrGmwOAw (if you want the slides too, see in the comments: someone suggested google for Must

Re: How to: reduce boolean operations?

2013-05-22 Thread atkaaz
On Wed, May 22, 2013 at 3:06 AM, Peter Mancini pe...@cicayda.com wrote: I noticed that '(nil nil true) will cause and to produce false, so I am aware of that edge case. Anything else I should be aware of? What about the other edge? user= (reduce #(and %1 %2) '(1 true 2)) 2 user= (eval (conj

Re: How to: reduce boolean operations?

2013-05-22 Thread atkaaz
I find the wording of this confusing otherwise it returns the value of the last expr. (and) returns true. I mean, I know it returns the last true value, but that's because I've tested it not because the doc is trying(failing) to tell me so with that phrase. On Wed, May 22, 2013 at 1:28 PM,

Re: How to: reduce boolean operations?

2013-05-22 Thread John D. Hume
On May 22, 2013 5:35 AM, atkaaz atk...@gmail.com wrote: I find the wording of this confusing otherwise it returns the value of the last expr. (and) returns true. I mean, I know it returns the last true value, but that's because I've tested it not because the doc is trying(failing) to tell me so

[ANN] tawny-owl 0.11

2013-05-22 Thread Phillip Lord
I'm pleased to announce the release of tawny-owl 0.11. What is it? == This package allows users to construct OWL ontologies in a fully programmatic environment, namely Clojure. This means the user can take advantage of programmatic language to automate and abstract the ontology over

Re: How to: reduce boolean operations?

2013-05-22 Thread atkaaz
Oh i see now, thank you! so it's like this: otherwise it returns the value of the last expression. (and) returns true. i though expr. is the short for of the word expression which requires a dot, but the dot was in fact an end of sentence. On Wed, May 22, 2013 at 2:40 PM, John D. Hume

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread atkaaz
For those who don't know the concepts (aka me) can we get a working example of what can be done ? I'm having a strange feeling that ontologies(although I've never heard the word/idea before except from you) might be something similar to what I am searching for... Possibly an example that

Re: asm-based clojure yet?

2013-05-22 Thread Julian
One more thought on the broader ideas of LISPy languages and ASM. One of the versions of Crash Bandicoot was developed in Game Oriented Assembly LISP (GOAL) - which was a common LISP DSL that generated assembler. I recalled this today because Michael Fogus tweeted about it:

Re: Compiling the Android version of Clojure

2013-05-22 Thread Alex Fowler
My aim is to enable Clojure programming directly on an Android device.. so, as I understand, I can use lein-droid to make the pre-compiled JAR to work on the device? I seen Clojure 1.4.0 REPL for Android and I wanted to get the compiler itself, preferably for 1.5.1, so that I can integrate it

Re: asm-based clojure yet?

2013-05-22 Thread atkaaz
thank you very much, my search has lead me to seeking a lisp that could compile to machine code (mainly because i cannot accept the 20-22 sec `lein repl` startup time and eclipse/ccw memory consumptions - so I was hoping for something fast even though the cost is portability and all else) On

Re: How to: reduce boolean operations?

2013-05-22 Thread Michał Marczyk
On 22 May 2013 08:09, Baishampayan Ghose b.gh...@gmail.com wrote: Using a lambda seems to be a sane approach - (reduce #(and %1 %2) '(false false true)) ;= false Note that this will always traverse the entire input collection, whereas every? stops at the first false value. Same thing goes

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread Andrew Wagner
I went looking for the same thing. There are a few partial examples in the docs directory that might be worth looking at. On Wed, May 22, 2013 at 8:06 AM, atkaaz atk...@gmail.com wrote: For those who don't know the concepts (aka me) can we get a working example of what can be done ? I'm

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread Phillip Lord
It's a good question; the library is more intended for people who know ontologies and don't care, or have never heard about, clojure. So the documentation is biased in that way. In this setting, an ontology is essentially a set of facts, that you can test with a computational reasoner; so, it's

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread atkaaz
Thank you very much for this! I find it very interesting, I shall keep reading On Wed, May 22, 2013 at 4:24 PM, Phillip Lord phillip.l...@newcastle.ac.ukwrote: It's a good question; the library is more intended for people who know ontologies and don't care, or have never heard about,

Time complexity of operations on collections

2013-05-22 Thread John Jacobsen
I'm studying for an interview and thought it might be nice to know the time complexity of primitive operations on collections in Clojure. A quick googling didn't turn up a definitive resource. I would be happy to put one together. What I had in mind was something like: Collections: strings,

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread atkaaz
Would you say that ontologies can be modeled on top of graphs? so in a way they can be seen as a specific use case for graphs? (maybe directed acyclic graphs), that's what I am getting the sense of so far On Wed, May 22, 2013 at 4:47 PM, atkaaz atk...@gmail.com wrote: Thank you very much for

Re: Time complexity of operations on collections

2013-05-22 Thread Timothy Baldridge
A few corrections: Lists are single linked lists, so nth on them (as well as last) is O(n). Get on lists is unsupported. Cons on a vector is O(1) since cons converts things to seqs (O(1)) before constructing the cons. Count on everything but Cons and LazySeq is O(1). For those two it's O(n)

Re: Time complexity of operations on collections

2013-05-22 Thread John Jacobsen
I should probably also have added sorted-map to the table, though the complexity for each operation is less clear 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

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread Jim
On 22/05/13 15:11, atkaaz wrote: Would you say that ontologies can be modeled on top of graphs? so in a way they can be seen as a specific use case for graphs? (maybe directed acyclic graphs), that's what I am getting the sense of so far I am certainly not an ontology guru but I can confirm

Re: How to: reduce boolean operations?

2013-05-22 Thread Peter Mancini
Thanks everyone for the help. The nil behavior of the 'or' version breaks what I wanted, but I may create functions that return just true or false though the odd edge case where and will return a value will mean I'll have to handle that. My preference would be to throw an exception but thats

Re: How to: reduce boolean operations?

2013-05-22 Thread Jim
On 22/05/13 15:54, Peter Mancini wrote: The nil behavior of the 'or' version breaks what I wanted, but I may create functions that return just true or false though the odd edge case where and will return a value will mean I'll have to handle that. wrap that call in a 'boolean' call (e.g.

Re: ClassNotfound Exception while loading JAR files in Clojure 1.2

2013-05-22 Thread Sean Corfield
You'll need to provide more details about exactly which Clojure JARs you use and the stack trace for the exception (at least telling us which class is not found and enough of the stack trace for us to see where the reference is coming from). My suspicion is you're using the Clojure 1.2 contrib

Re: Time complexity of operations on collections

2013-05-22 Thread Timothy Baldridge
You might also want to switch cons to conj. This is a super ugly part of the Java api that no one really ever sees. PersistentVector.cons is actually called by clojure.core/conj. clojure.core/cons is something else completely. When talking about how the java code performs it might be best to

Re: ClassNotfound Exception while loading JAR files in Clojure 1.2

2013-05-22 Thread vcomandur
Hi Sean, Thanks for your reply. I use Clojure.Jar version 1.2.0 and the contrib.jar is also the same version. Copied below is the stack trace of the Error: Caused by: java.lang.NoClassDefFoundError: com/gargoylesoftware/htmlunit/html/BaseFrameElement (agent.clj:1) at

Re: ClassNotfound Exception while loading JAR files in Clojure 1.2

2013-05-22 Thread Andy Fingerhut
I'll be more blunt than Sean was :-) Is there a reason why you *must* use Clojure 1.2? If so, what is it? If there isn't such a reason, you will likely get much better support from other Clojure users if you use Clojure 1.4 or 1.5.1 (1.5.1 was released a couple of months ago, so many are still

Re: ClassNotfound Exception while loading JAR files in Clojure 1.2

2013-05-22 Thread vcomandur
Hi Andy, I inherited the code written by some one who is no longer with us. First, I would like to migrate to new version of HTMLUnit and then look at migrating the clojure to the new version. Regards Vasu On Wednesday, May 22, 2013 9:03:03 PM UTC+5:30, Andy Fingerhut wrote: I'll

Re: asm-based clojure yet?

2013-05-22 Thread Mikera
On Wednesday, 22 May 2013 20:35:01 UTC+8, atkaaz wrote: thank you very much, my search has lead me to seeking a lisp that could compile to machine code (mainly because i cannot accept the 20-22 sec `lein repl` startup time and eclipse/ccw memory consumptions - so I was hoping for something

Re: How to: reduce boolean operations?

2013-05-22 Thread Peter Mancini
Well, excepts that it is not correct. It will return false when really there was a faulty collection handed to it. I'd rather catch an error like that than to pretend it didn't happen and give a result that isn't correct while also being hard to detect. If you can guarantee it won't get a bad

Re: How to: reduce boolean operations?

2013-05-22 Thread Ben Wolfson
On Wed, May 22, 2013 at 12:14 AM, Chris Ford christophertf...@gmail.comwrote: The reason and is a macro is that it's designed to short-circuit - ie if the first result is false the rest shouldn't even be evaluated. Using it on raw booleans works, because booleans evaluate to themselves, but

Re: Time complexity of operations on collections

2013-05-22 Thread John Jacobsen
I am indeed confused. I have both cons and conj operations in my table. Are you saying (conj coll item) and (cons item coll) are implemented the same way under the hood? That wasn't my understanding. Can you clarify? On Wednesday, May 22, 2013 10:05:22 AM UTC-5, tbc++ wrote: You might

Re: Time complexity of operations on collections

2013-05-22 Thread John Jacobsen
Updated draft of table in more readable form here: http://bit.ly/big-o-clojure Thanks to Timothy for corrections/additions! Will keep updating as other replies come in. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send

Re: Time complexity of operations on collections

2013-05-22 Thread Timothy Baldridge
No, what I'm saying is that in each persistent collection there is a method called cons: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentVector.java#L167 However, this is the function called by clojure.core/conj:

Re: How to: reduce boolean operations?

2013-05-22 Thread Peter Mancini
So I did some coding and came up with this but it is broken; (= java.lang.Boolean (type false)) ;;evaluates to true (defn all-true? [coll] (every? (cond (= java.lang.Boolean (type identity)) identity :else false) coll)) ;;compiles (all-true? '(true true true)) ;; throws

Re: How to: reduce boolean operations?

2013-05-22 Thread atkaaz
= (type identity) clojure.core$identity On Wed, May 22, 2013 at 7:17 PM, Peter Mancini peter.manc...@gmail.comwrote: So I did some coding and came up with this but it is broken; (= java.lang.Boolean (type false)) ;;evaluates to true (defn all-true? [coll] (every? (cond (=

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread Paul Gearon
On Wed, May 22, 2013 at 9:24 AM, Phillip Lord phillip.l...@newcastle.ac.ukwrote: It's a good question; the library is more intended for people who know ontologies and don't care, or have never heard about, clojure. So the documentation is biased in that way. This message originally

Re: How to: reduce boolean operations?

2013-05-22 Thread Michael Wood
Try: user= (every? #(= Boolean (type %)) [true false false]) true user= (every? #(= Boolean (type %)) [true false false 1]) false On 22 May 2013 18:20, atkaaz atk...@gmail.com wrote: = (type identity) clojure.core$identity On Wed, May 22, 2013 at 7:17 PM, Peter Mancini

Re: How to: reduce boolean operations?

2013-05-22 Thread Peter Mancini
Duh never mind - simplified it and it works like a charm now. (defn all-true? [coll] (every? (fn [x] (= x true)) coll)) (all-true? '(true true true)) (all-true? '(true true false)) (all-true? '(true true 3)) (all-true? '(3 \# !)) No exception on bad input data but if I really need to do

Re: How to: reduce boolean operations?

2013-05-22 Thread atkaaz
I think the exception is thrown because you basically called (every? false coll) however on my clojure version I cannot reproduce it oh wait there we go, some bug here with empty collection (maybe someone can pick it up): = (every? false [1 2 3]) ClassCastException java.lang.Boolean cannot be

Re: How to: reduce boolean operations?

2013-05-22 Thread atkaaz
there's another edge case when using and/or : getting passed an unbound var where for example `nil?` and `str` applied to it don't throw, and of course also `or` and `and`, ie.: = (def a) #'cgws.notcore/a = a #Unbound Unbound: #'cgws.notcore/a = (nil? a) false = (str a) Unbound:

Defining the ground truth

2013-05-22 Thread Tim Daly
Is the ground truth your spec or your code? Here is an interesting read: http://shanecelis.github.io/2013/05/20/why-im-trying-literate-programming Shane started with a co-worker, working from a spec, to create a program. He eventually found that only he could make changes because only he

Re: asm-based clojure yet?

2013-05-22 Thread atkaaz
Looks like I forgot to enable the paging file (windows virtual memory was disabled) and that is why my eclipse/firefox would crash when running out of memory and also had much eclipse.ini memory allocated -Xms228m -Xmx712m ; and because of all these I was unable to start repl most of the time in

Re: asm-based clojure yet?

2013-05-22 Thread Gary Trakhman
emacs does this navigation stuff.. M-. and M-, . For uses of a function, try grep -R or rgrep. On Wed, May 22, 2013 at 1:30 PM, atkaaz atk...@gmail.com wrote: Looks like I forgot to enable the paging file (windows virtual memory was disabled) and that is why my eclipse/firefox would crash

Re: How to: reduce boolean operations?

2013-05-22 Thread Sean Corfield
On Wed, May 22, 2013 at 9:32 AM, Peter Mancini peter.manc...@gmail.com wrote: (defn all-true? [coll] (every? (fn [x] (= x true)) coll)) (defn all-true? [coll] (every? true? coll)) -- Sean A Corfield -- (904) 302-SEAN An Architect's View -- http://corfield.org/ World Singles, LLC. --

Re: asm-based clojure yet?

2013-05-22 Thread atkaaz
I don't know about the emacs stuff, but I consider the latter to be a nice workaround/hack :) On Wed, May 22, 2013 at 8:35 PM, Gary Trakhman gary.trakh...@gmail.comwrote: emacs does this navigation stuff.. M-. and M-, . For uses of a function, try grep -R or rgrep. On Wed, May 22, 2013 at

Re: Compiling the Android version of Clojure

2013-05-22 Thread Daniel Solano Gómez
On Wed May 22 05:10 2013, Alex Fowler wrote: My aim is to enable Clojure programming directly on an Android device.. so, as I understand, I can use lein-droid to make the pre-compiled JAR to work on the device? I seen Clojure 1.4.0 REPL for Android and I wanted to get the compiler itself,

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread Phillip Lord
Jim jimpil1...@gmail.com writes: I am certainly not an ontology guru but I can confirm that what you describe is sort of valid...Ontologies will indeed help you find predicate-argument structures of the form subject-predicate-object (i.e John likes pizza), but in order to do that you have to

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread Phillip Lord
Ah, now, that is a complicated question with a long history. If I may duck the question slightly, and just answer about OWL (it's not the only ontology representation language). Trivially, of course, the answer is yes. An ontology is representable as a graph, but then a graph is a rich enough

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread Phillip Lord
Paul Gearon gea...@ieee.org writes: On Wed, May 22, 2013 at 9:24 AM, Phillip Lord phillip.l...@newcastle.ac.ukwrote: It's a good question; the library is more intended for people who know ontologies and don't care, or have never heard about, clojure. So the documentation is biased in that

Re: Auto-compiling HAML / SCSS

2013-05-22 Thread Timothy Washington
Hey Antonio, thanks for responding. I guess I'm a bit annoyed that *lein-haml-sass*, isn't managing it's own 3rd party tools itself. I'll check out the links you mentioned. Cheers Tim On Tue, May 21, 2013 at 3:59 PM, Antonio Terreno antonio.terr...@gmail.comwrote: I never used that lein

Re: [ANN] tawny-owl 0.11

2013-05-22 Thread Rich Morin
On May 22, 2013, at 04:41, Phillip Lord wrote: I'm pleased to announce the release of tawny-owl 0.11. What is it? == This package allows users to construct OWL ontologies ... Not surprisingly, most Clojurists are not familiar with ontologies in general or OWL ontologies in

Re: How to: reduce boolean operations?

2013-05-22 Thread Michał Marczyk
On 22 May 2013 18:34, atkaaz atk...@gmail.com wrote: I think the exception is thrown because you basically called (every? false coll) however on my clojure version I cannot reproduce it oh wait there we go, some bug here with empty collection (maybe someone can pick it up): = (every? false [1

Re: How to: reduce boolean operations?

2013-05-22 Thread atkaaz
Well, seems to me more like this: if [] is empty then return true otherwise check (pred everyx in coll) however this allows for any pred especially(in this case) invalid preds: `false` is not a function/pred = (false 1) ClassCastException java.lang.Boolean cannot be cast to clojure.lang.IFn