Re: Understanding the continuation monad's bind operator
On 8 Jan 2010, at 02:43, Steven E. Harris wrote: Can you recommend a book that covers aspects of monads like these? I'd like to learn more about the abstract concepts than their implementation in a particular language. I don't know about any books. There's a lot of monad material on the Web, coming mostly from the Haskell community. A good starting point are the monad-related publications by Philip Wadler: http://homepages.inf.ed.ac.uk/wadler/topics/monads.html For an introduction, look at Monads for functional programming and Comprehending monads. 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: Having difficulties with compilation in slime, emacs and clojure-project
After I do the swank clojure project command, enter the directory and press return my Emacs gets stuck doing this: http://imgur.com/Ap8mo When I just go to the Slime CLI that works fine. Any idea what could be wrong there? Zef -- 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
On 08.01.2010, at 06:21, joel r wrote: But right now I need some help. Either I'm using dist-m wrong, or it's a bug I've found. It's a bug. More specifically, a typo in a recent improvement. It is fixed now, so please try again with the current version - or in fact go back to an older version before December 28. BTW, I suppose that instead of (domonad dist-m [a die b die] [+ a b]) you want (domonad dist-m [a die b die] (+ a b)) i.e. the distribution of the sum of two dice. I modified dist-m to evaluate a map instead of a vector, like this: (defmonad dist2-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)}))) ]) That's exactly the right fix! 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: Recommended JVM flags for Clojure
Ok guys, After trying all your suggestions, here is the combination that worked best for me (in the order of their impact solving the problem): JVM_FLAGS=-server \ -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode \ -XX:+UseCompressedOops \ -XX:+DoEscapeAnalysis \ -XX:+UseBiasedLocking \ -XX:PermSize=64M \ -XX:MaxPermSize=256M \ -Xmx2g Now my app consumes ~500M of resident memory, but at least does not crash and performance does not deteriorate. BTW, I also tried the 'new' branch suggested . Didn't see any noticeable effect. On Jan 8, 4:40 am, Seth seth.schroe...@gmail.com wrote: Hi Gabi, This may not be useful, but have you tried running the Clojure new branch? Rich implemented fine-grained locals clearing on the new branch, and it helps avoid holding onto unused data accidentally. http://groups.google.com/group/clojure/browse_thread/thread/14baed8f2... Seth -- 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: Having difficulties with compilation in slime, emacs and clojure-project
On Thu, Jan 7, 2010 at 11:37 PM, Joel jboehl...@gmail.com wrote: Hello, I have an emacs setup on OSX using elpa with the latest clojure-mode, swank-clojure, slime, slime-repl all from ELPA. When I upgraded to the latest swank-clojure in ELPA (swank-clojure-1.1.0), I began to get this error as well: Searching for program: no such file or directory, lisp I traced it back a bit, and found that the before advice on slime-read- interactive-args wasn't being called. It apparently wasn't activated. I evaluated the following form: (ad-activate 'slime-read-interactive-args) And now all seems to be working well. I'm not sure why this advice hasn't been activated. On the prior versions of swank-clojure, I didn't have this problem. Loading order issue maybe? Anyhow, try explicitly activating that advice and see if that fixes your problem. Cheers, Joel In updating Clojure Box to the latest I found that the defadvice form has to be loaded before slime is loaded. (I didn't know about ad-activate.) This would be a problem if you somehow require slime before the ELPA's package-initialize is called, which loads the swank-clojure autoloads, which includes the defadvice. Shawn -- 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: Having difficulties with compilation in slime, emacs and clojure-project
On Fri, Jan 8, 2010 at 4:39 AM, Zef Hemel zefhe...@gmail.com wrote: After I do the swank clojure project command, enter the directory and press return my Emacs gets stuck doing this: http://imgur.com/Ap8mo When I just go to the Slime CLI that works fine. Any idea what could be wrong there? Zef Check your inferior-lisp buffer. There may be some errors in there indicating clojure.main or swank.swank is missing. swank-clojure-project won't work unless all dependencies live in appropriate places under the project directory. Here's how I hacked Clojure Box startup to not wipe out the entire classpath and build it from scratch: http://bitbucket.org/shoover/clojure-box/src/8015172a1dc3/default.el#cl-33 Shawn -- 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: SLIME/Swank problem with swank.util.sys/get-pid and RuntimeMXBean
Phil Hagelberg p...@hagelb.org writes: If someone would volunteer to fix it, I'd be thrilled. Nobody who is interested in using CL and Clojure at the same time has stepped forward so far, which is why it's currently broken. Can you characterize what needs to be fixed? -- 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: generating a fn with a body based on user inputs, possible?
Hello, parse-infix, being a macro, works on the code-as-datastructure it has as arguments. So (parse-infix x) receives the symbol x , unevaluated, is in charge of returning a new datastructure (generally involving the symbol x). Only then, the compiler will evaluate the result of having called parse-infix with the symbol x. So you cannot have the result of having evaluated x at compile time (when parse-infix is called). 2010/1/8 tristan tristan.k...@gmail.com: Hi guys, I've been working on a problem where I want the user to be able to input an equation in infix notation which includes variables and convert that to a clojure fn that my program can call later. i.e. the user inputs the string a*(b+c) and i generate the unnamed function (fn [a b c] (* a (+ b c))). note: rather than having (fn [a b c] body), (fn [inputs] body), where inputs is a map and reference to variables is replaces with (get inputs variable), is fine, and possibly even simpler to work with later. Is this possible? or will i have to parse and evaluate the infix string on each call to the function, or come up with some way to compile the code and load it back in? Here is what I have attempted so far: http://github.com/tristan/modelmaker/blob/41844b9376b57c05b457c02ac70dfc39c0935a03/infix_parser.clj My (parse) function expects a string containing an infix equation and returns a vector where the first element is a list of symbols reflecting the prefix version of the equation (i.e. (list '* 'a (list '+ 'b 'c))) and the 2nd element is the list of variables (i.e. (list 'a 'b 'c)). It is called by my macro (parse-infix) that takes the result from (parse) and expands to an unnamed function. At first I thought I had solved it, as calling (parse-infix a*(b+c)) returned the desired function that i could call. However as soon as i attempted to use it in the form (parse-infix users-input) it falls over with a Don't know how to create ISeq from: clojure.lang.Symbol error (examples in code at the bottom of the above file). I have fallen victim here to my own lack of understanding of macros. I now understand my folly and have a better understanding of how macro expansion works, however now I'm stuck as to how to solve this problem. Another thing i've attempted is as follows. I thought that I could simply return an unnamed function which accepts a map (i.e {'a 1 'b 2 'c 3}) and change my (parse) function to insert something along the lines of (list 'get 'inputs variable), such that i can just call (eval prefix). So i wrote this: (defn parse-infix [infix] (let [[f v] (parse infix)] (fn [inputs] (if (= (count inputs) (count v)) (eval f) (throw (Exception. (str expected (count v) inputs, got (count inputs but eval doesn't seem to use the same context as the Thread that calls it, so it complains that it's Unable to resolve symbol: inputs in this context. I've played a bit with with-bindings as well but cannot seem to get any results from it either. thanks .Tristan -- 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: generating a fn with a body based on user inputs, possible?
On Fri, Jan 8, 2010 at 9:10 AM, tristan tristan.k...@gmail.com wrote: At first I thought I had solved it, as calling (parse-infix a*(b+c)) returned the desired function that i could call. However as soon as i attempted to use it in the form (parse-infix users-input) it falls over with a Don't know how to create ISeq from: clojure.lang.Symbol error (examples in code at the bottom of the above file). I have fallen victim here to my own lack of understanding of macros. I now understand my folly and have a better understanding of how macro expansion works, however now I'm stuck as to how to solve this problem. I think you're very close. Having code that takes a string and returns a anonymous fn form is good, but as you noticed having that code in a macro doesn't seem to be what you want. Because you're starting with a user-supplied string, you are going to need to use 'eval'. Perhaps try chaning parse-infix to be a fn instead of a macro, but still have it return (list 'fn ...etc). Then (eval (parse-infix ...)) to get an actual fn object that you can call repeatedly. --Chouser -- -- I funded Clojure 2010, did you? -- 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] clj-peg v0.6 released
Currently I'm only providing the code in AOT form. If the JAR is on your classpath everything in the manual works just fine. Did that answer your question? -Rich 2010/1/7 Michał Kwiatkowski constant.b...@gmail.com On Mon, Jan 4, 2010 at 11:27 PM, Richard Lyman richard.ly...@gmail.com wrote: This project adds support in Clojure for Parsing Expression Grammars. You'll be able to write pseudo-ebnfs directly in your Clojure code. Sounds nice, but where's the source code? Cheers, mk -- 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: generating a fn with a body based on user inputs, possible?
Thanks Chouser! I had not thought of moving the (list 'fn ...etc) bit into the eval statement, it works perfectly! here is the final result! http://github.com/tristan/modelmaker/blob/d7dbdfa9b998cfc6b846ea5c235b4496ed8caa63/infix_parser.clj .Tristan On 8 Jan., 16:15, Chouser chou...@gmail.com wrote: On Fri, Jan 8, 2010 at 9:10 AM, tristan tristan.k...@gmail.com wrote: At first I thought I had solved it, as calling (parse-infix a*(b+c)) returned the desired function that i could call. However as soon as i attempted to use it in the form (parse-infix users-input) it falls over with a Don't know how to create ISeq from: clojure.lang.Symbol error (examples in code at the bottom of the above file). I have fallen victim here to my own lack of understanding of macros. I now understand my folly and have a better understanding of how macro expansion works, however now I'm stuck as to how to solve this problem. I think you're very close. Having code that takes a string and returns a anonymous fn form is good, but as you noticed having that code in a macro doesn't seem to be what you want. Because you're starting with a user-supplied string, you are going to need to use 'eval'. Perhaps try chaning parse-infix to be a fn instead of a macro, but still have it return (list 'fn ...etc). Then (eval (parse-infix ...)) to get an actual fn object that you can call repeatedly. --Chouser -- -- I funded Clojure 2010, did you? -- 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
First meeting of the NYC Clojure Users Group is scheduled
We'll be meeting on January 28th starting at 6:30pm at: NYC Seminar and Conference Center 71 West 23rd Street NY, NY 10010 1-866-807-1114 I'd like to invite people to do some lightening talks and/presentations about what they are doing with Clojure. Please contact me if you are interested in giving a lightening talk and/or a presentation. I'm very interested in what tools people are using to get things done with Clojure. I will do a short presentation on the features of Enclojure. If you are interested in joining us please RSVP at: http://www.meetup.com/Clojure-NYC/calendar/12228936/?a=fd_new_rsvp_multi_tl Thanks, Eric Eric Thorsen (914) 804-4954 [cell] -- 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
C interop lib (JNA wrapper)
Hello all. I've started work on a clojure library for interoperating with C. It's always been a pain to do in Java but recently JNA (java native access) has taken away most of that pain. When using clojure however, it's nice to be able to stay in clojure and not drop to java (or C *shudder*). It's possible to use JNA from dynamic jvm languages already but those interfaces are slower and less type safe than the direct mapping way of doing things. Since I wanted this to be as fast and safe as possible but still clojure code only I have resorted to all kinds of voodoo, including bytecode generation and eval usage (oh the horror) so be warned :) Currently it is very rough but it can already handle all primitive types and also typed pointer arguments as nio buffers. I have included jna type support for structs, unions and callbacks (c function pointers) but that's completely untested yet. Here it is: http://github.com/bagucode/clj-native -- 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: parallel vs serial iteration in a for loop
Take a look at pmap On Jan 8, 11:13 am, Conrad drc...@gmail.com wrote: Looping variables in a clojure for loop are iterated in a serial, cartesian fashion: (for [a (range 5) b (range 10 15)] (+ a b)) (10 11 12 13 14 11 12 13 14 15 12 13 14 15 16 13 14 15 16 17 14 15 16 17 18) I was wondering if there's a standard idiom for looping in parallel fashion- Doesn't look like it's supported by the for macro directly. The best code I can come up with to do this is: (for [[a b] (map vector (range 5) (range 10 15))] (+ a b)) (10 12 14 16 18) Is there a more elegant way to do this? (Of course, having parallel for loop variables is only valuable if you have a more complex loop- For this simple example you could write this in a nicer way by not using a for loop at all) On a side note, is there a good reason why range with no parameters doesn't just return the whole numbers? Then I wouldn't have to pepper my code with (iterate inc 0) everywhere... -- 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: parallel vs serial iteration in a for loop
On Fri, Jan 8, 2010 at 11:34 AM, Sean Devlin francoisdev...@gmail.com wrote: Take a look at pmap I don't think that's the kind of parallel being asked about. On Jan 8, 11:13 am, Conrad drc...@gmail.com wrote: Looping variables in a clojure for loop are iterated in a serial, cartesian fashion: (for [a (range 5) b (range 10 15)] (+ a b)) (10 11 12 13 14 11 12 13 14 15 12 13 14 15 16 13 14 15 16 17 14 15 16 17 18) I was wondering if there's a standard idiom for looping in parallel fashion- Doesn't look like it's supported by the for macro directly. The best code I can come up with to do this is: (for [[a b] (map vector (range 5) (range 10 15))] (+ a b)) (10 12 14 16 18) Is there a more elegant way to do this? Probably not. 'map' is the primary way to walk multiple seqs in step. 'zipmap' does this too, though only for building a hash-map. Of course you can always use recur as well. --Chouser -- -- I funded Clojure 2010, did you? -- 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: parallel vs serial iteration in a for loop
Thanks Sean... Sorry, I should have used a better word than parallel- The second code example shows what I mean... I'm not referring to multithreaded parallelism, but simply being able to iterate through two lists in step, as Chouser describes. (as you can do by passing two different seqs to map) On Jan 8, 11:34 am, Sean Devlin francoisdev...@gmail.com wrote: Take a look at pmap On Jan 8, 11:13 am, Conrad drc...@gmail.com wrote: Looping variables in a clojure for loop are iterated in a serial, cartesian fashion: (for [a (range 5) b (range 10 15)] (+ a b)) (10 11 12 13 14 11 12 13 14 15 12 13 14 15 16 13 14 15 16 17 14 15 16 17 18) I was wondering if there's a standard idiom for looping in parallel fashion- Doesn't look like it's supported by the for macro directly. The best code I can come up with to do this is: (for [[a b] (map vector (range 5) (range 10 15))] (+ a b)) (10 12 14 16 18) Is there a more elegant way to do this? (Of course, having parallel for loop variables is only valuable if you have a more complex loop- For this simple example you could write this in a nicer way by not using a for loop at all) On a side note, is there a good reason why range with no parameters doesn't just return the whole numbers? Then I wouldn't have to pepper my code with (iterate inc 0) everywhere... -- 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: clj-peg v0.6 released
At some point, hopefully someone will write an open-source parsing library with liberal licensing terms for clojure. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Newbie question on XML processing
Thanks Sean This is very helpful. Tzach On Jan 8, 5:44 am, Sean Devlin francoisdev...@gmail.com wrote: Tzach, I'd start will clojure.xml. At a very high level, my program would look like this 1. Load the xml file with clojure.xml/parse 2. Apply your filtering code with something like map-if (see below) (defn map-if [pred f coll] (map #(if (pred %) (f %) %) coll)) 3. Use clojure.contrib.prxml to output the data. Hope this helps, Sean On Jan 7, 11:33 am, Tzach tzach.livya...@gmail.com wrote: Hello I have a simple task of reading an XML structure, manipulate part of it and writing it back to XML. For example, adding 1$ for each book with a year element after 2005 in the following example: ?xml version=1.0 encoding=UTF-8? bookstore book category=COOKING title lang=enEveryday Italian/title authorGiada De Laurentiis/author year2005/year price30.00/price /book book category=CHILDREN title lang=enHarry Potter/title authorJ K. Rowling/author year2006/year price29.99/price /book /bookstore clojure.contrib.zip-filter.xml is getting me close to this, but I still do not see how can I use it (or other library) to modify values. What would be the idiomatic (and easiest) way to do that? I apologize in advance if this is too trivial. Thanks Tzach -- 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: parallel vs serial iteration in a for loop
Oh, right. I saw paralell and the brain hit autopilot. And I think you CAN improve on your fn a little bit. This should do the trick (map + (range 1 5) (range 11 15)) The mapping fn itself will be applied to as many arguments as you have collections. Since + is variadic, it will do the job nicely. Sean On Jan 8, 11:56 am, Chouser chou...@gmail.com wrote: On Fri, Jan 8, 2010 at 11:34 AM, Sean Devlin francoisdev...@gmail.com wrote: Take a look at pmap I don't think that's the kind of parallel being asked about. On Jan 8, 11:13 am, Conrad drc...@gmail.com wrote: Looping variables in a clojure for loop are iterated in a serial, cartesian fashion: (for [a (range 5) b (range 10 15)] (+ a b)) (10 11 12 13 14 11 12 13 14 15 12 13 14 15 16 13 14 15 16 17 14 15 16 17 18) I was wondering if there's a standard idiom for looping in parallel fashion- Doesn't look like it's supported by the for macro directly. The best code I can come up with to do this is: (for [[a b] (map vector (range 5) (range 10 15))] (+ a b)) (10 12 14 16 18) Is there a more elegant way to do this? Probably not. 'map' is the primary way to walk multiple seqs in step. 'zipmap' does this too, though only for building a hash-map. Of course you can always use recur as well. --Chouser -- -- I funded Clojure 2010, did you? -- 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
multiple ns defprotocol/deftype?
hi, might anybody have examples of how one deftype can implement protocols from multiple other namespaces? i have not yet been able to suss out the correct syntax i guess. thank you! -- 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: multiple ns defprotocol/deftype?
On 08.01.2010, at 20:21, Raoul Duke wrote: might anybody have examples of how one deftype can implement protocols from multiple other namespaces? i have not yet been able to suss out the correct syntax i guess. There's nothing special about protocols. defprotocol creates a protocol object and assigns it to a var named by a symbol. You can access this name from other namespaces using require or use, just like any other name. 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: multiple ns defprotocol/deftype?
ah hah. i think. (ns nst1) (deftype T1 [f1]) (println (ns-publics 'nst1)) (ns nst2) (defprotocol P2 (foo [this])) (deftype T2 [f2] :as this P2 (foo [] this)) (println (ns-publics 'nst2)) (ns nst3) (println nst3 using nst2 (nst2/foo (nst2/T2 1))) (ns nst4) (deftype T4 [f4] :as this nst2/P2 (foo [] this)) (nst2/foo (T4 4)) -- 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: First meeting of the NYC Clojure Users Group is scheduled
Also, everyone is welcome to join LispNYC on Tuesday, January 12 and celebrate release 1.1 of Clojure! -SS Join us Tuesday, January 12th from 7:00 to 9:00 at PG's for the first social of the year! Directions: Near the 1 stop at 79th and B,C stop at 81st. Head to the northwest corner of 78th and Columbus then down the outdoor stairs. http://bit.ly/4qnMnK (Google map) -- 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: C interop lib (JNA wrapper)
mac markus.gustavs...@gmail.com writes: Hello all. I've started work on a clojure library for interoperating with C. It's always been a pain to do in Java but recently JNA (java native access) has taken away most of that pain. When using clojure however, it's nice to be able to stay in clojure and not drop to java (or C *shudder*). It's possible to use JNA from dynamic jvm languages already but those interfaces are slower and less type safe than the direct mapping way of doing things. Since I wanted this to be as fast and safe as possible but still clojure code only I have resorted to all kinds of voodoo, including bytecode generation and eval usage (oh the horror) so be warned :) Currently it is very rough but it can already handle all primitive types and also typed pointer arguments as nio buffers. I have included jna type support for structs, unions and callbacks (c function pointers) but that's completely untested yet. Here it is: http://github.com/bagucode/clj-native Yes, there is a lot of voodoo. ;) Have you seen this library: http://github.com/Chouser/clojure-jna ? I'm using this one right now (it is really simple) and I'm wondering what will be the advantage of using your implementation? Br, Rob -- 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: C interop lib (JNA wrapper)
On Jan 8, 8:53 pm, Rob Wolfe r...@smsnet.pl wrote: mac markus.gustavs...@gmail.com writes: Hello all. I've started work on a clojure library for interoperating with C. It's always been a pain to do in Java but recently JNA (java native access) has taken away most of that pain. When using clojure however, it's nice to be able to stay in clojure and not drop to java (or C *shudder*). It's possible to use JNA from dynamic jvm languages already but those interfaces are slower and less type safe than the direct mapping way of doing things. Since I wanted this to be as fast and safe as possible but still clojure code only I have resorted to all kinds of voodoo, including bytecode generation and eval usage (oh the horror) so be warned :) Currently it is very rough but it can already handle all primitive types and also typed pointer arguments as nio buffers. I have included jna type support for structs, unions and callbacks (c function pointers) but that's completely untested yet. Here it is: http://github.com/bagucode/clj-native Yes, there is a lot of voodoo. ;) Have you seen this library:http://github.com/Chouser/clojure-jna? I'm using this one right now (it is really simple) and I'm wondering what will be the advantage of using your implementation? Br, Rob Yes I have seen that library and I've used it as well. The benefits of using my version are speed and safety. I'm using the direct mapping technique described on the JNA front page which is supposedly almost as fast as making custom JNI bindings. An additional (and perhaps more important) benefit of my approach is that it gives some measure of type and arity safety since the arguments must be of the correct type and the correct number of arguments on the java side for a call to succeed. It's very easy to crash the jvm if you mess up the arguments to a C function. This library is something I started because I had a need to wrap a rather large C library with many small functions so I wanted the call overhead to be small (hence the direct mapping) and errors to be comprehensible when I made a mistake instead of just getting a segfault. But interface-wise on the clojure side I guess my lib and clojure-jna are kind of similar so if clojure-jna good enough there is no reason to switch to my lib. I was certainly inspired by clojure-jna since I had used it before :) -- 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: C interop lib (JNA wrapper)
On Fri, Jan 8, 2010 at 3:38 PM, mac markus.gustavs...@gmail.com wrote: But interface-wise on the clojure side I guess my lib and clojure-jna are kind of similar so if clojure-jna good enough there is no reason to switch to my lib. I was certainly inspired by clojure-jna since I had used it before :) If clojure-jna serves as nothing but a gateway drug to clj-native, I'll be entirely content. :-) I look forward to trying out http://github.com/bagucode/clj-native --Chouser -- -- I funded Clojure 2010, did you? -- 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
the Bay Area Clojure user group is 1 year old!
And now for something completely different... The baclojure meetup had our 13th meetup yesterday, and here are some pictures - http://baclojure.org/photos/798526/12537681/ This was our largest attendance so far (not counting the one Rich Hickey came to, that was 80 people). We had about 35 people last night. Long live Clojure :) Regards, Amit Rathore, http://clojureinaction.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: parallel vs serial iteration in a for loop
Thanks again Sean/Chouser- Sounds like there isn't any easy way to do in-step iteration using the for construct, as I suspected- This is of course easily remedied for writing a convenience function for (map vec ...) (As I mentioned in the top post, I am aware the simple example I gave can be written more elegantly without the for construct.) On Jan 8, 2:07 pm, Sean Devlin francoisdev...@gmail.com wrote: Oh, right. I saw paralell and the brain hit autopilot. And I think you CAN improve on your fn a little bit. This should do the trick (map + (range 1 5) (range 11 15)) The mapping fn itself will be applied to as many arguments as you have collections. Since + is variadic, it will do the job nicely. Sean On Jan 8, 11:56 am, Chouser chou...@gmail.com wrote: On Fri, Jan 8, 2010 at 11:34 AM, Sean Devlin francoisdev...@gmail.com wrote: Take a look at pmap I don't think that's the kind of parallel being asked about. On Jan 8, 11:13 am, Conrad drc...@gmail.com wrote: Looping variables in a clojure for loop are iterated in a serial, cartesian fashion: (for [a (range 5) b (range 10 15)] (+ a b)) (10 11 12 13 14 11 12 13 14 15 12 13 14 15 16 13 14 15 16 17 14 15 16 17 18) I was wondering if there's a standard idiom for looping in parallel fashion- Doesn't look like it's supported by the for macro directly. The best code I can come up with to do this is: (for [[a b] (map vector (range 5) (range 10 15))] (+ a b)) (10 12 14 16 18) Is there a more elegant way to do this? Probably not. 'map' is the primary way to walk multiple seqs in step. 'zipmap' does this too, though only for building a hash-map. Of course you can always use recur as well. --Chouser -- -- I funded Clojure 2010, did you? -- 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
reader heisenbug
sometimes (i can't repro it now that i restarted the repl?!) (let [stream (new java.io.PushbackReader (new java.io.FileReader /tmp/foo.clj))] (loop [s stream] (println read (read s nil nil)) (recur s))) in Clojure 1.1.0-new-SNAPSHOT repl to echo a file, i get java.lang.NullPointerException (NO_SOURCE_FILE:0). other times it works and continues to print nil for ever and ever after the file is finished being read. when i get the exception, it happens before the file has been completely finished being read. i've attached the file it dies reading. the full trace: (#StackTraceElement clojure.lang.LispReader.matchSymbol(LispReader.java:310) #StackTraceElement clojure.lang.LispReader.interpretToken(LispReader.java:282) nil #StackTraceElement clojure.lang.LispReader.read(LispReader.java:171) nil #StackTraceElement clojure.lang.LispReader.readDelimitedList(LispReader.java:1057) nil #StackTraceElement clojure.lang.LispReader$ListReader.invoke(LispReader.java:897) nil #StackTraceElement clojure.lang.LispReader.read(LispReader.java:145) nil #StackTraceElement clojure.core$read__4820.invoke(core.clj:2391) nil #StackTraceElement clojure.core$read__4820.invoke(core.clj:2389) nil #StackTraceElement user$eval__32.invoke(NO_SOURCE_FILE:10) nil #StackTraceElement clojure.lang.Compiler.eval(Compiler.java:5258) nil #StackTraceElement clojure.lang.Compiler.eval(Compiler.java:5226) nil #StackTraceElement clojure.core$eval__4674.invoke(core.clj:2018) nil #StackTraceElement clojure.main$repl__6817$read_eval_print__6828.invoke(main.clj:183) nil #StackTraceElement clojure.main$repl__6817.doInvoke(main.clj:200) nil #StackTraceElement clojure.lang.RestFn.invoke(RestFn.java:422) nil #StackTraceElement clojure.main$repl_opt__6857.invoke(main.clj:254) nil #StackTraceElement clojure.main$main__6885.doInvoke(main.clj:347) nil #StackTraceElement clojure.lang.RestFn.invoke(RestFn.java:398) nil #StackTraceElement clojure.lang.Var.invoke(Var.java:361) nil #StackTraceElement clojure.lang.AFn.applyToHelper(AFn.java:172) nil #StackTraceElement clojure.lang.Var.applyTo(Var.java:482) nil #StackTraceElement clojure.main.main(main.java:37) -- 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 dt.clj Description: Binary data
reader and s
hi, i'm using (read) and it seems to get rid of double quotes e.g. (println foo) is read as (println foo) as far as i can tell so far. how do i get the quotes to come through? or don't i want to? 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: reader and s
On Fri, Jan 8, 2010 at 7:34 PM, Raoul Duke rao...@gmail.com wrote: hi, i'm using (read) and it seems to get rid of double quotes e.g. This seems very unlikely to me, though it would be easier to tell for sure if you included the code that was failing. Perhaps the problem is when you print the form after it's been read? If you're using 'print' or 'println', strings are printed without their double-quotes. Try using 'pr' or 'prn' instead. --Chouser -- -- I funded Clojure 2010, did you? -- 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
Strange problem when adding type to a var defined by a macro.
Hi, I'm using macros to define special vars (w/ a keyword as type) to retrieve them later with ns-utils/ns-vars and filter them. I don't know if this technique is recommended or if there's some better way to achieve this, but there's something weird happening when we try to evaluate the var defined at the REPL. For example, if you run this code: (defmacro defbar [foo body] `(def ~(with-meta foo {:type ::MyType}) (eval ~...@body))) (defbar baz (+ 1 1)) It throws a ClassCastException: clojure.lang.Var cannot be cast to clojure.lang.IObj, which is an error I encountered often and never truly understood. Can somebody help me find out what I'm missing? Thanks - budu -- 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