More Monads
A couple of weeks ago, I took a crack at figuring out monads by implementing them in Clojure. Inspired by Konrad's work, I pulled that out and completed it. I had chosen to implement a monad as a hash-map which is then passed in to the standard monadic operations as an additional parameter. Lifting 'with-monad' and 'domonad' from Konrad's file, I implemented versions using that idea. One thing I saw is that 'replace-syms' could be simplified. I rewrote it as: (defn- replace-syms [sym-map expr] (cond (seq? expr) (map #(replace-syms sym-map %) expr) (coll? expr) (into (empty expr) (map #(replace-syms sym-map %) expr)) :else (get sym-map expr expr))) And then I changed it further to accommodate my needs. I also changed 'monad-expr' to be a single call to 'reduce'. There's a quick explanation of monads at the beginning of the file. Thanks to Konrad for posting some good code. File is at: http://groups.google.com/group/clojure/web/monad-redux.clj Jim --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Monadic Parsing
Continuing with the monad theme, I decided to implement monadic parsing in Clojure. Erik Meijer and Graham Hutton published a paper called "Monadic Parsing in Haskell" and I implemented the examples from that paper in Clojure. The code is available here: http://groups.google.com/group/clojure/web/monad-parser.clj And you also need the monad code from here: http://clojure.googlegroups.com/web/monad-redux.clj The code is uncommented and should be read in parallel with the original paper from here (pdf): http://www.cs.nott.ac.uk/~gmh/pearl.pdf Comments welcome. Next up: monad transformers Jim --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: neo4j-clojure
Hey, I was just looking at neo4j last night. Can you point me to any papers about the theory behind those kinds of a databases? Thanks, Jim On Dec 6, 3:15 pm, Julian Morrison <[EMAIL PROTECTED]> wrote: > A wrapper for neo4j, which is a non-relational database using a > network of nodes with properties and traversable relationships. > > This is my first Clojure wrapper library, I've tried to keep the > spirit of Clojure by only wrapping things that were verbose or un- > lispy. Please comment and critique. Patches welcome. > > http://github.com/JulianMorrison/neo4j-clojure/tree/master --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: The return of the monads: lessons learned about macros
Konrad, I haven't had a chance to look at this in depth but I did see two things. First, the function 'group' that you define seems to be the same as Clojure's 'partition' function. Second, when I tried to load monads, I get the following error. java.lang.ExceptionInInitializerError (monads.clj: 165) Caused by: java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: user$m_PLUS_m_seq_PLUS_m__252 at clojure.lang.RT.readString(RT.java:1163) at user$m_PLUS_m_map_PLUS_m__272.(monads.clj:165) ... 26 more Caused by: java.lang.ClassNotFoundException: user $m_PLUS_m_seq_PLUS_m__252 (I snipped out some of the call stack.) Looking forward to digging into this later. Jim --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: The return of the monads: lessons learned about macros
Konrad, I got your code to work by doing the following: Replaced with-monad with: (defmacro with-monad [name & exprs] (let [bind-sym 'm-bind result-sym 'm-result zero-sym 'm-zero plus-sym 'm-plus] `(let [~bind-sym (:m-bind ~name) ~result-sym (:m-result ~name) ~zero-sym (:m-zero ~name) ~plus-sym (:m-plus ~name)] (do ~...@exprs And in defmonadfn changed (list ~fn-name '~'m-bind '~'m-result '~'m-zero '~'m-plus ~...@args)) to (list '~fn-name '~'m-bind '~'m-result '~'m-zero '~'m-plus ~...@args)) I'll probably have some more comments after I dig into the code. Jim --~--~-~--~~~---~--~~ 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 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: The return of the monads: lessons learned about macros
Konrad, I've looked over your monad code and I like it, FWIW. The macro programming will twist your mind if you don't have experience writing Lisp style macros, but the resulting syntax seems pretty clean. I would make some minor changes in two places. I would write with- monad as: (defmacro with-monad "Evaluates an expression after replacing the keywords defining the monad operations by the functions associated with these keywords in the monad definition given by name." [name & exprs] `(let [~'m-bind (:m-bind ~name) ~'m-result (:m-result ~name) ~'m-zero (:m-zero ~name) ~'m-plus (:m-plus ~name)] (do ~...@exprs))) And I would write m-lift as (defmacro m-lift "Converts a function f of n arguments into a function of n monadic arguments returning a monadic value." [n f] (let [expr (take n (repeatedly #(gensym "x_"))) vars (vec (take n (repeatedly #(gensym "mv_" steps (vec (interleave expr vars))] (list `fn vars (monad-expr steps (cons f expr) This removes the creation of the 'syms' list which you immediately tear apart to generate the other lists. All in all, a fine piece of code that I'll be using whenever I want to use monads in Clojure. I've also modified my parser combinator monad and uploaded a new version at: http://groups.google.com/group/clojure/web/monad-parser%20%282%29.clj Jim --~--~-~--~~~---~--~~ 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 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: The return of the monads: lessons learned about macros
Konrad, I did some more work from the paper the parser combinator is based on. From that I built what I think is a state monad transformer: (defn stateT [m] (monad [m-result (fn [v] (fn [s] ((:m-result m) (list v s m-bind (fn [stm f] (fn [s] ((:m-bind m) (stm s) (fn [[v ss]] ((f v) ss) m-zero (when (:m-zero m) (fn [s] (:m-zero m))) m-plus (when (:m-plus m) (fn [& stms] (fn [s] (apply (:m-plus m) (map #(% s) stms) ])) This function takes a monad and wraps it inside a state monad, producing a new monad with a combination of characteristics from both. I also rewrote the maybe monad as: (defmonad maybe "Monad describing computations with possible failures. Failure is represented by an empty vector, success by a vector with a single element, the resulting value." [m-zero [] m-result (fn [v] [v]) m-bind (fn [vs f] (into [] (mapcat f vs))) m-plus (fn [& mvs] (let [first-valid (first (drop-while empty? mvs))] (if (nil? first-valid) m-zero first-valid))) ]) (notice the change to the bind function). This let me write the parser monad as: (def parser-m (stateT maybe)) If that stateT function isn't actually a monad transformer, it still is a slick way of combining the two monads. Jim --~--~-~--~~~---~--~~ 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 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: The return of the monads: lessons learned about macros
Also, I came across set-state and fetch-state being implemented in terms of update-state. (defn set-state [s] (update-state (fn [x] s))) (defn fetch-state [] (update-state identity)) Jim --~--~-~--~~~---~--~~ 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 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: The return of the monads: lessons learned about macros
Konrad, Glad to know we were on the same page about monad transformers. That transformer was indeed a translation from the Haskell implementation. Using 'with-monad' does clean it up. I'll have to take a look at your implementation of m-bind. I did prefer the conciseness and the fact that it would handle a vector of more than one value. But the behavior is identical, so it seems it's more a matter of taste. > > I also rewrote the maybe monad as: > ... > > Why did you do this? Did you just want a more concise implementation, > or is there a difference in behaviour? As far as I can see, your > version of m-bind does exactly the same as mine for all input values > that can occur in the given context. Yours would also do something > useful given a vector of more than one value, but that should never > happen in the maybe monad. I've got some more thinking to do about transformers, when I get a chance. Jim --~--~-~--~~~---~--~~ 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 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: December monads
I also think this would be a great addition to clojure-contrib. Because of the way most monad tutorials are written, monads seem to be pretty hard to get your head around. Also, many of the reasons for the standard monads in Haskell don't exist in impure functional languages like Clojure. So there's less motivation to understand them. But I found that once I understood them, they are a powerful addition to my conceptual toolbox. Jim r wrote: > Hi, > > Although I am not a big fan of monads (I can't help the feeling this > abstraction is more difficult than the problem to solve) this starts > looking like a nice framework that should probably go into > clojure-contrib (perhaps with policy of not using this mechanism in > other clojure-contrib libs). --~--~-~--~~~---~--~~ 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 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: December monads
Definitely agree on the monad transformers. Haskell code can be very succinct, but it requires a particular perspective. I'm working towards a monad tutorial for Clojure using the intro I put in my monads implementation as a starting point. I've got quite a bit of work before I get to that point, though. Jim On Dec 22, 1:51 am, Konrad Hinsen wrote: > I also think that some aspects of monads are clearer in Clojure than > they are in Haskell. Haskell's way to implement monads as data types > has some practical advantages, but it also obscures the algorithmic > nature of monads a bit. Moreover, it makes some things impossible, > for example executing a single piece of code under different monads > (easy in Clojure by having the monad as a variable), which is quite > handy sometimes, e.g. for debugging. I also prefer monad transformers > implemented as functions to monad transformers implemented as pretty > complicated abstract data types with boilerplate code to get data in > and out. In the long run, we should have a monad tutorial for > Clojure, rather then let everyone learn Haskell first. --~--~-~--~~~---~--~~ 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 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: Functional way to implement a VM?
Just saw this thread. It's in my mind to do, but I don't know when I'll get to it. I've got a ton of code to write before I get to that item on my TODO list. However, if there'd be a place to put it on the Clojure page, I'd bump it to the top. Jim On Dec 23 2008, 1:07 am, Konrad Hinsen wrote: > On 22.12.2008, at 22:07, Mark Volkmann wrote: > > > Are you and or Jim planning to write an article onmonadsin Clojure > > any time soon? I'd love to see that. I don't understand them well now. > > Where would such an article best be published? I agree that there is > an interest in explainingmonadsspecifically in the context of Clojure. > > 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 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: Example of functional relational programming in clojure
I read that paper a couple of years ago and its what started me on the path toward functional programming which brought me to Clojure. As Rich said, it has some very important insights about complexity and presents an interesting idea of how to manage it. I took a crack at implementing it in SBCL but after I switched to Clojure, I've found the need for something like it greatly reduced because Rich has put such an emphasis on making concurrent programming easy. Jim Jack Norimi wrote: > I found this document > http://www.scribd.com/doc/3566845/FRP-Presentation-Web > and this document > http://web.mac.com/ben_moseley/frp/paper-v1_01.pdf > and this phrase > > Rich recommended a paper, Out of the Tar Pit, for a discussion of > > functional and relational techniques to manage state. > from http://stuartsierra.com/2008/08/08/clojure-for-the-semantic-web > > Can anybody provide an little example of *functional relational > programming* in clojure? > > Thank you. > > Jack Norimi --~--~-~--~~~---~--~~ 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 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: SVN branches
Rich, I like the way that's headed. I'm working on an network app where I'm parsing a stream from a TCP socket. Being able to get the chars from the socket in a lazy way, without reading one too many, would be great. I fudged that by defining a function to read a single char from the socket's input stream and then used lazy-cons to call it when needed. Look forward to using these lazy sequences. Jim Rich Hickey wrote: > On Feb 2, 2:27 pm, Chouser wrote: > > On Mon, Feb 2, 2009 at 2:05 PM, MikeM > > wrote: > > > > > There is a "lazy" branch in SVN. The "streams" branch has been > > > discussed, but I haven't seen any discussion of the "lazy" branch - > > > perhaps I missed it. > > > > Here's a discussion from earlier today, mainly about the "lazy" branch: > > > > http://clojure-log.n01se.net/date/2009-02-02.html#09:47 > > > > I've started documenting the lazy branch work here: > > http://clojure.org/lazier > > Feedback welcome, > > Rich --~--~-~--~~~---~--~~ 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 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: Parsec style library
Take a look at: http://clojure.googlegroups.com/web/monad-parser.clj It's the code from "Monadic Parsing in Haskell" written in Clojure. It'd have to be modified slightly to work with the new clojure.contrib.monads. But that would be easy to do. jim On Feb 3, 8:42 pm, sbkogs wrote: > Parsec is a very powerful parsing library for Haskell. I was mainly > attracted to Haskell because of this library (ala Pugs project which > used Parsec to create a Perl6 parser). > > I am wondering if there is an ongoing effort to write similar library > for Clojure. I have seen a very nice implementation of Monads in > Clojure.Contrib which can be used to build this library. Having such > powerful and easy way to build a parser could attract many more users > to Clojure. BTW, I have seen a parser combinator file by jim in the > files section, which could be used as a stepping stone. > > If anybody is working on similar library, please drop me a line. I > have some bandwidth to spend towards such work/fun. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Syslog
Has anyone done logging using syslog from clojure or java? Thanks --~--~-~--~~~---~--~~ 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 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: Syslog
Thanks Luc Prefontaine wrote: > We use apache common logging and log4j to do all our logging from both > Clojure and java components. > You can use the SyslogAppender iof log4j to log to syslog. > > To get log4j configured we use Spring but you could use the > -Dlog4j.configuration= when starting Clojure to load a log4j > configuration. > That would be simple an effective. > > To log from your code: > > (import '(org.apache.commons.logging LogFactory Log)) > > (defn get-logger [] > (LogFactory/getLog (str *ns*) ) > ) > > To get a logger specific to your current name space just call > (get-logger). You can do a (def log (get-logger)) at the top > of your files or you can call it dynamically each time you need it. > > (bean (. log getLogger)) > > will show you the details of your logger. > > Luc > > --~--~-~--~~~---~--~~ 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 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: Fully lazy sequences are coming - feedback wanted!
I also favor the optimal names. We're the pioneers in using clojure, so we should expect a few arrows. Hopefully, the number of clojure users in the future will be an order of magnitude greater than where we are now. For us to take short term hit, we can save a large number of people a lot of cycles later on. I also prefer it on aesthetic grounds. Breaking compatibility doesn't bother me much. Jim --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
state monad transformer
Konrad, Here's a shot at implementing a monad transformer for the state monad. Any chance of getting it added to clojure.contrib.monads? (defn state-t [m] (monad [m-result (with-monad m (fn [v] (fn [s] (m-result (list v s) m-bind (with-monad m (fn [stm f] (fn [s] (m-bind (stm s) (fn [[v ss]] ((f v) ss)) m-zero (with-monad m (when (not= ::undefined m-zero) (fn [s] m-zero))) m-plus (with-monad m (when (not= ::undefined m-zero) (fn [& stms] (fn [s] (apply m-plus (map #(% s) stms)) ])) I've also about finished with the first draft of a monad tutorial for Clojure based on clojure.contrib.monads. Jim --~--~-~--~~~---~--~~ 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 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: Parenscript in clojure?
I've got something that's pretty close. There are some other things in the queue before I can get it cleaned up and ready for public consumption, but I'm working towards that. Jim On Feb 18, 2:39 am, Jan Rychter wrote: > Is anyone working on a Parenscript > (http://common-lisp.net/project/parenscript/) for Clojure? > > If not, perhaps someone would like to start? :-) > > Parenscript is an incredibly useful Javascript generator which makes > writing web applications in Common Lisp much more pleasant. In > particular, it gives you macros in Javascript, which is unbelievably > useful. > > --J. --~--~-~--~~~---~--~~ 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 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: Clojure.contrib: name changes in monads
Konrad, Here's an updated state-m monad transformer. I dropped my CA in the mail today. I figure if I post a snippet of code to the list, it's public domain, so do with it as you wish. Or wait till Rich gets my CA. (defn state-t [m] (monad [m-result (with-monad m (fn [v] (fn [s] (m-result (list v s) m-bind (with-monad m (fn [stm f] (fn [s] (m-bind (stm s) (fn [[v ss]] ((f v) ss)) m-zero (with-monad m (if (not= ::undefined m-zero) ::undefined (fn [s] m-zero))) m-plus (with-monad m (if (= ::undefined m-plus) ::undefined (fn [& stms] (fn [s] (apply m-plus (map #(% s) stms)) ])) Jim On Feb 18, 2:24 am, Konrad Hinsen wrote: > The latest Clojure version broke many of my code by introducing the > function sequence whose name collided with my sequence monad. So I > decided that since now is the time for breaking changes, I should > solve that kind of problem thoroughly. I just renamed all monads in > clojure.contrib.monads and clojure.contrib.probabilities, the names > now have a -m suffix: sequence-m, maybe-m, etc. > > 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 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: Clojure.contrib: name changes in monads
Konrad, As long as your breaking things in monads, what would you think of changing m-seq to this. (defmonadfn m-seq "'Executes' the monadic values in ms and returns a sequence of the basic values contained in them." [& ms] (reduce (fn [q p] (m-bind p (fn [x] (m-bind q (fn [y] (m-result (cons x y ))) (m-result '()) (reverse ms))) so that it doesn't accept a list of monadic values but instead lets you call it with any number of mv's. Instead of: (m-seq [mv1 mv2 mv3]) you would write (m-seq mv1 mv2 mv3) That would make it be the same as the implementations of m-plus you've already done. Thanks On Feb 19, 1:45 am, Konrad Hinsen wrote: > On 18.02.2009, at 22:40, jim wrote: > > > Here's an updated state-m monad transformer. I dropped my CA in the > > mail today. I figure if I post a snippet of code to the list, it's > > public domain, so do with it as you wish. Or wait till Rich gets my > > CA. > > Thanks! It's in my working copy of themonadslibrary module > already, and I will check it in when I see your name on the > contributors' list. I'll be absent for a few days anyway, so it > hardly makes a difference. > > 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 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: Contributing
There's a logic programming module in the files section. It implements the system found in "The Reasoned Schemer". On Feb 18, 2:59 pm, Jeffrey Straszheim wrote: > Did you cover logic programming? Any bottom up logic query techniques? > (My motives are probably transparent.) > > On Wed, Feb 18, 2009 at 2:34 PM, Joshua wrote: > > > I am currently in a masters level Compiler class. We have a final > > project for the class and I was wondering if there would be any > > defects/enhancements that I could do in Clojure. I have about 5 years > > of professional Java experience with dabbling with some other > > languages. (not an expert, but pretty good). The amount of work for > > the project should be about 20-40 hours (I have a month). > > > Please let me know of any suggestions. > > > Joshua --~--~-~--~~~---~--~~ 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 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: Parenscript in clojure?
Seeing your comments, I've decided to try to get my Javascript generator suitable for public use. It'll take a day or two, I think. Have you got a catchy name for it? Jim Dan wrote: > > It depends on common lisp instead of clojure? :) > > How does ClojureScript integrates with Javascript libraries? It's almost > unthinkable now to do a site that is not based on some of the fine JS > libraries available. It's also a reason why I want the generated code not to > have overhead, we don't want to pay that cost twice (for the library and the > clojure-ish behaviour). --~--~-~--~~~---~--~~ 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 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: Parenscript in clojure?
Looking at qooxdoo was down a little further on my list, since Kenny Tilton mentioned it. I'd like to do some web app type stuff, which why I took a crack at the parenscript thing in the first place. On Feb 22, 2:18 pm, Dan wrote: > That would be great! My main reason to want this is for this library: > > http://qooxdoo.org/demo > > It's extremely desktop-ish but terribly verbose (java-like verbose) to > create a UI. There's an effort to make it less verbose by using XML to > translate to qooxdoo javascript but it's perpetually in beta and reeks of > greenspun's tenth law. > > Ideally, I'd like to be able to create everything in a lispy syntax and turn > UI building into easy functions / macros. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Becoming lazy
Is there a summary of the changes to Clojure that the lazy sequences required. For instance fnseq doesn't exist any more, that I see. Also, lazy-cons went away. Jim --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
with-meta and concat
In some old code, I did something like: (with-meta (concat [1 3] [8 4]) {:tail true})) which now fails. I believe it's because the result of concat is now some kind of reference. Does anyone have any advice on a workaround? Jim --~--~-~--~~~---~--~~ 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 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: Clojure.contrib: name changes in monads
I converted the code in the paper "Monadic Parsing in Haskell" to Clojure. Both m-plus and m-seq are used to combine lists of parsers. m-plus is used to build a parser that executes each parser in the list until one succeeds. m-seq is used to build a parser that executes all the parsers in the list sequentially and only succeeds if all the parsers succeed. Having m-plus accept a variable number of args is great, in that case. Having m-seq only accept one arg, which is a list, didn't feel like it followed the pattern established by m-plus. In any case, it's a pretty minor thing to adapt m-seq, so if there are other cases where the current implementation is easier, it's no big deal. Just felt like little rough edge. Jim On Feb 22, 3:10 pm, Konrad Hinsen wrote: > > Do you have a concrete use case where this would be advantageous? In > my certainly limited experience, m-plus is most frequently called > with two fixed arguments, whereas m-seq is typically called with a > list argument that was constructed using other list operations. In > the latter situation, the change you propose is a significant > disadvantage, all the more since m-seq is a macro and thus cannot be > used directly with apply. > > 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 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: Becoming lazy
Thanks, I had skimmed that link and then forgot about it. Jim On Feb 22, 3:13 pm, samppi wrote: > A good summary is here:http://clojure.org/lazier > --~--~-~--~~~---~--~~ 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 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: with-meta and concat
Thanks! That was exactly what I needed to get my old code to pass my unit tests. Now it's on to making changes to bring it up to date with the new lazy stuff. Jim On Feb 22, 3:32 pm, Chouser wrote: > > LazySeq extends AFn, so you can't change the metadata once the object > exists. However, Seq's still accept meta-data, so: > > (with-meta (seq (concat [1 3] [8 4])) > {:tail true}) > > --Chouser --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Logic Programming Contrib
One stepping stone to getting my parenscript-like javascript generator released is to get the logic programming module released. A couple of months ago, I implemented the system from "The Reasoned Schemer" in Clojure and posted it to the files section. I've updated it to take advantage of the monad library and the lazy sequence additions. This is what I've used to write the javascript generator. It could also have other uses like implementing Hindley-Milner type inference. I'd like to submit the revised version for inclusion in clojure.contrib. Any comments? Rich, I sent a CA last week. If you haven't gotten it or there's a problem, let me know. Jim --~--~-~--~~~---~--~~ 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 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: Logic Programming Contrib
Hadn't thought of that. There are two parts, the unification part and the implementation of the operators. In the interest of time and learning, I originally did a port of both parts. What I've since done is re-implement the operators, so that's a totally original implementation using lazy sequences and monads. The unification routines are about 50/50 since I had to implement some things differently because of differences between Scheme and Clojure. Before I submit it, I'll go back and see about re-implementing the unification concepts. Jim Rich Hickey wrote: > One concern I'd have is the originality of the code - did you port the > Reasoned Schemer code or just implement the concepts? > > Rich --~--~-~--~~~---~--~~ 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 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: Logic Programming Contrib
Good to know. Thanks. Michel S. wrote: > On Feb 24, 11:03 am, Rich Hickey wrote: > Kanren / Mini Kanren (Mini is the version in Reasoned Schemer) are MIT- > licensed: > > http://kanren.sourceforge.net/#Availability > > so even a port is alright. When I took Dan Friedman's class based on > the book, I recall he was encouraging the students to post their > implementations, so I don't think there'll be any problem with that. > > Regards, > > -- > Michel Salim --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Mini-Kanren
I've just uploaded a file that has the Mini-Kanren logic programming system described in "The Reasoned Schemer" implemented in idiomatic Clojure. The file is: http://clojure.googlegroups.com/web/mini_kanren.clj I'm offering this as a candidate for inclusion into clojure.contrib. There are three parts in the file; implementation, utility functions and unit tests. The implementation part is not a port. Whatever similarities exist between this and the code from the book are a result of the nature of the problem. This implementation takes advantage of Clojure's hash- maps, lazy seqs and monad library. There are 10 or so basic utility functions that provide some foundational capabilities. The rest of the utility functions are lifted straight from the book and are used in the unit tests. The unit tests, are Mini-Kanren statements lifted from the book that verify the validity of the implementation. If this goes into clojure.contrib, I would suggest separating the implementation and 10 basic functions and make that part of clojure.contrib. The rest I would put in a test script or something. I'd appreciate anyone with experience with mini-kanren making any suggestions for improvements for style or performance. Jim --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Javascript generator
I've just uploaded a javascript generator ala Parenscript. It's pretty half-baked, so be cautious using it until we get the bugs ironed out. http://clojure.googlegroups.com/web/js_gen.clj The code for the generator is about 250 lines. It depends on the mini- kanren implementation I just uploaded. The file also includes a bunch of unit tests of the various functions. At the bottom, there are some examples of javascript functions being generated. Bug reports very much appreciated. Jim --~--~-~--~~~---~--~~ 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 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: Mini-Kanren
I don't have a Scheme here to check it out, but doesn't (cons 1) yield '(1) or am I wrong? In either case how could it be stated more accurately/clearly? Thanks Jim On Feb 26, 7:52 am, "Michel S." wrote: > Hi Jim, > > "In Scheme, passing cons one parameter encloses that parameter in a > list, essentially cons'ing it to an empty list" > > As far as I know, no Scheme implementation does that. a cons is > strictly a pair of two things, where the idiomatic usage is that the > second thing is either another cons or the empty list, thus forming a > proper list, versus a list terminated by a dotted pair, which is an > improper list. > > (list x), in both Scheme and Clojure, produces a list with one item in > it. > > Regards, > > -- > Michel 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 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: Mini-Kanren
Looking at the code, lcons does indeed require two parms. I must've been zoned out when I wrote the comment. Thanks for catching that. On Feb 26, 9:10 am, Pierpaolo Bernardi wrote: > no. in scheme (and in all modern lisps), cons is a 2 arguments procedure. > Giving it 1 is an error. > > Some very old lisp dialects supplied NIL in place of missing arguments. In > these lisps > (cons 1) was equivalent to (cons 1 nil) > > Cheers > P. --~--~-~--~~~---~--~~ 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 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: Monad tutorial, part 1
Konrad, I just finished a tutorial last week. It'll be interesting to compare notes. I'm waiting for my shiny new web server to get here, so I can put it on line. Jim Konrad Hinsen wrote: > For those who are interested in monads but don't want to learn > Haskell first to understand the Haskell-based monad tutorials, I have > started to write a Clojure monad tutorial. Part 1 is now available: > > http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure- > programmers-part-1/ > > Feel free to post comments! > > 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 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: Monad tutorial, part 1
Interesting take on explaining monads. I hadn't articulated the link between 'let' and 'domonad' . Looking forward to part 2. On Mar 5, 12:21 pm, Konrad Hinsen wrote: > For those who are interested in monads but don't want to learn > Haskell first to understand the Haskell-based monad tutorials, I have > started to write a Clojure monad tutorial. Part 1 is now available: > > http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure- > programmers-part-1/ > > Feel free to post comments! > > 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 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 -~--~~~~--~~--~--~---
keys of struct-maps
Is there a more efficient way of getting the keys of a struct-map besides creating an instance and passing it to keys: >(def ts (create-struct :a :b)) >(keys (struct ts)) (:a :b) Thanks, Jim --~--~-~--~~~---~--~~ 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 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: keys of struct-maps
Thanks. I found a way to accomplish what I needed, but I'll tuck that patch in my back pocket for later. Jim On Mar 11, 5:07 pm, Timothy Pratley wrote: > They are not currently exposed, but a trivial patch will achieve what > you want:http://groups.google.com/group/clojure/web/struct.patch > --~--~-~--~~~---~--~~ 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 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: March 20th 2009 Rich Hickey Appreciation Day!
Ditto. > March 20th 2009 Rich Hickey Appreciation Day > > -Rayne --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Blow up
Hey Rich, I found an interesting way to blow up the stack. user=> (def tl (reduce #(concat %1 [%2]) [] (range 3500))) #'user/tl user=> (last tl) java.lang.StackOverflowError (NO_SOURCE_FILE:0) The 3500 is probably specific to my environment. I'm assuming that all the concats get deferred until needed and that the nested calls blow up the stack. Also, this works user=> (def tl (reduce #(conj %1 %2) [] (range 4000))) #'user/tl user=> (last tl) 3999 Jim --~--~-~--~~~---~--~~ 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 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: Nested loops
I didn't take time to read your post in detail because I'm on my way to bed and my brain has already checked out. However, as I've gotten better at Clojure and functional programming, I find I use loops less and less. I just got done putting the finishing touches on a package to analyse stock charts. Typically, I would have loop inside of loop inside of loop. But now, I use map, filter and reduce all over the place, but not a single loop keyword to be found. Nowadays, I feel like that if I have to use 'loop' in my code, it's a huge red flag that I'm doing something wrong. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Scan function
I implemented a scan function, that is a function like reduce but that returns a list of the intermediate results not just the last one. (defn scan ([f coll] (scan f (first coll) (rest coll))) ([f val coll] (when (not (empty? coll)) (let [new-val (f val (first coll))] (lazy-seq (cons new-val (scan f new-val (rest coll Is this best way to implement that or is there already a Clojure function that does this that I've missed? Thanks, Jim --~--~-~--~~~---~--~~ 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 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: Javascript generator
I'll be glad to support it if people choose to use it and report issues. My plans to use are still on my todo list, things just keep getting put on top of them. One of which is to get my own server set up to host this and some other projects. I'll check out those asserts and make them so they're not dependent on order. Have you seen anything else that needs to be fixed? Thanks Jim --~--~-~--~~~---~--~~ 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 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: Javascript generator
I got my static IP today. I'm setting up the web server now. I'll setup the Git server ASAP. --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Monads tutorial
I've just posted a tutorial on using monads in Clojure at http://intensivesystems.net/tutorials/monads_101.html It's one big chunk of text since I haven't had time to break it up yet. It's also kind of rough, so if you see any typos, misspellings, errors, etc., post 'em here. Comments as well. Thanks, Jim --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Comment from a friend
> On another note, "closure" is misspelled. If intentional, it should be more > like "clothure" since it is Lisp. :) --~--~-~--~~~---~--~~ 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 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: Monads tutorial
The sample code is available now. Took a little bit to get it set. It's the code from the tutorial with a little bonus. I implemented an HTTP protocol parser, using the parser-m monad, as an example. Jim On Apr 16, 12:37 am, Baishampayan Ghose wrote: > The code pagehttp://intensivesystems.net/tutorials/code/monads_101.clj > is giving a 404 :) > > Regards, > BG > > -- > Baishampayan Ghose > oCricket.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 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 -~--~~~~--~~--~--~---
Help
Someone sent me an email about some issues with javascript generator I posted a couple of weeks ago. I have searched all my email locations and can't find any record of those emails or the response I know I sent. It that was you, would you mind emailing me again? Thanks, Jim --~--~-~--~~~---~--~~ 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 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: Help
Nevermind. On Apr 16, 3:28 pm, jim wrote: > Someone sent me an email about some issues with javascript generator I > posted a couple of weeks ago. I have searched all my email locations > and can't find any record of those emails or the response I know I > sent. It that was you, would you mind emailing me again? > > Thanks, > Jim --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Monad mod
Konrad, Love your monad library, but somethings always bothered me. The monad functions like m-seq, m-lift, etc. were macros so they couldn't be applied, passed as parameters. I'm impressed you were able to implement them using macros. While working on an unrelated thing, I had a flash of inspiration and implemented with-monad as below. This makes all those functions actual function objects. What do you think? Jim http://groups.google.com/group/clojure/web/with-monad.clj --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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: Monad mod
I see the point about being able to add new functions. If you do something like this, you still have defmonadfn available. I also think that m-lift can be written so that you don't need to pass it an argument count, which is another burr under my saddle. Jim --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
vimclojure help
Meikel, I'm having a heck of a time getting started with VimClojure and it's probably all due to my lack of knowing vim. After a lot of poking, I got the plugin to load and got syntax highlighting working. I also have got some autocmd's in my .vimrc so that they're listed when I do a :map. I got the nailgun server running. But I can't get gvim to start a REPL in a buffer. Could you point me to some docs or give a quick howto on getting that going? Thanks, Jim --~--~-~--~~~---~--~~ 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 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 help
Thanks for the response. Here's specifically what's happening: I have vim 7.2, according to the :version command in gvim I start the nailgun server with: java -cp /home/jim/clojure/clojure.jar:/home/jim/clojure/ clojure.contrib/clojure-contrib.jar:/home/jim/clojure/vimclojure.jar com.martiansoftware.nailgun.NGServer 127.0.0.1 and I get the response: NGServer started on 127.0.0.1, port 2113. I start gvim and give the command ":e temp.clj". temp.clj is an empty file. The :map command give this for the sr shortcut: n \sr ClojureStartRepl In normal mode, when I type "\sr", I get a beep when I type the 'r'. In the bash shell, when I execute "ng ng-stop", the ng server shutsdown. So what am I missing? Thanks, Jim --~--~-~--~~~---~--~~ 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 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 help
I forgot to say that I have: let clj_want_gorilla = 1 in my .vimrc On Apr 27, 12:08 pm, Meikel Brandmeyer wrote: > Hi Jim, > > Am 27.04.2009 um 18:08 schrieb jim: > > > I'm having a heck of a time getting started with VimClojure and it's > > probably all due to my lack of knowing vim. After a lot of poking, I > > got the plugin to load and got syntax highlighting working. I also > > have got some autocmd's in my .vimrc so that they're listed when I do > > a :map. I got the nailgun server running. But I can't get gvim to > > start a REPL in a buffer. > > > Could you point me to some docs or give a quick howto on getting that > > going? > > Please note, that people reported problems with Vims < 7.2. > So please make sure that you have a reasonable up-to-date vim. > > As for the documentation: > For the installation there is information in the README.txt and > a screencast on kotka.blip.tv, which walks you through the steps. > > For the usage there is information in the doc/clojure.txt. When you > copied it to the ~/.vim/doc directory, do a ":helptags ~/.vim/doc". > Then you get the online help via ":help vimclojure". > > Make sure you have "let clj_want_gorilla = 1" in your .vimrc. > > The keymappings use the feature of Vim. More > info for this can be obtained by ":help mapleader". Important > to know: the default is \. So ef in the docs means > actually \ef for the default settings. Starting the Repl would be \sr. > > Also important: If your file contains a ns or in-ns clause, you have > to make sure, that the namespace can be loaded correctly! VC > relies on Clojure for its introspection facilities. So it needs to load > the namespace of the file to work correctly. If you often edit files > outside the classpath, files having side-effect when being loaded > or files with broken syntax you might want to disable the dynamic > features with "let clj_want_gorilla = 0". > > Hope this gets you started. If not, I need some more specific > background on the actual problems/errors. > > Sincerely > Meikel > > smime.p7s > 5KViewDownload --~--~-~--~~~---~--~~ 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 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 help
I forgot to say that I have: let clj_want_gorilla = 1 let vimclojure#NailgunClient = "/home/jim/clojure/ng" in my .vimrc file. --~--~-~--~~~---~--~~ 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 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 help
The lack of error message stuck me as well. The result of :messages simply lists Bram Molenaar as the messages maintainer. I also mapped "\ab" to "a" so that it would enter insert mode and that worked fine. So I don't think it's a problem with the mapping. I'm guessing the plugin isn't fully loaded or something. Is there a way to check that? Perhaps a way to attempt to start the REPL from the command prompt? Jim Meikel Brandmeyer wrote: > Hi, > > Am 27.04.2009 um 19:56 schrieb jim: > > > I forgot to say that I have: > > > > let clj_want_gorilla = 1 > > let vimclojure#NailgunClient = "/home/jim/clojure/ng" > > > > in my .vimrc file. > > That's clear. Otherwise you wouldn't have the mapping > in the :map output. > > I'm a bit confused about the beep... There is no error > message of some kind? You can also check this with > :messages. > > 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 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 help
I think in my attempt to fix the problem, I masked a symptom. When I saw that I didn't have the key mappings, I added some autocmds to my .vimrc. From reading the vim plugin, I believe those should have been generated automatically when a *.clj file is loaded. Removing those autocmds from the .vimrc and the mappings go away. Reading the vimclojure plugin, I see that it checks for the existence of b:vimclojure_namespace before adding those mappings. When I do a :echo b:vimclojure_namespace, I get an undefined variable error. Jim On Apr 27, 3:09 pm, Meikel Brandmeyer wrote: > Hi, > > Am 27.04.2009 um 19:56 schrieb jim: > > > I forgot to say that I have: > > > let clj_want_gorilla = 1 > > let vimclojure#NailgunClient = "/home/jim/clojure/ng" > > > in my .vimrc file. > > That's clear. Otherwise you wouldn't have the mapping > in the :map output. > > I'm a bit confused about the beep... There is no error > message of some kind? You can also check this with > :messages. > > Sincerely > Meikel > > smime.p7s > 5KViewDownload --~--~-~--~~~---~--~~ 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 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: Would it be worth rewriting a parser library to use monads?
Monads are a great thing to learn because they can be used in so many ways to make code simpler and more modular. But, they require an investment of time to understand. You'll definitely be a better programmer by trying to understand them. I'd say go for it, but realize that it's going to be a steep learning curve at first. Jim On Apr 27, 5:48 pm, samppi wrote: > I have a library called FnParse, and I'm wondering if I should rewrite > it using monads. (You can see FnParse's documentation at wiki.github.com/joshua-choi/fnparse> and its implementation at github.com/joshua-choi/fnparse/blob/ > 065cc97da4c368e10d901edacbe885bd3a8443a1/src/name/choi/joshua/ > fnparse.clj>.) It implements a bunch of "rule functions" that consume > tokens: > Sequence of tokens -> [a new product from the consumed tokens, > remaining tokens] > > Right now, my basic rule-combining functions use loops over the rules > to be combined. > > Now, I've been reading the Clojure monad introductions that have been > popping up around, and some things that struck me as interesting were > that parsers could be elegantly implemented using monads, and that > monads were modular and combinable. > > I don't know enough about monads, though, to know if it'd be worth > trying to rewrite my library in it. It seems like if do that, people > may be able to directly use the new monads in their own monads, but > I'm not sure. My library is working fine as of now—would it be worth > it to add monads to it? --~--~-~--~~~---~--~~ 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 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 help
That was exactly what I was reading through the vimclojure.vim plugin trying to find when I saw your post. It's a great thing to have when trying to trouble shoot problems because you can isolate the server. Anyway, I started over by wiping out my .vim and vimclojure-2.1.0 directories. Updated and rebuilt clojure and clojure-contrib. Re- downloaded and rebuilt vimclojure paying very careful attention to get all the details right. And when I ran the ng-server script, it still blew up with an error from 'find'. Finally discovered what I think is a bug in the ng-server script. The find command has a '1' between the "-depth" and "-print0". Removing this allowed me to start the ng server with the script, which helped. But I get the following error when I do the ng command you posted: java.lang.NoClassDefFoundError: clojure/lang/APersistentMap (wrong name: clojure/proxy/clojure/lang/APersistentMap) CLASSPATH for the server is: /home/jim/vimclojure-2.1.0/build/vimclojure.jar:src CLOJURE_EXT for the server is: /home/jim/clojure /home/jim/clojure contains clojure.jar and clojure-contrib.jar. On Apr 27, 4:29 pm, Meikel Brandmeyer wrote: > Hi, > > Am 27.04.2009 um 22:50 schrieb jim: > > > Reading the vimclojure plugin, I see that it checks for the existence > > of b:vimclojure_namespace before adding those mappings. When I do > > a :echo b:vimclojure_namespace, I get an undefined variable error. > > Please try the following from outside vim: > > ng de.kotka.vimclojure.nails.NamespaceOfFile < some.clj > > For an empty file this should return user, for a file with ns or in-ns > it should return the namespace. Does this work? > > Sincerely > Meikel > > smime.p7s > 5KViewDownload --~--~-~--~~~---~--~~ 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 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: cannot use swig native shared libraries
Hey Antonio, I'm getting a similar error. I wanted to call setuid from Clojure, so I followed this link's example: http://www2.sys-con.com/itsg/virtualcd/Java/archives/0510/Silverman/index.html to build a java class and a shared library. I added the class to my classpath and was able to import my UID class. But when I tried to call the UID.setuid method, it gave me that UnsatisfiedLinkError. Did you find a solution to your problem? Jim On Apr 22, 8:41 am, "Antonio, Fabio Di Narzo" wrote: > Hi all. > I'm having problems with using swig-generated wrappers with Clojure. > I'm running ubuntu-8.04-i386, gcc-4.2.4, swig-1.3.33, openjdk-1.6.0, > latest clojure release. > > I've cut down a minimal reproducible example. > The swig file: > ---file:swig_test.i--- > %module swig_test > %{ > int swig_test_whatever() { > return 3;} > > %} > int swig_test_whatever(); > ---cut--- > > Compile with: > ---cut--- > mkdir swig_test > swig -java -package swig_test -outdir swig_test swig_test.i > javac swig_test/*.java > export JAVA_HOME=/usr/lib/jvm/java-6-openjdk > export JNI_CFLAGS="-I${JAVA_HOME}/include -I${JAVA_HOME}/include/ > linux" > gcc -shared ${JNI_CFLAGS} swig_test_wrap.c -o libswig_test.so > ---cut--- > > The swig-generated java itfc file is: > ---file:swig_test/swig_test.java--- > package swig_test; > public class swig_test { > public static int swig_test_whatever() { > return swig_testJNI.swig_test_whatever(); > }} > > ---cut--- > > The clojure code: > ---cut--- > (import '(swig_test swig_test)) > > (System/load > (.concat (System/getProperty "user.dir") "/libswig_test.so")) > (swig_test/swig_test_whatever) > ---cut--- > I get: > java.lang.UnsatisfiedLinkError: > swig_test.swig_testJNI.swig_test_whatever()I (NO_SOURCE_FILE:0) > > I can use "manually written"JNIwrappers with clojure and, vice- > versa, swig-generated wrappers with plain java code. What I'm missing > here? Anybody can help? > > Bests, > Antonio, Fabio Di Narzo. --~--~-~--~~~---~--~~ 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 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 help
Success! After changing ng-server to be correct, I set up CLOJURE_EXT and CLASSPATH, then called it. Calling ng from the command line showed that it still couldn't find clojure-contrib.jar, so I added that to CLASSPATH. Then calling ng from the command line gave me 'usr'. Gvim was still failing when I started a REPL from command mode. It was giving an error that it couldn't find /home/jim/vimclojure-2.0.1/ng. Instead of figuring out why, I just created the directory and put ng into it. After that, things worked. Jim On Apr 28, 10:52 am, Meikel Brandmeyer wrote: > Hi, > > Am 28.04.2009 um 01:56 schrieb jim: > > > java.lang.NoClassDefFoundError: clojure/lang/APersistentMap (wrong > > name: clojure/proxy/clojure/lang/APersistentMap) > > This is a sign, that the clojure.jar is missing from the classpath. > Please change the -depth to -maxdepth (keeping the one) as > was noted by Micheal in the other message. Please let me > know if this fixes the problem for you. > > Hmmm... No one complained about this up to know.. However > I will fix the launcher script (it's a mess anyway) and provide > a fix in the next bugfix release. > > Sincerely > Meikel > > smime.p7s > 5KViewDownload --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
more vimclojure
Meikel, I've been poking at vimclojure and I like it. I'm looking forward to get good at using it. So far, I've changed it so that the preview window and new REPL's open to the right of the current window. One question, is it possible to restart a REPL so that any definitions loaded previously are gone and you have a brand new environment to work in? Thanks, Jim --~--~-~--~~~---~--~~ 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 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: more vimclojure
The position setting sounds good. As far as the new REPL goes, in much of my code, I set the namespace and I would like to have all those blown away as well. Would it be possible to add a command to the nailgun server that would cause it to shutdown and automatically restart? Alternatively, I got Java Service Wrapper, http://wrapper.tanukisoftware.org/doc/english/download.jsp, working with a network app of mine. Supposedly, it starts a JVM and restarts it if it crashes. If something like that was used, just killing the server would cause it to be restarted. Jim On Apr 28, 3:06 pm, Meikel Brandmeyer wrote: > Hi, > > Am 28.04.2009 um 21:55 schrieb jim: > > > I've been poking at vimclojure and I like it. I'm looking forward to > > get good at using it. So far, I've changed it so that the preview > > window and new REPL's open to the right of the current window. > > The next version will have a vimclojure#SplitPos so that one > can choose the position (left, right, top or bottom). > > > One question, is it possible to restart a REPL so that any definitions > > loaded previously are gone and you have a brand new environment to > > work in? > > Not yet. You have to restart the server. The problem is, that the > connection to the Repl is not continuous but re-established every > time a command is sent. So I have to distinguish the connections. > Hmm.. Maybe I will install one namespace per Repl. So closing > the Repl with ,close will nuke the namespace.. Hmm... > > Anyway noted down for the feature list. > > Thanks for the feedback. > > Sincerely > Meikel > > smime.p7s > 5KViewDownload --~--~-~--~~~---~--~~ 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 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: more vimclojure
Meikel, I'm liking what I've seen so far of vimclojure. One request is to have the preview window stay up all the time and keep adding to it with the \ef, \et, \eb, etc. commands. Having it come and go is distracting to me. My $0.02 Thanks, Jim On Apr 29, 12:07 pm, Meikel Brandmeyer wrote: > Hi, > > Am 29.04.2009 um 04:42 schrieb Johan Berntsson: > > > I've been emailing directly to Meikel, but perhaps a issue tracker of > > some kind would be good? It is of course up to Meikel, and VimClojure > > is already good enough for me to use for all my Clojure hacking > > (including some paid work). > > As for bug reports there are several possible places: > > - here (I feel a little uncomfortable with that, but as long as > the "I can't get SLIME to work" thread show up, it's ok, I > think) > > - me (writing a personal mail is always possible) > > - the issue tracker:http://bitbucket.org/kotarak/vimclojure/issues/ > Although I'd like to follow Rich's example and would like > to request, that issues are discussed with me before a ticket > is opened. > > I'm glad to see that VimClojure has a growing user basis > and people have good experiences with it. :) > > Sincerely > Meikel > > smime.p7s > 5KViewDownload --~--~-~--~~~---~--~~ 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 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 -~--~~~~--~~--~--~---
Monads tutorial Part 2
I've just posted the second part of my monads tutorial at: http://intensivesystems.net/tutorials/monads_201.html I need to proof it further, so if you see problems with content, grammar or spelling. Comment here or send me an email. Jim --~--~-~--~~~---~--~~ 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 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: Help w/ monadic parser
I'm trying to pack to leave town for a week. I'll try to post something, but Sunday will be the earliest since I'll be spending most of tomorrow in a small metal tube at 20,000 feet in the air. Jim Howard Lewis Ship wrote: > I've been struggling to create a monadic parser. I'm parsing XML > documents into a DOM tree. Step one is to use a SAX parser to create > a stream of XML tokens; each a struct map. The token types are > :start-element, :attribute, :text and :end-element. > > Next I'm feeding this list of tokens into a monadic parser I've > created following > http://intensivesystems.net/tutorials/monads_101.html. The output > should be a DOM tree structure; element nodes will contain an > :attributes key (containing attribute tokens) and a :body key > containing child text and elements nodes. > > I've had to make some minor changes to the tutorial's parser-m monad, > to allow for the fact that I'm parsing tokens, not character strings. > > As I parse :attribute elements, I take the original element node and > add the attribute token to the :attributes list inside the element > node struct, creating the vector as necessary. > > I have this working for the simple case, where I only allow for > at-most one attribute token. > > (defmonad parser-m > [m-result (fn [x] > (fn [tokens] > (list x tokens))) > >m-bind (fn [parser action] > (fn [tokens] > (let [result (parser tokens)] >(when-not (nil? result) > ((action (first result)) > (second result)) > >m-zero (fn [tokens] > nil) > >m-plus (fn [& parsers] > (fn [tokens] > (first > (drop-while nil? > (map #(% tokens) parsers)]) > > ; And some actions and parser generators > > (defn any-token > "Fundamental parser action: returns [first, rest] if tokens is not > empty, nil otherwise." > [tokens] > (if (empty? tokens) > nil > ; This is what actually "consumes" the tokens seq > (list (first tokens) (rest tokens > > ; Utilities that will likely move elsewhere > > (defn add-to-key-list > "Updates the map adding the value to the list stored in the indicated key." > [map key value] > (update-in map [key] #(conj (or % []) value))) > > (with-monad > parser-m > > (defn token-test > "Parser factory using a predicate. When a token matches the > predicate, it becomes > the new result." > [pred] > (domonad > [t any-token :when (pred t)] > ; return the matched token > t)) > > (defn match-type > "Parser factory that matches a particular token type (making the matched > token the result), or returns nil." > [type] > (token-test #(= (% :type) type))) > > (defn optional [parser] > (m-plus parser (m-result nil))) > > (declare element one-or-more) > > (defn none-or-more [parser] > (optional (one-or-more parser))) > > (defn one-or-more [parser] > (domonad [a parser > as (none-or-more parser)] > (cons a as))) > > (defn attribute > "Parser generator that matches attribute tokens, adding them to > :attributes key of the element-node, and returning the new > element-node." > [element-node] > (domonad [attribute-token (match-type :attribute)] > (add-to-key-list element-node :attributes attribute-token))) > > (defn text > "Parser generator that matches text tokens, adding them to the :body > key of the element-node, and returning the new element-node." > [element-node] > (domonad [text-token (match-type :text)] > (add-to-key-list element-node :body text-token))) > > (def match-first m-plus) > > (defn body-token > [element-node] > (match-first > (attribute element-node) > (text element-node) > (element element-node))) > > (defn process-body > [element-node] > (domonad [modified-element (optional (body-token element-node))] > (or modified-element element-node))) > > (defn element > "Parses an element token into an element-node, and then adds the > fully constructed element-node to the > :body of the containing element node." > [container-element-node] >
Re: Monad problems: finding an m-zero
Samppi, Here's a parser-m monad I did. (defmonad parser-m [m-result (fn [x] (fn [strn] (list x strn))) m-bind (fn [parser func] (fn [strn] (let [result (parser strn)] (when (not= nil result) ((func (first result)) (second result)) m-zero (fn [strn] nil) m-plus (fn [& parsers] (fn [strn] (first (drop-while nil? (map #(% strn) parsers)]) I explain it in: http://intensivesystems.net/tutorials/monads_101.html What kind of parsing are you doing? Jim -- 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: Monad problems: finding an m-zero
Glad you found that tutorial useful. I had to run this morning, so I couldn't really reply. I'll try to read your post more closely tomorrow and see if I can offer any useful insight. Jim -- 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: Monad problems: finding an m-zero
Samppi, Good work on figuring that out. It's by working through those kinds of problems that you really learn about monads. It is indeed the case that not all monads have m-zero and m-plus defined for them. The state- m monad is one of those. Not only that, but if you take a look at the state-t monad transformer, you'll see m-zero defined like this: m-zero (with-monad m (if (= ::undefined m-zero) ::undefined (fn [s] m-zero))) Notice that when you combine the state-m monad with another monad using state-t, an m-zero for the resulting monad is only defined if the original monad had an m-zero. Also notice that when an m-zero is defined for the original monad, the new m-zero is a function that accepts a state and returns the original m-zero without regard to the state that was passed in. And that's where your original monad ran into problems, you tried to make the new m-zero's return value dependent on the state that was passed in. Furthermore, it's hard to see it, but :when clauses in domonad require that m-zero exists, and obeys the monad laws for zero and plus. So if you're m-zero is incorrect, :when clauses won't work either. At this point, you need to drop back and understand exactly what you're trying to accomplish and make sure you really understand monads as fully as possible. I just spent almost 2 weeks working on my own monad for writing web applications. I finally gave up and sat down to really learn how the continuation monad works. After that, I discovered I could use it instead of writing my own and it turned out to be very easy. Very often, you can come up with something that almost works and think that it just needs one more tweak to get it right. That's what happened to me and I wasted a lot of effort before I finally tossed it out and really focused on understanding. If you'd like to post details of what you're doing, I'd guess some folks would lend some assistance. Jim On Nov 22, 11:04 am, samppi wrote: > Thanks for the help. > > After working it out, I just figured out that the reason why the > second axiom isn't fulfilled by the m-zero above is this part in m- > bind: > ((product-fn product) new-state)) > > product-fn, which in the second axiom's case is (fn [x] m-zero), gets > called and becomes m-zero, which is in turn called on new-state, not > the old state. > > I cannot figure out at all, though, what m-zero *is* valid under both > axioms. Now I don't see how it's simply possible at all—are there > monads for which there is no value of m-zero, and is this one of them? > > On Nov 21, 9:02 pm, jim wrote: > > > Glad you found that tutorial useful. I had to run this morning, so I > > couldn't really reply. I'll try to read your post more closely > > tomorrow and see if I can offer any useful insight. > > > Jim -- 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: Monad problems: finding an m-zero
I wrote one specifically for monads in Clojure. http://intensivesystems.net/tutorials/monads_101.html There's also a second part. Also, Konrad Hinson wrote one: http://onclojure.com/2009/03/06/a-monad-tutorial-for-clojure-programmers-part-1 it's in 4 parts, I believe. John Harrop wrote: > On Sun, Nov 22, 2009 at 4:25 PM, Martin DeMello > wrote: > > > On Mon, Nov 23, 2009 at 2:40 AM, John Harrop wrote: > > > Is there an explanation of monads out there that doesn't require the > > reader > > > to know Haskell to understand it? One that's generic to any FP-capable > > > language? > > > > Most of them use the concrete syntax of *some* language. But this is a > > good non-haskell one: > > > > > > http://www.ccs.neu.edu/home/dherman/research/tutorials/monads-for-schemers.txt > > > Thanks. -- 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: Monad problems: finding an m-zero
Konrad, Glad to see you're still around doing monads in Clojure. :) Jim -- 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
Sneak Peek
Evening all, I've been working on a library for writing web applications for compojure. I've got it written and (I think) working. First thing tomorrow is to write a sample app and post it along with the library. But in the meantime, I thought I'd let you all read about it if you're having trouble sleeping. :) http://intensivesystems.net/tutorials/web_sessions.html One thing I love about FP in general and Clojure specifically is the density of code that is possible. This library is only about 80 lines of code. Jim -- 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: Sneak Peek
Graham, That's exactly what it is. I used the continuation monad from clojure.contrib.monads. After I get the code out, I'll be writing a tutorial on how it works which will also explain the continuation monad. I found that monad to be the most difficult to get my head around, but it's hugely powerful. Using it, that library only took about 50 lines of code to write. Having to account for browser history took another 30. However, those 50 lines of code will turn your brain to mush if you don't have a handle on the continuation monad. :) Jim Graham Fawcett wrote: > Hi Jim, > > On Tue, Nov 24, 2009 at 11:21 PM, jim wrote: > > Evening all, > > > > I've been working on a library for writing web applications for > > compojure. I've got it written and (I think) working. First thing > > tomorrow is to write a sample app and post it along with the library. > > > > But in the meantime, I thought I'd let you all read about it if you're > > having trouble sleeping. :) > > > > http://intensivesystems.net/tutorials/web_sessions.html > > Neat. It looks like you're writing what's usually called a > "continuation-based web framework". When I read your title and first > couple paragraphs, I thought you were writing a session-management > library (e.g. setting cookies, keeping server-side state, etc.). You > might consider mentioning continuations somewhere in your article, if > only to attract Googling continuation-based fans. > > You might already be familiar with other continuation-based > frameworks. If not, consider looking at projects like Wee (for Ruby) > and Seaside (for Smalltalk) to steal some ideas. :) > > Best, > Graham > > > > > One thing I love about FP in general and Clojure specifically is the > > density of code that is possible. This library is only about 80 lines > > of code. > > > > Jim > > > > -- > > 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: Sneak Peek
I discovered a rather subtle bug as I was coding an example web-app, so I haven't got the code out yet. Will ASAP. That tutorial is going to take a little time to write, because as the Haskell folks note, "Here be dragons!". The continuation monad is one of the most powerful and can be considered the mother of all monads: http://blog.sigfpe.com/2008/12/mother-of-all-monads.html But it will turn your brain to mush if you're not careful. Jim Martin Coxall wrote: > On Nov 25, 2:59 pm, Konrad Hinsen wrote: > > On 25.11.2009, at 15:32, jim wrote: > > > > > That's exactly what it is. I used the continuation monad from > > > clojure.contrib.monads. After I get the code out, I'll be writing a > > > tutorial on how it works which will also explain the continuation > > > monad. I found that monad to be the most difficult to get my head > > > around, but it's hugely powerful. > > > > I can confirm that impression... And only wish you good luck writing > > that tutorial! > > > > From the Haskell boys: > > "Abuse of the Continuation monad can produce code that is impossible > to understand and maintain." > > That sounds to me like a challenge. -- 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
ANN: Web application framework (beta)
I finally got time to find the bug in my web application framework. Here is the code to the framework: http://intensivesystems.net/tutorials/code/web_session.clj And here is a very simple sample app: http://intensivesystems.net/tutorials/code/web_app.clj The top level app is defined like this: (def web-app (web-while (constantly true) (web-seq get-name get-age get-gender (web-cond male? male-options :else female-options) show-summary))) Documentation is here: http://intensivesystems.net/tutorials/web_sessions.html This is beta code, so I'd be interested in any feedback. I'm starting work on the tutorial that explains how the code works and also the continuation monad. Trying to figure the code out just by reading the source will be extremely difficult unless you already have a very good understanding of the continuation monad, and even then the things I had to do to make the browser back button work really clog up the code. Jim -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: ANN: Web application framework (beta)
Not yet. :) You bring up some good points that I hadn't thought of yet. The itch I was scratching was how to easily write a web application for a limited number of users. I wanted to make that task cheap enough to be something a single programmer could do very quickly. OTOH, your comments have sparked a few thoughts. I've got to get the continuation monad tutorial written and then I may think about them. Jim Jim Powers wrote: > On Sun, Nov 29, 2009 at 7:21 PM, jim wrote: > > > I finally got time to find the bug in my web application framework. > > Here is the code to the framework: > > > > http://intensivesystems.net/tutorials/code/web_session.clj > > > This does indeed look cool, but here's the problem I have with all of the > continuation-style web-frameworks: they do not scale. This is to say in a > web-server farm setting you need a workable stickiness approach since you > always have to be routed back to the machine with the continuation you need. > So: > >- In the case of machine or process failure all state information is >lost. >- It is pretty easy to wind up with a very unbalanced web farm as due to >the randomness of user activity it is possible to have all of your active >users load-balanced onto only a few machines. >- If you force-ably load balance based on session count you can easily >under-utilize your web farm. >- Since one of the benefits of continuation-based web frameworks is the >amount and richness of the data that can be "transferred" between pages, > but >this (potentially lots of data) coupled with the problems listed above, can >become a serious problem under certain (potentially not-predictable) >circumstances. > > Clearly what would be desired is portable continuations that can be loaded > on any machine and/or duplicated/replicated for failure cases. > > This said, the web_session code is cool, but any thoughts on addressing the > more general problems? > > -- > Jim Powers -- 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 application framework (beta)
Jim, I think I can see how to write a library that would scale across any number of servers and I don't think it would be too difficult. I've got other itches to scratch before I'd get to it, but if people started asking for it (or someone wanted to sponsor the work) I might decide to do it sooner. Jim Jim Powers wrote: > Re: not all web applications have to scale - true, but I haven't worked on > one of those since about 1998 (this is an analog to Rich Hickey's statement > about not having to build non-concurrent programs in the last N years), > including "admin-like" things. Further: once you build all those > non-continuation-based components to support the "real site" it simply makes > no sense to write the "admin portions" in a completely different style > (although you clearly can). Also, "scaling up" portions of your web site > tends to have an unwelcome "need it sooner than you are ready" property. > Clearly what would be nice would be a distributed runtime that transparently > handles this problem. No, not Erlang, which still requires explicit passing > of data to specific nodes, but something that can move code and data around > transparently. > > Re: javascript - kinda, maybe. Although you can use this kind of approach > with something JS/AJAXy it is not completly clear what are the advantages. > Personally, things seem to be moving to Comet and the server-side is holding > less state and acting more as a soup of stateless calls. > > Just sayin' > > On Nov 30, 2009 6:57 AM, "Joel Westerberg" > wrote: > > > Not every web application has to scale. I think that continuation based > stuff rocks for adminstration interfaces. > > The main benefit with continuation based stuff, is that it's possible to > build something that is more application like, so that one can avoid > building wizards, and having to split up stuff into separate steps. Another > good approach for managing state is to build the application in javascript. > > On Mon, Nov 30, 2009 at 5:09 AM, Jim Powers wrote: > > > > This does indeed look... > -- > > You received this message because you are subscribed to the Google Groups > "Clojure" group. To post 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
Continuation monad tutorial
Just finished the tutorial explaining the continuation monad in clojure. Haven't even proofed it but I want to head to the gym. :) http://intensivesystems.net/tutorials/cont_m.html -- 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: Continuation monad tutorial
Thanks. I'll add that comment. Konrad Hinsen wrote: > On 30 Nov 2009, at 23:07, jim wrote: > > > Just finished the tutorial explaining the continuation monad in > > clojure. Haven't even proofed it but I want to head to the gym. :) > > > > http://intensivesystems.net/tutorials/cont_m.html > > Great work! > > One comment I'd add is that in the last example: > > (def fn11 (m-chain [mf-a mark mf-b mf-c])) > (def mark-cont ((fn11 10) identity)) > (doall (map mark-cont [0 1 2])) > > the argument to fn11, 10, has no influence on the result. > > 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
New tutorial: web framework internals
Or how to use the continuation monad. I just posted the latest tutorial here: http://intensivesystems.net/tutorials/cont_m_web.html It covers the internals of the continuation-based web framework I wrote about here: http://intensivesystems.net/tutorials/web_sessions.html It's also a really good example of how to use the continuation monad to solve a problem. And there's a surprising (at least it was to me) realization at the end of the tutorial. Comments welcome. -- 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 use monads
Just posted a short piece on why monads are useful. This was prompted by some conversations last week with some folks. Comments, questions and criticisms welcome. http://intensivesystems.net/tutorials/why_monads.html Jim -- 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 use monads
Chouser, You're right that maybe-comp is simpler. Once you realize that the functions you want to compose are monadic functions under the maybe-m monad, you get that composition for 'free', with no further mental effort. With such a simple example, it's hard to see the benefit, but with more complicated monads the difference between the monad composition and ad-hoc style becomes greater. Where the ad-hoc version would have to be debugged, the monad version would already be proven to be correct. Beyond that, there are other things that you get 'for free' by using the monad functions. Don't have time to enumerate them now but might later. Jim On Dec 22, 3:14 pm, Chouser wrote: > > It's interesting to me that the definition of maybe-comp above is > arguably simpler that the definition of maybe-m, even without > counting the machinery of 'defmonad'. Presumably this is a hint > to how much more powerful maybe-m is than maybe-comp, and simply > shows I don't yet understand the power of monads. > > --Chouser > -- > -- I funded Clojure 2010, did you? http://clojure.org/funding -- 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
Stream processing
Here's a new piece I wrote about stream processing in Clojure. It's rushed and incomplete, just like the library. But I'm not going to have time to do much work on things after Christmas, so I wanted to get it out in case it might inspire others. http://intensivesystems.net/tutorials/stream_proc.html This is only a quick overview with a few hints of what it could be used for, so don't expect too much from it. Merry Christmas, Jim -- 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 use monads
I'll see what I can do. On Dec 23, 2:18 pm, Sean Devlin wrote: > +1 ataggart, Chouser > -- 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 use monads
I've expanded the tutorial a little. You can skip to "Another example" for the new stuff. I go through the same exercise using the probability monad. http://intensivesystems.net/tutorials/why_monads.html There are some corresponding additions to the sample code as well. Jim On Dec 23, 2:18 pm, Sean Devlin wrote: > +1 ataggart, Chouser > > On Dec 23, 3:02 pm, ataggart wrote: > > > I'd appreciate any added detail, since I had a similar reaction to > > Chouser, thus wasn't really grokking the monad (wikipedia's > > description is no more helpful). > > > On Dec 22, 2:10 pm, jim wrote: > > > > Chouser, > > > > You're right that maybe-comp is simpler. Once you realize that the > > > functions you want to compose are monadic functions under the maybe-m > > > monad, you get that composition for 'free', with no further mental > > > effort. With such a simple example, it's hard to see the benefit, but > > > with more complicated monads the difference between the monad > > > composition and ad-hoc style becomes greater. Where the ad-hoc version > > > would have to be debugged, the monad version would already be proven > > > to be correct. > > > > Beyond that, there are other things that you get 'for free' by using > > > the monad functions. Don't have time to enumerate them now but might > > > later. > > > > Jim > > > > On Dec 22, 3:14 pm, Chouser wrote: > > > > > It's interesting to me that the definition of maybe-comp above is > > > > arguably simpler that the definition of maybe-m, even without > > > > counting the machinery of 'defmonad'. Presumably this is a hint > > > > to how much more powerful maybe-m is than maybe-comp, and simply > > > > shows I don't yet understand the power of monads. > > > > > --Chouser > > > > -- > > > > -- I funded Clojure 2010, did you? http://clojure.org/funding -- 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
Probability Monad
Hey Konrad, I was looking at the probability monad today and think this definition of m-bind might be easier to understand. (defmonad dist-m [m-result (fn m-result-dist [v] {v 1}) m-bind (fn m-bind-dist [mv f] (reduce (partial merge-with +) (for [[x p] mv [y q] (f x)] {y (* q p)}))) ]) What do you think? Also, I was thinking about cond-dist-m. What if dist-m was redefined to be this (defmonad dist-m [m-result (fn m-result-dist [v] {v 1}) m-bind (fn m-bind-dist [mv f] (if (empty? mv) {} (reduce (partial merge-with +) (for [[x p] mv [y q] (f x)] {y (* q p)} m-zero {} m-plus (fn m-plus-dist [& mvs] (if-let [mv (first (drop-while empty? mvs))] mv {})) ]) I think that would roll cond-dist-m into dist-m, eliminating the need for a seperate monad. Don't know if you'd thought of that and discarded it or not. Love the work you've done to bring monads to Clojure. Jim -- 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: Probability Monad
I figured you'd had a good reason for doing it the way you did. Konrad Hinsen wrote: > On 24.12.2009, at 05:18, jim wrote: > > > I was looking at the probability monad today and think this definition > > of m-bind might be easier to understand. > > > > (defmonad dist-m > > [m-result (fn m-result-dist [v] > > {v 1}) > > m-bind (fn m-bind-dist [mv f] > > (reduce (partial merge-with +) > > (for [[x p] mv > >[y q] (f x)] > >{y (* q p)}))) > > ]) > > > > What do you think? > > I agree. In fact, I had reinvented merge-with because I wasn't aware > of its existence. > > > Also, I was thinking about cond-dist-m. What if dist-m was redefined > > to be this > > > > (defmonad dist-m > > [m-result (fn m-result-dist [v] > > {v 1}) > > m-bind (fn m-bind-dist [mv f] > > (if (empty? mv) > >{} > >(reduce (partial merge-with +) > >(for [[x p] mv > > [y q] (f x)] > > {y (* q p)} > > m-zero {} > > m-plus (fn m-plus-dist [& mvs] > > (if-let [mv (first (drop-while empty? mvs))] > >mv > >{})) > > ]) > > > > I think that would roll cond-dist-m into dist-m, eliminating the need > > for a seperate monad. Don't know if you'd thought of that and > > discarded it or not. > > At first glance I doubt that this works. Did you try it? > > Your m-bind looks equivalent to the one of my original dist-m, with > just an optimization for the case of an empty map. If that is true, > then your dist-m can't include the features of cond-dist-m, which > require a different m-bind. > > It is in fact essential for cond-dist-m not to eliminate invalid > values from the distributions immediately, but to accumulate their > weights into the map entry for some special value (nil in my > implementation). Otherwise the probabilities come out wrong for multi- > step computations containing more than one :when clause. > > 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: Why use monads
Don't really understand what point you're making. The way I see it, monads are incredibly useful for combining functions that all have the same signature. When you realize that that's the domain you're working in, you can use a monad and raise the level of abstraction that you're working at. In this area, the task seems to be educating programmers about how to use monads effectively. Lot of work yet to do, yet the theoretical foundation seems to be solid. Composing monads is a totally different subject with a lot of theoretical work yet to be done. Presently, monad transformers seem to be the way forward, but that's open to debate as you've pointed out. Vagif Verdi wrote: > On Dec 22, 2:10 pm, jim wrote: > > Chouser, > > > > You're right that maybe-comp is simpler. Once you realize that the > > functions you want to compose are monadic functions under the maybe-m > > monad, you get that composition for 'free', with no further mental > > effort. > > Except different types of monads do not compose, so you have to create > another artificial structure called monad transformers. And these new > structures introduce so much new artificial complexity that any > possible simplification becomes a moot point. > > This fact is realized even in haskell community: > http://lambda-the-ultimate.org/node/2749#comment-41078 > > I'd say that monads add way too much complexity in most cases. > Especially in impure languages where you can do many things much > simpler than involving 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
Language similarities
Had an interesting conversation with a programmer friend of mine. He's skeptical of my Lisp leanings and mostly sticks to the 'normal' languages; C++, Java, etc. I made that comment that pretty much all the languages derived from Algol like the C family, Java, Pascal, etc. were pretty much the same. He looked at me like I was insane. :) :) I guess when you're looking back on the world from the vantage point of s-expressions, they do look the same. IMHO. :) Erlang and Haskell would have a similar effect, I would suspect. Jim -- 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: Understanding the continuation monad's bind operator
Don't have time to go in depth on an explanation. But remember that m- bind must work with m-result according to the 3 monadic laws. This constrains what it can do. Don't know if you saw, but I did a whole tutorial on the continuation monad. It's at: http://intensivesystems.net/tutorials/cont_m.html Jim Steven E. Harris wrote: > In clojure.contrib.monads, there's a monad defined called "cont-m" to > model continuations. Its bind operator -- `m-bind` -- is defined as > follows: > > , > | (fn m-bind-cont [mv f] > | (fn [c] > | (mv (fn [v] ((f v) c) > ` > > I'm curious why there's an extra delaying wrapper function there. The > outermost `fn' form taking the argument "c" as a continuation looks like > it serves only to delay evaluation of the remaining forms. > > The parameter "mv" is a monadic value which, for the continuation monad, > is a function accepting a single continuation argument. The parameter > "f" is a monadic function which, again, for the continuation monad, is a > function accepting a value offered by a continuation and returning a > monadic value -- another function accepting a single continuation > argument. > > If all of that is true, then the form > > , > | (f v) > ` > > should evaluate to a monadic value and be suitable as a return value > from `m-bind'. In short, why is this not an acceptable implementation? > > , > | (fn m-bind-cont [mv f] > | (mv (fn [v] (f v > ` > > -- > 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: Lift and bind (was: Understanding the continuation monad's bind operator)
You know, I think you're right. I would refer you to part 2 of Konrad's monad tutorial, but the link is broken. Check google's cache, if you want to read an explanation immediately. I'll have to go change that. Thanks for pointing it out and sorry for any confusion. Jim Steven E. Harris wrote: > Konrad Hinsen writes: > > > For a function of a single argument, m-lift and m-fmap are equivalent. > > In Jim Duey's essay Higher Level Monads¹, he writes the following on the > lift operator: > > ,[ m-lift ] > | If you have a function that you would like to turn into a monadic > | function, that is a function that can be passed to m-bind, you use > | m-lift. > | > | m-lift takes two parameters, a function to lift and the number of > | arguments that function accepts. The argument count is the first > | parameter and the function is second. The return value is a function > | that can be passed to m-bind. > ` > > Isn't it the case, though, that a lifted function /can't/ be passed to > bind, because it's not a monadic function? A lifted function takes > monadic values as input, rather than a basic value. > > Is there some operator that converts a "normal" function > > a -> b > > to a monadic function > > a -> m b > > such that one could adapt a "normal" function for use in and among some > other monadic functions (such as with m-chain)? I'm not sure such a > translation is possible for all monads. > > I considered something like this > > , > | (defn as-monadic-fn [f] > | (fn [v] > | (m-result (f v > ` > > but it looks too simple. > > > Footnotes: > ¹ http://intensivesystems.net/tutorials/monads_201.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: Question about how to write efficient code in functional style
Here's a similar idea (also untested) (defn which-list [number] (let [by-5 (zero? (mod number 5))] (cond (and (odd? number) by-5) [:odd-5] by-5 [:even-5] (odd? number) [:odd] :else [:even]))) (reduce #(update-in %1 (which-list %2) conj %2) {} numbers) On Feb 28, 8:03 am, "Heinz N. Gies" wrote: > How about reducing it? > > Something along the limes of: (not tested) > > (reduce (fn [lists number] > (update-in lists [ > (if (odd? number) > (if (= 0 (mod number 5) :odd-5 :odd) > (if (= 0 (mod number 5) :even-5 :even)] (fn [l] (conj l number)) > numbers) > > Regards, > Heinz > > On Feb 28, 2010, at 2:54 , logan wrote: > > > Let's say I want to write a function that takes as an argument a list > > of n numbers, and returns 4 lists, a list of odd numbers that are > > multiples of 5, a list of even numbers that are multiples of 5, a list > > of odd numbers that are not multiples of 5, and a list of even numbers > > that are not multiples of 5. > > > If I were writing this function procedurally, I could create 4 empty > > lists, and iterate through my input list once, using a compound if > > statement to add to the appropriate list. > > > In functional style, I could use filter, but I can't seem to think of > > a solution that doesn't end up iterating through the whole list > > multiple times. > > > Can someone please teach me what is the correct clojure approach? > > Thanks. > > > -- > > 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
Logic programming in Clojure
I just posted a new tutorial about doing logic programming in Clojure. It makes use of the mini-Kanren port to Clojure I did last year. It's intended to reduce the learning curve when reading "The Reasoned Schemer", which is an excellent book. http://intensivesystems.net/tutorials/logic_prog.html Jim -- 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 To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: The % Schemer Series - are they worth the money?
Love 'em. Well worth the time and effort to go through them. They're often available used for good prices on Amazon. On Mar 23, 10:37 am, Sean Devlin wrote: > Hey folks, > I'm looking to add to my bookshelf. I was wondering what this groups > experience with the Schemer series of books is? > > Sean -- 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 To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Logic programming in Clojure
I've got to say that I'm not a logic programming guru. Mostly I just see the promise there. The observation about graph search came from the book "Simply Logical" that I linked to at the end, I believe. I certainly didn't originate it. If you check out Oleg's page, you'll find a lot of papers about logic programming that will answer your question better than I could. (Along with a ton of other interesting things to read. The man's a freakin genius.) Check out the sourceforge page for Kanren. http://kanren.sourceforge.net/ Konrad, you may be right about the optimizing compiler issue. With mini-Kanren being implemented in Clojure, perhaps Hotspot could do a good enough job optimizing to mitigate that issue somewhat. I don't know. As I was writing that tutorial, I started thinking about ways to implement mini-Kanren that would be better and other projects using it. Like a business rules engine written in Clojure. Too many cool things to work on, not enough time. :) Jim On Mar 23, 12:26 pm, Quzanti wrote: > Very interesting write up. > > What advantages would prolog have over such a language. Or if we are > trying to move beyond language wars - what styles of logic programming > would be more natural in either one or the other? > > I say that because my first thought is if you could build a logic > language on top of LISP then would prolog be needed as the other AI > language? > > I liked your insight on logic being a graph search. > > On Mar 23, 3:23 pm, jim wrote: > > > I just posted a new tutorial about doing logic programming in Clojure. > > It makes use of the mini-Kanren port to Clojure I did last year. It's > > intended to reduce the learning curve when reading "The Reasoned > > Schemer", which is an excellent book. > > >http://intensivesystems.net/tutorials/logic_prog.html > > > Jim -- 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 To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: Logic programming in Clojure
No. That's one of the improvements I would make if I get back to working on it again. Jim On Mar 26, 1:37 pm, Sophie wrote: > > Is it aware of all Clojure structures, including maps etc? -- 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 To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
Re: clojure unifier (also other symbolic reasoning support including rdf/owl/etc. ?)
Kevin, Check out file:///home/jim/logic-prog.html Jim On Apr 18, 10:19 pm, Kevin Livingston wrote: > does anyone have a clojure implementation of a unifier, eg. something > that does this: > > http://norvig.com/paip/unify.lisp > > if not I'll do it, but just thought I'd grab it quick if it was out > there. and any other good resources for symbolic reasoning? I've > been looking but haven't seen much that is clojure specific, obviously > there is Jena for Java (for RDF etc. support), but that's somewhat of > a mess to use in a language that affords the ability to just construct > lists etc. > > Kevin > > -- > 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 > athttp://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