Re: One benefit of having a REPL
Stefan Kamphausen wrote: Hi, On Nov 28, 2:20�pm, John Harrop jharrop...@gmail.com wrote: One benefit of having a REPL: it makes regular expressions usable. So easy to test and tweak your RE compared to the traditional compile/test/debug cycle! I never even bothered with the java.util.regex package before Clojure as it was too painful to use. I wonder how hard it would be in Clojure to implement something like Edi Weitz' RegexpCoach http://weitz.de/regex-coach/. I know Perl programmer who regularly create their (un)regular expressions with the help of that software. ;-) Really? Why would they need to do that? I always just used the perl REPL, perl -d. Ironically, that experience made it easier to learn Lisp, especially after reading Higher Order Perl. -- 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: [OT] Convincing others about Clojure
On Thu, 25 Jun 2009 11:29:24 +0530 Baishampayan Ghose b.gh...@ocricket.com wrote: Their concerns are thus: 1. How do you get Clojure programmers? Lisp is not for the faint hearted. You can always ask on this list. I'd guess that at any given point in time there are probably several people who'd rather being working with Clojure in their day job than whatever they're actually doing now. (Me, for instance...) 2. What about the performance of Clojure? Is it fast? It can be faster than a lot of other popular choices, like Ruby or Python. I wish it compiled to native code instead of Java, but that's mostly because I don't like Java. 3. People who want to use this are more academically inclined and are not practical. This will make the whole project fail. Many innovative ideas in computer science tend to in academia and only slowly make their way into more mainstream, practical environments. Consider garbage collection, or relational databases. Both very academic at one time, and now they're everywhere. Point being, really practical people use the best ideas they can, regardless of where they came from. Nathan --~--~-~--~~~---~--~~ 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: agent questions - DOS - asynchrony - protection
On Wed, 10 Jun 2009 12:44:00 -0600 Daniel Lyons fus...@storytotell.org wrote: On Jun 10, 2009, at 12:03 PM, Toralf Wittner wrote: On Wed, 2009-06-10 at 10:22 -0600, Daniel Lyons wrote: If the actions are executed serially, what is the benefit of having multiple threads per agent? There is none. Did anybody say there are multiple threads per agent? There are two thread pools shared by all agents - a cached thread pool where actions enqueued via send-off go into and a fixed thread pool for actions enqueued via send. The actions of all agents are submitted to these two pools and all together run interleaved in different threads. However at a given point in time there is only one thread for a given Agent. And an agent's actions run one after another. This makes more sense, actually. For some reason I thought each agent got its own thread pool. However, I still feel like I am not understanding when agents should be used or what an appropriate use of them would constitute, though. When you need to update shared state, but you don't want to block the current thread. I'm looking at them to simplify request processing in network applications with lots of state machines. Agents let me write state machines in functional style with multi-methods dispatching on the current state and the type of input. I also don't have to write the code to put the messages on a queue and manage a thread pool myself. Nathan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: What books have helped you wrap your brain around FP and Clojure?
Programming Erlang is also good. The syntax and message passing emphasis aren't relevant to Clojure, but Erlang also uses immutable data, and is definitely a functional language. On Sat, 6 Jun 2009 13:12:16 +0200 Robert Campbell rrc...@gmail.com wrote: Going beyond the language-specific Programming Clojure book, what other books have best helped you make the (sometimes mind-bending) transition from OOP thinking to FP thinking? My bookshelf is piled high with OOP books like Design Patterns, Domain Driven Design, Analysis Patterns, etc. I've recently ordered: - Concepts, Techniques, and Models of Computer Programming (mentioned on this/compojure's list) - Structure and Interpretation of Computer Programs (highly recommended on Stackoverflow, lectures posted online) Any others? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: What books have helped you wrap your brain around FP and Clojure?
Higher Order Perl. While I don't want to use Perl anymore, I do know it very well, and it provided a good introduction to FP in a more familiar language. YMMV. Robert Campbell wrote: Going beyond the language-specific Programming Clojure book, what other books have best helped you make the (sometimes mind-bending) transition from OOP thinking to FP thinking? My bookshelf is piled high with OOP books like Design Patterns, Domain Driven Design, Analysis Patterns, etc. I've recently ordered: - Concepts, Techniques, and Models of Computer Programming (mentioned on this/compojure's list) - Structure and Interpretation of Computer Programs (highly recommended on Stackoverflow, lectures posted online) Any others? --~--~-~--~~~---~--~~ 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: Clojure as a Java lib documentation / examples?
Try here: http://code.google.com/p/clojure/source/browse/ Brett Morgan wrote: Hi guys, I have some evil thoughts of using Clojure as a java library so that i can use both the STM and the persistent data structures in projects that my team of java developers can work with. As much as I'd like to get the team coding in Clojure properly, I have enough trouble selling the idea of using immutable data structures. If I hide the clojure magic behind interfaces, I can have the team coding in plain java, and wrap what they do in clojure transactions and what not. I'd like to do this in a way that the clojure repl can still be used to interact with the running server. So where do I start reading? =) --~--~-~--~~~---~--~~ 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: constructing maps
On Tue, 05 May 2009 09:39:21 +0200 Christophe Grand christo...@cgrand.net wrote: Kevin Downey a écrit : (into {} (apply map vector '((cars bmw chevrolet ford peugeot) (genres adventure horror mystery {ford mystery, chevrolet horror, bmw adventure, cars genres} or: user= (apply zipmap '((cars bmw chevrolet ford peugeot) (genres adventure horror mystery))) {ford mystery, chevrolet horror, bmw adventure, cars genres} But I'm unsure it's what Michel was after. I thought an alist was a list of pointed pairs (or a list of 2-elts lists) but I may be wrong since I come from Javaland. user= (into {} (map vec '((a 1) (b 2) (c 3 {c 3, b 2, a 1} Christophe On Mon, May 4, 2009 at 4:03 PM, Michel S. michel.syl...@gmail.com wrote: Yes, me too. The design is a bit unfortunate, as I cannot convert a Scheme-style association list to a map easily: user= (into {} '((cars bmw chevrolet ford peugeot) (genres adventure horror mystery))) java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to java.util.Map$Entry (NO_SOURCE_FILE:0) -- Michel In Common Lisp, an alist is something like this: ((cars . genres) (bmw . adventure) (chevrolet . horror) (ford . mystery)) Where (cars . genres) is a cons cell with values in both slots. So an alist is a list of key/value pairs where order is significant and keys could appear more than once. Not much different than: [[cars genres] [bmw adventure] [chevrolet horror] [ford mystery]] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
constructing maps
Possibly I'm going about this wrong. I'm trying to understand how best to construct maps from sequences, by applying a function which returns a key / value pair. Something like this: (ns test (:use clojure.contrib.str-utils)) (def test-str foo=1;bar=2;baz=3) (defn split-kv [text] (let [[k v] (re-split #= text )] {k v})) (defn split-pairs [text] (re-split #; text)) (map split-kv (split-pairs test-str)) - ({foo 1} {bar 2} {baz 3}) Doesn't really do what I had in mind. And yeah, I figured out that I can convert that to a hash-map in various ways, but I had expected map to be able to do this. So I wrote this: (defn map-assoc Returns a map consisting of f applied to coll, where f is a function returning a key and value. f can return either a sequence with two values or a single item map. [f coll] (loop [map {} s (seq coll)] (if s (let [item (f (first s))] (recur (if (associative? item) (conj map item) (assoc map (first item) (second item))) (next s))) map))) This seems a little bit more like what I expected: (map-assoc split-kv (split-pairs test-str)) - {baz 3, bar 2, foo 1} Am I overlooking some already existing function hidden away someplace that does this? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: constructing maps
On Mon, 4 May 2009 16:07:06 +0200 Christopher Taylor ccmtay...@gmail.com wrote: Hi Nathan, On 04.05.2009, at 15:47, Nathan Hawkins wrote: On Mon, 4 May 2009 06:16:14 -0700 (PDT) Drew Raines aarai...@gmail.com wrote: Whoops, that (seq) is a debugging artifact. You can remove that: (let [test-str foo=1;bar=2;baz=3] (reduce conj {} (map #(apply hash-map (.split % =)) (.split test-str ; Ok, my example seems to have misled. You're missing the point a little bit: 1. I was trying to avoid the (reduce conj {} ...), by having the map function do it. Why even build a list that's only going to get thrown away when I want a hash-map at the end? you're not actually building a list. The function map returns a (lazy) *sequence*, which is an instance of ISeq. This just means you're getting something that supports the operations first and rest. So, since map returns a sequence and you want a Map (i.e. key/value data structure), you'll have to turn it into one by using (conj {} ...) or (into {} ...). There's the source of my misunderstanding. I knew map returned a sequence, but hadn't quite connected lazy to the problem at hand. I had stumbled on a couple different ways of converting the sequence to a hash-map (I found (into {} ...), (apply hash-map ...) and (reduce conj {} ...)), but I was thinking in terms of how I'd solve the problem in Common Lisp so I thought that running map and then converting the result to a hash-map was going to iterate the list twice, as well as cons the results twice. Thanks for clearing that up. Nathan --~--~-~--~~~---~--~~ 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: constructing maps
On Mon, 4 May 2009 06:16:14 -0700 (PDT) Drew Raines aarai...@gmail.com wrote: On May 4, 8:05 am, Drew Raines aarai...@gmail.com wrote: user (let [test-str foo=1;bar=2;baz=3] (reduce conj {} (map #(apply hash-map (seq (.split % =))) (.split test-str ; Whoops, that (seq) is a debugging artifact. You can remove that: (let [test-str foo=1;bar=2;baz=3] (reduce conj {} (map #(apply hash-map (.split % =)) (.split test-str ; Ok, my example seems to have misled. You're missing the point a little bit: 1. I was trying to avoid the (reduce conj {} ...), by having the map function do it. Why even build a list that's only going to get thrown away when I want a hash-map at the end? 2. The functions used to split the strings were not important, only an example. It could just as easily be a function to extract fields from a java object. To some extent, I guess I'm thinking in terms of Common Lisp, where I'd build an a-list with mapcar and cons. Nathan --~--~-~--~~~---~--~~ 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: constructing maps
On Mon, 04 May 2009 16:31:21 +0200 Christophe Grand christo...@cgrand.net wrote: Nathan Hawkins a écrit : Ok, my example seems to have misled. You're missing the point a little bit: 1. I was trying to avoid the (reduce conj {} ...), by having the map function do it. Why even build a list that's only going to get thrown away when I want a hash-map at the end? 2. The functions used to split the strings were not important, only an example. It could just as easily be a function to extract fields from a java object. To some extent, I guess I'm thinking in terms of Common Lisp, where I'd build an a-list with mapcar and cons. With f a function that return a [key value] pair (or a (key value) pair but not a {key value} pair): (reduce #(apply assoc %1 (f %2)) {} coll) if you want to have f return a map you can (reduce #(merge %1 (f %2)) {} coll) This is exactly what I was trying to, but I hadn't thought of using reduce. Thank you. Nathan --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---