Re: A simulation of the Monty Hall Problem
On 10 May 2011, at 22:46, Ken Wesson wrote: Interesting. It is, as I thought, very short with monads -- though that version doesn't really use randomness, but instead enumerates all the possibilities. You'd need slightly different monads to thread a random bit-stream through instead of enumerating all the alternatives. Indeed. What's nice about monads is that you can use the same problem specification for both approaches. Just change the monad name to switch between enumeration and Monte-Carlo simulation. 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: Enlive update transformation
Hi, My 2 cents: this solution may be subject to escaping issues. When one needs to pass parameters to Javascript, I often recommend to inject one script tag whose content is the result of (str window.params = (write-json your-data)) or to encode them in html if their is only a handful of params (eg in meta tags). Christophe On Tue, May 10, 2011 at 2:36 PM, Thorsten Wilms t...@freenet.de wrote: On 05/09/2011 10:15 PM, Thorsten Wilms wrote: I tried to turn that into a transformation: (defn substitute-token [ values] #(map (fn [m] (update-in m [:content] (fn [c] (apply (partial replace-str token %) c values)) Apparently I had my brain knotted, but raek and fliebel on IRC helped with untying some misconceptions :) So the solution for applying a function, (partial replace-str token to) in this case, on the content in html nodes as Enlive transformation is: (defn substitute-token Replace text 'token' with to. [to] #(update-in % [:content] (fn [c] (apply (partial replace-str token to) c -- Thorsten Wilms thorwil's design for free software: http://thorwil.wordpress.com/ -- 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 -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.cgrand.net/ (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: sessions in Ring, Sandbar, Compojure, etc...
There's an example of Ring sessions linked from the Ring wiki: https://gist.github.com/608048 Does that help? - James On May 10, 6:19 am, James Reeves jree...@weavejester.com wrote: On 10 May 2011 07:24, Shree Mulay shreemu...@gmail.com wrote: For the life of me, I can't get sessions to work, immaterial of which tutorial I try and get going??? Is there any tutorial out there that explicitly explains everything for a newb like me? After several round, I did successfully get form params to work! YEAH! But now, I'd like to create a login so that the user can login and have state - but I can't get SESSIONS TO WORK??? There's an example of Ring sessions linked from the Ring wiki: https://gist.github.com/608048 Does that help? - James @James, the problem with the example you've linked to, is it doesn't help me figure out how to link, for example, a userid picked up from a form into a session. Or how to set a session value to true/false, etc. I would appreciate a more comprehensive example, perhaps - a few more simpler examples, etc. It's like compound example built into a single function. Also, would be nice to see session information passed around from one page to another (ie., routes???)... [is this even possible?] I don't want to use sandbar, either. Well, I couldn't figure out how to get its wrap-stateful-session to work properly. I'm trying to accomplish setting up a login form. At least I got rings params to work; I'd like to now have some of the information from submitted forms to get stored into session variables, eh... THANKS IN ADVANCE, shree -- 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: sessions in Ring, Sandbar, Compojure, etc...
On May 10, 9:20 pm, Matthew Boston matthew.bos...@gmail.com wrote: Maybe try looking at the source of a project on github using logins/ sessions. One I'm currently using for reference is from 4clojurehttps://github.com/dbyrne/4clojure Hey Matthew, I'm looking at the code. If I can't get headway on Ring, I might try again with Sandbar. The login at @https://github.com/dbyrne/4clojure/ blob/develop/src/foreclojure/login.clj might cover my requirements, except that it uses mongodb as it's store... hm Worth looking at nonetheless. : Thanks, shree -- 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: Bug? (vary-meta (promise) assoc :foo 1) hangs in Clojure 1.2
Hi, Am 11.05.2011 um 03:00 schrieb Ken Wesson: Anyway, maybe this will come in handy: Clojure 1.3 will support timeouts; however on the deref side, not on promise definition. It'll also handle the not-delivered issue. user= (def p (promise)) #'user/p user= (future (Thread/sleep 5000) (deliver p 42)) #core$future_call$reify__5399@7a7c3885: :pending user= p #core$promise$reify__5442@3288df60: :not-delivered user= p #core$promise$reify__5442@3288df60: 42 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
Re: sessions in Ring, Sandbar, Compojure, etc...
Hi Shree, while I wouldn't dare give you technical advice, I may have something to offer as a fellow Clojure noob. I did try Sandbar for my project, but found, as I delved deeper into the universe of Clojure web development, that I was altogether over-complicating everything. This, and the fact that Sandbar is undergoing something of a metamorphosis both the options of utilising the current stable release (which is likely to be relatively stagnant and unlikely to attract many more enhancements or documentation), and braving trunk (which is unstable, and unlikely to be adequately documented (for noobs, anyway) until at least some time after release). What I've discovered is that the whole deal is incredibly simple. Start with Ring. It's tiny, and all it does is speak html at one end (the end you don't need to care about unless you're a bona fide Clojurist), and Clojure at the other. Everything you need is available to you as Clojure maps, and all you have to do is write Clojure code to manipulate those maps. The bit between the request map and the response map are your Ring middlewares. Some of them might be part of Ring itself (such as the few bundled session middleware components which might be of use to you), middleware written by other people (which could do anything at all), and your own code. I have found that reducing the complexity of the tools you use greatly reduces the complexity of the task of gluing everything together and getting things working. Sandbar is a nice piece of work (props to Brendon), but as a noob, with simple requirements, I now understand that reaching for the most ornate magonote is probably the last thing I should be doing, and that my fingers and a bit of determination are all I need to get some satisfaction and get my immediate problems solved. Not that I'm suggesting you do the same, but I'm using Ring, Compojure, Hiccup, and Clojureql to serve up my application and manage sessions. Wiring those together with my application functions was very easily accomplished, with the vast majority of my time spent trying to get the presentation (HTML and CSS) right. Don't get allow yourself to get despondent - I really think you'll find solving your actual problems far simpler than you anticipated. It's just a matter of, well, 'getting it'. On May 11, 7:38 pm, Shree Mulay shreemu...@gmail.com wrote: On May 10, 9:20 pm, Matthew Boston matthew.bos...@gmail.com wrote: Maybe try looking at the source of a project on github using logins/ sessions. One I'm currently using for reference is from 4clojurehttps://github.com/dbyrne/4clojure Hey Matthew, I'm looking at the code. If I can't get headway on Ring, I might try again with Sandbar. The login at @https://github.com/dbyrne/4clojure/ blob/develop/src/foreclojure/login.clj might cover my requirements, except that it uses mongodb as it's store... hm Worth looking at nonetheless. : Thanks, shree -- 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
clj-ripple
I made a little library called clj-ripple for the easy embedding of Ripple code (for navigating the Semantic Web) inside Clojure programs. It works by translating Clojure sexps to Ripple code strings through a macro and then executes and returns the resulting stacks as lazy sequences. The git repo can be found here: https://github.com/eduardoejp/clj-ripple To include it in your projects, add this to your leiningen deps: [clj- ripple 0.1.0-SNAPSHOT] For more info about the Ripple scripting language, please visit the following links: * http://ripple.fortytwo.net/ * http://ripple.googlecode.com/svn/trunk/docs/screencast/index.html * https://github.com/joshsh/ripple/wiki Happy crawling! -- 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: possibly non-intuitive behaviour of clojure.set/rename-keys and possible enhancement suggestion
(clojure.set/rename-keys {1 :a 2 :b 3 :c} {1 2 2 3 3 4}) returns {4 :a} That's caused by the collision between new and existing keys. Renaming 1 to 2 blows [2 :b]: {2 :a, 3 :c}; then renaming 2 to 3 blows [3 :c], leaving {3 :a}; and the last just renames 3 to 4: {4 :a}. -- 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: possibly non-intuitive behaviour of clojure.set/rename-keys and possible enhancement suggestion
This renames keys to avoid collisions, using an array map to preserve the order of the keys: user= (rename-keys {1 :a 2 :b 3 :c} (array-map 3 4 2 3 1 2)) {2 :a, 3 :b, 4 :c} On May 11, 7:22 am, Armando Blancas armando_blan...@yahoo.com wrote: (clojure.set/rename-keys {1 :a 2 :b 3 :c} {1 2 2 3 3 4}) returns {4 :a} That's caused by the collision between new and existing keys. Renaming 1 to 2 blows [2 :b]: {2 :a, 3 :c}; then renaming 2 to 3 blows [3 :c], leaving {3 :a}; and the last just renames 3 to 4: {4 :a}. -- 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
Type hinting inconsistencies in 1.3.0
I've been using 1.3.0 alphas for real work for a little while now, and would like to raise a couple of issues around type hinting so as to calibrate my expectations and understanding and/or provoke some discussion about some inconsistencies I'm seeing. Some observations from a REPL interaction first: = *clojure-version* {:major 1, :minor 3, :incremental 0, :qualifier alpha6} = (set! *warn-on-reflection* true) true = (defn ^String foo []) #'user/foo = (fn [] (String. (foo))) #user$eval398$fn__399 user$eval398$fn__399@215b011c = (- #'foo meta :tag) java.lang.String Right, so hinting a var's name works just fine, as in 1.2.x. Things get wonky when hinting with primitives, though: = (defn ^long foo []) #'user/foo = (fn [] (Long. (foo))) #CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: clojure.core$long@41f6321, compiling:(NO_SOURCE_PATH:1) = (- #'foo meta :tag) #core$long clojure.core$long@41f6321 The compilation fails because the var's :tag metadata is a function, clojure.core/long! Bizarre. I would assume that that's a bug, except that it appears the intended way to hint _primitive_ returns (but no other returns?) is on the arg vector, and not the var name: = (defn foo ^long []) #'user/foo = (fn [] (Long. (foo))) #user$eval410$fn__411 user$eval410$fn__411@18287811 = (- #'foo meta :tag) nil = (meta @#'foo) nil So our compilation succeeds here, but the var's metadata is left :tag-less (understandably, since the hint is on the arg vector and not the var name), and the function has no metadata at all (this is surely a bug, but not my primary focus here). My understanding is that the objective in hinting the arg vector is to allow for variable return hints on functions with multiple arities (which was not possible in 1.2.x). This is an excellent aim, but it would seem that the current implementation presents some usage difficulties: = (defn foo (^String []) (^long [a]) (^double [a b])) #'user/foo = #(String. (foo)) #user$eval2241$fn__2242 user$eval2241$fn__2242@25c2cbee Reflection warning, NO_SOURCE_PATH:1 - call to java.lang.String ctor can't be resolved. = #(Long. (foo)) #user$eval2245$fn__2246 user$eval2245$fn__2246@508a8b07 Reflection warning, NO_SOURCE_PATH:1 - call to java.lang.Long ctor can't be resolved. = #(Long. (foo 0)) #user$eval2249$fn__2250 user$eval2249$fn__2250@c23c5ff = #(Double. (foo 0)) #user$eval2260$fn__2261 user$eval2260$fn__2261@35cfee57 Reflection warning, NO_SOURCE_PATH:1 - call to java.lang.Double ctor can't be resolved. = #(Double. (foo 0 0)) #user$eval2264$fn__2265 user$eval2264$fn__2265@5d504a84 So, we can have variable hinting of fn returns of different arities, but only for primitive types. This hurts, and should either be fixed or produce a compiler warning. Also, there is no metadata on the var indicating the types of the different function arities: = (meta #'foo) {:arglists ([] [a] [a b]), :ns #Namespace user, :name foo, :line 1, :file NO_SOURCE_PATH} Somewhat worse from the standpoint of semantic consistency, hinting the var with ^String yields good — yet confusing — results: = (defn ^String foo ([]) (^long [a]) (^double [a b])) #'user/foo = #(Double. (foo 0 0)) #user$eval2289$fn__2290 user$eval2289$fn__2290@69996e15 = #(String. (foo)) #user$eval2293$fn__2294 user$eval2293$fn__2294@220860ba And now the var metadata has a :tag, but only for the ^String hint: = (meta #'foo) {:arglists ([] [a] [a b]), :ns #Namespace user, :name foo, :line 1, :file NO_SOURCE_PATH, :tag java.lang.String} I understand that the generated function implements the necessary interfaces when primitive hints are involved: = (supers (class foo)) #{clojure.lang.IFn$OL java.lang.Object java.lang.Runnable clojure.lang.Fn clojure.lang.AFn clojure.lang.IObj clojure.lang.IMeta clojure.lang.AFunction java.util.concurrent.Callable clojure.lang.IFn$OOD java.io.Serializable java.util.Comparator clojure.lang.IFn} Having to touch (:tag (meta var)) as well as dig away at the implemented interfaces of generated function classes (which I have to assume are strictly implementation details) seems unnecessarily inconsistent. Finally, I'd like to question the current path of supporting hinting of primitive returns — and primitive returns only — via function arg vectors. Again, to me, it's a simple point of consistency, this time from a mostly syntactic perspective; most of the examples below have already been seen above, but I repeat them so that they're all co-located for easy comparison: We hint object returns via the var name: (defn ^String foo []) But we hint primitive returns via arg vectors: (defn foo ^long []) Different arities of functions can be hinted, but _only_ with primitive types, and on arg vectors: (defn foo (^long []) (^double [a])) While a hint added to a function's var cascades down to any unhinted arities of a function: (defn ^String foo ([] bar) (^double [a]) ([a
Type hinting inconsistencies in 1.3.0
(sorry for the prior hiccup, I accidentally sent a draft of my message) I've been using 1.3.0 alphas for real work for a little while now, and would like to raise a couple of issues around type hinting so as to calibrate my expectations and understanding and/or provoke some discussion about some inconsistencies I'm seeing. Some observations from a REPL interaction first: = *clojure-version* {:major 1, :minor 3, :incremental 0, :qualifier alpha6} = (set! *warn-on-reflection* true) true = (defn ^String foo []) #'user/foo = (fn [] (String. (foo))) #user$eval398$fn__399 user$eval398$fn__399@215b011c = (- #'foo meta :tag) java.lang.String Right, so hinting a var's name works just fine, as in 1.2.x. Things get wonky when hinting with primitives, though: = (defn ^long foo []) #'user/foo = (fn [] (Long. (foo))) #CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: clojure.core$long@41f6321, compiling:(NO_SOURCE_PATH:1) = (- #'foo meta :tag) #core$long clojure.core$long@41f6321 The compilation fails because the var's :tag metadata is a function, clojure.core/long! Bizarre. I would assume that that's a bug, except that it appears the intended way to hint _primitive_ returns (but no other returns?) is on the arg vector, and not the var name: = (defn foo ^long []) #'user/foo = (fn [] (Long. (foo))) #user$eval410$fn__411 user$eval410$fn__411@18287811 = (- #'foo meta :tag) nil = (meta @#'foo) nil So our compilation succeeds here, but the var's metadata is left :tag-less (understandably, since the hint is on the arg vector and not the var name), and the function has no metadata at all (this is surely a bug, but not my primary focus here). My understanding is that the objective in hinting the arg vector is to allow for variable return hints on functions with multiple arities (which was not possible in 1.2.x). This is an excellent aim, but it would seem that the current implementation presents some usage difficulties: = (defn foo (^String []) (^long [a]) (^double [a b])) #'user/foo = #(String. (foo)) #user$eval2241$fn__2242 user$eval2241$fn__2242@25c2cbee Reflection warning, NO_SOURCE_PATH:1 - call to java.lang.String ctor can't be resolved. = #(Long. (foo)) #user$eval2245$fn__2246 user$eval2245$fn__2246@508a8b07 Reflection warning, NO_SOURCE_PATH:1 - call to java.lang.Long ctor can't be resolved. = #(Long. (foo 0)) #user$eval2249$fn__2250 user$eval2249$fn__2250@c23c5ff = #(Double. (foo 0)) #user$eval2260$fn__2261 user$eval2260$fn__2261@35cfee57 Reflection warning, NO_SOURCE_PATH:1 - call to java.lang.Double ctor can't be resolved. = #(Double. (foo 0 0)) #user$eval2264$fn__2265 user$eval2264$fn__2265@5d504a84 So, we can have variable hinting of fn returns of different arities, but only for primitive types. This hurts, and should either be fixed or produce a compiler warning. Also, there is no metadata on the var indicating the types of the different function arities: = (meta #'foo) {:arglists ([] [a] [a b]), :ns #Namespace user, :name foo, :line 1, :file NO_SOURCE_PATH} Somewhat worse from the standpoint of semantic consistency, hinting the var with ^String yields good — yet confusing — results: = (defn ^String foo ([]) (^long [a]) (^double [a b])) #'user/foo = #(Double. (foo 0 0)) #user$eval2289$fn__2290 user$eval2289$fn__2290@69996e15 = #(String. (foo)) #user$eval2293$fn__2294 user$eval2293$fn__2294@220860ba And now the var metadata has a :tag, but only for the ^String hint: = (meta #'foo) {:arglists ([] [a] [a b]), :ns #Namespace user, :name foo, :line 1, :file NO_SOURCE_PATH, :tag java.lang.String} I understand that the generated function implements the necessary interfaces when primitive hints are involved: = (supers (class foo)) #{clojure.lang.IFn$OL java.lang.Object java.lang.Runnable clojure.lang.Fn clojure.lang.AFn clojure.lang.IObj clojure.lang.IMeta clojure.lang.AFunction java.util.concurrent.Callable clojure.lang.IFn$OOD java.io.Serializable java.util.Comparator clojure.lang.IFn} Having to touch (:tag (meta var)) as well as dig away at the implemented interfaces of generated function classes (which I have to assume are strictly implementation details) seems unnecessarily inconsistent. Finally, I'd like to question the current path of supporting hinting of primitive returns — and primitive returns only — via function arg vectors. Again, to me, it's a simple point of consistency, this time from a mostly syntactic perspective; most of the examples below have already been seen above, but I repeat them so that they're all co-located for easy comparison: We hint object returns via the var name: (defn ^String foo []) But we hint primitive returns via arg vectors: (defn foo ^long []) Different arities of functions can be hinted, but _only_ with primitive types, and on arg vectors: (defn foo (^long []) (^double [a])) While a hint added to a function's var cascades down to any unhinted
Small issue with swank-cdt on Windows
Swank cdt is unbelievably awesome and many thanks for the superb effort! On windows with swank-clojure 1.4.0-SNAPSHOT, there seems to be a small issue with displaying source once a breakpoint is hit. I get a message saying clojure\set.clj - source not found. Digging into swank source, the method swank.commands.basic/source-location- for-frame seems to be where the problem is, specifically the line - (str ns-path File/separator (.getFileName frame)) In window, java.io.File/separator returns \\ . However, in the method slime-find-resource, the separator is going to cause a failure user= (.getResource (clojure.lang.RT/baseLoader) clojure\\set.clj) nil user= (.getResource (clojure.lang.RT/baseLoader) clojure/set.clj) #URL jar:file:/C:/Users/ajohendran/.m2/repository/org/clojure/clojure/ 1.2.1/clojure-1.2.1.jar!/clojure/set.clj user= http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String) Can we just use the forward slashes in the method source-location-for- frame? Thanks Aravindh -- 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: Bug? (vary-meta (promise) assoc :foo 1) hangs in Clojure 1.2
On 1.3 master there is: clojure.core/deref ([ref] [ref timeout-ms timeout-val]) Also reader macro: @ref/@agent/@var/@atom/@delay/@future/@promise. Within a transaction, returns the in-transaction-value of ref, else returns the most-recently-committed value of ref. When applied to a var, agent or atom, returns its current state. When applied to a delay, forces it if not already forced. When applied to a future, will block if computation not complete. When applied to a promise, will block until a value is delivered. The variant taking a timeout can be used for blocking references (futures and promises), and will return timeout-val if the timeout (in milliseconds) is reached before a value is available. See also - realized?. Stu Anyway, maybe this will come in handy: (defn timeout-promise A promise with a timeout. When dereffed, returns the delivered value if already delivered, otherwise blocks until delivered or the deadline expires, whichever comes first. Returns the delivered value if delivered in time and if-timeout if the deadline expires first. Ex.: user= (def q (promise 1000 :timed-out)) user=(do (future (Thread/sleep 900) (deliver q 42)) @q) 42 user= (def q (promise 1000 :timed-out)) user=(do (future (Thread/sleep 1100) (deliver q 42)) @q) :timed-out [timeout-in-ms if-timeout] (let [d (java.util.concurrent.CountDownLatch. 1) v (atom nil)] (reify clojure.lang.IDeref (deref [_] (if (.await d timeout-in-ms ms) @v if-timeout)).lang.IFn (invoke [this x] (locking d (if (pos? (.getCount d)) (do (reset! v x) (.countDown d) this) (throw (IllegalStateException. Multiple deliver calls to a promise Since the above code is derived from the existing implementation of promise, it therefore automatically inherits the Clojure license terms as the terms for its use, if I understand copyright law correctly. The only changes from the implementation of promise are: 1. Docstring. 2. The two arguments. 3. Calls the await method of CountDownLatch that takes a timeout. 4. Conditions on the return value and returns if-timeout on failure. -- 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
swank-clj 0.1.0 - a refactored swank-clojure, with sldb support
For the intrepid, the first release of swank-clj is out. This is a refactored swank-clojure, and features sldb integration. Some highlights: * line based breakpoints * stepping * exception restarts See the readme at https://github.com/hugoduncan/swank-clj -- Hugo Duncan -- 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: Reading clojure code of larger domain specific projects
Thanks, that sound good! I'll have a look at the clojars project and yours once it is in the right state for that. On 10 Mai, 18:04, Paul deGrandis paul.degran...@gmail.com wrote: I'm also working on a project to augment clojars called clopi (Clojure Package Index), that will let you filter results based on project metrics (for example, line count), project activity, etc. It also displays the dependency information (the default rank score for searching), allowing you mostly to answer the question Which library should I choose? but also can help you find possible business applications (edge/external-nodes in the graph, ie: projects which nothing else depend upon). I'll ping you when it's live. Paul -- 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: Type hinting inconsistencies in 1.3.0
Have you seen this? http://www.assembla.com/wiki/show/clojure/Enhanced_Primitive_Support •hint for return goes on arg vector ◦e.g. (defn ^:static foo ^long [x] …) ◦this so it supports multi-arity with varied returns I couldn't find a practical use of doing (defn ^String foo [] ...) what's hinting the fn name good for? The code in 1.3 is actually better than I had anticipated since you get the speed benefits whether or not your arguments are primitives (see Static linking); I thought you'd need two implementations of every calls that takes primitives. You don't mention ^:static and that seems to be required for best performance. :static •defn supports {:static true} metadata •:static fns can take/return longs and doubles in addition to Objects •compiler will compile static methods in addition to IFn virtual methods The metadata isn't there, so I guess some symbol table is involved in compiling static functions, not just the var. user= (defn fib [n] (if (= n 1) 1 (+ (fib (dec n)) (fib (- n 2) #'user/fib user= (time (fib 38)) Elapsed time: 25383.208481 msecs 63245986 user= (defn ^:static fib ^long [^long n] (if (= n 1) 1 (+ (fib (dec n)) (fib (- n 2) #'user/fib user= (meta (var fib)) {:arglists ([n]), :ns #Namespace user, :name fib, :static true, :line 149, :file NO_SOURCE_PATH} user= (time (fib 38)) Elapsed time: 2792.755504 msecs 63245986 user= (time (fib 38N)) Elapsed time: 2777.905013 msecs 63245986 On May 11, 8:09 am, Chas Emerick cemer...@snowtide.com wrote: (sorry for the prior hiccup, I accidentally sent a draft of my message) I've been using 1.3.0 alphas for real work for a little while now, and would like to raise a couple of issues around type hinting so as to calibrate my expectations and understanding and/or provoke some discussion about some inconsistencies I'm seeing. Some observations from a REPL interaction first: = *clojure-version* {:major 1, :minor 3, :incremental 0, :qualifier alpha6} = (set! *warn-on-reflection* true) true = (defn ^String foo []) #'user/foo = (fn [] (String. (foo))) #user$eval398$fn__399 user$eval398$fn__399@215b011c = (- #'foo meta :tag) java.lang.String Right, so hinting a var's name works just fine, as in 1.2.x. Things get wonky when hinting with primitives, though: = (defn ^long foo []) #'user/foo = (fn [] (Long. (foo))) #CompilerException java.lang.IllegalArgumentException: Unable to resolve classname: clojure.core$long@41f6321, compiling:(NO_SOURCE_PATH:1) = (- #'foo meta :tag) #core$long clojure.core$long@41f6321 The compilation fails because the var's :tag metadata is a function, clojure.core/long! Bizarre. I would assume that that's a bug, except that it appears the intended way to hint _primitive_ returns (but no other returns?) is on the arg vector, and not the var name: = (defn foo ^long []) #'user/foo = (fn [] (Long. (foo))) #user$eval410$fn__411 user$eval410$fn__411@18287811 = (- #'foo meta :tag) nil = (meta @#'foo) nil So our compilation succeeds here, but the var's metadata is left :tag-less (understandably, since the hint is on the arg vector and not the var name), and the function has no metadata at all (this is surely a bug, but not my primary focus here). My understanding is that the objective in hinting the arg vector is to allow for variable return hints on functions with multiple arities (which was not possible in 1.2.x). This is an excellent aim, but it would seem that the current implementation presents some usage difficulties: = (defn foo (^String []) (^long [a]) (^double [a b])) #'user/foo = #(String. (foo)) #user$eval2241$fn__2242 user$eval2241$fn__2242@25c2cbee Reflection warning, NO_SOURCE_PATH:1 - call to java.lang.String ctor can't be resolved. = #(Long. (foo)) #user$eval2245$fn__2246 user$eval2245$fn__2246@508a8b07 Reflection warning, NO_SOURCE_PATH:1 - call to java.lang.Long ctor can't be resolved. = #(Long. (foo 0)) #user$eval2249$fn__2250 user$eval2249$fn__2250@c23c5ff = #(Double. (foo 0)) #user$eval2260$fn__2261 user$eval2260$fn__2261@35cfee57 Reflection warning, NO_SOURCE_PATH:1 - call to java.lang.Double ctor can't be resolved. = #(Double. (foo 0 0)) #user$eval2264$fn__2265 user$eval2264$fn__2265@5d504a84 So, we can have variable hinting of fn returns of different arities, but only for primitive types. This hurts, and should either be fixed or produce a compiler warning. Also, there is no metadata on the var indicating the types of the different function arities: = (meta #'foo) {:arglists ([] [a] [a b]), :ns #Namespace user, :name foo, :line 1, :file NO_SOURCE_PATH} Somewhat worse from the standpoint of semantic consistency, hinting the var with ^String yields good — yet confusing — results: = (defn ^String foo ([]) (^long [a]) (^double [a b])) #'user/foo = #(Double. (foo 0 0)) #user$eval2289$fn__2290 user$eval2289$fn__2290@69996e15 = #(String.
Re: Type hinting inconsistencies in 1.3.0
On May 11, 2011, at 1:20 PM, Armando Blancas wrote: Have you seen this? http://www.assembla.com/wiki/show/clojure/Enhanced_Primitive_Support Indeed, though that's old. See http://dev.clojure.org/display/doc/Enhanced+Primitive+Support instead. I couldn't find a practical use of doing (defn ^String foo [] ...) what's hinting the fn name good for? That's how one hints a non-primitive return type; that's been the case for a long time now. You don't mention ^:static and that seems to be required for best performance. :static •defn supports {:static true} metadata •:static fns can take/return longs and doubles in addition to Objects •compiler will compile static methods in addition to IFn virtual methods ^:static has been a no-op for a while AFAIK, made unnecessary after changes to vars a while back. The metadata isn't there, so I guess some symbol table is involved in compiling static functions, not just the var. The compiler relies upon a stack of interfaces that define primitive-hinted function invocation: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java#L91 I haven't investigated the details sufficiently enough to comment beyond that. - Chas -- 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: Type hinting inconsistencies in 1.3.0
On May 11, 2011, at 11:09 AM, Chas Emerick wrote: Of course, this isn't how 1.3.0 alphas work now, but unless things are really locked down, I hope the above is a reasonable starting point for discussing how to smooth out the inconsistencies that currently exist. After some clarifying discussion in #clojure, I wanted to explicitly state my concrete suggestions, as I should have done in my original message. I think that: as much as possible, return type information, whether obtained by a primitive or non-primitive hint, should be in the var and function metadata in a form amenable to tooling and other runtime introspection hinting arg vectors in order to indicate function return types is a syntactically poor choice In any case, the syntactic position of function return type hints should be consistent regardless of the category of return type - Chas P.S. BTW, my expectation that :tag metadata should trickle down to functions themselves was driven by what looks like a bug in 1.2.0 where it *appears* that that happens, but only after one has redefined a var: https://gist.github.com/248246a3ac545a20a7b3 -- 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: Type hinting inconsistencies in 1.3.0
Thanks for the link to the new documentation. That's how one hints a non-primitive return type; that's been the case for a long time now. I know, but haven't needed it; I guess it's for Java interop. hinting arg vectors in order to indicate function return types is a syntactically poor choice In any case, the syntactic position of function return type hints should be consistent regardless of the category of return type I can see the inconsistency but for multiple arity/body functions that's not a bad place to put it. My suggestion would be to extend (declare) à la maclisp and keep the actual fn clean of hints (at least the signature). http://bitsavers.trailing-edge.com/pdf/mit/ai/aim/AIM-421.pdf -- 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: Type hinting inconsistencies in 1.3.0
On Wed, May 11, 2011 at 11:04 AM, Chas Emerick cemer...@snowtide.com wrote: Somewhat worse from the standpoint of semantic consistency, hinting the var with ^String yields good — yet confusing — results: = (defn ^String foo ([]) (^long [a]) (^double [a b])) #'user/foo = #(Double. (foo 0 0)) #user$eval2289$fn__2290 user$eval2289$fn__2290@69996e15 = #(String. (foo)) #user$eval2293$fn__2294 user$eval2293$fn__2294@220860ba And now the var metadata has a :tag, but only for the ^String hint: = (meta #'foo) {:arglists ([] [a] [a b]), :ns #Namespace user, :name foo, :line 1, :file NO_SOURCE_PATH, :tag java.lang.String} What do you get from (map meta (:arglists (meta #'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
Re: Type hinting inconsistencies in 1.3.0
On Wed, May 11, 2011 at 11:09 AM, Chas Emerick cemer...@snowtide.comwrote: (defn foo ^String ([] bar) ^double ([a] 5.6) ([a b] :not-hinted-at-all)) Given the current implementation I really don't see how this could work. Keeping the old fn type-hint in a separate place from the new primitive type hints is wise until the implementation can actually deliver unified semantics. 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: Type hinting inconsistencies in 1.3.0
On Wed, May 11, 2011 at 3:10 PM, Armando Blancas armando_blan...@yahoo.comwrote: I can see the inconsistency but for multiple arity/body functions that's not a bad place to put it. My suggestion would be to extend (declare) à la maclisp and keep the actual fn clean of hints (at least the signature). http://bitsavers.trailing-edge.com/pdf/mit/ai/aim/AIM-421.pdf This is less generic then what already exists in Clojure 1.3.0, fns that consume primitives can efficiently dispatch on arities and types. 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: Type hinting inconsistencies in 1.3.0
On May 11, 2011, at 4:45 PM, Ken Wesson wrote: On Wed, May 11, 2011 at 11:04 AM, Chas Emerick cemer...@snowtide.com wrote: Somewhat worse from the standpoint of semantic consistency, hinting the var with ^String yields good — yet confusing — results: = (defn ^String foo ([]) (^long [a]) (^double [a b])) #'user/foo = #(Double. (foo 0 0)) #user$eval2289$fn__2290 user$eval2289$fn__2290@69996e15 = #(String. (foo)) #user$eval2293$fn__2294 user$eval2293$fn__2294@220860ba And now the var metadata has a :tag, but only for the ^String hint: = (meta #'foo) {:arglists ([] [a] [a b]), :ns #Namespace user, :name foo, :line 1, :file NO_SOURCE_PATH, :tag java.lang.String} What do you get from (map meta (:arglists (meta #'foo)))? = (- #'foo meta :arglists (map (juxt identity meta))) ([[] nil] [[a] {:tag long}] [[a b] {:tag double}]) Beautiful. I clearly wasn't clever enough to spelunk deeply enough into the metadataÎ. Thank you, Ken. I'd hope that the [] arity could get a :tag of java.lang.String, but that may be running into semantic difficulties as David is potentially pointing out separately. Thanks again, - Chas -- 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: sessions in Ring, Sandbar, Compojure, etc...
James, From this code, I can't figure out where you instantiate the session var, store to it, and read back from it? I know there's not instantiation in clojure(???). I hope your able to get what I'm having trouble figuring out. I'm not sure whether the magic happens here: (let [n (session :n 1)] -or- (assoc-in [:session :n] (inc n))) In the code from: https://gist.github.com/608048. Hope you get what I'm asking? Thanks again, shree On May 11, 3:32 am, Shree Mulay shreemu...@gmail.com wrote: There's an example of Ring sessions linked from the Ring wiki: https://gist.github.com/608048 Does that help? - James On May 10, 6:19 am, James Reeves jree...@weavejester.com wrote: On 10 May 2011 07:24, Shree Mulay shreemu...@gmail.com wrote: For the life of me, I can't get sessions to work, immaterial of which tutorial I try and get going??? Is there any tutorial out there that explicitly explains everything for a newb like me? After several round, I did successfully get form params to work! YEAH! But now, I'd like to create a login so that the user can login and have state - but I can't get SESSIONS TO WORK??? There's an example of Ring sessions linked from the Ring wiki: https://gist.github.com/608048 Does that help? - James @James, the problem with the example you've linked to, is it doesn't help me figure out how to link, for example, a userid picked up from a form into a session. Or how to set a session value to true/false, etc. I would appreciate a more comprehensive example, perhaps - a few more simpler examples, etc. It's like compound example built into a single function. Also, would be nice to see session information passed around from one page to another (ie., routes???)... [is this even possible?] I don't want to use sandbar, either. Well, I couldn't figure out how to get its wrap-stateful-session to work properly. I'm trying to accomplish setting up a login form. At least I got rings params to work; I'd like to now have some of the information from submitted forms to get stored into session variables, eh... THANKS IN ADVANCE, shree -- 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: sessions in Ring, Sandbar, Compojure, etc...
Paul, I'm using ring, hiccup, compojure, and clutch (for my database connectivity via CouchDB). I'm avoiding Sandbar, cause I can't figure too much of it out anyways) at this point, at least. I think the only thing I'm using compojure for is [GET POST ANY defroutes]. I'm building the core component for a social network project due for my j2ee class tomorrow. I'm STUCK cause I can't figure out sessions. :P I've got clutch to work, html rendering, can pick up params from forms using ring's wrap-params, etc... I just can't get all the pieces to come together - by having a users logged in state STORED into a session! I've been trying to remove all the complicated stuff and only focus on the basic stuff. I don't need to have a real world set up for this project, I just need my project to work. The last part I've got to do is build restful services to allow my component to coordinate with my other team member's components. I'ven't tried to do this, yet, but have several pages up; Doesn't appear to be something that should be a problem (hopefully). BUT, I DO REQUIRE A SESSION - Unless there's another way??? Thanks guys, shree On May 11, 7:32 am, Paul Dorman paul.dor...@gmail.com wrote: Hi Shree, while I wouldn't dare give you technical advice, I may have something to offer as a fellow Clojure noob. I did try Sandbar for my project, but found, as I delved deeper into the universe of Clojure web development, that I was altogether over-complicating everything. This, and the fact that Sandbar is undergoing something of a metamorphosis both the options of utilising the current stable release (which is likely to be relatively stagnant and unlikely to attract many more enhancements or documentation), and braving trunk (which is unstable, and unlikely to be adequately documented (for noobs, anyway) until at least some time after release). What I've discovered is that the whole deal is incredibly simple. Start with Ring. It's tiny, and all it does is speak html at one end (the end you don't need to care about unless you're a bona fide Clojurist), and Clojure at the other. Everything you need is available to you as Clojure maps, and all you have to do is write Clojure code to manipulate those maps. The bit between the request map and the response map are your Ring middlewares. Some of them might be part of Ring itself (such as the few bundled session middleware components which might be of use to you), middleware written by other people (which could do anything at all), and your own code. I have found that reducing the complexity of the tools you use greatly reduces the complexity of the task of gluing everything together and getting things working. Sandbar is a nice piece of work (props to Brendon), but as a noob, with simple requirements, I now understand that reaching for the most ornate magonoteis probably the last thing I should be doing, and that my fingers and a bit of determination are all I need to get some satisfaction and get my immediate problems solved. Not that I'm suggesting you do the same, but I'm using Ring, Compojure, Hiccup, and Clojureqlto serve up my application and manage sessions. Wiring those together with my application functions was very easily accomplished, with the vast majority of my time spent trying to get the presentation (HTML and CSS) right. Don't get allow yourself to get despondent - I really think you'll find solving your actual problems far simpler than you anticipated. It's just a matter of, well, 'getting it'. On May 11, 7:38 pm, Shree Mulay shreemu...@gmail.com wrote: On May 10, 9:20 pm, Matthew Boston matthew.bos...@gmail.com wrote: Maybe try looking at the source of a project on github using logins/ sessions. One I'm currently using for reference is from 4clojurehttps://github.com/dbyrne/4clojure Hey Matthew, I'm looking at the code. If I can't get headway on Ring, I might try again with Sandbar. The login at @https://github.com/dbyrne/4clojure/ blob/develop/src/foreclojure/login.clj might cover my requirements, except that it uses mongodb as it's store... hm Worth looking at nonetheless. : Thanks, shree -- 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: sessions in Ring, Sandbar, Compojure, etc...
The magic is in wrap-session, which adds the session middleware to your stack. At that point, your ring handler will see that it's request map has a new key (:session) which is a map containing all your session variables. You can assoc anything into that map and it will be stored in the session. By default, this is all stored in-memory, it's possible to use a database instead if you specify options to wrap-session. See (doc wrap-session) or http://clojuredocs.org/ring/ring.middleware.session/wrap-session From your gist: ; The next line is using destructuring to split out the session map into a local variable named session. (defn handler [{session :session, uri :uri}] ; The next line is reading the :n value out of the session map. (let [n (session :n 1)] -- 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: Type hinting inconsistencies in 1.3.0
On May 11, 2011, at 4:47 PM, David Nolen wrote: On Wed, May 11, 2011 at 11:09 AM, Chas Emerick cemer...@snowtide.com wrote: (defn foo ^String ([] bar) ^double ([a] 5.6) ([a b] :not-hinted-at-all)) Given the current implementation I really don't see how this could work. Keeping the old fn type-hint in a separate place from the new primitive type hints is wise until the implementation can actually deliver unified semantics. Assuming the JVM as it is today (i.e. no fixnums, etc.), is there any potential that primitive and non-primitive semantics can be unified? Is that even desirable considering the host? Even if the answer is 'yes', if one wanted different syntax to correspond with different semantics, this is not the most obvious distinction: ^double ([a] 5.6) (^double [a] 5.6) My only point with the strawman you quoted is that the hint is for the return type, and has nothing to do with that arity's arguments – so, why put it there? Syntactically (and semantically before they started participating in IFn class interface selection), type hints are metadata on the expression following the hint, so their current position implies that they relate to arguments. This is more clear with a single-arity declaration: (defn ^String foo []) (defn foo ^long []) Those that understand the nuanced semantic distinction will understand what's going on regardless of where the hint is placed; those that don't will think the syntactic difference is arbitrary, a just-so difference. - Chas -- 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: sessions in Ring, Sandbar, Compojure, etc...
On 12 May 2011 00:04, Shree Mulay shreemu...@gmail.com wrote: From this code, I can't figure out where you instantiate the session var, store to it, and read back from it? I know there's not instantiation in clojure(???). I hope your able to get what I'm having trouble figuring out. The session is read from a :session key on the request map, and written using a :session key on the response map. For example, this route returns the value of the session key :x (GET /get {session :session} (str x = (:x session))) It's equivalent to the Sinatra route: get /get do x = #{session[:x]} end The main difference is that the session has to be bound explicitly. We don't just get a magic session map hanging around in the background. Writing a session is a little trickier: (GET /set [x :as {session :session}] {:session (assoc session :x x) :body (str You set x = x)}) The equivalent Sinatra route is: get /set do |x| session[:x] = x You set x = #{x} end Ring sessions are a little unwieldy because you write by changing the response, rather than calling a side-effectful function. Sandbar takes a slightly different approach that looks more like the Sinatra code: (GET /get [] (str x = (session-get :x))) (GET /set [x] (session-put! :x x) (str You set x = x)) Sandbar is a little cleaner for simple things, but Ring sessions have the advantage of working well with middleware. Idiomatic Ring tends to use a lot of middleware, far more than one might use in Rack (for instance). - James -- 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: Type hinting inconsistencies in 1.3.0
On Wed, May 11, 2011 at 7:43 PM, Chas Emerick cemer...@snowtide.com wrote: (defn ^String foo []) (defn foo ^long []) The real problem is that first case was never actually specifying a return type - it is a type hint on the var that happened to store an fn. The fn itself can only return Object (=1.2.0). Now fns can return Object, long, double. 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: Type hinting inconsistencies in 1.3.0
On May 11, 2011, at 9:04 PM, David Nolen wrote: On Wed, May 11, 2011 at 7:43 PM, Chas Emerick cemer...@snowtide.com wrote: (defn ^String foo []) (defn foo ^long []) The real problem is that first case was never actually specifying a return type - it is a type hint on the var that happened to store an fn. The fn itself can only return Object (=1.2.0). Now fns can return Object, long, double. Yes, I understand that, but is the differentiated placement of the hint intended to communicate that difference? I assume there's only one or two people that might know… - Chas -- 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: sessions in Ring, Sandbar, Compojure, etc...
Shree, I would suggest that you try to use only Ring first. Once you get how it works, take a look at Sandbar and see if that may work better for you in specific situations. The session code in Sandbar is stable. It will not change much in the next release. In fact it may become its own project by then. Here is one small application that shows how to use both styles in one app. I hope you find this helpful. http://github.com/brentonashworth/sandbar/blob/master/src/examples/sessions/session_with_reload.clj Brenton On May 9, 11:24 pm, Shree Mulay shreemu...@gmail.com wrote: For the life of me, I can't get sessions to work, immaterial of which tutorial I try and get going??? Is there any tutorial out there that explicitly explains everything for a newb like me? After several round, I did successfully get form params to work! YEAH! But now, I'd like to create a login so that the user can login and have state - but I can't get SESSIONS TO WORK??? frustrated!, shree -- 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
Learning Idiomatic Clojure
I'm wondering what resources would be best to learn how Clojurians write their code. I've been developing for about 4 years in several object-oriented languages (mostly C# and Ruby). I understand Clojure's syntax well and I'm familiar with a lot of the features of Clojure (although I'm sure several of you would prove me wrong). One problem I keep running into is how to attack a problem the Clojure way. I often find myself writing Clojure like I would write C# code with LINQ, only in Clojure's syntax. I'm not interested in Java interop or Clojure on the web or Clojure's syntax. I've had no problem finding answers for those things on the Internet. I'm really more interested in stuff like http://www.bestinclass.dk/index.clj/2010/10/taking-uncle-bob-to-school.html, but covering a wider range of things rather than a small example. I'm interested in any resource whether it's a book, a video, a blog, a person, etc. Any suggestions? J.R. Garcia -- 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: sessions in Ring, Sandbar, Compojure, etc...
Dear James, et al., Here is what I'm trying to do: --- ;;Login form to login. To login successfully, let ;;password = secret (defn login-view [] (html [:p (form-to [:post /login/ ] User name: [:input {:name name, :type text}] [:br] Password: [:input {:name password, :type password}] [:br] [:input {:type submit :value Log in}])])) ;;takes the input params from the login form and stores the ;;logged in user into a session. You get logged in when the ;;password value is = secret (defn login-controller [params session] (do (println (params password) (params name))) (dosync (if (= secret (params password)) ; Username can include letters, numbers, ; spaces, underscores, and hyphens. ;(.matches (params :name) [\\w\\s\\-]+)) (do {:session (assoc session :name (params name))} (redirect /page/)) (redirect /oops/ ;;In the repl, the following appears: ;; ;;Getting userid: nil ;; (defn page [request session title body] (do (println Getting userid: (:name session)) ) ) ;; I'm using compojure's defroutes (as you can see) (defroutes main-routes (GET /login/ [] (login-view)) (POST /login/ {params :params session :session} (login-controller params session)) (ANY /page/ {request :request session :session} (page request session hello world)) ) --- PROBLEM: I can't retrieve the session :name that I've been attempted to store to. I don't know if it's getting stored into the session in the first place. And finally, is it that I'm unable to retrieve it. I know it's probably a very minor problem that needs to be fixed, but I've been going up the wall on this one! Thanks in advance, shree ps. My code may seem a bit contrived. It's been bundled together off of a bunch of examples I've seen at the ring, compojure, sandbar examples, and elsewhere... On May 11, 8:01 pm, James Reeves jree...@weavejester.com wrote: On 12 May 2011 00:04, Shree Mulay shreemu...@gmail.com wrote: From this code, I can't figure out where you instantiate the session var, store to it, and read back from it? I know there's not instantiation in clojure(???). I hope your able to get what I'm having trouble figuring out. The session is read from a :session key on the request map, and written using a :session key on the response map. For example, this route returns the value of the session key :x (GET /get {session :session} (str x = (:x session))) It's equivalent to the Sinatra route: get /get do x = #{session[:x]} end The main difference is that the session has to be bound explicitly. We don't just get a magic session map hanging around in the background. Writing a session is a little trickier: (GET /set [x :as {session :session}] {:session (assoc session :x x) :body (str You set x = x)}) The equivalent Sinatra route is: get /set do |x| session[:x] = x You set x = #{x} end Ring sessions are a little unwieldy because you write by changing the response, rather than calling a side-effectful function. Sandbar takes a slightly different approach that looks more like the Sinatra code: (GET /get [] (str x = (session-get :x))) (GET /set [x] (session-put! :x x) (str You set x = x)) Sandbar is a little cleaner for simple things, but Ring sessions have the advantage of working well with middleware. Idiomatic Ring tends to use a lot of middleware, far more than one might use in Rack (for instance). - James -- 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: sessions in Ring, Sandbar, Compojure, etc...
Dear Aaron, et al., I have been wrapping my sessions. Perhaps there's something I'm missing??? (def app (- #'main-routes (wrap-reload '(SocialNetworkCore.core)) ;;remove wrap-reload from production code (wrap-params) ;; wraps params (inputs from forms) - makes 'em available ;(wrap-flash);; (wrap-session) ;; wraps session (wrap-request-logging) ;; gives me request logging (wrap-bounce-favicon) ;; skirts favicon request logging (wrap-exception-logging);; logs exceptions (wrap-stacktrace))) ;; detailed stacktrace of errors I'm using compojure's defroutes, as well. Let me know if you spot anything that I may be missing, eh. Thanks, shree On May 11, 7:32 pm, Aaron Cohen aa...@assonance.org wrote: The magic is in wrap-session, which adds the session middleware to your stack. At that point, your ring handler will see that it's request map has a new key (:session) which is a map containing all your session variables. You can assoc anything into that map and it will be stored in the session. By default, this is all stored in-memory, it's possible to use a database instead if you specify options to wrap-session. See (doc wrap-session) orhttp://clojuredocs.org/ring/ring.middleware.session/wrap-session From your gist: ; The next line is using destructuring to split out the session map into a local variable named session. (defn handler [{session :session, uri :uri}] ; The next line is reading the :n value out of the session map. (let [n (session :n 1)] -- 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: sessions in Ring, Sandbar, Compojure, etc...
Thanks Brenton, I've gone through your example, and tried to replicate it at my end(for my use cases) but was unable to. I demoed most of the examples you've provided and they look GREAT! I hope that I'll be able to make projects work (and look) like the examples you've shared with us one day. The problem with: https://github.com/brentonashworth/sandbar/blob/master/src/examples/sessions/session_with_reload.clj -and- https://gist.github.com/608048 is they deal with sessions on a single page that is reloaded, rather than the session getting transfered from one page to another, via GET, POST, PUT, ALL, etc, in defroutes. Um, moreso, using hiccup's redirect, eh Any thoughts, would be appreciated! Thanks again, shree On May 11, 9:48 pm, Brenton bashw...@gmail.com wrote: Shree, I would suggest that you try to use only Ring first. Once you get how it works, take a look at Sandbar and see if that may work better for you in specific situations. The session code in Sandbar is stable. It will not change much in the next release. In fact it may become its own project by then. Here is one small application that shows how to use both styles in one app. I hope you find this helpful. http://github.com/brentonashworth/sandbar/blob/master/src/examples/se... Brenton On May 9, 11:24 pm, Shree Mulay shreemu...@gmail.com wrote: For the life of me, I can't get sessions to work, immaterial of which tutorial I try and get going??? Is there any tutorial out there that explicitly explains everything for a newb like me? After several round, I did successfully get form params to work! YEAH! But now, I'd like to create a login so that the user can login and have state - but I can't get SESSIONS TO WORK??? frustrated!, shree -- 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: sessions in Ring, Sandbar, Compojure, etc...
On Wed, May 11, 2011 at 10:27 PM, Shree Mulay shreemu...@gmail.com wrote: ;;takes the input params from the login form and stores the ;;logged in user into a session. You get logged in when the ;;password value is = secret (defn login-controller [params session] (do (println (params password) (params name))) (dosync What is this dosync for? (if (= secret (params password)) ; Username can include letters, numbers, ; spaces, underscores, and hyphens. ;(.matches (params :name) [\\w\\s\\-]+)) (do {:session (assoc session :name (params name))} This line accomplishes nothing, it creates a map and then throws it away. Try returning something like: (assoc (redirect /page/) :session (assoc session :name (params name))) (redirect /page/)) (redirect /oops/ -- 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: sessions in Ring, Sandbar, Compojure, etc...
Aaron, et al., That didn't seem to make any difference. I believe the example I got dosync from wanted the whole thing to move forward as a transaction (???). Anyhow, this is what it looks like now: (defn login-controller [params session] (do (println (params password) (params name))) (dosync (if (= secret (params password)) ; Username can include letters, numbers, ; spaces, underscores, and hyphens. ;(.matches (params :name) [\\w\\s\\-]+)) (do (assoc (redirect /page/) :session (assoc session :name (params name))) ;{:session (assoc session :name (params name))} ;(redirect /page/)) ) (redirect /oops/ my repl(output) still gets me: Getting userid: nil Any thoughts? Thanks, shree On May 11, 10:54 pm, Aaron Cohen aa...@assonance.org wrote: On Wed, May 11, 2011 at 10:27 PM, Shree Mulay shreemu...@gmail.com wrote: ;;takes the input params from the login form and stores the ;;logged in user into a session. You get logged in when the ;;password value is = secret (defn login-controller [params session] (do (println (params password) (params name))) (dosync What is this dosync for? (if (= secret (params password)) ; Username can include letters, numbers, ; spaces, underscores, and hyphens. ;(.matches (params :name) [\\w\\s\\-]+)) (do {:session (assoc session :name (params name))} This line accomplishes nothing, it creates a map and then throws it away. Try returning something like: (assoc (redirect /page/) :session (assoc session :name (params name))) (redirect /page/)) (redirect /oops/ -- 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: sessions in Ring, Sandbar, Compojure, etc...
James, I even tried the examples you gave me: (defroutes main-routes (GET / [] (welcome)) (GET /form [] (render-form)) (GET /login/ [] (login-view)) ; (POST /login/ {request :request params :params} (login- controller request params)) (POST /login/ {params :params session :session} (login- controller params session)) ; (ANY /logout/ [] (logout-controller session)) (ANY /page/ {request :request session :session} (page request session hello world)) (GET /a [] (ooops)) (GET /set [x :as {session :session}] {:session (assoc session :x Shree) :body (str You set x = x)}) (GET /get {session :session} (str x = (:x session))) (POST /form {params :params} (handle-form params)) (route/not-found (page_not_found))) But for WHATEVER reason, the sessions are NOT getting stored? When I goto the set page, I get: http://localhost:3000/set You set x = -and- http://localhost:3000/get x = respectively. I must REALLY be messing SOMETHING up at my end??? Why else would this NOT be working??? Thanks, shree On May 11, 8:01 pm, James Reeves jree...@weavejester.com wrote: On 12 May 2011 00:04, Shree Mulay shreemu...@gmail.com wrote: From this code, I can't figure out where you instantiate the session var, store to it, and read back from it? I know there's not instantiation in clojure(???). I hope your able to get what I'm having trouble figuring out. The session is read from a :session key on the request map, and written using a :session key on the response map. For example, this route returns the value of the session key :x (GET /get {session :session} (str x = (:x session))) It's equivalent to the Sinatra route: get /get do x = #{session[:x]} end The main difference is that the session has to be bound explicitly. We don't just get a magic session map hanging around in the background. Writing a session is a little trickier: (GET /set [x :as {session :session}] {:session (assoc session :x x) :body (str You set x = x)}) The equivalent Sinatra route is: get /set do |x| session[:x] = x You set x = #{x} end Ring sessions are a little unwieldy because you write by changing the response, rather than calling a side-effectful function. Sandbar takes a slightly different approach that looks more like the Sinatra code: (GET /get [] (str x = (session-get :x))) (GET /set [x] (session-put! :x x) (str You set x = x)) Sandbar is a little cleaner for simple things, but Ring sessions have the advantage of working well with middleware. Idiomatic Ring tends to use a lot of middleware, far more than one might use in Rack (for instance). - James -- 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: Type hinting inconsistencies in 1.3.0
On Wed, May 11, 2011 at 9:04 PM, David Nolen dnolen.li...@gmail.com wrote: On Wed, May 11, 2011 at 7:43 PM, Chas Emerick cemer...@snowtide.com wrote: (defn ^String foo []) (defn foo ^long []) The real problem is that first case was never actually specifying a return type - it is a type hint on the var that happened to store an fn. The fn itself can only return Object (=1.2.0). ?? Using 1.2: sandbox= (defn bar [] foo) #'sandbox/bar sandbox= (defn foo [] (.length (bar))) #'sandbox/foo Reflection warning, NO_SOURCE_PATH:1 - reference to field length can't be resolved. sandbox= (defn ^String baz [] foo) #'sandbox/baz sandbox= (defn foo [] (.length (baz))) #'sandbox/foo Looks like it recognizes it as hinting the return type to me. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts 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: Learning Idiomatic Clojure
On Wed, May 11, 2011 at 10:10 PM, J.R. Garcia mrjohngar...@gmail.com wrote: I'm wondering what resources would be best to learn how Clojurians write their code. I've been developing for about 4 years in several object-oriented languages (mostly C# and Ruby). I understand Clojure's syntax well and I'm familiar with a lot of the features of Clojure (although I'm sure several of you would prove me wrong). One problem I keep running into is how to attack a problem the Clojure way. I often find myself writing Clojure like I would write C# code with LINQ, only in Clojure's syntax. I'm not interested in Java interop or Clojure on the web or Clojure's syntax. I've had no problem finding answers for those things on the Internet. I'm really more interested in stuff like http://www.bestinclass.dk/index.clj/2010/10/taking-uncle-bob-to-school.html, but covering a wider range of things rather than a small example. I'm interested in any resource whether it's a book, a video, a blog, a person, etc. Any suggestions? I don't know about any books or other resources, but a few general pointers: 1. Think functional. Try to express as much as possible as data plumbing: here is an input, here is the desired result, how to get there from here? Think in terms of calculating a new value in terms of an existing one, rather than changing things in place. Familiarize yourself with map, filter, remove, reduce, iterate, and friends, and the data structures (maps, sets, vectors, seqs) and use those to represent as much as possible and to do as much as possible. In particular, when a processing step has to be repeated: 1a. If it's for each element of a sequence, consider map, reduce, and for. If it has to walk several sequences in tandem, use map, or maybe reduce or for with (map vector s1 s2 ...). If it's for each combination in some sequences, so for all in the first sequence, and for each of those for all in the second, etc., use for. 1b. If it's accumulating a result, consider reduce, even if the input isn't (obviously) a sequence, or iterate, before resorting to loop/recur. 2. When the time comes to abstract things, abstract as much as you can using function arguments and, perhaps, returns and using maps before resorting to defmulti/defrecord/etc. 3. Look at other Clojure code, including what shows up here from time to time, and ask here about making specific code more idiomatic. Many people here will likely answer fairly quickly, and even when they disagree, the disagreement and their stated reasons for disagreeing may themselves be illuminating -- and then anything *everyone* agrees is ugly or poor practice almost certainly is. :) -- 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-daemon 0.3
I've released a new version of lein-daemon. daemon is like 'lein run', only it runs the process in the background rather than blocking. 0.3 and up is a complete re-write, that no longer depends on apache commons daemon. The new version has no dependencies on any external programs. For more, see https://github.com/arohner/lein-daemon -- 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: Type hinting inconsistencies in 1.3.0
On Wed, May 11, 2011 at 11:58 PM, Ken Wesson kwess...@gmail.com wrote: On Wed, May 11, 2011 at 9:04 PM, David Nolen dnolen.li...@gmail.com wrote: On Wed, May 11, 2011 at 7:43 PM, Chas Emerick cemer...@snowtide.com wrote: (defn ^String foo []) (defn foo ^long []) The real problem is that first case was never actually specifying a return type - it is a type hint on the var that happened to store an fn. The fn itself can only return Object (=1.2.0). ?? Using 1.2: sandbox= (defn bar [] foo) #'sandbox/bar sandbox= (defn foo [] (.length (bar))) #'sandbox/foo Reflection warning, NO_SOURCE_PATH:1 - reference to field length can't be resolved. sandbox= (defn ^String baz [] foo) #'sandbox/baz sandbox= (defn foo [] (.length (baz))) #'sandbox/foo Looks like it recognizes it as hinting the return type to me. https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L3236 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: Who's using Clojure?
Factual has been using Clojure for over a year now in narrowly defined corners of our production stack. Just recently, we've made a decision to use it more widely. For one thing, Cascalog is starting to be a big win for us. And we'll most likely be starting up whole new projects that are mainly Clojure based. On Apr 28, 10:07 pm, Ken Wesson kwess...@gmail.com wrote: This fractal video claims to have been made using Clojure: http://vimeo.com/22725635 I stumbled on it earlier today while bored and was quite surprised to see the word Clojure about halfway down the lengthy description text. I doubt it was very idiomatic Clojure. The described use, interpolating between video frames of some sort, would probably involve a loop/recur full of Java2D and ImageIO interop calls. Nor does it seem to be a large organization, but an individual hobbyist. Still, the more Clojure is in the public eye, the better. -- 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