Re: bounded memoize
Hi, as threatened previously I wrote a summery blog post of this discussion: http://kotka.de/blog/2010/03/memoize_done_right.html. Please let me know in case I missed something crucial. I'm also working on a protocol/type based implementation here: http://paste.pocoo.org/show/190179. More to come this evening. 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: Long-running STM updates will never complete... is there a solution?
On Mon, Mar 15, 2010 at 11:24 PM, Garth Sheldon-Coulson wrote: > Christophe, thanks for the partial memoization tip. I think that would > work in many cases, but for my current use case I really need to put a > lock on the ref, because the function is very expensive and other > threads will be updating it with previously unseen values so quickly > that memoization can't help. Are you saying that the fact that ensure > works in my example isn't to be counted on? > Ensure seems to mitigate the problem but I think that with a different timing and bad luck (which always happen under load in concurrent systems), you may still experience a high-level of retries. (The readlock fastened by ensure is released just after the computation of f for alter to writelock it, tag it and release the lock. So there are two moments where the current transaction can be barged by another (older) transaction.) Two questions: Do you care about the return value of the long running computation inside the transaction? Does this computation depends on the value of other refs? If you anwser no to both, you should consider commute. If you answered no only to the first, a delay may help you (by making the transaction shorter): (dosync (alter r #(delay (f @% ;; don't forget to capture all the ref values you depend on hth, Christophe -- 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: Long-running STM updates will never complete... is there a solution?
Hi Chouser, On Mon, Mar 15, 2010 at 11:27 PM, Chouser wrote: > I make no claims about the Rightness of this suggestion, but > simply offer another example of a work-around: > >(dosync (alter r identity) (alter r f)) > > That is, a "dummy write" via alter is also sufficient to allow > the transaction to succeed, just like 'ensure'. > This is an interesting idea which can be automated (well, to be frank, an implicit ensure could also be automated but it doesn't feel kosher) by adding a doAlter to c.l.LockingTransaction: Object doAlter(Ref ref, IFn fn, ISeq args)){ if(!info.running()) throw retryex; if(commutes.containsKey(ref)) throw new IllegalStateException("Can't alter after commute"); Object val; if(!sets.contains(ref)) { sets.add(ref); val = lock(ref); } else val = vals.get(ref); Object ret = fn.applyTo(RT.cons(val, args)) vals.put(ref, ret); return ret; } and in c.l.Ref: public Object alter(IFn fn, ISeq args) throws Exception{ LockingTransaction t = LockingTransaction.getEx(); return t.doalter(this, fn, args))); } What do you think? Christophe -- 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
Why do functions in the state monad only accept one value?
I've been comparing the definition of the Clojure's state monad -- state-m in clojure.contrib.monads -- to definitions I've found elsewhere, and there's a facet of the Clojure definition that's puzzling: Why do monadic functions in state-m only accept one argument (a "basic value") and return a monadic value (a function accepting a state), as opposed to accepting both the "basic value" and a state? Looking at the definitions for the state monad in Haskell, it seems ambiguous as to whether the monadic functions accept one or two values, but then functions in Haskell can all be curried, so it's hard to tell. The paper "Monads for functional programming"¹ by Philip Wadler shows the following definition of the bind operator on page 9: m * k = \X.let (a, y) = m x in let (b, z) = k a y in (b, z) Note the application of function "k" is shown as k a y where "a" is the basic value resulting from "m" and "y" is the state as updated last by "m". This definition suggests that function "k" doesn't make much sense without these two arguments supplied. Again, though, this is Haskell, so supplying multiple arguments at once doesn't mean much. In the Haskell tutorial's article "The State monad"², the definition looks more like Clojure's: (State x) >>= f = State $ \s -> let (v,s') = x s in runState (f v) s' There we see monadic function "f" applied to basic value "v", and then the result applied to the pending state "s'". Clojure's definition is as follows: (fn m-bind-state [mv f] (fn [s] (let [[v ss] (mv s)] ((f v) ss There, similarly, monadic function "f" is applied first to basic value "v", and then the result applied to the pending state "ss". My question: What's the benefit of having the monadic function accept only the basic value, deferring consideration of the state, as opposed to having it accept both the basic value and the pending state together? As I write this, I realize that following Clojure's definition ensures that "monadic functions return monadic values", and here a monadic value is a function that accepts a state. What's been difficult, though, is actually writing monadic functions for use in the state monad. It feels wrong to define a function whose outcome depends both on the input basic value and the input state, but to have to "cut the function in half", receiving the two values as separate steps. Sometimes the function depends only upon the input value, in which case the `m-result' is sufficient to provide the resulting monadic value. Sometimes the function depends on both the input value and the state, in which case we have to just close over the input value and defer its consideration until we receive the state later. What would be lost by defining Clojure bind operator like this: (fn m-bind-state [mv f] (fn [s] (let [[v ss] (mv s)] (f v ss Is there more to it than, "Monadic functions must return monadic values"? Any clarifying advice would be welcome. Footnotes: ¹ http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf ² http://www.haskell.org/all_about_monads/html/statemonad.html -- Steven E. Harris -- 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: Why do functions in the state monad only accept one value?
> What would be lost by defining Clojure bind operator like this: > > (fn m-bind-state [mv f] > (fn [s] > (let [[v ss] (mv s)] > (f v ss > > Is there more to it than, "Monadic functions must return monadic > values. My first thought was that it would be problematic for the "result" operator, which would have to take two parameters (or at least accept two parameters, with a default if passed only one) Perhaps more importantly, the power of the monad abstraction is that the types of monadic functions and all the operators are similar. ie. *all* monadic functions, regardless of the monad, have the (haskell) type a -> M b This way, you can write a function that works under many different monads, as long as it uses the generic facilities to return monadic values. eg. a lifted inc: (defn m-inc [v] (m-result (inc v)) which can be used in the state monad as an argument to bind, even though it doesn't care about the state at all. If you *do* need the state (add it to the parameter, for example), you would write (defn add-state [v] (fn [s] [(+ v s) s])) used like ((m-bind (m-result 4) add-state) 10), giving [14 10] I hope I got this correct... I'm not an expert on all the mathematical theory behind monads. -- 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: Why do functions in the state monad only accept one value?
*facepalm* I should've known GG was just hiding the post from 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: Why do functions in the state monad only accept one value?
> Is there more to it than, "Monadic functions must return monadic > values"? > > Any clarifying advice would be welcome. > Gah, I already wrote a reply, but looks like I lost it somehow. To summarise: I think one of the main benefits of the monad abstraction is the uniformity of all monads. ie. all monad functions have the type a -> m b What this means is that you can write functions which work under arbitrary monads, as long as they use the generic monad functions. For example, a monadic inc: (defn minc [v] (m-result (inc v)) This function works in any monad, and threads the state properly, even though it's never mentioned. A function that actually does care about the state will just access it by returning a "custom" state monad value (a function of s). -- 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: Vimclojure Performance on Windows
Meikel, Is Vimclojure stable enough to have it on my Window's Vista? I tried it out before without success. Regards, Emeka On Fri, Feb 26, 2010 at 6:22 AM, Meikel Brandmeyer wrote: > Hi, > > On Feb 25, 4:46 pm, Vitaly Peressada wrote: > > > Installed vimclojure-2.1.2 on Windows XP SP3. Have dual-core machine > > and 4GB of RAM. In VimRepl > > (println "Hello World") takes about 10 seconds. Is this expected? > > No. Vim shells out to another process. This is the only real portable > and stable way to talk to other process with Vim. This is slow. > However on my MacBook (dual-core, 1G RAM) the delay is not noticeable. > On my crappy Windows Laptop (single-core, 1.7Gh, 2G RAM) at work, the > delay is noticeable but well below a second. > > The only exception is the first command, which (as a side effect) sets > up the whole clojure machinery in the background. But subsequent > commands should be much faster. > > > Any suggestions how to speed this up? > > No clue. You are the first to report such a problem. > > Sincerely > Meikel > > PS: there is also the vimclojure google group for such support issues. > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Interest in Google Summer of Code 2010?
Did Clojure ever submit to GSoC for 2010? On Feb 14, 11:59 am, Vivek Khurana wrote: > On Feb 14, 11:27 am, Vivek Khurana wrote: > > > I had moved to Clojure recently. I had been GSoC mentor twice and I > > have the t-shirt to prove it ;-) . If clojure is accepted in GSoC, I > > will be happy to co-mentor some student. I cant be full blown mentor > > as I am only 4 months old in clojure world. > > Thanks to Arun for pointing to the error and me gaining an extra hour > in 12 hours. its 3 months not 4 months :) > > regards > Vivek -- 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
[Newbie] leiningen and random jars
I'd really like to use leiningen to assemble my classpath for me, but need to reference a jdbc jar. What is the approved method of doing 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
Web Programming with clojure
My niche currently is web programming and web interfaces. I have not used java and I have a certain comfort level with lisp dialects. I use emacs 22.3.1 on slackware 13.0 32-bit. Therefore clojure is of interest to me. I would welcome links to discussions, resources etc. on this topic. Thanks -- Tim t...@johnsons-web.com http://www.akwebsoft.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
Re: Long-running STM updates will never complete... is there a solution?
On Tue, Mar 16, 2010 at 5:25 AM, Christophe Grand wrote: > On Mon, Mar 15, 2010 at 11:27 PM, Chouser wrote: >> >> I make no claims about the Rightness of this suggestion, but >> simply offer another example of a work-around: >> >> (dosync (alter r identity) (alter r f)) >> >> That is, a "dummy write" via alter is also sufficient to allow >> the transaction to succeed, just like 'ensure'. > > This is an interesting idea which can be automated (well, to be frank, an > implicit ensure could also be automated but it doesn't feel kosher) by > adding a doAlter to c.l.LockingTransaction: Well, what you've got there seems much cleaner than a dummy write, and makes 'alter' do a lot less work than it did. I won't pretend to understand the STM well enough to know if it's all correct though. --Chouser http://joyofclojure.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
Re: Web Programming with clojure
On Mon, Mar 15, 2010 at 3:11 PM, Tim Johnson wrote: > My niche currently is web programming and web interfaces. I have not > used java and I have a certain comfort level with lisp dialects. > I use emacs 22.3.1 on slackware 13.0 32-bit. > > Therefore clojure is of interest to me. > I would welcome links to discussions, resources etc. on this topic. > Thanks > There's a growing number of web related projects. All of which could use a considerable amount of documentation ;) You should look into Ring, Compojure, and Enlive. All of these can be found on Github. There's also quite a few libs now for persisting your data in one database or another. I personally have my eyes on Clutch as I'm a fan of CouchDB and the CouchDB-Lucene project. 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: [Newbie] leiningen and random jars
On Tue, Mar 16, 2010 at 12:22 PM, stevel wrote: > I'd really like to use leiningen to assemble my classpath for me, but > need to reference a jdbc jar. > What is the approved method of doing this? > You should put your jar into the lib directory of your project folder. You can customize this but it's wiser you follow the convention until you're comfortable/familiar with how lein works. 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: Web Programming with clojure
Hi people! I'm not use it, but first link to explore http://github.com/weavejester/compojure My collected links http://delicious.com/ajlopez/compojure http://delicious.com/ajlopez/clojure+webdevelopment Angel "Java" Lopez http://www.ajlopez.com http://twitter.com/ajlopez On Mon, Mar 15, 2010 at 4:11 PM, Tim Johnson wrote: > My niche currently is web programming and web interfaces. I have not > used java and I have a certain comfort level with lisp dialects. > I use emacs 22.3.1 on slackware 13.0 32-bit. > > Therefore clojure is of interest to me. > I would welcome links to discussions, resources etc. on this topic. > Thanks > > -- > Tim > t...@johnsons-web.com > http://www.akwebsoft.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 -- 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: Why do functions in the state monad only accept one value?
A major part of the "point" behind monads is that they can hide some implicit parameter passing. In the case of State, the implicit parameter is the current state and it is passed "inside" the bind operator. Haskell is no different from Clojure on this point: a State-using programme builds up a stateful computation first, then uses runState (or perhaps execState / evalState) to run it as a whole; only at this final step does the initial state actually get poured into the opening of the monadic pipe, as it were. N.B. the stateful computation itself -- the monadic value -- is actually a function, both in Clojure and in Haskell (and presumably in any other setting where people talk of the "state monad"). You can use it multiple times, each time injecting a different initial value of state. For this to be the case, you need to have a useful representation of monadic values in State which you can carry around, bind to names etc.; and in a Lambda the Ultimate kind of language like Haskell and Clojure, a function is the natural fit. For comparison, see how Haskell's State is an instance of MonadState (in other words, here are the Haskell definitions of get and put; note how put is a function returning a function when given a single parameter): http://hackage.haskell.org/packages/archive/mtl/1.1.0.2/doc/html/Control-Monad-State-Class.html#t%3AMonadState BTW, if you feel you'd rather write something like (defn put [v s] [v v]) than a "two-tier" function like c.c.monads/set-state, you're free to do so; then you can use #(partial put %) for set-state. Note that the Haskell code prefers a point-free approach which actually looks more like the c.c.m code. (Or you could say it emphasises the function-returning nature of put, like c.c.m does.) Sincerely, Michał PS. Sorry if this is a bit chaotic... I can't clean it up now, so I'll post in the hope that it's a least somewhat helpful. Might take another shot at it if it isn't. -- 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: [Newbie] leiningen and random jars
On Tue, Mar 16, 2010 at 9:22 AM, stevel wrote: > I'd really like to use leiningen to assemble my classpath for me, but > need to reference a jdbc jar. > What is the approved method of doing this? The best way to do it would be to push it to a public repository so everyone on your team can have access to it in an automated fashion. If the project is only going to be developed on one machine you could put it in lib/ as David suggests (just be careful not to run clean) or use mvn install:install-file if you have a pom file for it. -Phil -- 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: Vimclojure Performance on Windows
Hi, On Tue, Mar 16, 2010 at 07:01:38PM +, Emeka wrote: > Is Vimclojure stable enough to have it on my Window's Vista? I tried it out > before without success. I have a stable setup on Windows XP. I can't tell for Vista but I would not expect any problems beyond the usual Windows annoyances. 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: Web Programming with clojure
* David Nolen [100316 12:12]: > On Mon, Mar 15, 2010 at 3:11 PM, Tim Johnson wrote: > > > My niche currently is web programming and web interfaces. I have not > > used java and I have a certain comfort level with lisp dialects. > > I use emacs 22.3.1 on slackware 13.0 32-bit. > > > > Therefore clojure is of interest to me. > > I would welcome links to discussions, resources etc. on this topic. > > Thanks > > > > There's a growing number of web related projects. All of which could use a > considerable amount of documentation ;) You should look into Ring, > Compojure, and Enlive. All of these can be found on Github. There's also > quite a few libs now for persisting your data in one database or another. I > personally have my eyes on Clutch as I'm a fan of CouchDB and the > CouchDB-Lucene project. Keep 'em (links) coming. I appreciate the input. Also, I am testing to see how email works for this ML, I've been having problems with my emails getting to you folks. thanks -- Tim t...@johnsons-web.com http://www.akwebsoft.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
Re: Why do functions in the state monad only accept one value?
Jarkko Oranen writes: [...] > This way, you can write a function that works under many different > monads, as long as it uses the generic facilities to return monadic > values. eg. a lifted inc: > > (defn m-inc [v] > (m-result (inc v)) > > which can be used in the state monad as an argument to bind, even > though it doesn't care about the state at all. Ah, I hadn't realized that such functions -- of which I've now written several for use in the state monad -- actually say nothing about the state, and can be used in other monads as well. That was helpful to consider. -- Steven E. Harris -- 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: Why do functions in the state monad only accept one value?
Michał Marczyk writes: > a State-using programme builds up a stateful computation first, then > uses runState (or perhaps execState / evalState) to run it as a whole; > only at this final step does the initial state actually get poured > into the opening of the monadic pipe, as it were. That's a good metaphor. [...] > You can use it multiple times, each time injecting a different initial > value of state. Ah, but here's where part of my confusion arises. With this treatment of such a built-up computation, it's a kind of a zero-argument function, in that there's no way to pass in a "basic value" to kick it off. Where does the first "basic value" to be fed into the first monadic function come from? Presumably it comes from the first monadic value in the "pipe". In your description above, it sounds like this first monadic value must be committed to when "buld[ing] up a stateful computation first". In the parser examples I've seen, the state provides the input value. It's hard to find examples of other kinds of computations using the state monad, but even something like "do these arithmetic steps to some input number, and count the number of operations in the state" would want to start off with some number as input, distinct from the state, which would presumably start off with a count of zero. That sounds like we'd have to build up the arithmetic steps as a monadic function, not a monadic value, which we'd bind to (m-result initial-value) to kick it off. [...] > BTW, if you feel you'd rather write something like (defn put [v s] [v > v]) than a "two-tier" function like c.c.monads/set-state, you're free > to do so; then you can use #(partial put %) for set-state. Interesting idea. > PS. Sorry if this is a bit chaotic... I like the challenge of following your mental process. More examples on this topic would be welcome. -- Steven E. Harris -- 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: Web Programming with clojure
There's also Conjure which is a Rails like framework for Clojure. It includes everything you need, templating with clj-html, persistence with clj-record, and Ring to bind them all. You can find it on Github at: http://github.com/macourtney/Conjure I've added considerable documentation on the wiki: http://wiki.github.com/macourtney/Conjure/getting-started http://wiki.github.com/macourtney/Conjure/hello-world-tutorial-2 http://wiki.github.com/macourtney/Conjure/how-to I hope that helps. -Matt -- 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: Web Programming with clojure
* Matt [100316 17:16]: > There's also Conjure which is a Rails like framework for Clojure. It > includes everything you need, templating with clj-html, persistence > with clj-record, and Ring to bind them all. > > You can find it on Github at: http://github.com/macourtney/Conjure > > I've added considerable documentation on the wiki: > > http://wiki.github.com/macourtney/Conjure/getting-started > http://wiki.github.com/macourtney/Conjure/hello-world-tutorial-2 > http://wiki.github.com/macourtney/Conjure/how-to > > I hope that helps. Thank you Matt. :) I'm taking notes like crazy here. cheers -- Tim t...@johnsons-web.com http://www.akwebsoft.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
Re: Web Programming with clojure
there is a good screencast that deal with compojure + emacs. http://www.bestinclass.dk/index.php/2009/12/dynamic-interactive-webdevelopment/ compujure is a route based webframework, very much like ruby's sinatra. I figure with your emacs background, this will feel very much at home. On Mon, Mar 15, 2010 at 3:11 PM, Tim Johnson wrote: > My niche currently is web programming and web interfaces. I have not > used java and I have a certain comfort level with lisp dialects. > I use emacs 22.3.1 on slackware 13.0 32-bit. > > Therefore clojure is of interest to me. > I would welcome links to discussions, resources etc. on this topic. > Thanks > > -- > Tim > t...@johnsons-web.com > http://www.akwebsoft.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 -- Omnem crede diem tibi diluxisse supremum. -- 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: take-to-first & partition-when
Just saw that I need to sign the contributor agreement. Will do promptly. I additionally have implemented two new functions that I believe could fit in clojure-contrib.seq and clojure- contrib.combinatorics. The seq function partition-at-fenceposts allows you to partition a seq based upon bits flipped in an integer value passed in, where 1-bits correspond to partition boundaries, the least significant bit being earlier fenceposts in the seq. As such, this makes it possible to easily implement a function named partitions for clojure-contrib.combinatorics, which yields a lazy seq of all possible partitions of a seq. user=> (partition-at-fenceposts 1 '(1 2 3 4 5)) ((0) (1 2 3 4)) user=> (partition-at-fenceposts 2 '(1 2 3 4 5)) ((0 1) (2 3 4)) user=> (partition-at-fenceposts 3 '(1 2 3 4 5)) ((0) (1) (2 3 4)) user=> (partitions '(1 2 3)) (((0 1 2)) ((0) (1 2)) ((0 1) (2)) ((0) (1) (2))) user=> (partitions '(1 2 3 4 5)) (((0 1 2 3 4)) ((0) (1 2 3 4)) ((0 1) (2 3 4)) ((0) (1) (2 3 4)) ((0 1 2) (3 4)) ((0) (1 2) (3 4)) ((0 1) (2) (3 4)) ((0) (1) (2) (3 4)) ((0 1 2 3) (4)) ((0) (1 2 3) (4)) ((0 1) (2 3) (4)) ((0) (1) (2 3) (4)) ((0 1 2) (3) (4)) ((0) (1 2) (3) (4)) ((0 1) (2) (3) (4)) ((0) (1) (2) (3) (4))) implementation: (defn take-to-first "Returns a lazy sequence of successive items from coll up to and including the point at which it (pred item) returns true. pred must be free of side-effects." [pred coll] (lazy-seq (when-let [s (seq coll)] (if-not (pred (first s)) (cons (first s) (take-to-first pred (rest s))) (list (first s)) (defn partition-when "Applies f to each value in coll, splitting it each time f returns true. Returns a lazy seq of lazy seqs." [f coll] (when-let [s (seq coll)] (lazy-seq (let [run (take-to-first f s) res (drop (count run) s)] (cons run (partition-when f res)) (defn partition-at-fenceposts [b coll] "Partitions coll at fenceposts corresponding to bits in b that are set to 1. Returns a lazy seq of lazy seqs." (let [bits b] (map #(map first %) (partition-when (fn [[i v]] (not (zero? (bit-and (bit-shift-left 1 i) bits (indexed coll) (defn partitions [coll] "Returns a lazy seq of possible partitions of coll." (map #(partition-at-fenceposts % coll) (range (expt 2 (- (count coll) 1) On Mar 15, 1:24 pm, Greg Fodor wrote: > Hi there, I am just learning Clojure and am processing some BER > encoded integer values. Basically, the most significant bit of the > integer in the stream indicates the split point between integers, and > so I was looking into partition-by to see if that would help. Turns > out, what I really need are two complementary functions: take-to-first > and partition-when. Take-to-first is similar to take-while, but is > *inclusive* and also inverts the boolean. For example: > > Clojure=> (take-to-first even? [1 1 1 1]) > (1 1 1 1) > Clojure=> (take-to-first even? [1 1 1 1 2 3 3 3]) > (1 1 1 1 2) > Clojure=> (take-to-first even? [2 2 2 ]) > (2) > > Additionally, partition-when runs through the seq and partitions it on > demand when a predicate is true. (Leaving the entry where it is seen > to be true in the current partition: > > Clojure=> (partition-when even? [1 1 1 2 3 3 3 4 3 3 3 4 3 3 3]) > ((1 1 1 2) (3 3 3 4) (3 3 3 4) (3 3 3)) > Clojure=> (partition-when even? [1 1 1]) > ((1 1 1)) > Clojure=> (partition-when even? [1 1 1 2 3 3 3]) > ((1 1 1 2) (3 3 3)) > Clojure=> (partition-when even? [2 2 2 2]) > ((2) (2) (2) (2)) > > These seem to sit aside the current take and partitioning functions > since they are basically looking at an truth value that indicates a > partition or stopping event that we want to capture and cease moving > forward. Here is the source: > > (defn take-to-first > "Returns a lazy sequence of successive items from coll up to > and including the point at which it (pred item) returns true. > pred must be free of side-effects." > [pred coll] > (lazy-seq > (when-let [s (seq coll)] > (if-not (pred (first s)) > (cons (first s) (take-to pred (rest s))) > (list (first s)) > > (defn partition-when > "Applies f to each value in coll, splitting it each time f returns > true. Returns a lazy seq of lazy seqs." > [f coll] > (when-let [s (seq coll)] > (let [run (take-to-first #(f %) s) > res (drop (count run) s)] > (lazy-seq > (cons run (partition-when f res)) > > I think these could make a good addition to clojure.contrib.seq. > Please let me know if there is an easier way to get this in if you > agree. Also, please let me know if these are the best ways to write > these functions, since I am still a newbie! -- 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
Re: Web Programming with clojure
* Wilson MacGyver [100316 18:17]: > there is a good screencast that deal with compojure + emacs. > > http://www.bestinclass.dk/index.php/2009/12/dynamic-interactive-webdevelopment/ > > compujure is a route based webframework, very much like ruby's sinatra. > > I figure with your emacs background, this will feel very much at home. And again ... my many thanks. Here's a story for you: Some years ago, I posted a query to an online lisp community regarding a recommended lisp. One common lisp programmer recommended newlisp. I did a little with newlisp, really liked it, but one day I posted to the newlisp community whether any of them had contemplated writing newlisp in java. The developer replied: "That's clojure". So here I am. cheers -- Tim t...@johnsons-web.com http://www.akwebsoft.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
Re: Why do functions in the state monad only accept one value?
On 17.03.2010, at 00:17, Steven E. Harris wrote: > Ah, but here's where part of my confusion arises. With this treatment of > such a built-up computation, it's a kind of a zero-argument function, in > that there's no way to pass in a "basic value" to kick it off. Where > does the first "basic value" to be fed into the first monadic function > come from? There are a two kinds of inputs to a monadic computation in the state monad: 1) The initial state, provided when the computation is finally run. 2) The arguments to the functions that create the monadic values. It seems that your confusion comes from the second case. Superficially, it looks rather different in Clojure and Haskell because Haskell programs use currying. Fundamentally, there is no difference, however. Let's look at a simple use case: (domonad state-m [x (fetch-val :x)] (set-val :x (+ x 2))) This assumes that the state is a map, and adds 2 to the entry :x of the map. The two inputs to this computation are the map (provided when the computation is run), and the integer 2. This becomes even clearer when you define this as a named computational step: (def add-to-x [y] (domonad state-m [x (fetch-val :x)] (set-val :x (+ x y Now you can use this in a compound computation; (domonad state-m [_ (add-to-x 2) _ (add-to-x 5)] nil) Here it is pretty clear that 2 and 5 are inputs to the monadic computation. The key point is that each line of the domonad provides not a monadic value, but a function call that returns a monadic value. The arguments of that function call are all inputs to the computation. 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