Re: every-nth
Thanks Meikel for such an insightfull feedback. Its hard to imagine so much thought goes into writing trivial looking functions. Sunil. On Thu, Nov 25, 2010 at 1:00 PM, Meikel Brandmeyer wrote: > Hi, > > On 25 Nov., 05:06, Sunil S Nandihalli > wrote: > > > (defn every-nth [n coll] > > (letfn [(evn [cn s] > > (when s > > (if (= cn 1) > > (lazy-seq (cons (first s) (evn n (next s > > (evn (dec cn) (next s)] > > (evn n coll))) > > Since you want to learn how lazy-seq works here some feedback. > > * Make the lazy-seq the outer-most part of your function > to allow as much laziness as possible. There other > opinions out there about the placement of lazy-seq, but > there are also a lot of people complaining about eg. a > filter doing an expensive predicate call because the > input sequence is not as lazy as it could be. By placing > lazy-seq outermost you leave the decision to them when > to realize an element. > > * You should call seq on coll before passing it to evn. > Think of [] as input. It will be truthy in the when check > and we do some unnecessary loop, where we actually could > short circuit. > > * Don't call next in the true branch of the if. It realises > an element of the input sequence where it is not > necessary. Use rest. > > * Don't call evn in the false branch of the if. It will be > true recursion and might blow the stack for large n. You > Use recur. > > Here is the version I would write in this case. > > (defn every-nth > [n coll] > (let [step (fn step [s] > (lazy-seq > (loop [s (seq s) >cnt n] > (when s > (if (= cnt 1) > (cons (first s) (step (rest s))) > (recur (next s) (dec cnt)))] >(step coll))) > > * lazy-seq is outer-most. > * The recur is turned into a loop to avoid stacking lazy-seq > on lazy-seq. > * The input sequence is only realised inside the lazy-seq. > Also in the true branch we use rest to defer realisation > of the next seq step. In the false branch we use next, > because we need the value anyway. > > As a rule of thumb: write your generating function with > "normal" recursion first. Then simply wrap a lazy-seq > around it. > > Hope that helps. > > Sincerely > Meikel > > -- > 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 from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ANN: ClojureQL 1.0.0 finally released as public beta
On Nov 25, 8:28 am, LauJensen wrote: > ClojureQL: > > (defn oracle-take > [tname limit] > (-> (table (str "(SELECT ROW_NUMBER() OVER (ORDER BY key ASC)" > " AS rownumber,columns" > " FROM " (to-tablename tname) ")")) > (select (where (<= :rownumber limit))) > (project ["*"]))) > > (to-sql (oracle-table :users 10)) > ["SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY key ASC) AS > rownumber,columns FROM users) WHERE (rownumber <= ?)" 10] > > From the outset it has been my ambition to make ClojureQL extremely > composable and as far as possible allow users to directly insert > strings into the query to allow for backend specific customization. > The entire design-plan of this customization is not yet thought out so > input is welcomed. To me, flexibility and leaving with the power to > the user is the key to wide adoption across various backends. > My experience would agree with this assumption. I looked at the original Clojure QL for use with H2 but didn't want to put in the effort of writing a H2 driver to TEST a library that I may want to use. If I can play with the library and I like it, its then no problem at all to write some small workarounds for the non-standard behaviour of the database I'm using. Ideally though, it would be nice if workarounds for various databases were added to the library as the appear - so in this example I can call oracle-take without having to write it myself. Saul -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ANN: ClojureQL 1.0.0 finally released as public beta
Database dialect independence may be a useful thing to have for ClojureQL, so that users can work based on intent rather than syntax. Consider something like this (just an idea): ;; by default in ClojureQL ;; make-sql92-handler is a factory fn for a protocol (def *dialect-handler* (make-sql92-handler)) ;; somewhere in an app (binding [cql/*dialect-handler* (make-oracle-handler)] ;; do usual stuff ..) This kind of a structure may allow others to write dialect handlers for different databases as contrib and ClojureQL can stay as the composable core. Databases that do not support all of SQL-92 constructs can throw a FeatureNotAvailable exception when an unsupported intent is asked for. Regards, Shantanu On Nov 25, 12:28 pm, LauJensen wrote: > Hi Brenton, > > Yes the OFFSET/LIMIT syntax differs from backend to backend. However > in some instances (like MySQL/PostgreSQL) they have ensured > compatability so that the same statement will run on several DBs > although the syntax might not be considered 'native'. For something > like Oracle there actually isnt a syntax for LIMIT so instead they do > something like > > SELECT * FROM ( > SELECT > ROW_NUMBER() OVER (ORDER BY key ASC) AS rownumber, > columns > FROM tablename > ) > WHERE rownumber <= n > > But as you can see it would be trivial to express this in terms of > ClojureQL: > > (defn oracle-take > [tname limit] > (-> (table (str "(SELECT ROW_NUMBER() OVER (ORDER BY key ASC)" > " AS rownumber,columns" > " FROM " (to-tablename tname) ")")) > (select (where (<= :rownumber limit))) > (project ["*"]))) > > (to-sql (oracle-table :users 10)) > ["SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY key ASC) AS > rownumber,columns FROM users) WHERE (rownumber <= ?)" 10] > > From the outset it has been my ambition to make ClojureQL extremely > composable and as far as possible allow users to directly insert > strings into the query to allow for backend specific customization. > The entire design-plan of this customization is not yet thought out so > input is welcomed. To me, flexibility and leaving with the power to > the user is the key to wide adoption across various backends. > > Lau > > On Nov 24, 11:42 pm, Brenton wrote: > > > > > > > > > > ClojureQL does not take the backend in to account. This is the one > > > feature from the old CQL that I didn't want to carry over because it > > > would be impossible for me to cater to all backends. If you hit > > > specific problems, let me know and I'll see what we can do. > > > > We adhere to SQL92 and test everything on MySQL and Postgres. If > > > you're in a situation where thats not good enough, its always possible > > > to supply part of your expression as a string. > > > Lau > > > Off the top of my head, I know that the LIMIT syntax for SQL Server is > > totally different. A lot of the apps that I write end up getting > > deployed using Oracle and SQL Server. If you plan for CQL to be widely > > used I think you will need to take backends into account. You don't > > need to implement them all yourself, but you should provide a way so > > that others can implement them when they need to. > > > Brenton -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: memcache, redis connection pooling
On Nov 24, 9:12 pm, Wilson MacGyver wrote: > I highly recommend jedis for redis java lib. It supports connection > pooling, pub/sub. > and works with the 2.0 protocol. > > https://github.com/xetorthio/jedis > Many thanks for that. Now it looks like the best way forward is to wrap existing Java libraries. > Any reason why you want to use both memcached and redis at the same time? > redis is basically memcached++, with collection/queue support as values, > and persist the data to disk periodically. I'm not sure what memcached > fits in here if you already have redis. > I started with a general library for my own use copied from existing code: (https://github.com/alienscience/cache-dot-clj). That has evolved into a hobby project for general use. The idea is that somebody can start with an in-process cache and move to other systems as the application scales without changing the Clojure API. I take your point and will go with redis support first though. Saul -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: every-nth
Hi, On 25 Nov., 09:40, Sunil S Nandihalli wrote: > Thanks Meikel for such an insightful feedback. Its hard to imagine so much > thought goes into writing trivial looking functions. There are several interpretations of the word "trivial." One is "easy" or "simple" (where one could dispute whether "simple" is always "easy"). Another one is the "mathematical" trivial. When a mathematician says, that something "is trivial", this does not mean, that this something is "easy". But simply well understood. The understanding itself is maybe a PhD, but was already done by someone. Here it is basically the same: this issues re-occur every time you power-up lazy-seq. Then you have to understand the implications once. >From this you derive some "rules" which let you operate in auto-pilot mode when working on a similar problems in the future. The catalogue of rules you end up with is then called "best practices." Best practices are frowned upon. But this is stupid. It means one repeats the same mistakes again and again, which others did before. So - as a beginner - follow best practises. If you deviate, give a good reason for the deviation. But understand the practises as you dive in further into the language. Why are they the way they are? Are they maybe obsolete? &c. The art is to turn off the autopilot, before crashing into the cliff. :) Oh! And no one claimed that things are "easy". ;) Sincerely Meikel PS: This is also true for other fields. Take for example Joseki in Go (the game, not the prog. language). Joseki are sequences of moves developed by professional players over years. Deviating from such a sequence is likely to be punished in some way. So you should know what you are doing. Nevertheless Joseki are always refined, obsoleted, modified as time advances and play styles change. Best practises and Joseki are tools. Use them well, and they will serve you. Use them blindly, and they will cut off your foot. -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: *warn-on-reflection* broken in 1.2?
Hi Ken, I repeated your commands in IDE REPL and do not see anything in *out* or *err*. Probably this bug is not as simple as it looks :) On Wed, Nov 24, 2010 at 9:39 PM, Ken Wesson wrote: > On Wed, Nov 24, 2010 at 11:18 AM, Sergey Didenko > wrote: > > Here is the Enclojure ticket - > > > https://www.assembla.com/spaces/enclojure/tickets/83-rebinding-of-vars-does-not-work-in-ide-repl--e-g--*print-meta*--*warn-on-reflection* > > It seems to me that *warn-on-reflection* is working, but the > reflection warnings are being sent to *out* and *out* isn't being > flushed when they are; sending a println to *out* with e.g. (future > (println "foo")) forces all undisplayed reflection warnings to come > vomiting forth. > > user=> (set! *warn-on-reflection* true) > true > user=> (defn foo [x] (.length x)) > #'user/foo > (nothing else in Repl, nothing in *out*) > user=> (println "foo") > foo > nil > (nothing else in Repl, nothing in *out*) > user=> (future (println "foo")) > # > user=> > (and over in *out*:) > Reflection warning, NO_SOURCE_PATH:9 - reference to field length can't > be resolved. > foo > > -- > 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 from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
clojure 1.3 alpha3 and swank
Hello Everybody, I would like to have a go at 1.3 alpha3 .. but having a lot of trouble with the swank.. can somebody suggest me a version of swank-clojure that has worked for them along with 1.3 alpha3 Thanks, Sunil. -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: priority queue for scheduling events in the future
Ken, Thanks for putting this together. As a newbie, this gives me a lot to mull over. Can you explain the convention of a * at the end of a function name? On Nov 24, 12:39 am, Ken Wesson wrote: > On Tue, Nov 23, 2010 at 11:45 PM, HiHeelHottie wrote: > > > Does anybody know of an implementation for a priority queue that can > > be used for scheduling events in the future? I would like to put a > > map associated with a timestamp into the queue and be able to pull out > > all maps at or before a given time in order. > > That's something you can slap together in a few minutes. > > user=> (def sched (ref (sorted-map ))) > > (def jobber (agent nil)) > > (defn schedule-job!* [time runnable] > (dosync > (alter sched assoc time runnable))) > > (defn- next-job-time [] > (key (first @sched))) > > (defn- do-next-job! [] > (dosync > (when-let [[k v] (first @sched)] > (alter sched dissoc k) > (send-off jobber (fn [_] (v) nil) > > (defn- job-runner [] > (loop [] > (if-not (empty? @sched) > (if (> (System/currentTimeMillis) (next-job-time)) > (do-next-job!))) > (Thread/sleep 10) > (recur))) > > (doto (Thread. job-runner) > (.setDaemon true) > (.start)) > > (defn schedule-job-after!* [delay runnable] > (schedule-job!* (+ (System/currentTimeMillis) delay) runnable)) > > (defmacro schedule-job! [time & body] > `(schedule-job!* ~time (fn [] ~...@body))) > > (defmacro schedule-job-after! [delay & body] > `(schedule-job-after!* ~delay (fn [] ~...@body))) > > (schedule-job-after! 1 > (println "foo")) > > (schedule-job-after! 3 > (println "bar")) > > (schedule-job-after! 2 > (println "baz")) > {1290576825292 > #, > 1290576835296 > #, > 1290576845294 > #} > user=> > foo > baz > bar > > The last three lines will print at ten-second intervals and may not > appear in the same console as your user=> prompt depending on how your > REPL/IDE handles asynchronous printlns. With NetBeans they'll appear > in *out* instead of Repl (for sure) and in slime in the inferior-lisp > buffer (I think). > > This could be reworked to use java.util.Date but the basic > architecture would remain the same. > > You'll need to (shutdown-agents) during shutdown of any application > where you use this if you don't want the JVM to linger as a zombie > process. -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: priority queue for scheduling events in the future
2010/11/25 HiHeelHottie > > Ken, > > Thanks for putting this together. As a newbie, this gives me a lot to > mull over. Can you explain the convention of a * at the end of a > function name? > Hi, it's a common convention when you have both a macro and a function, the macro generally delegating as quick as possible the real work to its supporting function. The function is for composability, etc. The macro is for syntactic sugar. HTH, -- Laurent -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: a macro to debug the let form
I just tried to re-write with-seperator without using the symbol-macros from macro-utils and it seems to work fine .. On Thu, Nov 25, 2010 at 1:27 PM, Sunil S Nandihalli < sunil.nandiha...@gmail.com> wrote: > Hello everybody, > I was trying to learn to write clojure macros and the code is posted here > in the following link > https://gist.github.com/715047 > There are basically three macros > > 1. with-seperator - a zero argument macro and is supposed to just draw a > line to indicate beginning and ending of the execution of the body. > > 2. display-local-bindings - a function to print the local bindings in the > lexical scope where the macro is called > > 3. letd - a helper macro to print the values of all the bindings followed > by printing of the local bindings using display-local-bindings > > The letd macro as posted works as expected but without the seperation line > . It is supposed to print the seperation line when I uncomment line 14 and > comment line 15 but some how this is causing the &env variable automatically > passed with every macro to be nil display-local-binding .. but the I feel it > is not the case .. can somebody help me understand this. This was an > exercise to learn macro writing than to writing a letd debugging helper > function.. > > Thanks, > Sunil. > -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: distinguishing the symbols generated by gensym from those that were part of the code
thanks Ken Sunil On Thu, Nov 25, 2010 at 11:41 AM, Ken Wesson wrote: > On Thu, Nov 25, 2010 at 1:06 AM, Sunil S Nandihalli > wrote: > > Hello everybody, > > Is there a function which can tell me if a particular symbol was > generated > > by gensym or was present in the code? > > Sunil. > > I don't think so. > > On the other hand: > > (def my-gensyms (atom #{})) > > (defn my-gensym > ([] >(let [s (gensym)] > (swap! my-gensyms conj s) > s)) > ([prefix] >(let [s (gensym prefix)] > (swap! my-gensyms conj s) > s))) > > (defn is-my-gensym? [s] > (contains? @my-gensyms s)) > > will let you create gensyms with my-gensym and later check is a symbol > was created with is-my-gensym?. > > Warning: a hashset grows in memory for every gensym created with my-gensym. > > -- > 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 from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: discussing Clojure with non-CS types
On Nov 24, 2010, at 7:47 PM, CuppoJava wrote: > The other reason is that Clojure emphasizes functional programming and > discourages mutation. This is fine, as I believe well-written code is > usually functional anyway. The problem is that bad code is usually > easier to write in an imperative way than a functional way, and the > ability to write bad code is important I think. It's usually a lot > quicker to whip up a mutative hack than think through the problem and > factor out components and be functional about the whole thing. And > usually, in the very very early stages of programming something, when > you don't clearly know what it is you're programming, it's nice to be > able to whip out a quick and dirty mutative hack. And then make it > nice and elegant and functional later on, but Clojure makes doing that > difficult for me. I think this is a matter of mindset. Like learning a new human language: it takes a while to begin thinking in the new language. Until then, you have to think in your native language and translate on-the-fly, which makes certain things awkward to express. Similarly with functional programming: once you begin to "think functionally", the functional solutions are the ones that come to mind first, rather than the imperative ones. -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: discussing Clojure with non-CS types
On Wed, Nov 24, 2010 at 8:47 PM, CuppoJava wrote: > > Numerical software involves a lot of array indexing, and loops, and > not much else. Clojure's functional data structures are elegant, but > are not quite fast enough for heavy numerical processing so I still > need to use native arrays. And if all I'm using is native arrays, the > java syntax for arrays is much easier on the eyes than a bunch of > nested s-exps. > > -Patrick I find it curious that noone's created a library of useful macros for primitive array manipulation. Certainly the foundation for it is there. David -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ANN: ClojureQL 1.0.0 finally released as public beta
Allowing implementation-specific and optimized SQL only via strings and not via a mechanism within ClojureQL allows its use in specific applications but effectively prevents use for libraries and frameworks. Indirect use of ClojureQL could yield unacceptable performance with no elegant fix. On Nov 24, 11:28 pm, LauJensen wrote: > Hi Brenton, > > Yes the OFFSET/LIMIT syntax differs from backend to backend. However > in some instances (like MySQL/PostgreSQL) they have ensured > compatability so that the same statement will run on several DBs > although the syntax might not be considered 'native'. For something > like Oracle there actually isnt a syntax for LIMIT so instead they do > something like > > SELECT * FROM ( > SELECT > ROW_NUMBER() OVER (ORDER BY key ASC) AS rownumber, > columns > FROM tablename > ) > WHERE rownumber <= n > > But as you can see it would be trivial to express this in terms of > ClojureQL: > > (defn oracle-take > [tname limit] > (-> (table (str "(SELECT ROW_NUMBER() OVER (ORDER BY key ASC)" > " AS rownumber,columns" > " FROM " (to-tablename tname) ")")) > (select (where (<= :rownumber limit))) > (project ["*"]))) > > (to-sql (oracle-table :users 10)) > ["SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY key ASC) AS > rownumber,columns FROM users) WHERE (rownumber <= ?)" 10] > > From the outset it has been my ambition to make ClojureQL extremely > composable and as far as possible allow users to directly insert > strings into the query to allow for backend specific customization. > The entire design-plan of this customization is not yet thought out so > input is welcomed. To me, flexibility and leaving with the power to > the user is the key to wide adoption across various backends. > > Lau > > On Nov 24, 11:42 pm, Brenton wrote: > > > > > > ClojureQL does not take the backend in to account. This is the one > > > feature from the old CQL that I didn't want to carry over because it > > > would be impossible for me to cater to all backends. If you hit > > > specific problems, let me know and I'll see what we can do. > > > > We adhere to SQL92 and test everything on MySQL and Postgres. If > > > you're in a situation where thats not good enough, its always possible > > > to supply part of your expression as a string. > > > Lau > > > Off the top of my head, I know that the LIMIT syntax for SQL Server is > > totally different. A lot of the apps that I write end up getting > > deployed using Oracle and SQL Server. If you plan for CQL to be widely > > used I think you will need to take backends into account. You don't > > need to implement them all yourself, but you should provide a way so > > that others can implement them when they need to. > > > Brenton -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ANN: ClojureQL 1.0.0 finally released as public beta
There's some valuable food for thought in this thread. My major problem with support various backends is the amount of work thats involved. Every single backend needs to play nice with all the primitives defined in Relational Algebra and that are implemented in ClojureQL. I believe that the SQL92 standard takes us very far down the middle road, but I realize that it wont take us all the way. ClojureQL is actually two sets of primitives. Firstly its the RA stuf (select, project, join, etc) and then internally there is a number of primitives defined which help translate the RTable record into a query string. At the highest level only two functions need to be changed in order to effectively replace the entire compiler: to-sql and build- join. These call each other to build complex queries. If these were supplied as plugins, I think most backends could be fully supported simply by providing these two methods. They are not trivial however, so anybody interested in contributing should check out whats already there. Still thinking this through but the input is appreciated! Lau On Nov 25, 6:14 pm, rickmode wrote: > Allowing implementation-specific and optimized SQL only via strings > and not via a mechanism within ClojureQL allows its use in specific > applications but effectively prevents use for libraries and > frameworks. Indirect use of ClojureQL could yield unacceptable > performance with no elegant fix. > > On Nov 24, 11:28 pm, LauJensen wrote: > > > Hi Brenton, > > > Yes the OFFSET/LIMIT syntax differs from backend to backend. However > > in some instances (like MySQL/PostgreSQL) they have ensured > > compatability so that the same statement will run on several DBs > > although the syntax might not be considered 'native'. For something > > like Oracle there actually isnt a syntax for LIMIT so instead they do > > something like > > > SELECT * FROM ( > > SELECT > > ROW_NUMBER() OVER (ORDER BY key ASC) AS rownumber, > > columns > > FROM tablename > > ) > > WHERE rownumber <= n > > > But as you can see it would be trivial to express this in terms of > > ClojureQL: > > > (defn oracle-take > > [tname limit] > > (-> (table (str "(SELECT ROW_NUMBER() OVER (ORDER BY key ASC)" > > " AS rownumber,columns" > > " FROM " (to-tablename tname) ")")) > > (select (where (<= :rownumber limit))) > > (project ["*"]))) > > > (to-sql (oracle-table :users 10)) > > ["SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY key ASC) AS > > rownumber,columns FROM users) WHERE (rownumber <= ?)" 10] > > > From the outset it has been my ambition to make ClojureQL extremely > > composable and as far as possible allow users to directly insert > > strings into the query to allow for backend specific customization. > > The entire design-plan of this customization is not yet thought out so > > input is welcomed. To me, flexibility and leaving with the power to > > the user is the key to wide adoption across various backends. > > > Lau > > > On Nov 24, 11:42 pm, Brenton wrote: > > > > > ClojureQL does not take the backend in to account. This is the one > > > > feature from the old CQL that I didn't want to carry over because it > > > > would be impossible for me to cater to all backends. If you hit > > > > specific problems, let me know and I'll see what we can do. > > > > > We adhere to SQL92 and test everything on MySQL and Postgres. If > > > > you're in a situation where thats not good enough, its always possible > > > > to supply part of your expression as a string. > > > > Lau > > > > Off the top of my head, I know that the LIMIT syntax for SQL Server is > > > totally different. A lot of the apps that I write end up getting > > > deployed using Oracle and SQL Server. If you plan for CQL to be widely > > > used I think you will need to take backends into account. You don't > > > need to implement them all yourself, but you should provide a way so > > > that others can implement them when they need to. > > > > Brenton -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Enclojure for Clojure 1.2
Sorry to bother you, but where do I download Enclojure 1.4? Could you please give me a URL? Thanks. On Nov 18, 3:28 am, Ken Wesson wrote: > On Wed, Nov 17, 2010 at 3:54 PM, Harrison Maseko wrote: > > DoesEnclojuresupport Clojure1.2yet? > > Yes. I've been using Clojure1.2/Enclojure1.4/NB 6.9.1 for the past > few weeks myself. -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
lein compile for clj-time problem..
Hi Steve, I am new on clojure and testing cascalog . I needed clj-time library .. I downloaded its files from git and cd clj-time than type lein deps && lein compile.. its creating classes and lib directory but nothing inside. So i am miising something.. what is the proper way to compile clj-time to use from clj like : (use 'clj-time.core) ? need help :) thanks On Oct 11, 3:57 pm, "Stephen C. Gilardi" wrote: > On Oct 10, 2010, at 3:05 PM, HiHeelHottie wrote: > > > I'm runningleinswank and using slime-connect from emacs. When I use > >leincompileafter making changes to a method, they don't appear to > > get picked up unless I bring downleinswank, bring it up again, slime- > > connect, etc. > > > Is there a way to getleincompilechanges to be picked up by an > > already runningleinswank? Also, would be interested to hear about > > the workflow others are using withleinto develop a java class. > > I believe you're seeing the effects of the Java behavior that (at least by > default) a class loader will only load a given ".class" file once in the > lifetime of a given JVM. Its contents are cached and the cache is used for > all further reference to the classes defined in it. > > To be more dynamic than that you can arrange for your generated class to call > out to Clojure functions to do some or all of its actual work. New versions > of the Clojure functions you're working on can be loaded into a > runningleinswank as many times as you'd like from ".clj" files. > > --Steve -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: lein compile for clj-time problem..
If you're using leiningen, you can create a new project with 'lein new'. In that project, you'll find a file called 'project.clj'. Open that file, and under :dependencies, add this to the vector: [clj-time "0.2.0-SNAPSHOT"] Save the file and then run 'lein deps'. After that, running lein repl/ swank will put it on the classpath. However, if you just want to create a jar out of clj-time that you're going to put on the classpath manually for some reason, you can just do 'lein jar' and it should jar it right up. There is no reason to compile it. On Nov 25, 9:05 am, Prometheus wrote: > Hi Steve, > > I am new on clojure and testing cascalog . I needed clj-time > library .. > > I downloaded its files from git and cd clj-time than type lein > deps && lein compile.. > > its creating classes and lib directory but nothing inside. So i am > miising something.. > > what is the proper way to compile clj-time to use from clj > like : (use 'clj-time.core) ? > > need help :) > > thanks > > On Oct 11, 3:57 pm, "Stephen C. Gilardi" wrote: > > > > > On Oct 10, 2010, at 3:05 PM, HiHeelHottie wrote: > > > > I'm runningleinswank and using slime-connect from emacs. When I use > > >leincompileafter making changes to a method, they don't appear to > > > get picked up unless I bring downleinswank, bring it up again, slime- > > > connect, etc. > > > > Is there a way to getleincompilechanges to be picked up by an > > > already runningleinswank? Also, would be interested to hear about > > > the workflow others are using withleinto develop a java class. > > > I believe you're seeing the effects of the Java behavior that (at least by > > default) a class loader will only load a given ".class" file once in the > > lifetime of a given JVM. Its contents are cached and the cache is used for > > all further reference to the classes defined in it. > > > To be more dynamic than that you can arrange for your generated class to > > call out to Clojure functions to do some or all of its actual work. New > > versions of the Clojure functions you're working on can be loaded into a > > runningleinswank as many times as you'd like from ".clj" files. > > > --Steve -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Porting libraries to ClojureCLR
On Nov 24, 1:24 pm, Ken Wesson wrote: > I gave some thought to the Integer vs. Int32 issue. > > I think what would help here is a way to alias classes when :importing them. > > It would require tweaking the ns macro and possibly parts of the > runtime. The outcome would be to allow something like > > (ns foo > (:import (java.util.concurrent > AtomicBoolean (ConcurrentHashMap :as CHM) AtomicInteger))) > > (defn make-default-chm [] > (CHM. 12 12 12)) > > ... > > Handy so far for abbreviating some longer classnames, and the > application to CLR portability is apparent: > > (ns foo > (:import (System (Int32 :as Integer > > In theory, you'd just add this import to make code full of ^Integer > hints compile under ClojureCLR. You'd still need two versions of the > source file though, a CLR version with the import and a JVM version > without. > > But then why not go even further and have the ns macro able to tell > what platform it's on? > > (ns foo > (:import-jvm (package1.package2 BarBaz as BBaz)) > (:import-clr (Package3.Package4.BooBaz as BBaz))) > Regarding enhancements to ns/import/etc.: Not to speak for Rich, but he has in the past been resistant to modifications to these elements to support CLR vs JVM. Regarding Int32 vs Integer: They are really not equivalent. Int32 is equivalent to Integer/TYPE or a ^int type hint, not to java.lang.Integer. There is no CLR equivalent to the JVM Integer, Long, Number, etc., a fact which is currently cause me no end of problems as I try to incorporate into ClojureCLR all the compiler work RIch &co have done for 1.3. In fact, with 1.3, you will not be able to provide Int32 type hints on fn args or return values. CLojureJVM in 1.3 disallows primitive type hints in these places, wiping out ^int (JVM) and ^Int32 (CLR). You might find this discussion relevant: http://groups.google.com/group/clojure-dev/browse_thread/thread/6f9c9b7f36ae3134 -David -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Enclojure for Clojure 1.2
On Thu, Nov 25, 2010 at 3:51 PM, Harrison Maseko wrote: > Sorry to bother you, but where do I download Enclojure 1.4? Could you > please give me a URL? Actually you should be able to select it and install it from inside NB 6.9.1's package manager. -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
problems using javax.sound.midi from clojure on windows
Hello clojure group, First off, everything I'm about to say only applies to Windows. The code in question works fine (for me anyhow) on Linux, and I haven't tried it on OSX. Here's some Java code to get the first channel out of the default midi synth. Assume the appropriate things are imported from javax.sound.midi: Synthesizer synth = MidiSystem.getSynthesizer(); MidiChannel c0 = synth.getChannels()[0]; In clojure: (with-open [synth (MidiSystem/getSynthesizer)] (first (.getChannels synth))) And that works fine, except that it closes the synthesizer. For my purposes I have to keep the synth around and open, so I do something like this: (def synth (MidiSystem/getSynthesizer)) ...later... (some stuff (first (.getChannels synth))) At which point I get the following exception: java.lang.IllegalArgumentException: Can't call public method of non- public class: public javax.sound.midi.MidiChannel[] com.sun.media.sound.AbstractPlayer.getChannels() synth is reported as being of type com.sun.media.sound.MixerSynth in every case. I thought, hey, maybe it's a concurrency issue, since in the code where this originally cropped up getChannels was being called by an agent and calling stuff on the synth obviously has side effects. But unless I'm mistaken, doing (do (def synth (MidiSystem/getSynthesizer)) (.getChannels synth)) at the REPL should restrict it to happening sequentially in one thread, and I still get the same exception. Help? /brian -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
using symbol macros from clojure.contrib.macro-utils does not seem to bind the &env environment variable correctly in the nested macro calls
Hello everybody, I am not sure if this is the expected behaviour .. or I am using it incorrectly .. The code is pasted at https://gist.github.com/716293 . (ns symbol-macro-problem (:require [clojure.contrib.macro-utils :as m])) (defmacro sym-macro [& body] `(m/symbol-macrolet [begin :begin end :end] (m/with-symbol-macros (println begin) ~...@body (println end (defmacro display-local-bindings [] `(do ~@(map (fn [x#] (list 'println [`'~x# x#])) (keys &env (sym-macro (let [x 10] (display-local-bindings))) the above form is not passing the correct &env variable to the nested macros .. It is turning out to be nil. The above code just prints :begin :end while (let [x 10] (display-local-bindings)) prints [x 10] I was expecting the code (sym-macro (let [x 10] (display-local-bindings))) to print :begin [x 10] :end but this is not happening since the &env variable that is being passed to (display-local-bindings) is nil when called inside a sym-macro can somebody help me understand this. Thanks, Sunil. -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: using symbol macros from clojure.contrib.macro-utils does not seem to bind the &env environment variable correctly in the nested macro calls
I just realized that we don't need to use the with-symbol-macros when using symbol-macrolet .. but the problem persists all the same.. I have modified the gist to reflect this change.. Sunil. On Fri, Nov 26, 2010 at 10:35 AM, Sunil S Nandihalli < sunil.nandiha...@gmail.com> wrote: > Hello everybody, > I am not sure if this is the expected behaviour .. or I am using it > incorrectly .. The code is pasted at > https://gist.github.com/716293 . > > (ns symbol-macro-problem > > (:require [clojure.contrib.macro-utils :as m])) > > > > (defmacro sym-macro [& body] > > `(m/symbol-macrolet [begin :begin > >end :end] > > (m/with-symbol-macros > > (println begin) > > ~...@body > > (println end > > > > (defmacro display-local-bindings [] > > `(do ~@(map (fn [x#] (list 'println [`'~x# x#])) (keys &env > > > > (sym-macro > > (let [x 10] > >(display-local-bindings))) > > > the above form is not passing the correct &env variable to the nested > macros .. It is turning out to be nil. The above code just prints > > :begin > :end > > while > > (let [x 10] > (display-local-bindings)) > > prints > > [x 10] > > I was expecting the code > > (sym-macro > (let [x 10] >(display-local-bindings))) > > to print > > :begin > [x 10] > :end > > but this is not happening since the &env variable that is being passed to > (display-local-bindings) is nil when called inside a sym-macro > can somebody help me understand this. > > Thanks, > Sunil. > -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: discussing Clojure with non-CS types
Curious if anyone has given Lush a try here? http://lush.sourceforge.net/ It's essentially a lisp-like way to write C, with lots of integration with libraries to do numerical computing, machine learning, etc. Carson On Nov 24, 5:47 pm, CuppoJava wrote: > I must admit that even though I love Clojure and use it daily for many > things, I don't like using it very much for my research (machine > learning) which involves a lot of number crunching. > > The main reasons being: > > Numerical software involves a lot of array indexing, and loops, and > not much else. Clojure's functional data structures are elegant, but > are not quite fast enough for heavy numerical processing so I still > need to use native arrays. And if all I'm using is native arrays, the > java syntax for arrays is much easier on the eyes than a bunch of > nested s-exps. > > The other reason is that Clojure emphasizes functional programming and > discourages mutation. This is fine, as I believe well-written code is > usually functional anyway. The problem is that bad code is usually > easier to write in an imperative way than a functional way, and the > ability to write bad code is important I think. It's usually a lot > quicker to whip up a mutative hack than think through the problem and > factor out components and be functional about the whole thing. And > usually, in the very very early stages of programming something, when > you don't clearly know what it is you're programming, it's nice to be > able to whip out a quick and dirty mutative hack. And then make it > nice and elegant and functional later on, but Clojure makes doing that > difficult for me. > > -Patrick > > On Nov 24, 3:12 pm, Mike Meyer > 620...@mired.org> wrote: > > On Wed, 24 Nov 2010 09:20:49 -0800 (PST) > > > cej38 wrote: > > > I am a physicist. I have been using Clojure full time for the last > > > year and a half. The reasons that Rich (and most other Clojure > > > evangelists) give for using Clojure, are all nice and good, but they > > > point to what computer scientists think about. If you want scientists > > > and engineers to think about switching to Clojure, you need to talk to > > > the concerns that they have. Of course, there is some overlap. > > > The thing is, I'm not sure it's the best choice for such people. At > > least, not yet. The LISP-like syntax means you have to explain the > > code if you publish it, a problem that some alternatives - which have > > most of your advantages - don't have. Look at Python, a descendant of > > ABC, which was designed for teaching/prototyping. It's been described > > as "executable pseudo-code". > > > > Here are some reasons that I would give for using clojure: > > > 1. Most data analysis gets done by writing little programs that do > > > certain tasks. When writing in Fortran I more or less have to write a > > > new program to do each task. In clojure, I might have to write a new > > > function, but I keep finding that functions that I wrote before, will > > > help with these new problems. Code re-use is much higher! Less time > > > coding. > > > I think this says more about your coding style than Clojure. I find > > that true in most of the languages I write in, but I structure > > programs to make it so. > > > > 2. fewer number of parameters that need to be passed into > > > subroutines. When writing fortran/C programs, you not only need to > > > pass in the data, but you also need to pass in parameters that > > > describe the data. In clojure, you usually only pass in the data. > > > The same is true of Python, and most modern languages. Clojure's data > > structures - which make this possible - have been around in other > > languages for quite a while now. > > > > 3. (related to 2) Everything is a function, thus, as long as the > > > inputs and outputs are the same, you can change the internals at > > > will. This makes it super easy to try rewriting code to make it run > > > faster. > > > The same is true of Python. > > > > 4. Using the REPL you write fewer bugs. In an imperative language you > > > have to make a guess as to how a whole (possibly very long) subroutine > > > should be written before writing it and then debug. Using the REPL > > > you start with the most basic steps of the subroutine, make sure those > > > work, and then continue to build until you have something that works. > > > This is also true of Python's REPL. > > > > 5. ease of changing function calls to allow for extra stuff/ > > > functionality without breaking other stuff. An example would be best > > > here. Suppose I had defined some function that worked for a specific > > > purpose: > > > (defn setzero [value] > > > "If value is less than 1.0E-8 setzero returns zero.." > > > (if (tolerance? value 1.0E-8) 0 value)) > > > The same is true of Python: > > > def setzero(value): > > "If value is less than 1.0E-8 setzero returns zero" > > return 0 if tolerance_p(value, 1.0E-8) else value > > > > and later I decided
Re: problems using javax.sound.midi from clojure on windows
On Thu, Nov 25, 2010 at 11:10 PM, Brian Gruber wrote: > At which point I get the following exception: > java.lang.IllegalArgumentException: Can't call public method of non- > public class: public javax.sound.midi.MidiChannel[] > com.sun.media.sound.AbstractPlayer.getChannels() I think that's a reflection exception. This framework was probably not designed to be called via reflection. Try type-hinting the thing you're calling .getChannels on. -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: lein compile for clj-time problem..
Thanks Steve.. Regards P: On Nov 26, 1:51 am, Rayne wrote: > If you're using leiningen, you can create a new project with 'lein > new'. In that project, you'll find a file called 'project.clj'. Open > that file, and under :dependencies, add this to the vector: [clj-time > "0.2.0-SNAPSHOT"] > > Save the file and then run 'lein deps'. After that, running lein repl/ > swank will put it on the classpath. > > However, if you just want to create a jar out of clj-time that you're > going to put on the classpath manually for some reason, you can just > do 'lein jar' and it should jar it right up. There is no reason to > compile it. > > On Nov 25, 9:05 am, Prometheus > wrote:> Hi Steve, > > > I am new on clojure and testing cascalog . I needed clj-time > > library .. > > > I downloaded its files from git and cd clj-time than type lein > > deps && lein compile.. > > > its creating classes and lib directory but nothing inside. So i am > > miising something.. > > > what is the proper way to compile clj-time to use from clj > > like : (use 'clj-time.core) ? > > > need help :) > > > thanks > > > On Oct 11, 3:57 pm, "Stephen C. Gilardi" wrote: > > > > On Oct 10, 2010, at 3:05 PM, HiHeelHottie wrote: > > > > > I'm runningleinswank and using slime-connect from emacs. When I use > > > >leincompileafter making changes to a method, they don't appear to > > > > get picked up unless I bring downleinswank, bring it up again, slime- > > > > connect, etc. > > > > > Is there a way to getleincompilechanges to be picked up by an > > > > already runningleinswank? Also, would be interested to hear about > > > > the workflow others are using withleinto develop a java class. > > > > I believe you're seeing the effects of the Java behavior that (at least > > > by default) a class loader will only load a given ".class" file once in > > > the lifetime of a given JVM. Its contents are cached and the cache is > > > used for all further reference to the classes defined in it. > > > > To be more dynamic than that you can arrange for your generated class to > > > call out to Clojure functions to do some or all of its actual work. New > > > versions of the Clojure functions you're working on can be loaded into a > > > runningleinswank as many times as you'd like from ".clj" files. > > > > --Steve -- 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 from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en