Re: Mapping first element only: how to preserve vectors
On Mon, Mar 19, 2012 at 2:40 PM, Bojan bojandoli...@hotmail.com wrote: Hi! I'm a beginner at clojure and enjoying the learning process. While writing my first nontrivial program, I noticed that I'm transforming only first elements in the list, so I factored this transformation out by writing next function: (defn map-first [f coll] (map #(cons (f (first %)) (rest %)) coll)) If coll is always a collection of vectors, then you can simply use 'assoc' since vectors support near-constant-time random access. Also, the name map-first is a bit misleading in my opinion, since it does not map f over the first element in coll, but over the first element of each collection in coll. Here's an example using assoc: (defn map-first [f v] (assoc v 0 (f (nth v 0 (defn map-firsts [f coll] (map #(map-first f %) coll)) (map-firsts #(* 2 %) [[2] [3 3] [3 [2 4]] [4 10]]) ;= ([4] [6 3] [6 [2 4]] [8 10]) The complexity of map-firsts is O(log_32(n) * m). The log_32(n) part comes from assoc, which creates a new updated vector with n elements. (log_32 is practically close to constant. log_32 of four billion is about 6 or 7) The m part comes from mapping over the outer collection (of size m). The complexity can be approximated to just O(m) if you approximate log_32 as constant time. The 'assoc' here is very cheap. // raek -- 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: Accessing vals in clojure.lang.PersistentVector
On Wed, Jan 25, 2012 at 10:45 AM, Simon Holgate simon.holg...@gmail.com wrote: I've retrieved some data from my database which is returned as a clojure.lang.PersistentVector: org.psmsl.netcdf.core res [{:name BREST, :time #Date 1807-01-01, :rlrdata 6882M} {:name BREST, :time #Date 1807-02-01, :rlrdata 6908M} {:name BREST, :time #Date 1807-03-01, :rlrdata 6873M}...{:name BREST, :time #Date 2008-11-01, :rlrdata 7140M} {:name BREST, :time #Date 2008-12-01, :rlrdata 7088M}] org.psmsl.netcdf.core (class res) clojure.lang.PersistentVector I thought I should be able to do: (vals res) and org.psmsl.netcdf.core (get res :time) returns nil What am I doing wrong? From what I can tell, you want to list the values and extract the value associated with :time for a map. The problem is that res is not a map, but a vector of maps. If you want to do these operations on every map in the vector you can use the map function (map as in to map): (map vals res) (map :time res) In the last example I made use of the fact that keywords also work as functions. (:some-keyword some-map) is the same as (get some-map :some-keyword). To play in the repl with the first value in the vector in the repl you can extract it with nth or get: user (def res ...) #'res user (def first-res (nth res 0)) #'first-res user (vals first-res) ... user (get first-res :time) ... // raek -- 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: strange problem
Den 16 januari 2012 16:58 skrev joachim joachim.de.be...@gmail.com: However, when I try the same in an emacs repl, I get Lisp connection closed unexpectedly: connection broken by remote peer. I have no idea what is going on or how to deal with this problem. Sometimes during development I like to print the strings to see what is going on, but this also causes the connection to close. Any ideas? Joachim. From what I can tell those characters are indeed characters outside the Basic Multilingual Plane. They should not cause any problems in Clojure itself if you merely relay them through your app. (They have some quirks though. For example they count as two characters.) First I thought this was another very common problem, namely the issue Ulises linked to, but then I tried to print supplementary characters myself in my (correctly configured) slime repl and it failed there too! This is obviously a bug in either slime or swank-clojure. Could you open an issue in the swank-clojure github repo for this, so we can track the progress? https://github.com/technomancy/swank-clojure/issues Den 16 januari 2012 16:58 skrev joachim joachim.de.be...@gmail.com: I would also be happy if I could recognize problematic strings, so that I can skip them when printing, thus avoiding the problem (although this would not really be a solution), You can use this as a temporary workaround: (require '[clojure.string :as str]) (defn strip-supplementary [s] (str/replace s #[^\u-\u]+ (removed supplementary characters))) (strip-supplementary The first three letters of the Gothic alphabet are: \uD800\uDF30\uD800\uDF31\uD800\uDF32) ;= The first three letters of the Gothic alphabet are: (removed supplementary characters) // Rasmus -- 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: Problem with Greeks!
2011/8/17 cran1988 rmanolis1...@hotmail.com: My jvm is already UTF-8 however it works with clojure 1.3.0 beta1 but i have problems i get an error NoSuchMethodError clojure.lang.KeywordLookupSite.init(ILclojure/lang/ Keyword;)V clout.core/request-url (core.clj:53) The encoding problem and this version incompatibility problem should not be related. Nothing encoding related has changed between Clojure 1.2 and 1.3, as far as I know. I decided to reply with my answer (even though your problem is apparently fixed), because I had already begun writing it and this is a problem many people have. (So hopefully this could be useful for someone else too.) 2011/8/17 cran1988 rmanolis1...@hotmail.com: I tried (str Γεια!) and i got ! what can I do to fix it ? Clojure has a modern string model in which a string is a logical sequence of characters, not bytes. However, Clojure cannot fix problems outside the Clojure process, so you can still get problems like this. Track A - You are running the Clojure REPL in a terminal window Before you check for any Clojure-related issues, let's make sure it's not caused by the terminal or your OS. Make sure that your locale is set to one with the UTF-8 encoding scheme (in most modern OSes this should be the case). In Unix-like systems, you can check it like this: raek@sirius:~$ echo $LANG sv_SE.utf8 Here sv_SE means Swedish, but it's the part after the dot that's interesting. After this, make sure the encoding in your terminal is set to UTF-8 too. In gnome-terminal (default terminal application in Ubuntu) make sure that Unicode (UTF-8) is selected in the Terminal - Set Character Encoding menu. This should hopefully already be UTF-8 in most modern OSes. In PuTTY (a common terminal application on Windows) go to the Window - Translation tree item and select UTF-8 in the topmost drop down list. UTF-8 is *not* the default encoding scheme in PuTTY, - ISO 8859-1 is. Now when you have a confirmed UTF-8 terminal, let's look at the Clojure side. If you use JLine or use the default installation of Leiningen (which uses JLine), you should abandon it. JLine does not support modern encoding schemes like UTF-8 and garbles the data without warnings. Use the rlwrap application instead. It does the same thing but works for encodings like UTF-8. If you install it using your OS package manager (e.g. apt-get on Ubuntu), Leiningen will pick it up and use it instead of JLine automatically. At this point, using any characters in the repl should just work. There can be subtle problems with encodings if you happen to configure things badly for both the input and output of the REPL - you can have a problem that undoes itself. To verify that the text the Clojure REPL receives is really the one you wrote, you can use this simple test: user= (seq Γεια) (\Γ \ε \ι \α) I.e. you give Clojure a string and ask it to display its individual characters. If you see a sequence of four characters here (and they display correctly), everything is good. If you see another number of characters something is still wrong. Track B - You are using the Slime REPL in Emacs If you recent versions of clojure-mode use the clojure-jack-in way of doing things, this should just work. Oherwise you just need to set a variable: M-x customize-variable RET slime-net-coding-system (select utf-8-unix and save) Or you can add this to your config: (setq slime-net-coding-system 'utf-8-unix) And that should be it. Use the seq test above to verify. I hope this helps! Please tell me if any step is not working. the Encoding Guy at your service, Rasmus Svensson (raek) -- 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: Spitting out a lazy seq to file???
2011/8/16 Thomas th.vanderv...@gmail.com: Hi everyone, I have been struggling with this, hopefully, simple problem now for quite sometime, What I want to do is: *) read a file line by line *) modify each line *) write it back to a different file This is a bit of sample code that reproduces the problem: == (def old-data (line-seq (reader input.txt))) (defn change-line [i] (str i added stuff)) (spit output.txt (map change-line old-data)) == #cat output.txt clojure.lang.LazySeq@58d844f8 Because I get the lazy sequence I think I have to force the execution? but where exactly? And how? Thanks in advance!!! spit operates on strings, so therefore you have to turn your data into one big string first. (spit implicitly calls str on its argument, but this is not very useful.) What you have is a sequence of string, so depending of what you want to appear in the file you have multiple options: For an arbitrary clojure data structure you can use pr-str to convert it into the same format you get at the repl: (spit output.txt (pr-str (map change-line old-data))). This can be useful to dump some data to a file and will yield something like this: (line1 added stuff line2 added stuff) To simply write a file where each line corresponds to a string element in the sequence, you can either build a new string with consisting of the strings of the seq, each with a newline character appended to the end, concatenated together and spit that, or you can use something else that doesn't require you to build this monolithic string. Since you used line-seq rather than slurp to read in the file, I will instead demonstrate an other approach than spit: (require '[clojure.java.io :as io]) (with-open [in (io/reader input-filename) out (io/writer output-filename)] (binding [*out* out] (- in (line-seq) (map change-line) (map println) (dorun This consumes the sequence line by line and writes the lines to the file. This solution only needs to have one line in memory at a time. The spit approach would require one big string to be constructed, and might not be very suited for big files. The code would output a file like this: line1 added stuff line2 added stuff So in general, use slurp together with spit or read-line (or its line-seq variant) together with println. // raek -- 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: Being able to use blank?
2011/7/21 octopusgrabbus octopusgrab...@gmail.com: Thanks. You're right. (:require [clojure.contrib.string :as cstr]) ; str already defined There should be no conflict between the var str (clojure.core/str) and the namespace alias str (clojure.string). Names for vars and namespaces never occur at the same place and cannot be mistaken for each other (by the compiler for sure, but I don't know about humans). Yout first attempt failed because of the quote. since 'x is equivalent to (quote x), this (ns test-csv (:require '[clojure.string :as str])) becomes (ns test-csv (:require (quote [clojure.string :as str]))) which is interpreted as the prefix syntax: (foo [b :as b] [c :as c]) is the same as [foo.b :as b] [foo.c :as c]. However, the stuff that comes first in the vector (b and c) must not have a dot in it, hence the error message. // raek -- 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: Namespace Docstrings?
2011/7/14 OGINO Masanori masanori.og...@gmail.com: Hello. What is the right way to display namespace docstrings? One day, as usual, I typed: (doc 'clojure.core) ; or other namespace Then the REPL said clojure.lang.Cons cannot be cast to clojure.lang.Symbol. I thought Ah, I know, the message means (quote clojure.core) cannot be cast to the symbol clojure.core. I'm wrong. and typed: (doc clojure.core) Then the REPL said ClassNotFoundException clojure.core. I thought Indeed, clojure.core seems to be an class name... Precisely, can (doc) display namespace docstrings? and typed: (source doc) Oh, (doc) uses (find-ns), so (doc) should display namespace docstrings. But how? Finally I wrote (:doc (meta (the-ns 'clojure.core))) but I know this is a wrong way. When I forget this ad-hoc solution, I'll repeat above. I determined to ask it because I have repeated again just now and I'm annoyed. Any thought? Thanks. 'doc' is only used for things that are vars (functions, and other globals). Namespaces are not vars, so you cannot use 'doc' with them. To see the docs for a namespace, use the 'print-namespace-doc' function: (print-namespace-doc 'the.name.space) // raek -- 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 and swedish characters on windows...
2011/6/20 Andreas Liljeqvist bon...@gmail.com: I still have encoding problems in repl outside of Emacs (of course...). This is fine while I am developing, but problematic for rolling out to customers. Setting -Dfile.encoding=UTF8 Doesn't solve it. Anyone? What repl? Bare java -cp clojure.jar clojure.main? lein repl? If you use lein repl, you *should* install the rlwrap program on your system (e.g. on a Debian based GNU/Linux distro: apt-get install rlwrap). If rlwrap is not installed, Leiningen will use JLine, which does not support UTF-8 properly... :( The *in* and *out* streams are opened with the default encoding, which I believe you set with the file.encoding property. // Rasmus Svensson (raek) -- 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: using regex reader macro with generated code
2011/6/16 Alex Baranosky alexander.barano...@gmail.com: IS it possible to use the regex reader macro # with generated code? What I mean is do something like: #${(join | (range 1 1))} I'm using ${...} to mean string interpolation, though I know Clojure doesn't have that syntax. Is there a way to get this effect or must I use (re-pattern (join | (range 1 1))) Thanks for the help! Alex When you generate code programmatically (e.g. in a macro), you generate the data structures as objects rather than their string form. Consider this macro*: (defmacro unless [cond-expr false-expr true-expr] (liist 'if cond-expr true-expr false-expr)) To make the (if ...) list you don't dive into the string representation of this data structure -- i.e. you don't try to do something like (str (if cond-expr ... )). You should think about what kind of objects the syntax represent and try to generate those instead. Code is data. The string representation is only for storing code in files and interacting with a human. Clojure itself works with the data as objects. To construct a regex pattern object re-pattern is the function to use, as you already know. There is no reason to dive into string syntax. If you happen to want to serialize this object later (e.g. print it at the repl or dump it to a text file), this regex object will print as an ordinary regex literal. * Using syntax-quote is probably more ideomatic here. // Rasmus Svensson (raek) -- 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: ClojureBox on Window 7: classpath in .emacs file not working
In Clojurebox, this seems to be unnecessarily hard to do. Also, Clojurebox precedes the Clojure-centric build tools (Leiningen and Cake) which are the most common way to handle the classpath today, The docs recommend to use swank-clojure-project, but I recommend a more up to date approach: use Leiningen to handle your project layout and use the clojure-jack-in of the most recent clojure-mode to start a repl in the project. Clojurebox could be described as an installer for some components: Emacs, Slime (repl client in emacs), clojure-mode (syntax highlighting and indentation), Swank Clojure (repl server in Clojure) and Clojure itself. It is nowadays simple enough to install these yourself. My personal opinion is that this is a much better setup than what Clojurebox gives you. My recommended approach: 1. Prepare a clean install of Emacs 23 or 24 (the one from Clojurebox contains versions of libraries that might cause conflicts) 2. Take a look at Leiningen, read (at least briefly) about project structure, and install it: https://github.com/technomancy/leiningen, https://github.com/technomancy/leiningen/blob/master/TUTORIAL.md 3. Make a new Leiningen project (lein new my-project) and put Halloway's code in the src/ directory so that introduction.clj is in src/examples/introductions.clj. 4. Edit project.clj and set the Clojure version you want to use.I think the book uses 1.1.0. 5. Follow the tutorial by Phil Hagelberg to set up the rest (three steps): http://technomancy.us/149 There is also a thread about this (Radically simplified Emacs and SLIME setup) which can be useful if you happen to have any problems: http://groups.google.com/group/clojure/browse_thread/thread/91d4f13090afb876 After this, you should have state of the art integration between Emacs and Clojure. Let me know if something in my instructions does not work, or if you have other questions. // Rasmus Svensson (raek) -- 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: Parsing HTML in clojure
2011/6/6 Base basselh...@gmail.com: hi all, I am working on an app that will parse web pages to do some NLP and statistics. I am able to parse the HTML using several different tool ( enlive, HTML parser, etc). However I would like to discard all the rest of the junk in the web page that is not pertinent (I.e. Ads). Does anyone have any experience doing this? Any tips On how to do this - or even better, tools that you can recommend? I have been digging around on this for a while now and am stuck! Thanks! Base In Enlive there are at least two approaches available: The first approach is to use the 'select' function to pick out the interesting part of the element tree. You use CSS-style selectors to describe the element. The second approach is to use the 'at' macro. You give it an element tree and pairs of selectors and transformations. For each selector-transformation pair, the transformation is applied to all elements that matches the selector. A transformation takes a node and returns what it should be replaced with. You can do almost anything with them, including removing the element (which might be useful for the ads in your case) or extracting the text of the node (the matching nodes deepest in the tree are processed first). The result of the 'at' form is the element tree with all transformations applied. Both 'select' and 'at' accepts a element tree which you can create with the html-resource function which accepts, among other things, URLs. You probably need to write some html element processing functions, so it's probably a good idea to get familiar with the data format of the nodes: Element: {:tag :a, :attrs {:href http://example.com/}, :content sequence of nodes} Text: text node Comment: {:type :comment, :data comment node} I found the wiki of Enlive very useful. The Getting Started explains what's there and how to use it very well, I think. https://github.com/cgrand/enlive/wiki/_pages I should also mention David Nolen's comprehensive tutorial which begins with scraping: https://github.com/swannodette/enlive-tutorial // raek -- 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: Parameterizing project.clj
2011/5/23 Ulrik Sandberg ulrik.sandb...@gmail.com: How can I parameterize stuff in Leiningen's project.clj? For example, I don't want to put my AWS credentials inside the project file: ... :aws {:access-key XX :secret-key Y} but instead use some kind of property names that refer to environment variables or something: ... :aws {:access-key ${aws.access.key} :secret-key ${aws.secret.key}} Actually, the project.clj file is evaluated by Leiningen using the ordinary Clojure evaluator. This means that you can put arbitrary code at the top level of the file to, for example, extract the keys from environment variables. Any dev-dependencies will be available in this Leiningen JVM instance too. 'defproject' is a macro, so its contents is not evaluated the usual way. But it does have a helpful feature: Unquoted forms will be evaluated with normal Clojure rules, so it's possible to do something like this: (def access-key ...) (def secret-key ...) (defproject foo 1.0.0 ...the usual stuff... :aws {:access-key ~access-key :secret-key ~secret-key} You can of course write the whole expressions directly after the tildes, but I wanted to demonstrate the possibility of using def here. Hope this helps! // Rasmus Svensson (raek) -- 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: (just) emacs mode
2011/4/27 John V johnv02...@gmail.com: Hi, I would like to have syntax highlighting for Clojure code in Emacs. I am using Emacs on Windows (23.2.1). I found this page: http://dev.clojure.org/display/doc/Getting+Started+with+Emacs ... but it was clearly much more involved than I was looking for. Nevertheless, I downloaded package.el, loaded it, set the location for marmalade, and gave it a shot, but as expected, it didn't work. It said, Failed to download 'gnu' archive. I would like to use Emacs as a text editor, not as a combination IDE/ ftp browser. Is there a clojure mode written which is simple to download and use? I used ILISP for many years, and I've encountered SLIME when I was using SBCL, but never got it working properly on Windows. I know how cool and powerful an integrated environment like ILISP can be, but also how buggy it can be, and at the moment, I just don't think it's worth the effort to get it working. For now, I prefer to run Clojure in a Command Prompt, and use Emacs solely as a text editor. Thanks very much for any advice. If you are only interested in the editing features, you just need clojure-mode. You can get it directly at: https://github.com/technomancy/clojure-mode // raek -- 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: (just) emacs mode
2011/4/27 John V johnv02...@gmail.com: Hi, I would like to have syntax highlighting for Clojure code in Emacs. I am using Emacs on Windows (23.2.1). I found this page: http://dev.clojure.org/display/doc/Getting+Started+with+Emacs ... but it was clearly much more involved than I was looking for. Nevertheless, I downloaded package.el, loaded it, set the location for marmalade, and gave it a shot, but as expected, it didn't work. It said, Failed to download 'gnu' archive. I happened to have access to a computer running Windows 7 with exactly that Emacs version, so I thought I'd try to investigate the error. However, I could not reproduce it. For me, package.el was able to access the GNU repo. Maybe this was a network issue? One thing you could try (if you still are interested in using package.el, that is) is to leave out the GNU repo, since it's not used in the tutorial. The Marmalade repo, which supersedes the original ELPA repo, should contain everything you need to follow the tutorial. In the instructions you linked, replace this: (add-to-list 'package-archives '(marmalade . http://marmalade-repo.org/packages/;)) with this: (setq package-archives '((marmalade . http://marmalade-repo.org/packages/;))) I could add editing-only instructions to the Getting Started page this evening. Do you have any comments regarding what they should contain? // raek -- 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: help--reading keyboard input from Clojure is surprisingly difficult
See this tread for why stdin is not directly available with lein: http://groups.google.com/group/leiningen/browse_thread/thread/f9f9ed97eb8a2928/ccab95588ef50d05?lnk=gstq=stdin This is currently impossible due to a bug in ant; it just swallows stdin completely, and they seem to have no intention of fixing it. // raek -- 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: General question about concurrency in Clojure
The answer would be a mix of A and B, mostly because there seems to be an assumption that you have to consider concurrency everywhere in order to be able to have it at some point later. This is not the case. You do tend to be very explicit about concurrency and only use the concurrency primitives (refs, atoms, agents and vars) at a few selected spots, but most of the time you don't have to think about concurrency at all, since even the smallest parts of the system is written in a way that allows for concurrency (by using pure functions and not using the concurrency primitives). Clojure is a functional programming language, which among other things means that computation is in general carried out using referentially transparent (pure) functions. A pure function always return the same value for the same input and is free from side-effects. Pure functions are always thread safe and will never be any problem to concurrency. In a language like Java, mutation of variables and objects is very often used for performing computations. But this intervenes calculations that has nothing to do with each other, since a mutating step in computation A can affect computation B if they operate on the same objects. The result is that in Java, you have to think about concurrency when you perform computations, unlike in Clojure. (Here, I use the word compute to mean something like produce new data of interest.) You tend to write the largest part of a Clojure application as compositions of pure functions. You only have to introduce reference primitives when you have a long-running process whose state changes and evolves over time (for instance a game or a server, or anything that communicates with the outside world and changes thereafter). Clojure acknowledges the need for things to be able to change, but keeps that separate from computation. Most library code I have written hasn't used the concurrency primitives at all. The state changing part of an application often resides at a higher level. // raek -- 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: Better Workflow with App Engine?
2011/2/15 Thorsten Wilms t...@freenet.de: Hi! I managed to get to a Hello world level using appengine-magic, plus an Emacs Swank/Slime setup. I haven't used appengine-magic myself, but I do interactive web programming from Emacs (mainly using Ring + Moustache + Enlive), so I thought I'd share how my typical workflow looks like. While I'm pretty sure I won't look back to Python regarding the language itself, I already miss the speed and simplicity of just saving, switching to a browser, reloading and seeing results. Updating some code and seeing the results shouldn't be more complicated than hitting a keystroke and refreshing the page in Clojure too. :-) Assuming a project.clj file like this: (defproject my-web 1.0.0-SNAPSHOT :description FIXME: write :dependencies [[org.clojure/clojure 1.2.0] [ring 0.3.6]] :dev-dependencies [[swank-clojure 1.2.1]]) And some source files: (ns my-web.controller) (defn my-app [request] {:status 202 :headers {Content-Type text/plain; charset=UTF-8} :body Hello, world!}) (ns my-web.main (:use [my-web.controller :only [my-app]] [ring.adapter.jetty :only [run-jetty]])) (defn -main [] (run-jetty #'my-app {:port 8080, :join? false})) My first step is to start Emacs and open the main.clj file. I then start a swank server and connect to it with M-x durendal-jack-in. (durendal takes care of finding the project directory, running the lein commands, and connecting slime.) When the repl is ready, I evaluate the whole main.clj file by pressing C-c C-k in its buffer. (This will also load controller.clj, since main.clj uses it.) To start the web server, I first enter the main namespace by pressing C-c M-p RET in the main.clj buffer and then evaluate (-main) in the slime repl. When the web server has started, I'm ready to start coding. (The long startup time is a great disadvantage of Clojure. However, I don't see it as a very big problem practically. I usually start the Clojure instance once when I begin developing, and after that there is really no reason to restart it. The advantage that IMHO outweighs the startup time problem is that the interactive development features of Clojure allows you to change the code while it's running, correct mistakes, and remove old unused code without having to restart the process.) With the web server up an running, I open up http://localhost:8080/ in my browser. Now, lets assume that I want to change the Hello, world! text to Hello, Clojure-land!. I open the controller.clj file, edit the corresponding line and press C-M-x somewhere within the defn form to evaluate it. The change is then visible directly when refreshing the page in the browser. If I have written a new function in the controller namespace and want to try it in the repl, I first enter the namespace by pressing C-c M-p RET in the controller.clj file. The slime repl is now in that namespace, and I can, for instance, evaluate (my-app {:uri /test, :request-method :get}). Would it be sensible/feasible to somehow hook compiling of the core to saving any .clj file in Emacs? Or would monitoring the filesystem and recompile on changes, daemon-style be better, and if so, how to accomplish that? There is a ring middleware called wrap-reload that automatically reloads a namespace when its file has changed. I don't use it myself, since I feel that reevaluating code is simple enough in Emacs. How would I best go about writing a script that starts swank, emacs (with project files), automatically connects slime Durendal (https://github.com/technomancy/durendal) takes care of running lein swank for the correct project and connect slime to it. and evaluates a few lines in the slime REPL (switch namespace, compile, run Jetty ...)? The first ones can be solved by C-c C-k (eval file) and C-c M-p (enter namespace). For, the rest, you can invoke a function containing all the startup code, or you could keep the code in a (comment ...) block and evaluate the lines by pressing C-x C-e at the end of the lines. Notes: * durendal required me to have leiningen on some directory in the system path, e.g. /usr/local. * Some prefer putting the code that I put in the -main function directly at the top level of the namespace. This works equally well for interactive development, but the approach presented here is also suitable for compiling into jar files (code at the top level - e.g. starting the server - level will then be executed at compile time rather than at runtime) and use with lein run. // raek -- 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: Better Workflow with App Engine?
P.S. I forgot to mention that a lot of really useful slime commands are documented at the swank-clojure project site: https://github.com/technomancy/swank-clojure // raek -- 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.contrib.condition
2011/2/8 Brian Marick mar...@exampler.com: The header documentation for clojure.contrib.condition says: Note: requires AOT compilation. What do I therefore do differently? How should my program text change? The clojure-contrib jar file that your build tool - or yourself, if you do stuff manually - downloaded contains an ahead of time compiled version of that namespace. So, unless you compile contrib yourself, you shouldn't have to do anything special. Conditions seem to work in the REPL, but not in my program. I don't know if that's due to the mysteries of AOT compiling or something else I'm doing wrong. Please enlighten. I guess that depeds on what you mean by in my program. (The way I do development, I would consider my program and the repl to be the same thing.) I think this is a problem caused by how you launch clojure. Do you use leiningen, cake or something else (if manually, how have you set up the class path)? What behaves differently if you run (require 'clojure.contrib.condition) in the repl and in your program? // raek -- 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: Handling of unsigned bytes
To turn a signed byte (-128 to 127) into an unsigned one: (bit-and the-byte 0xff) The byte (for example 0x80, which is negative) will be extended to an int (0xff80) and anded with 0x00ff (and you get 0x0080, which is positive). The javadoc for the methods of DataInput[1] contain formulas for how to convert shorts and ints and longs too. DataOutput[2] contains comments for the opposite opereration. 1. http://download.oracle.com/javase/6/docs/api/java/io/DataInput.html 2. http://download.oracle.com/javase/6/docs/api/java/io/DataOutput.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: How does pmap partition its work?
2011/1/24 Michael Gardner gardne...@gmail.com: Suppose I have a sequence of tasks I'd like to parallelize using pmap. The amount of CPU time these tasks require varies greatly; in particular, many of them will require virtually no work. Can I rely on pmap to divide the work efficiently even if there is some pattern to the distribution of easy tasks (e.g. clumped at the beginning, or every nth)? Assume it's not possible to identify the easy tasks beforehand. If you simply want all tasks to be performed as quickly as possible, one alternative could be to use an ExecutorService (perhaps one created with newFixedThreadPool) with its invokeAll method. invokeAll takes a collection of callables (in clojure terms: you can pass it a seq of zero-arg functions) and returns a collection of futures. An ExecutorService could perhaps give you fine-grained control. I recently wrote a blog post on this; you might find it interesting: http://blog.raek.se/2011/01/24/executors-in-clojure/ // raek -- 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: How does pmap partition its work?
2011/1/27 Ken Wesson kwess...@gmail.com: On Thu, Jan 27, 2011 at 2:09 PM, Michael Gardner gardne...@gmail.com wrote: On Jan 27, 2011, at 7:24 AM, Rasmus Svensson wrote: If you simply want all tasks to be performed as quickly as possible, one alternative could be to use an ExecutorService (perhaps one created with newFixedThreadPool) with its invokeAll method. invokeAll takes a collection of callables (in clojure terms: you can pass it a seq of zero-arg functions) and returns a collection of futures. An ExecutorService could perhaps give you fine-grained control. I recently wrote a blog post on this; you might find it interesting: http://blog.raek.se/2011/01/24/executors-in-clojure/ Thanks for the tip. By coincidence, I just stumbled across ExecutorService yesterday via the example at http://clojure.org/concurrent_programming. I'm never thrilled about having to use Java APIs directly, but in this case an ExecutorService does what I want much better than pmap, and isn't too difficult to use. Perhaps pmap should be rewritten to use ExecutorService, if that is so. Actually, 'pmap' is built on top of 'future' which is built on top of an ExecutorService. // raek -- 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 does (.foo (new Bar)) use a different method invocation mechanism than (def bar (new Bar)) (.foo bar)?
2011/1/16 Robert Campbell rrc...@gmail.com: The second form - (.foo bar), expanded to (. bar foo) - eventually calls Reflector.invokeNoArgInstanceMember. For that form, the clojure compiler cannot infer the type of bar, and does not know which exact method (class + type signature) .foo represents. Due to this, a runtime lookup that uses the reflector is inserted, since a method invocation in java byte code must be statically typed (at least currently). The first form - (.foo (new Bar)), expanded to (. (new Bar) foo) - doesn't seem to use any Reflector _invocation_ methods. I also added a breakpoint to java.lang.reflect.Method.invoke() and it never hits that breakpoint. This is because the compiler knows the type of the arg to .foo, and can emit bytecode for a plain old (statically typed) method invocation. Since reflective method invocations are pretty slow, you often try to add type hints so that it can be avoided: (.foo ^Bar bar) The generated bytecode for this method invocation should be very similar (if not identical) to the bytecode for (.foo (new Bar)) // raek -- 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: Queues in Clojure
2010/12/3 Andreas Kostler andreas.koestler.le...@gmail.com: Hi All, May I cite an Author of a populer Clojure book: If you find yourself wishing yourself to repeatedly check a work queue to see if there's an item of work to be popped off, or if you want to use a queue to send a task to another thread, you do *not* want the PersistenQueue discussed in this section Why do I not want to use clojure.lang.PersistentQueue for that purpose and what would I want to use instead? Can anyone fill me in please? clojure.lang.PersistentQueue is a collection data structure with queue operations. It is persistent, so it lets you (and other threads) create modified versions of it with elements enqueued or dequeued in a thread-safe manner. java.util.concurrent.LinkedBlockingQueue[1] is not a persistent data structure. It is often used as a communication channel between threads, since it allows its operations to block (potentially with a timeout). One thread can dequeue (and block if the queue is empty) simultaneously as another thread can enqueue (and block if the queue is full) at the other end. It makes it easy to make programs in a producer-consumer style. // raek [1] http://download.oracle.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingQueue.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: priority queue for scheduling events in the future
2010/11/24 HiHeelHottie hiheelhot...@gmail.com: Does anybody know of an implementation for a priority queue that can be used for scheduling events in the future? I would like to put a map associated with a timestamp into the queue and be able to pull out all maps at or before a given time in order. I would also recommend looking into the classes in java.util.concurrent, especially DelayQueue. http://download.oracle.com/javase/6/docs/api/java/util/concurrent/DelayQueue.html // raek -- 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: println from within a thread
2010/11/21 HiHeelHottie hiheelhot...@gmail.com: Does anybody know how to redirect the output into the repl? Thread local bindings are not passed on to new threads. Since you might have multiple connections to the swank server, there might me multiple repls, each one with their own *out*. Most often though, you only have one connection and in that case one option is to set the root binding for *out* (which is the default value to use, if it hasn't been overridden in the thread) to the stream connected to the emacs buffer: (alter-var-root #'*out* (constantly *out*)) You should evaluate this in the repl where you want the output. Another more general approach is to let the body of the new thread inherit the bindings of the parent thread. This is done by bound-fn, which has the same syntax as fn. The result of that call will be a fn, whose body is evaluated with the same thread local bindings as the parent thread. The thread where the bound-fn call is evaluated in is the one from which bound-fn remembers its bindings. In your case, the code would look like this (I took the liberty of rearranging it a bit): (def my-thread (doto (Thread. (bound-fn [] (println inside thread))) .start)) Regarding the *inferior lisp* buffer: It is where the master repl will be if you start the Clojure process from within Emacs. If you start it with lein/cake swank (which seems to be the preferred approach nowadays), the terminal where you ran that command will play the same role (as you already noticed). I hope this answers your question... // raek -- 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: string interpolation
2010/11/21 HiHeelHottie hiheelhot...@gmail.com: I think ruby has nice string interpolation. You can put the following in a textfield that a user can modify This is a #{adjective} string. Then, you can take that string, put it in quotes and have ruby evaluate it as a string. What is the clojure way of doing something similar. Presenting something like This is a adjective string and then wrapping that in (str ) before evaluating it in clojure seems less attractive. There's also the String/format wrapper in clojure.core, which can be used for simpler interpolations (you can use usual printf directives): (format This is a %s string adjective) // raek -- 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: REQUEST for feedback on http://clojure.org
I also noticed that clojure.org/agents does not mention the *agent* var... // raek -- 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: Jython Interoperability problem
2010/10/29 Dilvan dil...@gmail.com: Any clues? I don't know much about how Jython works, but from the stack trace it seems like Clojure cannot load its source files from the classpath. Are there other ways to add jars to the classpath in Jython? // raek -- 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: Jython Interoperability problem
It seems like this is a class loader issue... The guys working on clojure-ant-tasks seems to have hit the same problem: https://github.com/jmcconnell/clojure-ant-tasks/issues#issue/5/comment/223478 I also found these two issues: http://dev.clojure.org/jira/browse/CLJ-260 http://dev.clojure.org/jira/browse/CLJ-379 It seems like it should be possible to make a workaround, but unfortunately I don't have any experience at all with how class loaders work. So I'm afraid I'm out of advice... // raek -- 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: - related error in clojure 1.2
2010/11/9 Carlos Moscoso moscoso@gmail.com: user= (- {:a 1} (keyword a)) - is simply a code rewrite macro. You can use macroexpand-1 to see how the rewrite is done: user= (macroexpand-1 '(- {:a 1} (keyword a))) (keyword {:a 1} a) As Sunil said, you can get the desired behaviour by adding parentheses: user= (macroexpand-1 '(- {:a 1} ((keyword a ((keyword a) {:a 1}) In this simple case, a simple get would be sufficient: user= (get {:a 1} (keyword a)) 1 ...but I guess the code you posted was only the minimal case to reproduce the error. Sometimes, get-in can also be an alternative to -. // raek -- 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: How to rewrite code to avoid bashing transients in-place?
2010/11/9 Greg g...@kinostudios.com: I think to answer both questions I should explain the context of this problem. I'm currently in the process of learning Clojure, and as an ex cerise to assist in this endeavor I set about solving a problem presented in the classic game called Myst. One of my favorite games! I can assuredly inform you all that this whole business is a red herring! There is no possible way to obtain 2,2,1 from any series of left or right turns if you're starting at 3,3,3! So don't bother wasting your time trying it. It's a code for something else. Clojure tells me so. :-p - Greg I remember that I simply gave up and assumed that there were no such sequence. I admire your systematic approach to this! A red herring indeed, as in many of the puzzles in the Myst games... On your request, I could give you a very tiny hint. (I won't reveal any details in this mail, in case you prefer to solve it on your own.) // raek -- 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: How to rewrite code to avoid bashing transients in-place?
For fun, I made my own code for proving your result: https://gist.github.com/668830 (contains? (reachable-states [3 3 3]) [2 2 1]) = false //raek -- 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: Documentation lacking for ns macro
2010/11/4 Ken Wesson kwess...@gmail.com: The ns macro seems to be poorly documented as yet. The Namespaces page at the main Clojure site does not go into detail about its syntax; Yes. The docs related to the ns form are indeed insufficient and need attention. However, have you seen the http://clojure.org/libs page? I think it will answer *some* of you questions. That page isn't perfect, but it seems to contain the kind of examples you are looking for. // raek -- 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: REQUEST for feedback on http://clojure.org
I think there should be a link from the Namespaces page to the Libs page. Hopefully, this will make it easier for people to find examples on how to use the ns form. -- 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: figuring out sets
2010/11/1 tonyl celtich...@gmail.com: I was wondering since it uses the dispatch macro and AFAIK there is no api fn to create them like hash-maps to create maps, vector/vec for vectors, or list for lists. There are parallels to 'hash-map' and 'sorted-map' in the api: user= (hash-set :a :b :c) #{:a :c :b} user= (sorted-set :a :b :c) #{:a :b :c} Literal maps are hash-maps. //raek -- 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: Can't locate str_utils in classpath
2010/10/31 Steven Arnold thoth.amon.i...@gmail.com: Hello, I am trying to use the str-utils library with Clojure (or the str-utils2, I understand str-utils was deprecated). Neither of these work for me. I am on OS X 10.6.4 and have installed clojure-contrib via the MacPorts system. The clojure-contrib is in my classpath; see below for a transcript of what I did. I have been struggling with this for hours, searching through Google, asking on the IRC channelall to load a library from clojure- contrib. Any ideas what I'm missing This is not an answer to your original question, but I hope you find this useful anyway (if not now, some time in the future). Managing the classpath manually can indeed be tedious. Unless you for some reason really need to do it manually, I would recommend using one of Clojure's build tools (Leiningen[1] and Cake[2] are very common) to manage it for you. Here is an example of how you would do it with Leiningen (assuming it is installed; see the instructions on its web page): lein new foobar cd foobar/ editor of choice project.clj With Leiningen and Cake (they use the same project structure), you declare the versions of Clojure, Contrib and any other dependencies you need in the project.clj file. Here is an example of it for using Clojure 1.2: (defproject foobar 1.0.0-SNAPSHOT :description FIXME: write :dependencies [[org.clojure/clojure 1.2.0] [org.clojure/clojure-contrib 1.2.0]]) Leiningen will fetch the correct versions of the jar files and set up the classpath for you: lein deps lein repl Happy hacking! // raek [1] http://github.com/technomancy/leiningen [2] http://github.com/ninjudd/cake -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: [Bug] StackOverflowError while using map inside a reduce
2010/11/3 John Szakmeister j...@szakmeister.net: I'm sorry... I don't quite understand this explanation. Do you mean that reduce is realizing the entire list all at once? I would think it would grab an element one at a time. Sorry for the stupid question, but there's something subtle here that I'm not understanding. user= (reduce #(doall (map + %1 %2)) (partition 5 (range 1e6))) (950 970 990 1010 1030) Is it because of the way the lazy sequence is being generated? Would different implementations of partition or range do better? Thanks in advance! -John I think the problem is that this reduction will build an expression like this: (map + ... (map + ... (map + ... (map + ... one million nesting levels When clojure tries to realize an element of the resulting lazy seq, every level will result in a nested method call, which will eventually blow the stack. // raek -- 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
Linköping Clojure User Group Startup Meeting
Hi Clojurians of Linköping! This is an invitation for the upcoming startup meeting of a new Clojure group in Linköping. On 29th of September (next Wednesday), Linköping Clojure User Group will have its first meeting. (Those of you who hang around in House B at the University may have already seen the posters...) The meeting will be in SU15/16 at 19:00. You can bring a laptop if you want to, but I have confirmed that Leiningen, Cljr and Emacs work on the lab computers. For more information, see the website: http://raek.se/lcug See you there! // raek -- 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 meetup group listing
2010/9/20 Andrew Gwozdziewycz apg...@gmail.com: I'd like to propose that we make an effort to list these groups on Meetup Everywhere (http://www.meetup.com/everywhere), which is a free platform useful for finding a nearby meetup about a given topic. Hi! Linköping Clojure User Group will have its startup meeting next week (see website http://raek.se/lcug and thread http://groups.google.com/group/clojure/browse_thread/thread/b28a712381b03754 ). I also added it to the Meetup site. // raek -- 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.string
2010/9/24 cej38 junkerme...@gmail.com: I noticed that clojure.string is not showing up on the API webpage, http://clojure.github.com/clojure/, is that an oversight? -- 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 All the clojure.java.* namespaces and clojure.test are gone too... I don't think this is intentional... // raek -- 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: Byte Literals
There's also 'bytes', 'byte-array' and 'into-array': (byte-array (map byte [1 2 3])) (into-array Byte/TYPE (map byte [1 2 3])) // raek -- 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: trouble getting library structure right: can't let files talk to each other
2010/8/17 jandot jan.ae...@gmail.com: Hi all, I'm trying to write a library to perform some statistical and data mining analyses. Clojure has proven a great help here, especially with the incanter library. Writing the code has been kind of an organic process (read: no planning), and I ended up with different conceptual groups of functions all within one file. So it makes sense to split this up and start organizing it. Unfortunately, I am having trouble making the different files (and namespaces) talk to each other, and need some help. Let's say I have two parts in my analysis, each of which require quite a few underlying functions. I would ideally start up a repl and focus on just one analysis: playing with the data, making some graphs, ... I've created a leiningen project with lein new my-important-project, to which I added two files in src: analysis-1.clj and analysis-2.clj. Directory structure: +- project.clj +- test | +- my-important-project | +- core.clj +- src +- my-important-project +- core.clj +- analysis-1.clj +- analysis-2.clj Let's say this is the contents for those 3 files in src/ (core.clj contains functions and constants that are necessary for both analyses): core.clj (ns my-important-project.core (:use [incanter core io stats charts] [somnium congomongo])) (mongo! :db the-database) (def some-constant 3.141592) analysis-1.clj (ns my-important-project.analysis-1) (defn say-from-one [text] (println (str from 1: text))) analysis-2.clj (ns my-important-project.analysis-2) (defn say-from-two [text] (println (str from 2: text))) Here, the ns declaration looks right. If I want to work on analysis 2, I'd start up the repl in the main directory created by lein (so one *up* from src) and type: user= (ns '(my-important-project core analysis-2)) user= (say-from-two some text) ns is a macro normally used at the top of the source files. To force the code of a namespace/file to be loaded, call require (which, unlike ns, is a function and thus requires the args to be quoted): (require '(my-important-project core analysis-2)) At this point, you should be able to call say-from-to with its full name: my-important-project.analysis-2/say-from-two. You can use the :as option to make a shorter prefix if you like (see link below). If you want to play around inside the namespace, you can go into it by calling: (in-ns 'my-important-project.analysis-2) or simply use the ns macro: (ns my-important-project.analysis-2) You will see the prompt change when you do this and from here you should be able to call say-from-two directly. But as you'd have guessed: this doesn't work. The (ns) returns the following error: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IObj (core.clj:1) I've tried different versions of the (ns) function, including a vector as its argument, periods instead of spaces, ... In addition: in the end I'd like to write a script that does the analysis automatically. So instead of going into the repl, I'd cljr run a clj file. What should the (ns) bit of that file look like? I've been searching the web for what I'm doing wrong, but haven't found the solution yet. It's quite frustrating to see so many discussions about namespaces, but not being able to solve this issue. The ns macro and library conventions are described here: http://clojure.org/libs Any help very much appreciated, jan. The ns macro is pretty complex and unfortunately I don't have time to write longer about it right now. I hope this could at least get you started. // Rasmus -- 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 Web Programming group?
I think there's a lot of questions that a Clojure programmer faces when doing web programming, not only regarding how the libraries work, but also regarding how to design a larger-than-trivial web applications. A mail list would be a very good way to be able to ask for advice or to be inspired by solutions other people have come up with. I think there is a lack of articles and blog posts on the web where people write about the experiences they had during the development of their web applications. I always get the feeling that what I am struggling with, some else has already struggled with too and maybe even solved. During the time I've done web development, I've been searching for something like this. // Rasmus -- 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: multiline strings and multiline comments ?
2. multiline comments like java /* this is a multiline comment */ I don't know. Comment blocks are usually done by starting each line with ;; ;; this is ;; a comment ;; block (some-code) Anything after a ; is a comment, like python's #. There is a convention for how many ;s to begin the line with. (Basically ; for same line comments, ;; for comments above code and ;;; for top-level comments not commenting on the form below) There is also the (comment ...) form that disregards the containing forms. Note that the contents has be well-formed clojure code (matching parentheses, etc). (comment ; Usage examples (foo 1 2 3) (bar :a :b :c)) // raek -- 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: Trouble upgrading to clojure 1.2
2010/8/16 Alan a...@malloys.org: I hear that swank.core/break has more functionality in 1.2, so I am trying to upgrade to it, but I think I don't have a clear enough understanding of what is going on when lein/clojure run, as I am running into problems. $ cat project.clj (defproject ddsolve 1.0.0-SNAPSHOT :description FIXME: write :dependencies [[org.clojure/clojure 1.2.0] [org.clojure/clojure-contrib 1.2.0]] :dev-dependencies [[swank-clojure 1.2.0]]) $ lein deps Downloading: org/clojure/clojure/1.2.0/clojure-1.2.0.pom from central Downloading: org/clojure/clojure/1.2.0/clojure-1.2.0.pom from clojure # a dozen more lines like this... An error has occurred while processing the Maven artifact tasks. Diagnosis: Unable to resolve artifact: Missing: -- 1) org.clojure:clojure:jar:1.2.0 Try downloading the file manually from the project website. It works with no problems if I change 1.2.0 in clojure.core and clojure.contrib to 1.1.0. I assume I need to somehow tell lein where to find the 1.2.0 jar, but since I don't really know the answer myself... For what it's worth, I've built 1.2 from source and it works if I launch it independently of leiningen, with the clj script provided in clojure.contrib. Thanks a bunch, ~Alan -- 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 Clojure 1.2 has not been released yet... :) We're currently at Release Candidate 3. Here is a some currently available releases and snapshots (see http://build.clojure.org/releases/ and http://build.clojure.org/snapshots/): Releases: * 1.0.0 * 1.1.0 * 1.2.0-beta1 * 1.2.0-RC1 * 1.2.0-RC2 * 1.2.0-RC3 (most recent) Snapshots: * 1.2.0-master-SNAPSHOT (clojure) * 1.2.0-SNAPSHOT (clojure-contrib) Happy hacking! // raek -- 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: chinese character in hiccup
2010/8/12 James Reeves jree...@weavejester.com: On 12 August 2010 14:33, limux liumengji...@gmail.com wrote: The solution in http://tiny.cc/3cmrx is useful, thanks. That what cause the issue should be compojure. That thread's time is 6, June. and compjure haven't fixed it. The solution you mention is some middleware that sets the content-type charset header to a specific value. Has this fixed the issue? I was under the impression from Rasmus's post that raw strings worked fine, and it was just an issue with Hiccup. However, that in itself is odd, as Hiccup only uses raw strings and the str function to join them together. I believe this should maintain the correct string encoding. So assuming both str and literal strings work, Hiccup should work. I guess we need to determine whether the string itself has the wrong encoding, or whether an incorrect encoding has been specified in the content type. - James -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en From what I can tell, the problem he had was caused by compojure's default content type text/html being replaced by text/html; charset=iso8859-1. If he added the charset attribute (with the middleware proposed in the link) the problem went away. I asked him to check the page info in firefox to see what content-type the web server served. Without the middleware, it was text/html; charset=iso8859-1 and with it, it was text/html; charset=utf-8, as expected. The only value existing in the compojure code is text/html, iirc. It appears that Jetty rewrites any text/html content type it serves and adds a charset attribute (maybe with the dreaded OS default charset as its value) if there isn't one. Time for some tests, maybe? // Rasmus -- 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: Eclipse and Compojure
I assume the problem is that there are no .class files in the jar. I tried to rebuild the compojure jar using lein jar but still didn't get .class files, even though: Clojure looks for both .class files and .clj files, so you don't need to compile anything manually. I'm seeing the following error: java.io.FileNotFoundException: Could not locate compojure/ core__init.class or compojure/core.clj on classpath:core.clj/web- app-adder/src/adder line 1 Clojure Compilation Problem As you can see, it actually said that it looked for: 1) compojure/core__init.class 2) compojure/core.clj and didn't find any of them. This means that the compojure jar file is not on the CLASSPATH somehow. I'm not a clojure + eclipse user, so I can't give you any advice on how to setup eclipse so that it uses the correct CLASSPATH . But one thing that might be useful to know is that, for the JVM, jar files counts as directories. Thus you might have to add the paths to all the jar file, not the directory that contains them. I hope that this could be helpful, or perhaps narrow down your debugging a little... // raek -- 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: chinese character in hiccup
2010/8/10 limux liumengji...@gmail.com: There is some chinese chararters in the tables. I want to display them by hiccup, but browser display those chinese character as ???. I spoke to him on #clojure and from what I could tell from some experiments I asked him to run: (map int 刘孟江) - (21016 23391 27743) = no source file encoding issues (.name (java.nio.charset.Charset/defaultCharset)) - GBK = his OS default encoding is GBK (GBK is an extension of the GB2312 character set for simplified Chinese characters, used in the People's Republic of China.) some libs might erroneously rely on that the OS default encoding is UTF-8 or something else (defroutes app (GET / [] (java.io.ByteArrayInputStream. (.getBytes htmlheadmeta http-equiv='Content-Type' content='text/html; charset=UTF-8'/headbody刘孟江/body/html UTF-8 - showed up correctly = works, since we do the encoding ourselves (defroutes app (GET / [] htmlheadmeta http-equiv='Content-Type' content='text/html; charset=UTF-8'/headbody刘孟江/body/html)) - showed up correctly = ring uses UTF-8 as the default encoding no matter what the OS default is. a very reasonable behavior, since then the result is always deterministic. This leaves me to the conclusion that the error is caused by hiccup somehow (which he also used), since everything seems to work fine without it. I might look into this later this evening to see if I can reproduce the error that occurred for him. // raek, your encoding wizard -- 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: chinese character in hiccup
I looked into the source of hiccup and tried entering the string 刘孟江 at various places, but I couldn't reproduce the error or find any code that did any form of encoding. When playing around with the repl, I was reminded that JLine (used by lein repl) does not support multibyte encodings (including UTF-8 and GBK). Could this be the problem, Limux? // raek -- 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: Can't get my nesting right
2010/8/10 Alan a...@malloys.org: I have the following function as part of a card-game system I'm developing: (defn make-suit [suit owner ranks] {suit (map (partial struct-map card :suit suit :owner owner :rank) ranks)}) (make-suit :spade :west [9 5]) yields {:spade ({:suit :spade, :owner :west, :rank 9} {:suit :spade, :owner :west, :rank 5})} which is exactly what I want. But I have failed countless times to define a make-hand function - I'd like to be able to call (make- hand :west {:spade [9 5], :club [10]}) and get back {:spade ({:suit :spade, :owner :west, :rank 9} {:suit :spade, :owner :west, :rank 5}), :club ({:suit :club, :owner :west, :rank 10})} Can someone put me on the right track? I'm sure the solution for this is trivially simple but I can't quite find 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 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 My attempt: (defn make-hand [owner cards] (into {} (for [[suit ranks] cards] [suit (for [rank ranks] {:suit suit :owner owner :rank rank})]))) Notice that a sequence of a map is a sequence of its [key value] pairs. The keys are in this case the suits and the values which ranks of that suits that should be included. To generate a map, it is often useful to make [key value] pars and conj them into an empty map using 'into'. The generated map has the suits as its key, and for each suit the ranks are looped over. A card map, including suit, rank and owner is generated for each rank. The current suit and owner is accessed through the for body's closure. // raek -- 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: abstract structural binding
2010/8/1 doug 395curra...@gmail.com Hey all! can't seem to get the last element to bind. tia -doug user cj-mpdata [0010335602 40.00 1060.51 6/23/2010 DISCOVER E- PAYMENT 7796 (DISCOVER)] user (let [[[_ ck db cr _ dt _ _ _][dsc]] [[Acct Chk Debt Crd Bal Date Desc Payee Catagory] [newDescript]]] [dt ck db cr dsc]) [Date Chk Debt Crd newDescript] user (let [[[_ ck db cr _ dt _ _ _][dsc]] [cj-mpdata]] [dt ck db cr dsc]) [6/23/2010 40.00 nil] user The data you pass to the first let is structured like this: [[:a :b :c :d :e :f :g :h :i] [:j]] i.e., a 2-vector with a 9-vector and a 1-vector in it. But the data in cj-mpdata is structured like this: [:a :b :c :d :e :f :g :h :i [:j]] i.e., a 10-vector with a 1-vector as its last element. In your second let case, doing this should work: (let [[_ ck db cr _ dt _ _ _ [dsc]] cj-data] [dt ck db cr dsc]) Also, adding square brackets to both the left hand side and the right and side in a let binding is a no-op, and can be removed. // raek -- 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 on namespace/packages of defrecord
2010/7/17 Moritz Ulrich ulrich.mor...@googlemail.com clojure-namespaces should be treated like java-namespaces: (ns foo.bar) instead of (ns foo-bar) I think he refered to the fact that the hyphen in the (single) namespace segment was not translated into an underscore. // raek -- 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 1.2: Unicode string length bug?
This is most probably a repl-terminal encoding mismatch issue. Are you using JLine? It seems to be the case that it cannot handle UTF-8. There is a simple way to see if there is encoding mismatch issues: just make a seq of the string: (seq t) if everything is working correctly: = a seq of the 9 chinese characters else: = a seq of 27 unkown character symbols It could worth investigating how the clojure repl creates a Reader (which reads *characters*) from the System.in InputStream (which reads *bytes*) too. BEGIN TECHNICAL DETAILS A bit of background: That string of chinese characters consists of 9 *characters*. (Try to select the text. You will be able to select it in 9 discrete steps). These can be encoded to bytes with the UTF-8 encoding, in which case the encoded string will consist of 27 *bytes*. Terminals are not character oriented, but byte oriented. This means that both the user side (keyboard and screen) and the application (the clojure repl) needs to choose an encoding to use if they want to be working with characters. In this case, the terminal is probably configured to use UTF-8, as it is able to both emit and display the chinese characters correctly. The 9 characters are then sent as 27 bytes to the clojure repl. If everything was configured correctly, the repl should decode the 27 bytes into 9 characters again. Now, the repl was not configured correctly and probably used the OS default encoding (which can be anything) that in this case must have been a single-byte-encoding like Latin-1/ISO-8859-1 or Mac Roman. The 27 bytes were then decoded into 27 characters. If you evaluate t, the repl will encode the 27 characters into 27 bytes again, send it to the terminal, which will decode them into the 9 chinese caracters and display them. END TECHNICAL DETAILS // raek 2010/7/1 ngocdaothanh ngocdaoth...@gmail.com With 1.2-master-SNAPSHOT: (def t 車馬象士將士象馬車) (count t) ; = 27 (.length t) ; = 27 With 1.1, the result is 9. -- 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.comclojure%2bunsubscr...@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: classpath and require
2010/6/18 Mohammad Khan beepl...@gmail.com C:\Projects.cljjava -cp c:\clojure-contrib\clojure-contrib.jar;c:\clojure\clojure.jar clojure.main Clojure 1.1.0-alpha-SNAPSHOT user= (require 'examples.introduction) java.io.FileNotFoundException: Could not locate examples/introduction__init.class or examples/introduction.clj on classpath: (NO_SOURCE_FILE:0) user= C:\Projects.cljecho %CLASSPATH% C:\Projects.clj;C:\clojure;C:\clojure-contrib C:\Projects.cljdir examples\introduction.clj Volume in drive C is xxx Volume Serial Number is - Directory of C:\Projects.clj\examples 06/18/2010 04:52 PM40 introduction.clj 1 File(s) 40 bytes 0 Dir(s) xx,xxx,xxx bytes free C:\Projects.clj Hello! To me it looks like you have gotten the most things right. As I see you understand, you must have clojure, clojure-contrib and the source on the class path. However, how these are specified can be a bit tricky. There are basically two cases: directories and jar files. When using jar files, the jar file itself must be in the class path, not the directory which contains it. In our case, the entries would be c:\clojure\clojure.jar and c:\clojure-contrib\clojure-contrib.jar, just as you wrote. When using folders with clojure source files or ahead-of-time compiled classes, the directory that contains the folder that represents the topmost component of the namespace. For example, in your case the namespace examples.introduction is stored in the file C:\Projects.clj\examples\introduction.clj so the directory C:\Projects.clj\ should be inlcuded in the class path. When Clojure loads the namespace examples.introduction, it will try to find examples\introduction.clj in every directory (or jar file) in the class path. The error you got is an indication that no matching file could be found. On windows, the paths are delimited with semicolons, but on most other platforms colons are used. That's why most examples will use colons. If the paths in the class path contains spaces or other special characters, you should enclose the thing in spaces, like this: java -cp C:\path one\;C:\path two\ clojure.main From what I can tell, Rob's example should work. I'm not sure if a trailing backslash is required for directories, but you could try with and without it to see if it makes any difference. If that doesn't work, try renaming projects.clj to something without a dot in it. Also, look carefully for typos... I hope this helps... // raek -- 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: code review request: clojure.java.io
2010/5/11 Stuart Halloway stuart.hallo...@gmail.com Assembla Ticket #311 [1] calls for the promotion of clojure.contrib.iointo clojure (as clojure.java.io). I have attached a patch, and am requesting comments and code review from the community. I think I have found a bug in the clojure.contrib.io code. The current 1.2 master branch contains the following : (extend Socket IOFactory (assoc default-streams-impl :make-input-stream (fn [^Socket x opts] (.getInputStream x)) :output-stream (fn [^Socket x opts] (output-stream (.getOutputStream x) opts Note that :output-stream is not part of the IOFactory protocol. The intended keyword was most probably :make-output-stream. Also, the body should not contain a call to output-stream, since it calls make-output-stream. I propose that the last line is changed so that the code becomes the following: (extend Socket IOFactory (assoc default-streams-impl :make-input-stream (fn [^Socket x opts] (.getInputStream x)) :make-output-stream (fn [^Socket x opts] (.getOutputStream x Now, one can make output streams from sockets again (this threw an exception[1] before): (output-stream (Socket. example.com 1234)) So what is the next step for me now? I am not formally a contributor yet. It will take approx a week until my signed CA arrives. I will gladly help with whatever I can do in the mean time... // raek [1] The exception: java.lang.IllegalArgumentException: Cannot open #Socket Socket[addr=clojure.org/75.126.104.177,port=80,localport=50897] as an OutputStream. -- 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: agents sending-off to other agents blocks?
2010/6/12 Dan Larkin d...@danlarkin.org Does anyone have insight as to the reasoning here? Is it a bug? If it's intended behavior is there something I can do to circumvent it? I do think this is intentional. Agents holding on to their sends until its state transition function is done can be a useful thing. Either the function completes and the actions get sent, or (maybe due to an exception being thrown) the function fails, the agent doesn't change its state and the pending sends are dropped. This results in a everything-or-nothing update model for agents, somewhat similar to transactions (which are also holding on to sends, btw). If this wasn't the default behaviour, I think it would be very tedious to write code that needs it. One solution to the sleep problem could perhaps be to let the agent send this to it self: (fn [state millis] (Thread/sleep millis) state) // raek -- 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: special forms
I thought I'd just share some thoughts on special forms... 2010/5/20 Konrad Hinsen konrad.hin...@fastmail.net You can't redefine special forms. What you define in your examples is the symbols that serve to identify special forms. But they indicate special forms only when used in the first position of a list that is evaluated. Everywhere else, they behave just like symbols, so you can use them to name vars or provide local bindings in a let form. One thing that this implies is that you cannot for example pass a reference to 'if'. (map if [true false] [:a :b] [:c :d]) ; throws java.lang.Exception: Unable to resolve symbol: if in this context (NO_SOURCE_FILE:1) Also, you can't circumvent this by using macros: (defmacro if-macro [pred tbranch fbranch] `(if ~pred ~tbranch ~fbranch)) ; The var #'if-macro now holds a real reference to something that does what if does. (map if-macro [true false] [:a :b] [:c :d]) ; throws java.lang.Exception: Can't take value of a macro: #'user/if-macro (NO_SOURCE_FILE:4) Special forms and macros are compile time constructs (all expressions are compiled when evaluated). The symbols that represent special forms are not resolved into vars at all. If special forms were a special kind of value, the var holding them could be rebound at run time, implying that the control flow structure of the code could be changed at run time. Just imagine what rebinding 'cond' to 'do' would do... This does not make a lot of sense in a compiled language, so the Clojure compiler simply looks for symbols with the right name, and unconditionally treats them as special forms. Special forms are a part and special case of the function invocation syntax. As Konrad said, the symbols identifying special forms only have special meaning in the function position of evaluated lists. Everywhere else they work as ordinary symbols. 2010/5/20 Аркадий Рост arkr...@gmail.com In my opinion, this situation must be resolved. For example it is possible to 1) prohibit such definition 2) allow redefining keywords in namespaces I agree that it would probably be good to make the use of one of those symbols outside the function position of an evaluated list an error (or at least emit a warning). // raek -- 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 Cheat Sheet
2009/10/19 Gorsal s...@tewebs.com: All right, so this is probably way off topic, but what software was used to create the clojure cheat sheet? http://clojure.org/cheatsheet I really like the format and would like to make one for my own utilities so that I can actually remember what general utility functions i have written! In case you were interested in the HTML version, you can find the HTML and CSS without the Clojure website stuff here: http://raek.se/clojure-cheat-sheet.html As for tools, all I used when I reformatted the cheat sheet to HTML was a text editor, but I don't think it's too difficult to write a program that generates this sort of cheat sheets -- both in HTML and LaTeX. If you're choosing from LaTeX and HTML, I recommend going for LaTeX, since HTML's layout capabilities are really primitive and you have to use some ugly trick to get things the way you want. However, HTML has the advantage that you don't need any additional software. -- raek --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---