Re: disk-backed memoize?
On Sep 18, 3:00 am, David McNeil mcneil.da...@gmail.com wrote: Is there a disk-backed memoize available? I have an application where I would like the cache of values to survive restarts of the app. I don't know of one but in the next few weeks I was planning to add memcache functionality to cache-dot-clj to support my use of the google app engine: http://github.com/alienscience/cache-dot-clj The scary thing for me is reliably serialising and hashing the function arguments. If this is done, adding other (out of process) storage should be quite easy. I normally cache database accesses but I guess you're trying to memoize something much slower. Would JDBC suit your needs as a storage medium? You could use H2, HSQLDB or Derby by adding a dependency in your build tool of choice. If this is of interest I'll add it. Also, if you come up with a solution sooner, I'd be eager to steal your code. 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: Using macro to generate part of fn
On 18 Sep 2010, at 07:15, Stuart Campbell wrote: In the following contrived example, I get an error when macroexpanding (defn foo ...): (defmacro special-fn-spec [] '([bar baz] (println bar baz))) (defn foo ([bar] (foo bar :default)) (special-fn-spec)) The error is: Parameter declaration special-fn-spec should be a vector [Thrown class java.lang.IllegalArgumentException] I'm a bit confused about the order in which things are happening here. My assumption was that (special-fn-spec) would be evaluated before the fn definition. Is there a way to do something like this? Macroexpansion is part of the expression evaluation mechanism. In your example (defn foo ([bar] (foo bar :default)) (special-fn-spec)) the whole defn-form is macroexpanded first, yielding something like (def foo (fn ([bar] (foo bar :default)) (special-fn-spec)) Then the fn form is evaluated, yielding a compiled function. At that point, the compiler checks its syntax, and finds two bodies, one well- formed (arg list followed by expression) and a second ill-formed one (just an expression). The function bodies are *not* macroexpanded because they are not evaluated either. The only other subform of your example that is ever macroexpanded is (foo bar :default). There are a couple of ways to generate function bodies programmatically, but it is difficult to give useful advice without knowing what you need this for. Konrad. -- 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: disk-backed memoize?
http://github.com/alienscience/cache-dot-clj Thanks for the link. That is helpful. Would JDBC suit your needs as a storage medium? I suppose that would work, but I am thinking that an ehcache based plugin for cache-dot-clj might be a good solution. -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
Timed caches?
Working in the web dev world, I'm fairly used to systems offering ways to cache data for a period of time to improve performance - to reduce database traffic, to reduce complex data manipulation. The pattern is pretty much always: if ( thing not in cache ) { do expensive calculation / data loading put thing in cache for X minutes } get thing from cache (and return it or do something to it) Since memoize seems to be 'forever' and caching in general smells of mutable state, I wondered how folks are tackling this sort of thing in Clojure? Are you simply dropping down to Java libraries and being 'non-functional' or is there some more idiomatic approach available? -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ If you're not annoying somebody, you're not really alive. -- Margaret Atwood -- 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: Timed caches?
Check out http://kotka.de/blog/2010/03/The_Rule_of_Three.html for a very flexible implementation of memoiz On Sep 18, 2010 1:40 PM, Sean Corfield seancorfi...@gmail.com wrote: Working in the web dev world, I'm fairly used to systems offering ways to cache data for a period of time to improve performance - to reduce database traffic, to reduce complex data manipulation. The pattern is pretty much always: if ( thing not in cache ) { do expensive calculation / data loading put thing in cache for X minutes } get thing from cache (and return it or do something to it) Since memoize seems to be 'forever' and caching in general smells of mutable state, I wondered how folks are tackling this sort of thing in Clojure? Are you simply dropping down to Java libraries and being 'non-functional' or is there some more idiomatic approach available? -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ If you're not annoying somebody, you're not really alive. -- Margaret Atwood -- 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.comclojure%2bunsubscr...@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: Timed caches?
On Sat, Sep 18, 2010 at 10:40 AM, Sean Corfield seancorfi...@gmail.com wrote: Since memoize seems to be 'forever' and caching in general smells of mutable state, I wondered how folks are tackling this sort of thing in Clojure? Are you simply dropping down to Java libraries and being 'non-functional' or is there some more idiomatic approach available? I think memoization in clojure(and other language like Haskell) at the language level is mainly used for speeding up algorithm, like the famous finbonacci number sequence in Haskell and not as a cache feature. In other words, the memoization will disappear outside the function call. caching as in web application is a completely different thing which i would use whatever is needed for the application(memcache for example). -- 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: Timed caches?
On Sat, Sep 18, 2010 at 11:00 AM, Wilson MacGyver wmacgy...@gmail.com wrote: Check out http://kotka.de/blog/2010/03/The_Rule_of_Three.html for a very flexible implementation of memoiz Very nice. A good illustration of a lot of Clojure features too, especially with the detailed follow-up: http://kotka.de/blog/2010/03/memoize_done_right.html I notice Maikel refers to a version of the above using protocols and deftypes from the bleeding edge - since that post was in March, would I be right to assume the protocol / deftype version should be compatible with 1.2? It would be great if something like this was built into the standard libraries... or am I in a minority of users with such requirements? At least it gives me some pointers on how to implement timed caches... Thanx! -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ If you're not annoying somebody, you're not really alive. -- Margaret Atwood -- 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: Timed caches?
It would be great if something like this was built into the standard libraries... or am I in a minority of users with such requirements? At least it gives me some pointers on how to implement timed caches... It has been built into a library, so you won't need to implement it. http://github.com/alienscience/cache-dot-clj -- 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: Timed caches?
On Sat, Sep 18, 2010 at 1:12 PM, Eric Lavigne lavigne.e...@gmail.com wrote: It has been built into a library, so you won't need to implement it. http://github.com/alienscience/cache-dot-clj Thanx! I saw this mentioned in another thread recently but didn't make the connection with the strategy-based caches. -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ If you're not annoying somebody, you're not really alive. -- Margaret Atwood -- 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
Displaying source of function typed into the REPL?
OK, this feels like a really dumb question... I'm playing around in the REPL, I type in a function, I use it and continue to work on other stuff... I can't remember what the function looked like and I want to display the source of it again... I know I can go back through the REPL history but maybe I typed it in ages ago or maybe I typed it on multiple lines so it's hard to piece together from the history. That seems like hard work. I know I can go directly to the .jline-clojure.main.history file in my home directory. That seems like cheating (and it means I have to jump out of the REPL and hunt thru the file). I know I can use (source sym) to get the source of something whose .clj is on the classpath - that doesn't work for stuff typed directly into the REPL. Is there something easy within the REPL to show the source of something you defined earlier? -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ If you're not annoying somebody, you're not really alive. -- Margaret Atwood -- 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: what's up with user.clj?
you can also run into issues with things being on the classpath for your project, but not being on the classpath for lein, but user.clj being on the classpath for both, so when lein runs it can't find things your user.clj tries to load On Sat, Sep 11, 2010 at 8:17 AM, Stuart Sierra the.stuart.sie...@gmail.com wrote: Don't know if this is the source of the problem, but your use syntax is funky. You want: (use '[clojure.java.javadoc :only (javadoc)]) -S On Sep 11, 3:51 am, Robert McIntyre r...@mit.edu wrote: In the clojure getting started guide, it says that if user.clj is found on the classpath, then that file will be evaluated and the repl will start with any modifications made from that file. My directory structure looks like this /src/user.clj /src/rlm/quick.clj /lib/*all-my-jars* I have a function (dirty) in quick.clj that essentially does: (defn dirty [] (use :reload-all '[clojure.java [javadoc :only [javadoc]]) (clojure.java.javadoc/add-local-javadoc /path/to/local/javadocs)) (dirty) works fine at the repl if I type (do (require 'rlm.quick) (rlm.quick/dirty)) If I define user.clj like so: (ns user) (require 'rlm.quick) (rlm.quick/dirty) Then I get the error : java.lang.ClassNotFoundException: clojure.java.javadoc If I move the (clojure.java.javadoc/add-local-javadoc /path/to/local/javadocs) from (dirty) straight into user.clj it works fine. what's up with this? --Robert McIntyre and user.clj reads like this -- 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 -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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: practical clojure
On Sep 17, 8:23 pm, David J acts.as.da...@gmail.com wrote: I second faenvie's request for applications of Clojure books, especially on AI. AI is the reason I started looking at a Lisp in the first place. I'd also like to see Clojure become *the* language for statistics, though I understand that R statisticians aren't so fond of Lisps. Have a look at Incanter 8) http://incanter.org/ -- 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-daemon problems
On Aug 7, 2:10 am, Mark Rathwell mark.rathw...@gmail.com wrote: Anyone using lein-deamon and have success getting it working? When trying to start a daemon with 'lein daemon start daemon-name', I'm getting java.lang.IllegalArgumentException: No matching method: with-bindings (daemonProxy.clj:27). The entire error log is athttp://gist.github.com/512327. Mark, I posted a fix for this here: http://github.com/ericdwhite/lein-daemon/tree/init-fails-with-bindings And opened these issues: * http://github.com/arohner/lein-daemon/issues/#issue/1 * http://github.com/arohner/lein-daemon/issues/#issue/2 Until that patch goes into 'arohner/lein-daemon' you can do what I did. 1) Fork 'arohner / lein-daemon' 2) Apply the change 3) Bump the revision number in lein-daemon/project.clj (e.g. 0.2.1) 4) lein jar lein install 5) Finally make the dependency in your project 0.2.1 I hope that helps. Cheers, Eric e...@ericwhite.ca -- 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-daemon problems [RESOLVED]
On Aug 7, 2:10 am, Mark Rathwell mark.rathw...@gmail.com wrote: Anyone using lein-deamon and have success getting it working? When trying to start a daemon with 'lein daemon start daemon-name', I'm getting java.lang.IllegalArgumentException: No matching method: with-bindings (daemonProxy.clj:27). The entire error log is athttp://gist.github.com/512327. Mark, I posted a fix for this here: http://github.com/ericdwhite/lein-daemon/tree/init-fails-with-bindings And opened these issues: * http://github.com/arohner/lein-daemon/issues/#issue/1 * http://github.com/arohner/lein-daemon/issues/#issue/2 Until that patch goes into 'arohner/lein-daemon' you can do what I did. 1) Fork 'arohner / lein-daemon' 2) Apply the change 3) Bump the revision number in lein-daemon/project.clj (e.g. 0.2.1) 4) lein jar lein install 5) Finally make the dependency in your project 0.2.1 I hope that helps. Cheers, Eric -- 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: Displaying POSTed string from form text-field in Compojure
Miki, Thanks a lot - the mystery has been solved. It had to do with the way I was handling the POST route. It seems it needs explicit 'binding' as you mentioned (POST / {params :params} (view-output (params my_datum or (POST / {{a my_datum} :params} ...) Thanks again! Victor On Fri, Sep 17, 2010 at 9:18 PM, Miki miki.teb...@gmail.com wrote: See http://clojure.pastebin.com/ncaULRbU (works for me). I've changed the POST handler to use *params* and I also think you're not closing the :h2 in view output. On Sep 17, 3:11 pm, Victor Olteanu bluestar...@gmail.com wrote: Sure, here it is: (defn view-layout [ content] (html (doctype :xhtml-strict) (xhtml-tag en [:head [:meta {:http-equiv Content-type :content text/html; charset=utf-8}] [:title Datum]] [:body content]))) This was actually taken from an online tutorial with some changes ( http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applica... ) More specifically, in the original tutorial there was an additional intermediate step when the input was parsed: (parse-input a b) with the function (defn parse-input [a b] [(Integer/parseInt a) (Integer/parseInt b)])(parse-input a b) However in my case I'm just dealing with strings, so there's no parseInt involved. So I assumed my input is strings-- which doesn't seem to be the case, and there are no parseString methods that I could use instead. Thank you, Victor On Fri, Sep 17, 2010 at 5:30 PM, Miki miki.teb...@gmail.com wrote: My *guess* it's somehow connected to the code of view-layout since it shows the representation of the function str. Can place the full code (including view-layout) somewhere? On Sep 17, 12:35 pm, Victor bluestar...@gmail.com wrote: Hi all, I'm having a problem that may or may not be Compojure specific, so I thought I'd try this group since the answer is probably easy- I am just stuck. I am reading the string through a simple form (defn view-input [] (view-layout [:h2 Enter one datum:] [:form {:method post :action /} [:input.datum {:type text :name my_datum}] [:input.action {:type submit :value Add}]])) where the route for posting is (POST / [a] (view-output a))) I then simply want to display what I entered and submitted (say I typed the string a). (defn view-output [a] (view-layout [:h2 (str This is what you entered: a))) However what I get is this: clojure.core$...@1e731e90 Thanks in advance for your help! Victor -- 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.comclojure%2bunsubscr...@googlegroups.com clojure%2bunsubscr...@googlegroups.comclojure%252bunsubscr...@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.comclojure%2bunsubscr...@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
Macro closing over atom gives Can't embed object in code error.
I am playing around with a macro to define accessor functions for a closed-over atom. Here is a simplified example: (defmacro hidden-atom [] (let [a (atom :hello)] `(defn get-value [] (deref ~a When I evaluate this macro, I get the error: Can't embed object in code, maybe print-dup not defined: clojure.lang.a...@1a7693a I imagined this should work, as the above macro doesn't seem too different from the following macro, which does work: (defmacro hidden-function[] (let [a (fn [] :hello)] `(defn get-value [] (~a When using macroexpand-1, both macros return nearly identical forms: gdsl.proc (macroexpand '(hidden-atom)) (def gdsl.proc/get-value (.withMeta (clojure.core/fn gdsl.proc/get- value ([] (clojure.core/deref #a...@10a5e22: :hello))) (.meta (var gdsl.proc/get-value gdsl.proc (macroexpand '(hidden-function)) (def gdsl.proc/get-value (.withMeta (clojure.core/fn gdsl.proc/get- value ([] (#proc$hidden_function$a__15149 gdsl.proc$hidden_function $a__15...@bde2da))) (.meta (var gdsl.proc/get-value I'm afraid I don't know enough about macro expansion to understand what is wrong here. -- 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 macro to generate part of fn
Macroexpansion is part of the expression evaluation mechanism. In your example (defn foo ([bar] (foo bar :default)) (special-fn-spec)) the whole defn-form is macroexpanded first, yielding something like (def foo (fn ([bar] (foo bar :default)) (special-fn-spec)) Then the fn form is evaluated, yielding a compiled function. At that point, the compiler checks its syntax, and finds two bodies, one well-formed (arg list followed by expression) and a second ill-formed one (just an expression). The function bodies are *not* macroexpanded because they are not evaluated either. The only other subform of your example that is ever macroexpanded is (foo bar :default). There are a couple of ways to generate function bodies programmatically, but it is difficult to give useful advice without knowing what you need this for. Konrad. Thanks Konrad, that makes sense. I suppose I was a bit confused about when macroexpansion occurs. My real use-case involves wrapping a Java object, which has a number of methods with varying numbers of optionally nullable parameters. E.g. DatabaseMetaData#getExportedKeys(String, String, String) In this method, the first two parameters may be null. So, my fn looks like this: (defn exported-keys ([table] (exported-keys nil table)) ([schema table] (exported-keys nil schema table)) ([catalog schema table] (fetch-metadata-rs .getExportedKeys catalog schema table))) I was trying to automatically generate the final function body since it duplicates the parameter list, and I expect to have a lot of these kinds of methods. Although, it's not too bad as it is (I've already pulled some common bits into fetch-metadata-rs). Not sure if that makes sense or not... ? Cheers, Stuart -- 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