Re: Best practice for looping

2013-06-21 Thread Cedric Greevey
An algorithm like that generating StackOverflowErrors suggests it's recursing deeply, which suggests you're not using recur *enough*. If the function calls itself, try to see if you can get that call into tail position and change it to "recur". On Fri, Jun 21, 2013 at 4:06 PM, P Martin wrote: >

Re: generating core.logic queries

2013-06-21 Thread Cedric Greevey
Please stop focusing on just the one instance -- it's the trend that concerns me, not any individual data point on it. I don't want to see Clojure become wed to something closed-source, yet it seems I'm seeing the early stages of just such a courtship lately. On Fri, Jun 21, 2013 at 8:53 PM, Bran

Web Framework update

2013-06-21 Thread Kelker Ryan
Some major changes have been made to the CHP framework. This library provides the following Clojure on the front end Run Clojure inside a HTML file with the tagsStyle templates can be written in CHTML ex. chp.template/using-template Parameters Request params ex. ($p userid)Common web headers ex. (

Re: database wrapper lib

2013-06-21 Thread Sean Corfield
On Fri, Jun 21, 2013 at 8:56 AM, Michael Klishin wrote: > Relational databases: https://github.com/clojure/java.jdbc (this one is not > very extensively documented but is also small compared to Korma) FYI, Korma is built on top of java.jdbc and if you want a different DSL on top of java.jdbc, I h

Re: database wrapper lib

2013-06-21 Thread Carlo Zancanaro
Hey Justin, I'm also working on a wrapper lib for SQL queries (which can optionally use jdbc for performing the queries). At the moment it's pretty new, so it might not actually work for you, but if you want to take a look the code's at https://bitbucket.org/czan/clojure-sql. It's also been pushed

Re: representing clojure source code as data?

2013-06-21 Thread Brandon Bloom
> I think there are 2 representations that could be useful: I think there are really two axis: 1) Shape of the data and 2) Language being described You've outlined 2 out of the 3 interesting (to me) shapes: 1) raw data structures and 2) datoms. I think that the 3rd interesting one is a map/vec

Re: generating core.logic queries

2013-06-21 Thread Brandon Bloom
> Perhaps not, but apparently the developers of core.logic are. That's kinda a funny remark to make to David Nolen, who is *the* developer of core.logic. In this case, he's talking about this wiki page: https://github.com/clojure/core.logic/wiki/Extending-core.logic-(Datomic-example) That's no

Re: Problem filtering with definline'd function

2013-06-21 Thread Colin Fleming
Does anyone have an idea for what I might do to diagnose/fix this? Is this just a misunderstanding on my part? If not I'll file a bug against definline. On 21 June 2013 18:04, Colin Fleming wrote: > So this has just happened to me again: > > Clojure 1.5.1 > (plugin.psi/symbol? 2) > => false > (

Best practice for looping

2013-06-21 Thread P Martin
Hi, I am new to clojure and I am trying to reimplement some optimization code that uses gradient descent. I have attached the source to this post. My experience with gradient descent is in Matlab, which is procedural. When I run my function gradient-descent I supply step sizes and error value

Re: database wrapper lib

2013-06-21 Thread serialhex
Hey, thanks for the links!! I searched around but never found those, this helps a lot!!! Justin On Fri, Jun 21, 2013 at 11:56 AM, Michael Klishin < michael.s.klis...@gmail.com> wrote: > > 2013/6/21 serialhex > >> Hi all, I'm looking for a decent database wrapper library. > > > Relational data

Re: generating core.logic queries

2013-06-21 Thread Timothy Baldridge
One reason why Datomic works so well with core.logic is that it exposes raw index data to the client. I am unaware of any other database that decouples data storage from the query engine. If you can find one that does, I'm sure someone could expose a core.logic interface to that DB as well. But, i

Re: generating core.logic queries

2013-06-21 Thread Cedric Greevey
Perhaps not, but apparently the developers of core.logic are. And it's only one of several similar instances to come to my attention in recent weeks. On Fri, Jun 21, 2013 at 12:22 PM, David Nolen wrote: > I wasn't suggesting using Datomic. > > > On Fri, Jun 21, 2013 at 12:19 PM, Cedric Greevey w

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Colin Yates
Ah OK, I didn't realise. I thought the vars would be locally scoped, i.e. semantically equivalent to 'let'ed symbols. Thanks everyone for contributing. On Friday, 21 June 2013 14:49:52 UTC+1, Jim foo.bar wrote: > > On 21/06/13 14:34, Colin Yates wrote: > > Is it correct but simply non-idiom

Re: generating core.logic queries

2013-06-21 Thread Karsten Schmidt
Thanks, David! I wasn't aware the macros are just sugar. Time to study the source more closely! The above code was very naive indeed, but for sake of illustration only. These queries would only ever deal with a small subset of facts, which have already been selected from a number of indexes. K. --

Re: interval trees..

2013-06-21 Thread David Williams
Hi Sunil, I created one here: https://github.com/mobiusinversion/interval-trees Here is the marginalia documentation http://mobiusinversion.github.io/interval-trees/ and the Clojars page https://clojars.org/interval-trees Please let me know if you have a chance to try this out and I would gr

Re: generating core.logic queries

2013-06-21 Thread David Nolen
I wasn't suggesting using Datomic. On Fri, Jun 21, 2013 at 12:19 PM, Cedric Greevey wrote: > On Fri, Jun 21, 2013 at 11:56 AM, David Nolen wrote: > >> Datomic integration notes on the core.logic wiki >> > > I'm concerned with this trend towards favoring Datomic over other > solutions when addin

Re: generating core.logic queries

2013-06-21 Thread Cedric Greevey
On Fri, Jun 21, 2013 at 11:56 AM, David Nolen wrote: > Datomic integration notes on the core.logic wiki > I'm concerned with this trend towards favoring Datomic over other solutions when adding database integration to libraries. If one DB is going to be singled out for preferred treatment by a lo

Re: matching, assigning and branching in one form

2013-06-21 Thread David Nolen
Not a specific answer to your question, but it would be cool to see someone make the core.match regex facilities handle this. (match [msg] [(#"^:(.*?)!.*PRIVMSG (.*) :(.*)" :>> [from to message])] ... true form ... :else ... false form ..) David On Fri, Jun 21, 2013 at 11:43 AM, Steven D. A

Re: database wrapper lib

2013-06-21 Thread Michael Klishin
2013/6/21 serialhex > Hi all, I'm looking for a decent database wrapper library. Relational databases: https://github.com/clojure/java.jdbc (this one is not very extensively documented but is also small compared to Korma) MongoDB: http://clojuremongodb.info Cassandra: http://clojurecassandra.i

Re: generating core.logic queries

2013-06-21 Thread David Nolen
It's common misconception that core.logic is a bunch of macros. The macros are just sugar, there are functions for *everything*. You can load a stream of "facts" however you please, you should look at `to-stream` which can take any Clojure sequence of data and make it useable from core.logic as a

database wrapper lib

2013-06-21 Thread serialhex
Hi all, I'm looking for a decent database wrapper library. I'm probably going to end up using PostgrSQL & maybe SQLite for testing. I've looked at Korma & a few others, but I'm getting lost on how to *actually use* them. I'm new to Clojure, so something with a good tutorial would be best! Thank

matching, assigning and branching in one form

2013-06-21 Thread Steven D. Arnold
Hi, I am writing a simple IRC bot, pretty much just for fun, starting with a simple implementation originally posted by Nurullah Akkaya on his blog. It already does what it's supposed to, which is message a fortune from mod-fortune (shelling out) when someone asks it to. However, there's a bit

generating core.logic queries

2013-06-21 Thread Karsten Schmidt
Hi all, am toying around with the thought of generating core.logic queries dynamically. However, I'm stuck at square one since all the core.logic functions are macros and am not sure how to refer to logic vars within a query generator fn. E.g. given this list of facts... (def myfacts [[:karsten

Re: Function returns nil

2013-06-21 Thread Phillip Lord
"Jim - FooBar();" writes: > On 21/06/13 14:01, Neale Swinnerton wrote: >> >> >> I really wish there were support for this in clojure.core: both >> "dofor" >> and "domap" would be very useful. >> >> >> mapv is non-lazy, which gives you the semantics of a domap as long as you >> don't m

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Jim - FooBar();
On 21/06/13 15:06, Andy Fingerhut wrote: Colin showed pretty clearly in his email that he was using "lein uberjar" followed by running the JVM explicitly with his own command line, so Leiningen has no way to affect the JVM command line options in that case. oops! I thought Michael meant the g

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Michael Klishin
2013/6/21 Jim - FooBar(); > Did you read the entire thread? > both Jason and Leon (who originally posted) admit that this was the > problem...Stuart even opened this issue: > https://github.com/technomancy/leiningen/pull/1230 > Leiningen's default only apply if you, hm, run Leiningen. If you ru

Re: fastest way to produce a PersistentList

2013-06-21 Thread Jim - FooBar();
Hi David, On 21/06/13 14:51, David Nolen wrote: The problem is the reversing of the list if you want to convert back to a list. You can avoid this but you have to use a custom mapping operation, continuation passing style, and a trampoline - it won't be fast. Another option is to realize th

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Andy Fingerhut
:jvm-opts and that ticket for Leiningen only affect the options passed to the JVM if you let Leiningen invoke the JVM for you, e.g. via "lein run ..." Colin showed pretty clearly in his email that he was using "lein uberjar" followed by running the JVM explicitly with his own command line, so Lein

Re: fastest way to produce a PersistentList

2013-06-21 Thread David Nolen
The problem is the reversing of the list if you want to convert back to a list. You can avoid this but you have to use a custom mapping operation, continuation passing style, and a trampoline - it won't be fast. Another option is to realize that concrete types simply don't matter. What you're tryi

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Jim - FooBar();
Did you read the entire thread? both Jason and Leon (who originally posted) admit that this was the problem...Stuart even opened this issue: https://github.com/technomancy/leiningen/pull/1230 the very last post reads: I should follow up on this and clarify that core.matrix's esum is in fact a

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Michael Klishin
2013/6/21 Jim - FooBar(); > If you're using leiningen, add this entry to your project.clj and rerun > your benchmarks. > > :jvm-opts ^replace [] > Original post suggests the code is executed by building an uberjar running java -jar target/… so Leiningen default JVM options are not relevant. --

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Michael Klishin
2013/6/21 Colin Yates > Is it correct but simply non-idiomatic? It's not how defs are supposed to be used. It's like using fields for everything in Java even though you could use local variables for a lot of things, just because you can. def produces a shared (well, namespace-local) var. You p

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Jim - FooBar();
On 21/06/13 14:34, Colin Yates wrote: Is it correct but simply non-idiomatic? no no it's actually very *dangerous*...by doing this you're essentially introducing mutable global state in your program and Clojure is a language that strives hard to minimise mutable and especially global state!

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Colin Yates
Thanks Jim and David. David, can you expand on why it is incorrect? That is such a strong word. Is it correct but simply non-idiomatic? Also note that if I move the body out of the 'let' version of the array into another function passing in the array then the performance is the same as the 'def

Re: fastest way to produce a PersistentList

2013-06-21 Thread Jim - FooBar();
On 21/06/13 14:08, Philip Potter wrote: Your logic here is incorrect. To say "transients == fast, persistents == slow" is to grossly oversimplify things. Yes, I am indeed oversimplifying things but that doesn't change the fact that 'into' will be *slower* for collections that don't have transi

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread David Nolen
Using `def` like that is simply incorrect. `def` should always be at the top level unlike say Scheme. I would first remove all internal defs and then rerun your benchmarks. On Fri, Jun 21, 2013 at 8:36 AM, Colin Yates wrote: > Hi all, > > I am doing some (naive and trivial) performance tests b

Re: Function returns nil

2013-06-21 Thread Jay C
Cheers Jim, my problem is now solved using :when and then doing (apply str (fn)) to the return value. On Friday, 21 June 2013 14:08:19 UTC+1, Jim foo.bar wrote: > > 'for' accepts a :when clause which will get you even further :) > > Jim > > ps: it also accepts a :let clause if you find it usefu

Re: Function returns nil

2013-06-21 Thread Jay C
On Friday, 21 June 2013 11:17:44 UTC+1, Jay C wrote: > > Hi, I'm fairly new to Clojure and need help with a problem. The following > function always returns nil, whereas it should return the value of "line" > (which is not nil - I've tested). > > (defn find-line-in-output [regex] >> (wi

Re: Function returns nil

2013-06-21 Thread Jim - FooBar();
'for' accepts a :when clause which will get you even further :) Jim ps: it also accepts a :let clause if you find it useful On 21/06/13 14:06, Jay C wrote: Thanks for all the input. Using for as in Phillip's suggestion seems to have gotten me somewhere, but now the function returns during eve

Re: fastest way to produce a PersistentList

2013-06-21 Thread Philip Potter
On 21 June 2013 13:37, Jim - FooBar(); wrote: > Hi all, > > what do you guys do when you want to map a fn over a list but you want to > produce a list as the result (not vector or lazy-seq). What is the fastest > way of doing this? > > My first attempt was this: > > (->> (mapv f coll) > rseq ;;r

Re: Function returns nil

2013-06-21 Thread Jay C
Thanks for all the input. Using for as in Phillip's suggestion seems to have gotten me somewhere, but now the function returns during every iteration. What am I missing to have it only return when a conditional statement is satisfied? -- -- You received this message because you are subscribed

Re: Function returns nil

2013-06-21 Thread Jim - FooBar();
On 21/06/13 14:01, Neale Swinnerton wrote: I really wish there were support for this in clojure.core: both "dofor" and "domap" would be very useful. mapv is non-lazy, which gives you the semantics of a domap as long as you don't mind a vector over a sequence exactly! also, that

Re: Function returns nil

2013-06-21 Thread Neale Swinnerton
I really wish there were support for this in clojure.core: both "dofor" > and "domap" would be very useful. > mapv is non-lazy, which gives you the semantics of a domap as long as you don't mind a vector over a sequence -- -- You received this message because you are subscribed to the Google Gr

Re: Function returns nil

2013-06-21 Thread Jim - FooBar();
aaa yes, of course! :) Jim On 21/06/13 13:47, John D. Hume wrote: If you use for, which is lazy, wrap it in a doall to force it to do its work before with-open closes your reader. On Jun 21, 2013 6:52 AM, "Jim" > wrote: Only use 'doseq' when you don't ca

Re: fastest way to produce a PersistentList

2013-06-21 Thread Jim - FooBar();
On 21/06/13 13:51, Cedric Greevey wrote: (apply list the-seq) seems to work, but (list* the-seq), oddly, does not. In most contexts, PersistentLists and seqs are interchangeable. Are you needing to use the seq as a stack after constructing it in some manner that produces a seq? No, my requi

Re: Function returns nil

2013-06-21 Thread Phillip Lord
I don't think that will work. for is lazy, so by the time it evals, the code will have dropped out of the scope of with-open. So: (defn read-stuff-2 [] (with-open [r (java.io.BufferedReader. (java.io.FileReader. "myfile.txt"))] (for [line (line-seq r)] line))) fail

Re: (clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Jim - FooBar();
a start would be to set *warn-on-reflection* & *unchecked-math* to true...I think you're not properly type-hinting your 'aget' calls. areduce is the fastest way to sum up an array of primitives given that there are no reflective calls. This takes just over 19 ms on my humble machine and don't f

Re: fastest way to produce a PersistentList

2013-06-21 Thread Cedric Greevey
(apply list the-seq) seems to work, but (list* the-seq), oddly, does not. In most contexts, PersistentLists and seqs are interchangeable. Are you needing to use the seq as a stack after constructing it in some manner that produces a seq? On Fri, Jun 21, 2013 at 8:37 AM, Jim - FooBar(); wrote:

Re: Function returns nil

2013-06-21 Thread John D. Hume
If you use for, which is lazy, wrap it in a doall to force it to do its work before with-open closes your reader. On Jun 21, 2013 6:52 AM, "Jim" wrote: > Only use 'doseq' when you don't care about the reuturn value. In other > words only for side-effect-y code. Use 'for' instead... > > Jim > >

fastest way to produce a PersistentList

2013-06-21 Thread Jim - FooBar();
Hi all, what do you guys do when you want to map a fn over a list but you want to produce a list as the result (not vector or lazy-seq). What is the fastest way of doing this? My first attempt was this: (->> (mapv f coll) rseq ;;reverse fast (into '())) but I quickly realised that lists

(clojure 1.5.1) Weird performance results when using let versus def for variable

2013-06-21 Thread Colin Yates
Hi all, I am doing some (naive and trivial) performance tests before deciding whether and how to use Clojure for some performance critical number cruching and I wanted help understanding the behaviour. I am defining an array inside a function, setting the contents to be 1 and then summing them

Re: Function returns nil

2013-06-21 Thread Alan Forrester
On 21 June 2013 11:17, Jay C wrote: > Hi, I'm fairly new to Clojure and need help with a problem. The following > function always returns nil, whereas it should return the value of "line" > (which is not nil - I've tested). > >> (defn find-line-in-output [regex] >> (with-open [rdr (reader

Re: Function returns nil

2013-06-21 Thread Jim
Only use 'doseq' when you don't care about the reuturn value. In other words only for side-effect-y code. Use 'for' instead... Jim On 21/06/13 11:17, Jay C wrote: Hi, I'm fairly new to Clojure and need help with a problem. The following function always returns nil, whereas it should return

Function returns nil

2013-06-21 Thread Jay C
Hi, I'm fairly new to Clojure and need help with a problem. The following function always returns nil, whereas it should return the value of "line" (which is not nil - I've tested). (defn find-line-in-output [regex] > (with-open [rdr (reader belarc-output-filepath)] > (do