Re: when performance matters
I remember from 5 years ago that a collegue of mine improved a diffusion algorithm for a successor of me by some heavy algorithms. My own algorithm was a simple loop-over-the- array once, dump-a-fraction- of-each-cell-into-spatially-neighbouring-cells-in-the-new-array, and sum what is in every cell of the new array (you are doing the same thing, right?). However, there are far faster algorithms. If you are interested, I'll inquire. On Jan 15, 7:03 am, "Mark H." wrote: > On Jan 14, 6:37 pm, Asbjørn Bjørnstad wrote: > > > Look closer, I'm using a 1-D array and indexing by hand :-) > > oops, sorry about that -- i see you are doing the right thing here ;-) > > > > 3. I noticed you are doing 20 iterations of Gauss-Seidel. There are > > > some smart ways to speed up multiple stencil applications. I can > > > point you to references if you are interested. > > > That would be cool. Although, I just copied someone elses algorithm, > > and I think he knew what he were doing so it may be hard to improve > > on it. (Apart from the unchecked- functions pointed out by Chouser > > and Rich.) > > Just for optimizing the stencil computations, check > outhttp://bebop.cs.berkeley.edu/#pubs-- in particular: > > --> "Stencil Computation Optimization and Auto-Tuning on State-of-the- > Art Multicore Architectures" > > --> "Avoiding Communication in Sparse Matrix Computations" (check out > the bibliography for references on "time skewing," as our paper is > more general than what you need) > > As for the algorithm itself, the paper is making an accuracy / > performance tradeoff in the diffusion solve by using very few > iterations of a slowly converging iteration (Gauss-Seidel). I'd have > to investigate the problem further to see whether a more accurate > solver can reduce time-to-solution. For now, maybe you could replace > the 20 steps of Gauss-Seidel with some kind of multigrid cycle -- it > could save some time since you won't have to sweep over the whole grid > so many times. > > mfh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Delays and their efficiency
Thanks for reminding me about #1 ;) On Jan 14, 11:08 pm, Rich Hickey wrote: > On Jan 14, 2:57 pm, Rich Hickey wrote: > > > > > On Jan 13, 12:39 pm, samppi wrote: > > > > Recently, I asked how to make a function evaluate its arguments lazily > > > (http://groups.google.com/group/clojure/browse_thread/thread/ > > > cd01ef39c2b62530), and I was given a good solution: use Delay objects > > > (with the delay and force functions). > > > > I wanted to do this for the efficiency of a functional parser library > > > that uses many meta-functions and meta-meta-functions: I thought that > > > stopping arguments from being evaluated until needed was a good way to > > > prevent useless creation of objects, especially in huge trees of meta- > > > meta-functions. But I was very surprised when running my library's > > > unit tests to see that using Delay objects took much more time to run > > > the tests than not using Delays. Here's an example in a REPL: > > > > Clojure > > > user=> (defn alt [& functions] > > > (fn [tokens] > > > (some #(% tokens) functions))) > > > #'user/alt > > > user=> (defn sub-function1 [c] (println "1:" c) (fn [c] false)) > > > #'user/sub-function1 > > > user=> (defn sub-function2 [c] (println "2:" c) (fn [c] true)) > > > #'user/sub-function2 > > > user=> (defn sub-function3 [c] (println "3:" c) (fn [c] false)) > > > #'user/sub-function3 > > > user=> (defn a-meta-meta-function [c] > > > (alt (sub-function1 c) (sub-function2 c) (sub-function3 c))) > > > #'user/a-meta-meta-function > > > user=> (time ((a-meta-meta-function "CONTEXT") [:a :b :c])) > > > 1: CONTEXT > > > 2: CONTEXT > > > 3: CONTEXT > > > "Elapsed time: 1.018 msecs" > > > true > > > > ...vs... > > > > Clojure > > > user=> (defn alt [& functions] > > > (fn [tokens] > > > (some #((force %) tokens) functions))) > > > #'user/alt > > > user=> (defn sub-function1 [c] (println "1:" c) (delay (fn [c] > > > false > > > #'user/sub-function1 > > > user=> java.lang.Exception: Unmatched delimiter: ) > > > user=> (defn sub-function1 [c] (println "1:" c) (delay (fn [c] > > > false))) > > > #'user/sub-function1 > > > user=> (defn sub-function2 [c] (println "2:" c) (delay (fn [c] true))) > > > #'user/sub-function2 > > > user=> (defn sub-function3 [c] (println "3:" c) (delay (fn [c] > > > false))) > > > #'user/sub-function3 > > > user=> (defn a-meta-meta-function [c] > > > (alt (sub-function1 c) (sub-function2 c) (sub-function3 c))) > > > #'user/a-meta-meta-function > > > user=> (time ((a-meta-meta-function foo) some-tokens)) > > > java.lang.Exception: Unable to resolve symbol: foo in this context > > > (NO_SOURCE_FILE:13) > > > user=> (time ((a-meta-meta-function "CONTEXT") [:a :b :c])) > > > 1: CONTEXT > > > 2: CONTEXT > > > 3: CONTEXT > > > "Elapsed time: 2.443 msecs" > > > true > > > > Why would it take so much more time? Is it because it might take a > > > long time to construct a Delay object? Can I do something different to > > > make it more efficient, or should I just not use Delay objects? > > > It's hard to enumerate everything that is problematic with this > > approach to determining efficiency. > > > Let's start with the basics: > > > 1) Premature optimization is the root of all evil > > 2) See #1 > > 3) You can't draw conclusions from a single execution of a short > > function > > 4) See #1 > > 5) If you design with Delays etc to put off, avoid or cache a time- > > consuming computation, then test with trivial computations, you know > > nothing > > 6) See #1 > > 7) timings that include I/O tend to be dominated by it > > 8) see #1 > > ... > > On rereading this I see #5 could be taken the wrong way - I mean you > learn nothing from that test, as the Delays/parallelization etc > dominate the time, when with a long computation they wouldn't. > > Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Problem with simple web-app
Hi, I am trying an example in Stuart Halloway's book but I am not getting anywhere: loading the following: (ns reader.snippet-server (:use [compojure html http jetty file-utils] examples.snippet)) (use 'compojure.http) (defservlet snippet-servlet "Create and view snippets." (GET "/ping" "pong") (ANY "*" (page-not-found))) (use 'compojure.jetty) (defserver snippet-server {:port 8080} "/*" snippet-servlet) gives: user=> (use :reload 'reader.snippet-server) java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Character (snippet_server.clj:10) I commented out (GET "/ping" "pong") and it loads and runs. The GET seems to look like the doc string, I will get the compojure source and have a look but pointers would be very welcome. Thanks Tom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Problem with simple web-app
Oops, sorry, wrong group, I have posted to the compojure list now. 2009/1/15 Tom > > Hi, > > I am trying an example in Stuart Halloway's book but I am not getting > anywhere: > > loading the following: > > (ns reader.snippet-server > (:use [compojure html http jetty file-utils] >examples.snippet)) > > (use 'compojure.http) > (defservlet snippet-servlet > "Create and view snippets." > (GET "/ping" "pong") > > (ANY "*" >(page-not-found))) > > (use 'compojure.jetty) > (defserver snippet-server > {:port 8080} > "/*" snippet-servlet) > > gives: > > user=> (use :reload 'reader.snippet-server) > java.lang.RuntimeException: java.lang.RuntimeException: > java.lang.IllegalArgumentException: > Don't know how to create ISeq from: Character (snippet_server.clj:10) > > I commented out (GET "/ping" "pong") and it loads and runs. The GET > seems to look like the doc string, I will get the compojure source and > have a look but pointers would be very welcome. > > Thanks > > Tom > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Synchronization Benchmarks
Hey gang, First time poster! I figured the best way to explore the interesting parts of Clojure (for me: STM, Java interop) would be to implement a simple locking problem in Java and Clojure, and pit them against eachother. The results are about what I expected, but I'm sure you all can tell me how I might make Clojure more competitive. http://github.com/stuhood/clojure-conc/tree/master The benchmark contains 4 bi-directional dictionary implementations: * MDict - Java implementation using the synchronized keyword, * RWDict - Java implementation using a ReadWriteLock, * CLJDict - Clojure implementation using the (locking x) macro on Java HashMaps, * STMDict - Clojure implementation using two refs on maps. Run `ant test` to execute the tests. The tests run once with the number of threads set to Runtime.getRuntime().availableProcessors(), and then again with THREAD_MULTIPLIER times that value. The ratio of reads/write can be tuned with READ_MULTIPLE, and the total number of operations is OPERATIONS. The 3 tunables are set in http://github.com/stuhood/clojure-conc/blob/master/src/java/test/com/mailtrust/dict/BaseTestDict.java I can't figure out how to get Clojure to generate a class that accepts generics parameters, so there are some warnings while compiling the tests. Ideas? On a quad core machine: > [junit] Running com.mailtrust.dict.TestCLJDict > [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 24.938 sec > [junit] Running com.mailtrust.dict.TestMDict > [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 2.269 sec > [junit] Running com.mailtrust.dict.TestRWDict > [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 2.096 sec > [junit] Running com.mailtrust.dict.TestSTMDict > [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 12.996 sec On a single core machine: > [junit] Running com.mailtrust.dict.TestCLJDict > [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 12.54 sec > [junit] Running com.mailtrust.dict.TestMDict > [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.422 sec > [junit] Running com.mailtrust.dict.TestRWDict > [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.486 sec > [junit] Running com.mailtrust.dict.TestSTMDict > [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 5.882 sec Thanks! Stu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
No Indentation in SLIME
Hello, I'm new to Clojure, SLIME, and emacs in general but I've noticed my SLIME REPL does not indent properly when I use or C-j. This is the error message I see: "calculate-lisp-indent: Symbol's function definition is void: clojure- indent-function" I've experienced this when setting up Clojure + SLIME via .emacs and also when running Clojure Box. When I open a .clj file indentation works just fine. I just have trouble with the SLIME REPL. One thing I noticed is if I evaluate the function clojure-indent- function, function clojure-backtracking-indent, and custom clojure- mode-use-backtracking-indent (from clojure-mode.el) within the *scratch* buffer my SLIME REPL will indent correctly. I've seen a few posts with similar problems but I haven't found a solution that works. Thanks, Kyle --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: question about understanding/exploring agents
On Jan 15, 2009, at 2:57 AM, bOR_ wrote: That is, if I understand blocking correctly. Currently assuming that blocking only happens when two things would like to write the same ref? Blocking in this case refers to this definition: http://en.wikipedia.org/wiki/Blocking_(computing) You should use "send-off" if any of the operations in the action may cause the the thread it runs in to "block" (sleep) while waiting for something. That something is often I/O completion, but a thread can also block waiting to acquire a lock, or waiting for a time interval to elapse. If anything in the action requires waiting, use send-off, otherwise use send. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: *1 *2 isn't working properly
Do *1 *2 *3 ... are saved in a built in sequence that we can inspect its contents? On Jan 14, 2:20 pm, Martin Wood-Mitrovski wrote: > On Wed, 14 Jan 2009 04:15:18 -0800 (PST) > > HB wrote: > > > Lets say that the result of each method invocation will be saved in a > > stack. > > The stack now contains, Google and Wicket > > When I run (str *1) , I will get the last item in the stack which it > > is "Wicket" and the result of the method invocation iteself (which it > > is also "Wicket") will be pushed into the stack. > > So the stack now contains: > > Google, Wicket, Wicket > > Am I right? > > sounds right to me. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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: Synchronization Benchmarks
stuhood a écrit : > Hey gang, > > First time poster! > > I figured the best way to explore the interesting parts of Clojure > (for me: STM, Java interop) would be to implement a simple locking > problem in Java and Clojure, and pit them against eachother. The > results are about what I expected, but I'm sure you all can tell me > how I might make Clojure more competitive. > > http://github.com/stuhood/clojure-conc/tree/master > > The benchmark contains 4 bi-directional dictionary implementations: > * MDict - Java implementation using the synchronized keyword, > * RWDict - Java implementation using a ReadWriteLock, > * CLJDict - Clojure implementation using the (locking x) macro on > Java HashMaps, > * STMDict - Clojure implementation using two refs on maps. > I'm pretty sure that STMDict doesn't need two refs on maps but one ref on two maps (which would allow you to use commute in lieu of alter) and since 'this is not hinted in STM-put, STM-getValue and STM-getKey I think you have a reflective call for each (.state this). (defn STM-init [] ; returns the state of a new STMDict: a ref to two HashMaps ; see gen-class docs [[] (ref [{} {}])]) (defn- bidi-assoc [[ktov vtok] k v] [(assoc ktov k v) (assoc vtok v k) ]) (defn STM-put [#^com.mailtrust.dict.STMDict this key value] (dosync (commute (.state this) bidi-assoc key value))) (defn STM-getValue [#^com.mailtrust.dict.STMDict this key] (get (first @(.state this)) key)) (defn STM-getKey [#^com.mailtrust.dict.STMDict this value] (get (second @(.state this)) value)) (untested code) Christophe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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: *1 *2 isn't working properly
On Jan 15, 2009, at 7:28 AM, HB wrote: Do *1 *2 *3 ... are saved in a built in sequence that we can inspect its contents? No, they are separate vars. Here's the code from the core of the read- eval-print loop in clojure/src/clj/clojure/main.clj that shows how they're updated: (let [input (read)] (skip-if-eol *in*) (let [value (eval input)] (print value) (set! *3 *2) (set! *2 *1) (set! *1 value))) As a group, *1, *2, and *3 form (effectively) a small queue (not a stack as someone mentioned previously). If at any point, you want to see all three together, you can evaluate an expression that puts them all in a vector: Clojure user=> :a :a user=> :b :b user=> :c :c user=> :d :d user=> [*1 *2 *3] [:d :c :b] Note that evaluating the vector makes that the new "most recent value": it causes a new "*1" to be pushed into the queue: user=> [*1 *2 *3] [[:d :c :b] :d :c] user=> --Steve smime.p7s Description: S/MIME cryptographic signature
Re: *1 *2 isn't working properly
>>As a group, *1, *2, and *3 form (effectively) a small queue (not a stack as >>someone mentioned previously). It was me :) On Jan 15, 3:00 pm, "Stephen C. Gilardi" wrote: > On Jan 15, 2009, at 7:28 AM, HB wrote: > > > Do *1 *2 *3 ... are saved in a built in sequence that we can inspect > > its contents? > > No, they are separate vars. Here's the code from the core of the read- > eval-print loop in clojure/src/clj/clojure/main.clj that shows how > they're updated: > > (let [input (read)] > (skip-if-eol *in*) > (let [value (eval input)] > (print value) > (set! *3 *2) > (set! *2 *1) > (set! *1 value))) > > As a group, *1, *2, and *3 form (effectively) a small queue (not a > stack as someone mentioned previously). If at any point, you want to > see all three together, you can evaluate an expression that puts them > all in a vector: > > Clojure > user=> :a > :a > user=> :b > :b > user=> :c > :c > user=> :d > :d > user=> [*1 *2 *3] > [:d :c :b] > > Note that evaluating the vector makes that the new "most recent > value": it causes a new "*1" to be pushed into the queue: > > user=> [*1 *2 *3] > [[:d :c :b] :d :c] > user=> > > --Steve > > smime.p7s > 3KViewDownload --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
(newby) Quicksort in clojure
What would be a good way to implement quicksort in clojure (or any persistent language)? I mean, not just something that works or has the right theoretical runtime. I've thought about just looking to see how sort was implemented in clojure, but I don't know if it would get to my point once I found out -- for all I know heapsort is way better in such pointer-machine-like environments (that's how I think of it, at least). So I know about the way Haskell intros do it: *recursively concatenate the quicksort of everything less than a pivot with the pivot, and append the quicksort of everything greater than the pivot to the end of that. That gets you the right answer, but it is pointed out (for example here: http://augustss.blogspot.com/2007/08/quicksort-in-haskell-quicksort-is.html) that the preferred, elegant, in place partition algorithm (that I think I read Knuth came up with?) is noteworthy, starting from both ends and walking toward the middle, swapping as you go. I admire Lennart Augustsson for doing that exercise -- whatever the controversy surrounding it might be (did he show Haskell can be just as serious as C, or did he defeat the point of high-level languages? . . . .etc, etc.) Now in clojure, I could just use var-set and var-get, like folks helped me (on my stubbornness) to get going here, but what should I do, short of * above? One interesting answer I came up with was to step back and say, "HOLD IT. This language was built with concurrency in mind. You don't make your money doing it the single threaded way. just use C for that." So I'm even considering (but not limiting the challenge to) parallel approaches. In such an environment it might be ok to do a little extra work . . . maybe make some extra copies, etc., because of the speedups. Step one could start with one thread that spawns a thread (agent here?) for each partition (those in turn doing the same thing) and when those answers come back, the sort it done. I may do the parallel route to understand the thread model, but is there something simple, also, as to the best way to think about quicksort in clojure? I could see something like this adding to Tim's examples page. Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
configurable bash script to launch Clojure available
I've checked in a bash script for launching Clojure to clojure-contrib/ launchers/bash/clj-env-dir. It's configured using environment variables (one required and several optional). It sets up the CLASSPATH for the Clojure instance it launches based on the contents of a directory. This is a mechanism similar to Java's java.ext.dirs facility but implemented without using java.ext.dirs. I've tested this on Mac OS X Leopard and Ubuntu Intrepid. Here's a description of the environment variables it uses: # Environment variables: # # Required: # # CLOJURE_EXT The path to a directory containing (either directly or as # symbolic links) jar files and/or directories whose paths # should be included in CLASSPATH. These paths will be # prepended to any prior definition of the CLASSPATH # environment variable. # # Optional: # # CLOJURE_JAVA The command to launch a JVM instance for Clojure # default: java # example: /usr/local/bin/java6 # # CLOJURE_OPTS Java options for this JVM instance # default: # example:"-Xms32M -Xmx128M -server" # # CLOJURE_MAIN The Java class to launch # default: clojure.main # example: clojure.contrib.repl_ln clj-env-dir can be used directly to launch Clojure or as a building block for creating launch scripts for a variety of purposes. Here are two examples of using it as a building block: (these also use CLOJURE_CONTRIB whose value should be the path to an svn download directory for clojure-contrib) "clj" (stock clojure.main call, can launch a repl, script, or just eval based on arguments to clj) #!/bin/bash export CLOJURE_MAIN=clojure.main CLJ=$CLOJURE_CONTRIB/launchers/bash/clj-env-dir OPTS= exec $CLJ $OPTS "$@" "cljr" (repl using clojure.contrib.repl_ln) #!/bin/bash export CLOJURE_MAIN=clojure.contrib.repl_ln CLJ=$CLOJURE_CONTRIB/launchers/bash/clj-env-dir OPTS="--init @repl_init.clj --repl" exec $CLJ $OPTS "$@" --Steve smime.p7s Description: S/MIME cryptographic signature
Re: question about understanding/exploring agents
I think I know when to use one and when to use the other, but the extra clarification doesn't hurt. However, what happens if you get it wrong? use send where you should have used send-off, and visa versa? I would like to know what they do differently. On 15 jan, 13:12, "Stephen C. Gilardi" wrote: > On Jan 15, 2009, at 2:57 AM, bOR_ wrote: > > > That is, if I understand blocking correctly. Currently assuming that > > blocking only happens when two things would like to write the same > > ref? > > Blocking in this case refers to this definition: > > http://en.wikipedia.org/wiki/Blocking_(computing) > > You should use "send-off" if any of the operations in the action may > cause the the thread it runs in to "block" (sleep) while waiting for > something. That something is often I/O completion, but a thread can > also block waiting to acquire a lock, or waiting for a time interval > to elapse. > > If anything in the action requires waiting, use send-off, otherwise > use send. > > --Steve > > smime.p7s > 3KWeergevenDownloaden --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
newbie destructuring question
came across over the net the following examples. I can understand full destructuring because "[" and "]" mirrors the structure of tree. But in partial desctructuring, [[a [b]] has extra pair of outer-most [] which leads to confusion. Any explanation on that? Also not sure about the last (on strings). Thanks in advance sun (def flat "flat") (def tree '(("one" ("two")) "three" ((("four") ;; Simple binding (like Common Lisp's LET*). (let [var1 flat var2 tree] (list var1 var2)) -> ("flat" (("one" ("two")) "three" ((("four") ;; Full destructuring. (let [var1 flat [[a [b]] c [[[d tree] (list var1 a b c d)) -> ("flat" "one" "two" "three" "four") ;; Partial destructuring. (let [[[a [b]] & leftover :as all] tree] (list a b leftover all)) -> ("one" "two" ("three" ((("four" (("one" ("two")) "three" ((("four") ;; Works on strings, too. (let [[a b c & leftover] "123go"] (list a b c leftover)) -> (\1 \2 \3 (\g \o)) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: question about understanding/exploring agents
On Jan 15, 2009, at 9:26 AM, bOR_ wrote: I think I know when to use one and when to use the other, but the extra clarification doesn't hurt. However, what happens if you get it wrong? use send where you should have used send-off, and visa versa? I would like to know what they do differently. There are two pools of threads servicing agent actions. The send pool is fixed in size and based on the number of available cores. The send- off pool is variable in size and grows as needed to accommodate the largest number of simultaneous pending send-off calls that your program produces. If you use send-off when you could have used send, your send-off thread pool may grow larger than it needed to grow. If you use send when you should have used send-off, other actions sent to other agents may be delayed. Where the expected to run very soon, they may now have to wait behind a blocking operation which could easily increase the wait time from tens of microseconds or less to tens of milliseconds or more--a huge factor. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: No Indentation in SLIME
By default Return is bound to the command newline which does not indent. If you press the Tab key, you'll be placed at the correct indentation spot. To make this automatic, you need to rebind Return to newline-and-indent: (global-set-key (kbd "C-m") 'newline-and-indent) Hope this helps. Vincent On Jan 15, 2:27 am, Kyle Smith wrote: > Hello, > > I'm new to Clojure, SLIME, and emacs in general but I've noticed my > SLIME REPL does not indent properly when I use or C-j. This > is the error message I see: > > "calculate-lisp-indent: Symbol's function definition is void: clojure- > indent-function" > > I've experienced this when setting up Clojure + SLIME via .emacs and > also when running Clojure Box. When I open a .clj file indentation > works just fine. I just have trouble with the SLIME REPL. > > One thing I noticed is if I evaluate the function clojure-indent- > function, function clojure-backtracking-indent, and custom clojure- > mode-use-backtracking-indent (from clojure-mode.el) within the > *scratch* buffer my SLIME REPL will indent correctly. > > I've seen a few posts with similar problems but I haven't found a > solution that works. > > Thanks, > Kyle --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Accessing "this" in gen-class constructor
On Tue, Dec 30, 2008 at 1:24 PM, CuppoJava wrote: > > Haha yeah... it's a rather poor API. > > I'm making do with a temporary post-constructor hook that I manually > call after instantiating the object right now. But it's tedious and > error-prone. I've posted a feature request: http://code.google.com/p/clojure/issues/detail?id=45 Now you can submit your CA, submit a patch, and nobody will ever have to suffer your pain again. :-) --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: command-line in clojure.contrib suggestions
On Mon, Jan 12, 2009 at 10:58 PM, aria42 wrote: > > Couldn't it have access to the other bindings so far like let? And > then just have the order of options reflect the partial order induced > by dependency? So is this possible... > > (with-command-line *command-line-args* > "my-program" > [[size "The size of something" #(if % (Integer/parseInt %) 99)] > [picture "Path to Picture" #(load-picture % size)]] > (do-stuff-with-picture)) I guess I'm not convinced it's good to have code mixed in with the command-line specs like that. Can you show me your real-world example? > Also, other suggestions might be being able to declare an option or > conditional dependencies. Ideally we could have lots > of optional keyword arguments :default, :required, :depends, etc... > > This is probably more heavy than most people use, but I would > definitely find it useful. There are certainly plenty of features that could be added, and I'm not at all opposed to that. But every feature added to the API will be painful to change later as it might break people's code, so I'd like to add features slowly and carefully. Thanks for the ideas. --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: No Indentation in SLIME
Hi Kyle, On Wed, Jan 14, 2009 at 11:27 PM, Kyle Smith wrote: > I'm new to Clojure, SLIME, and emacs in general but I've noticed my > SLIME REPL does not indent properly when I use or C-j. This > is the error message I see: > > "calculate-lisp-indent: Symbol's function definition is void: clojure- > indent-function" > > I've experienced this when setting up Clojure + SLIME via .emacs and > also when running Clojure Box. When I open a .clj file indentation > works just fine. I just have trouble with the SLIME REPL. > > One thing I noticed is if I evaluate the function clojure-indent- > function, function clojure-backtracking-indent, and custom clojure- > mode-use-backtracking-indent (from clojure-mode.el) within the > *scratch* buffer my SLIME REPL will indent correctly. > > I've seen a few posts with similar problems but I haven't found a > solution that works. The function "clojure-indent-function" is defined in clojure-mode.el but clojure-mode.el is only loaded when a Clojure source file is opened. Therefore, if for example you opened a Clojure source file and then started the slime repl, you would not have the problem. However, you don't want to always open a Clojure source file before you start a repl, so to fix this, make certain that clojure-mode.el is started before you start the repl. This can be done in a number of ways - adding the following to your .emacs startup code is probably the easiest: (add-hook 'slime-connected-hook (lambda () (require 'clojure-mode))) -- Bill Clementson --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: command-line in clojure.contrib suggestions
On Jan 15, 2009, at 10:51 AM, Chouser wrote: > > On Mon, Jan 12, 2009 at 10:58 PM, aria42 wrote: >> >> Couldn't it have access to the other bindings so far like let? And >> then just have the order of options reflect the partial order induced >> by dependency? So is this possible... >> >> (with-command-line *command-line-args* >> "my-program" >> [[size "The size of something" #(if % (Integer/parseInt %) 99)] >> [picture "Path to Picture" #(load-picture % size)]] >> (do-stuff-with-picture)) > > I guess I'm not convinced it's good to have code mixed in with the > command-line specs like that. Can you show me your real-world > example? This is an interesting example. I don't imagine anyone would have a problem supporting the conversion of Strings to another basic type such as an Integer, but jumping from String to Picture from within the command-line spec is a bit steep. Perhaps for built-in types, the command-line spec should support defining the destination type and handle the conversion from string. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: configurable bash script to launch Clojure available
On Thu, Jan 15, 2009 at 8:58 AM, Stephen C. Gilardi wrote: > I've checked in a bash script for launching Clojure to > clojure-contrib/launchers/bash/clj-env-dir. I had a launch script (which I've now lost due to my own clumsiness) that defaulted to a repl if given no file options, and always loaded a .clojurerc.clj file before starting a repl (whether it was by default or specifically asked via -r). This allowed me to load repl-utils and get *print-length* set up before getting a prompt. But if a file was named with now -r, it was run with no repl. It used appropriate combinations of clojure.lang.Repl or clojure.lang.Script and file paths to make this happen. As far as I can tell this is impossible with clojure.main, which appears to only allow loading a file *or* starting a repl. Am I missing a method to support this, or should I go back to using Script/Repl? My script also accepted a -cp argument to augment any automatic or default classpath it set up. I found this useful when tracking down gen-class issues, but I never had this nice symlink-dir setup, which might very well be better. I apologize for not speaking up earlier in clojure.main's development, when such issues probably could have been addressed more easily. --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: command-line in clojure.contrib suggestions
On Thu, Jan 15, 2009 at 11:10 AM, Matt Revelle wrote: > > Perhaps for built-in types, the command-line spec should support > defining the destination type and handle the conversion from string. That's an interesting idea. It would allow the automatic help text to be more specific as well. --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: test-is: set! *e
Hi Allen, Good idea. But instead of setting *e I've modified "report" to print a brief stack trace for every error. See if that works. -Stuart Sierra On Jan 14, 11:30 pm, Allen Rohner wrote: > Here's a trivial patch that I've found useful. After catching an > uncaught exception in a test, set! *e so you can examine the stack > trace afterward. > > === > --- src/clojure/contrib/test_is.clj (revision 314) > +++ src/clojure/contrib/test_is.clj (working copy) > > @@ -233,7 +289,8 @@ > (try (t) > (catch Throwable e > (report :error "Uncaught exception, not in assertion." > - nil e)) > + nil e) > + (set! *e e)) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: configurable bash script to launch Clojure available
On Jan 15, 2009, at 17:31, Chouser wrote: > I had a launch script (which I've now lost due to my own clumsiness) > that defaulted to a repl if given no file options, and always loaded a > .clojurerc.clj file before starting a repl (whether it was by default > or specifically asked via -r). This allowed me to load repl-utils and > get *print-length* set up before getting a prompt. But if a file was > named with now -r, it was run with no repl. It used appropriate > combinations of clojure.lang.Repl or clojure.lang.Script and file > paths to make this happen. > > As far as I can tell this is impossible with clojure.main, which > appears to only allow loading a file *or* starting a repl. Am I > missing a method to support this, or should I go back to using > Script/Repl? If I understand correctly what you are looking for, it exists. Here is my standard command line for starting Clojure: java -cp $HOME/.clojure/clojure.jar:$HOME/.clojure/clojure- contrib.jar clojure.main -i $HOME/.clojure/repl-init.clj -r This first executes repl-init.clj (from where I load repl-utils, set *print-length* etc.) and then starts the repl. Konrad. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: configurable bash script to launch Clojure available
I think a script like this should be included with the Clojure download. It's seems to me that everyone needs one and currently has to write their own by copying example script code from the Getting Started page. Maybe we can't reach a concensus on everything the script should do, but providing a good, basic starting point would be useful. The basic features I would want include: 1) If I run "clj", it starts a REPL. 2) If I run "clj file-path", it runs that file as a Clojure script. 3) Some way to modify the classpath used by the script without modifying the script. On Thu, Jan 15, 2009 at 7:58 AM, Stephen C. Gilardi wrote: > I've checked in a bash script for launching Clojure to > clojure-contrib/launchers/bash/clj-env-dir. > > It's configured using environment variables (one required and several > optional). It sets up the CLASSPATH for the Clojure instance it launches > based on the contents of a directory. This is a mechanism similar to Java's > java.ext.dirs facility but implemented without using java.ext.dirs. I've > tested this on Mac OS X Leopard and Ubuntu Intrepid. > > Here's a description of the environment variables it uses: > > # Environment variables: > # > # Required: > # > # CLOJURE_EXT The path to a directory containing (either directly or as > # symbolic links) jar files and/or directories whose paths > # should be included in CLASSPATH. These paths will be > # prepended to any prior definition of the CLASSPATH > # environment variable. > # > # Optional: > # > # CLOJURE_JAVA The command to launch a JVM instance for Clojure > # default: java > # example: /usr/local/bin/java6 > # > # CLOJURE_OPTS Java options for this JVM instance > # default: > # example:"-Xms32M -Xmx128M -server" > # > # CLOJURE_MAIN The Java class to launch > # default: clojure.main > # example: clojure.contrib.repl_ln > > clj-env-dir can be used directly to launch Clojure or as a building block > for creating launch scripts for a variety of purposes. > > Here are two examples of using it as a building block: (these also use > CLOJURE_CONTRIB whose value should be the path to an svn download directory > for clojure-contrib) > > "clj" (stock clojure.main call, can launch a repl, script, or just eval > based on arguments to clj) > >#!/bin/bash > >export CLOJURE_MAIN=clojure.main >CLJ=$CLOJURE_CONTRIB/launchers/bash/clj-env-dir >OPTS= > >exec $CLJ $OPTS "$@" > > "cljr" (repl using clojure.contrib.repl_ln) > >#!/bin/bash > >export CLOJURE_MAIN=clojure.contrib.repl_ln >CLJ=$CLOJURE_CONTRIB/launchers/bash/clj-env-dir >OPTS="--init @repl_init.clj --repl" > >exec $CLJ $OPTS "$@" > > --Steve > > -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: configurable bash script to launch Clojure available
On Thu, Jan 15, 2009 at 11:45 AM, Konrad Hinsen wrote: > > If I understand correctly what you are looking for, it exists. Here > is my standard command line for starting Clojure: > > java -cp $HOME/.clojure/clojure.jar:$HOME/.clojure/clojure- > contrib.jar clojure.main -i $HOME/.clojure/repl-init.clj -r > > This first executes repl-init.clj (from where I load repl-utils, set > *print-length* etc.) and then starts the repl. You're absolutely right, that works just fine. In fact, it's essentially what I already have. But it wasn't working for me, because in my startup .clj I had (left over from my old script): (when (= (System/getProperty "repl") "yes") (set! *print-length* 103) (use 'clojure.contrib.repl-utils)) Maybe I should always start a repl. Why did I think I sometimes wanted no repl? :-) Anyway, thanks for the example. --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: configurable bash script to launch Clojure available
On Jan 15, 2009, at 11:31 AM, Chouser wrote: I had a launch script (which I've now lost due to my own clumsiness) that defaulted to a repl if given no file options, and always loaded a .clojurerc.clj file before starting a repl (whether it was by default or specifically asked via -r). This allowed me to load repl-utils and get *print-length* set up before getting a prompt. But if a file was named with [no] -r, it was run with no repl. It used appropriate combinations of clojure.lang.Repl or clojure.lang.Script and file paths to make this happen. As far as I can tell this is impossible with clojure.main, which appears to only allow loading a file *or* starting a repl. Am I missing a method to support this, or should I go back to using Script/Repl? Given the clj script I posted earlier (which uses clojure.main directly) all of the following are possible. I think one of these covers the case you're asking about. If not, please let me know. Launch a repl with no command-line-arguments: clj Run a script: clj my-script Run a script with command line args: clj my-script 1 2 3 Load an init file from classpath then run a repl: clj --init @my-init.clj --repl Load an init file from classpath then run a repl with command line args: clj --init @my-init.clj --repl 1 2 3 Load an init file from classpath and run a script with command line args: clj --init @my-init.clj my-script 1 2 3 Load two init files and run a repl with command line args: clj --init @my-init.clj --init my-script --repl 1 2 3 I recognize that having this documented at http://clojure.org/repl_and_main will be very helpful to everyone. I'm working on that and I'll upload it before the end of this weekend. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Only 9 agent "send-off"s complete?
I found my problem. There were some issues with the underlying Subversion actions happening at the same time. I wasn't catching those errors though because I wasn't looking at agent-errors. I have it working correctly now with an agent per project (since a series of updates for the project is the task), with the call to (apply await agents), and ending with (shutdown-agents). Thanks for your response. Justin On Wed, Jan 14, 2009 at 5:47 PM, Timothy Pratley wrote: > > Your omission of (apply await agents) is allowing the program to > terminate before all your created threads finish I think. > If I might further comment, your threading model is not quite right to > me... > You've created 5 agents and then used them to 'send-off' as many > threads as there are projects. > I would recommend instead using an agent to represent each task and > using send to take advantage of the thread pool so you don't need to > worry about how many threads there are. > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: (newby) Quicksort in clojure
On Jan 15, 1:37 pm, e wrote: > What would be a good way to implement quicksort in clojure (or any > persistent language)? Lennart Augustsson's point is that destructive updates are part of the Quicksort algorithm. If we accept that, then you'd want to use a plain old java array in your algorithm. Personally, I'd be inclined to use mergesort in a functional programming language. It's easier to implement, easier to parallize and better with linked lists. - 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 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: configurable bash script to launch Clojure available
"Mark Volkmann" writes: > I think a script like this should be included with the Clojure > download. It's seems to me that everyone needs one and currently has > to write their own by copying example script code from the Getting > Started page. Strongly agree. If 1.0 is released without this it would be a shame. -Phil --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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 reduce a list of booleans?
On Jan 15, 2009, at 1:53 PM, Daniel Jomphe wrote: What would you consider the normal way of solving this small problem of mine? (reduce #(and %1 %2) [true false true]) --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Bug in .hashCode for vectors/lists (Old subject: "Bugs in contains? (?))
Er, oops, forgot you can't HTML here. Anyway, the upshot is that now user=> (import '(java.util ArrayList)) nil (doseq [s ['(1 2) (seq '(1 2)) [1 2] (seq [1 2]) (ArrayList. [1 2])]] (print "\n" (.hashCode s)) (doseq [t ['(1 2) (seq '(1 2)) [1 2] (seq [1 2]) (ArrayList. [1 2])]] (print "\t" (.equals s t 994 truetruetruetruetrue 994 truetruetruetruetrue 994 truetruetruetruetrue 994 truetruetruetruetrue 994 truetruetruetruetrue and user=> (map #(contains? (hash-set [1 2]) %) '((1 2) [1 2])) (true true) Woohoo, thanks Rich! -Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: No Indentation in SLIME
Thanks Bill. That's just what I needed. On Jan 15, 7:58 am, Bill Clementson wrote: > Hi Kyle, > > > > On Wed, Jan 14, 2009 at 11:27 PM, Kyle Smith wrote: > > I'm new to Clojure, SLIME, and emacs in general but I've noticed my > > SLIME REPL does not indent properly when I use or C-j. This > > is the error message I see: > > > "calculate-lisp-indent: Symbol's function definition is void: clojure- > > indent-function" > > > I've experienced this when setting up Clojure + SLIME via .emacs and > > also when running Clojure Box. When I open a .clj file indentation > > works just fine. I just have trouble with the SLIME REPL. > > > One thing I noticed is if I evaluate the function clojure-indent- > > function, function clojure-backtracking-indent, and custom clojure- > > mode-use-backtracking-indent (from clojure-mode.el) within the > > *scratch* buffer my SLIME REPL will indent correctly. > > > I've seen a few posts with similar problems but I haven't found a > > solution that works. > > The function "clojure-indent-function" is defined in clojure-mode.el > but clojure-mode.el is only loaded when a Clojure source file is > opened. Therefore, if for example you opened a Clojure source file and > then started the slime repl, you would not have the problem. However, > you don't want to always open a Clojure source file before you start a > repl, so to fix this, make certain that clojure-mode.el is started > before you start the repl. This can be done in a number of ways - > adding the following to your .emacs startup code is probably the > easiest: > > (add-hook 'slime-connected-hook (lambda () > (require 'clojure-mode))) > > -- > Bill Clementson --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How to reduce a list of booleans?
Daniel Jomphe a écrit : > I'm in the following situation: > >(and '(true true)) >;doesn't work > > (every? identity [true false true]) Christophe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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 -~--~~~~--~~--~--~---
How to reduce a list of booleans?
I'm in the following situation: (and '(true true)) ;doesn't work I tried apply, reduce, and a few other things. Reading the apidocs, reduce is said to be the proper choice to compute a boolean from a seq. But: (reduce and '(true true)) ;Exception: Can't take value of a macro: #'clojure.core/and Also, the following isn't the solution: (reduce 'and '(true false true)) ;true In any case, I think using reduce with "and" wouldn't be nice because it won't return false as soon as it can like "and" does. Therefore, I came up with the following working solution: (defmacro and-booleans [logical-booleans-list] `(and ~...@logical-booleans-list)) (and-booleans (true false true)) ;false But I wonder if I have overlooked something fundamental, either about reduce or anything else. Of course, I could have built my final boolean value imperatively, in effect reimplementing "and" for lists as a function that wraps the "ant" built-in macro. But I'm hoping to leave imperative programming as much behing me as possible. What would you consider the normal way of solving this small problem of mine? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How to reduce a list of booleans?
Look at every?. The predicate true? returns true if its argument is the boolean literal true, and false otherwise. If, instead, you want to check for logical truth (false and nil are false, everything else is true), then use identity. As you can see, every? falls out at the first false result. user=> (every? true? (list true true true)) true user=> (every? true? (lazy-cat [true false] (println "not executed"))) false user=> (every? true? (lazy-cat [true true] (println "executed"))) executed true user=> (every? true? []) true user=> (every? true? (list true 1)) false user=> (every? identity (list true 1)) true On Jan 15, 1:53 pm, Daniel Jomphe wrote: > I'm in the following situation: > > (and '(true true)) > ;doesn't work > > I tried apply, reduce, and a few other things. Reading the apidocs, > reduce is said to be the proper choice to compute a boolean from a > seq. But: > > (reduce and '(true true)) > ;Exception: Can't take value of a macro: #'clojure.core/and > > Also, the following isn't the solution: > > (reduce 'and '(true false true)) > ;true > > In any case, I think using reduce with "and" wouldn't be nice because > it won't return false as soon as it can like "and" does. Therefore, I > came up with the following working solution: > > (defmacro and-booleans [logical-booleans-list] > `(and ~...@logical-booleans-list)) > > (and-booleans (true false true)) > ;false > > But I wonder if I have overlooked something fundamental, either about > reduce or anything else. > > Of course, I could have built my final boolean value imperatively, in > effect reimplementing "and" for lists as a function that wraps the > "ant" built-in macro. But I'm hoping to leave imperative programming > as much behing me as possible. > > What would you consider the normal way of solving this small problem > of mine? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How to reduce a list of booleans?
> (every? identity [true false true]) So obvious, yet so overlooked each time I read the function names in the api! Thanks to both you! Looks like I'll be having a bunch of fun through this learning curve in the future. :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Problem using fn macro
I just encountered a surprise attempting to return a function from a function. In the below case, if the function parameter is named "fn", then calling the function throws an exception. If the function parameter is named "f", no problem. (Using svn as of yesterday) (defn no-problem[f] (fn [] (apply f []))) (no-problem #(prn 99)) ;; returns a function as expected (defn problem[fn] (fn [] (apply fn [])));; same code as above but renamed function parameter to "fn" (problem #(prn 99)) ;; prints out "99" and throws an exception : java.lang.IllegalArgumentException: Wrong number of args passed to: dispatch$eval--3402$fn (NO_SOURCE_FILE:0) [Thrown class clojure.lang.Compiler$CompilerException] Restarts: 0: [ABORT] Return to SLIME's top level. 1: [CAUSE] Throw cause of this exception Backtrace: 0: clojure.lang.Compiler.eval(Compiler.java:4179) 1: clojure.core$eval__3733.invoke(core.clj:1582) --more-- Regards, Hugh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: newbie destructuring question
On Jan 15, 2:54 pm, wubbie wrote: > But in partial desctructuring, [[a [b]] has extra pair of outer-most > [] which leads to confusion. Any explanation on that? Extra pair of []? What do you mean? The destructuring pattern is: [[a [b]] & leftover] The pattern you're matching is: (("one" ("two")) "three" ((("four" So: a = "one" b = "two" leftover = '("three ((("four" All seems pretty correct to me. Is it just the "&" that's confusing? > Also not sure about the last (on strings). Well, if you turn a string into a sequence, you get a sequence of chars. \a is a char, so (seq "abc") is (\a \b \c). The destructuring pattern is: [a b c & leftover] The pattern you're matching is: (\1 \2 \3 \g \o) So: a = 1, b = 2, c = 3 and leftover = (\g \o) Does that make things any clearer, or have I just confused you further? :) - 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 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 destructuring question
> Extra pair of []? What do you mean? Sorry, my bad. -sun On Jan 15, 1:25 pm, James Reeves wrote: > On Jan 15, 2:54 pm, wubbie wrote: > > > But in partial desctructuring, [[a [b]] has extra pair of outer-most > > [] which leads to confusion. Any explanation on that? > > Extra pair of []? What do you mean? > > The destructuring pattern is: [[a [b]] & leftover] > The pattern you're matching is: (("one" ("two")) "three" ((("four" > > So: > a = "one" > b = "two" > leftover = '("three ((("four" > > All seems pretty correct to me. Is it just the "&" that's confusing? > > > Also not sure about the last (on strings). > > Well, if you turn a string into a sequence, you get a sequence of > chars. \a is a char, so (seq "abc") is (\a \b \c). > > The destructuring pattern is: [a b c & leftover] > The pattern you're matching is: (\1 \2 \3 \g \o) > > So: a = 1, b = 2, c = 3 and leftover = (\g \o) > > Does that make things any clearer, or have I just confused you > further? :) > > - 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 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 in .hashCode for vectors/lists (Old subject: "Bugs in contains? (?))
Update: Rich just fixed this in http://code.google.com/p/ clojure/issues/detail?id=37&colspec=ID%20Type%20Status%20Priority %20Reporter%20Owner%20Summary">svn 1215 . -Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Problem using fn macro
Even if this gets fixed, I don't think it's a good idea to give parameters the same name as a widely used function. It's bound to confuse someone. On Thu, Jan 15, 2009 at 1:12 PM, Hugh Winkler wrote: > > I just encountered a surprise attempting to return a function from a > function. In the below case, if the function parameter is named "fn", > then calling the function throws an exception. If the function > parameter is named "f", no problem. (Using svn as of yesterday) > > (defn no-problem[f] > (fn [] (apply f []))) > (no-problem #(prn 99)) ;; returns a function as expected > > (defn problem[fn] > (fn [] (apply fn [])));; same code as above but renamed > function parameter to "fn" > > (problem #(prn 99)) ;; prints out "99" and throws an exception : > > > java.lang.IllegalArgumentException: Wrong number of args passed to: > dispatch$eval--3402$fn (NO_SOURCE_FILE:0) > [Thrown class clojure.lang.Compiler$CompilerException] > > Restarts: > 0: [ABORT] Return to SLIME's top level. > 1: [CAUSE] Throw cause of this exception > > Backtrace: > 0: clojure.lang.Compiler.eval(Compiler.java:4179) > 1: clojure.core$eval__3733.invoke(core.clj:1582) > --more-- > > Regards, > > Hugh > > > > -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: (newby) Quicksort in clojure
but loop/recur for the partition could try to reuse as much of an existing structure as possible and then be quite nice as things get gc'd early on. Mergesort uses a lot of temporary space as things move along. Yes I like mergesort. folks already helped me get that one going. On Thu, Jan 15, 2009 at 12:59 PM, James Reeves wrote: > > On Jan 15, 1:37 pm, e wrote: > > What would be a good way to implement quicksort in clojure (or any > > persistent language)? > > Lennart Augustsson's point is that destructive updates are part of the > Quicksort algorithm. If we accept that, then you'd want to use a plain > old java array in your algorithm. > > Personally, I'd be inclined to use mergesort in a functional > programming language. It's easier to implement, easier to parallize > and better with linked lists. > > - 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 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 using fn macro
When you're using fn as a parameter name, you are shadowing the fn special form. Like Mark Volkmann said, it is best that you refrain from using special form names and core macros and functions names to name your own things. f is the prefered notation to name a function passed to another function. Be safe, Vince. On Jan 15, 2:12 pm, "Hugh Winkler" wrote: > I just encountered a surprise attempting to return a function from a > function. In the below case, if the function parameter is named "fn", > then calling the function throws an exception. If the function > parameter is named "f", no problem. (Using svn as of yesterday) > > (defn no-problem[f] > (fn [] (apply f []))) > (no-problem #(prn 99)) ;; returns a function as expected > > (defn problem[fn] > (fn [] (apply fn []))) ;; same code as above but renamed > function parameter to "fn" > > (problem #(prn 99)) ;; prints out "99" and throws an exception : > > java.lang.IllegalArgumentException: Wrong number of args passed to: > dispatch$eval--3402$fn (NO_SOURCE_FILE:0) > [Thrown class clojure.lang.Compiler$CompilerException] > > Restarts: > 0: [ABORT] Return to SLIME's top level. > 1: [CAUSE] Throw cause of this exception > > Backtrace: > 0: clojure.lang.Compiler.eval(Compiler.java:4179) > 1: clojure.core$eval__3733.invoke(core.clj:1582) > --more-- > > Regards, > > Hugh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Problem using fn macro
by having a parameter named "fn" you are shadowing the global "fn" so what is happening is the "(fn ...)" form inside the function is trying to apply the function you passed in to the arguments. the function you passed in takes no arguments so you get the " Wrong number of args passed to" exception. On Jan 15, 11:12 am, "Hugh Winkler" wrote: > I just encountered a surprise attempting to return a function from a > function. In the below case, if the function parameter is named "fn", > then calling the function throws an exception. If the function > parameter is named "f", no problem. (Using svn as of yesterday) > > (defn no-problem[f] > (fn [] (apply f []))) > (no-problem #(prn 99)) ;; returns a function as expected > > (defn problem[fn] > (fn [] (apply fn []))) ;; same code as above but renamed > function parameter to "fn" > > (problem #(prn 99)) ;; prints out "99" and throws an exception : > > java.lang.IllegalArgumentException: Wrong number of args passed to: > dispatch$eval--3402$fn (NO_SOURCE_FILE:0) > [Thrown class clojure.lang.Compiler$CompilerException] > > Restarts: > 0: [ABORT] Return to SLIME's top level. > 1: [CAUSE] Throw cause of this exception > > Backtrace: > 0: clojure.lang.Compiler.eval(Compiler.java:4179) > 1: clojure.core$eval__3733.invoke(core.clj:1582) > --more-- > > Regards, > > Hugh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Jan 15, 12:09 am, bOR_ wrote: > I remember from 5 years ago that a collegue of mine improved a > diffusion algorithm for a successor of me by some heavy algorithms. My > own algorithm was a simple loop-over-the- array once, dump-a-fraction- > of-each-cell-into-spatially-neighbouring-cells-in-the-new-array, and > sum what is in every cell of the new array (you are doing the same > thing, right?). However, there are far faster algorithms. > > If you are interested, I'll inquire. It's just idle curiosity on my part but Asbjørn may very well be interested ;-) "Dump a fraction of each cell into spatially neighbouring cells in the new array" is a stationary iterative method, probably Jacobi iteration (since there is a "new array" -- Asbjørn is recycling the "old" array so he is doing Gauss-Seidel iteration). Gauss-Seidel often converges a bit faster but the "heavy algorithms" (FFT, multigrid, preconditioned iterative solvers) converge much faster. However there is a higher setup cost with some of these and for the application it's not clear whether an accurate solve is needed. mfh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Synchronization Benchmarks
Welcome to the group! :-) On Jan 15, 1:38 am, stuhood wrote: > The benchmark contains 4 bi-directional dictionary implementations: > * MDict - Java implementation using the synchronized keyword, > * RWDict - Java implementation using a ReadWriteLock, > * CLJDict - Clojure implementation using the (locking x) macro on > Java HashMaps, > * STMDict - Clojure implementation using two refs on maps. Doesn't Java already have a more optimized thread-safe hash table that works by locking individual buckets, rather than the whole table? Maybe I'm just confused ;-P mfh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Synchronization Benchmarks
On Thu, Jan 15, 2009 at 8:35 PM, Mark H. wrote: > > Welcome to the group! :-) > > On Jan 15, 1:38 am, stuhood wrote: >> The benchmark contains 4 bi-directional dictionary implementations: >> * MDict - Java implementation using the synchronized keyword, >> * RWDict - Java implementation using a ReadWriteLock, >> * CLJDict - Clojure implementation using the (locking x) macro on >> Java HashMaps, >> * STMDict - Clojure implementation using two refs on maps. > > Doesn't Java already have a more optimized thread-safe hash table that > works by locking individual buckets, rather than the whole table? > Maybe I'm just confused ;-P It does: http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentHashMap.html Alternative implementations of concurrency-aware HashMaps also exists out on the 'nets (NBHashMap by Cliff Click and FashHashMap in Javolution). > > mfh > > > -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Synchronization Benchmarks
On Thu, Jan 15, 2009 at 8:47 PM, Christian Vest Hansen wrote: > On Thu, Jan 15, 2009 at 8:35 PM, Mark H. wrote: >> On Jan 15, 1:38 am, stuhood wrote: >>> The benchmark contains 4 bi-directional dictionary implementations: ... >> >> Doesn't Java already have a more optimized thread-safe hash table that >> works by locking individual buckets, rather than the whole table? >> Maybe I'm just confused ;-P Ah! but a mere hash table is not bi-directional :-) -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Problem using fn macro
OK, thanks all, got it. Hugh On Thu, Jan 15, 2009 at 1:33 PM, redc...@gmail.com wrote: > > by having a parameter named "fn" you are shadowing the global "fn" > so what is happening is the "(fn ...)" form inside the function is > trying to apply the function you passed in to the arguments. the > function > you passed in takes no arguments so you get the " Wrong number of args > passed to" > exception. > > On Jan 15, 11:12 am, "Hugh Winkler" wrote: >> I just encountered a surprise attempting to return a function from a >> function. In the below case, if the function parameter is named "fn", >> then calling the function throws an exception. If the function >> parameter is named "f", no problem. (Using svn as of yesterday) >> >> (defn no-problem[f] >> (fn [] (apply f []))) >> (no-problem #(prn 99)) ;; returns a function as expected >> >> (defn problem[fn] >> (fn [] (apply fn [])));; same code as above but renamed >> function parameter to "fn" >> >> (problem #(prn 99)) ;; prints out "99" and throws an exception : >> >> java.lang.IllegalArgumentException: Wrong number of args passed to: >> dispatch$eval--3402$fn (NO_SOURCE_FILE:0) >> [Thrown class clojure.lang.Compiler$CompilerException] >> >> Restarts: >> 0: [ABORT] Return to SLIME's top level. >> 1: [CAUSE] Throw cause of this exception >> >> Backtrace: >> 0: clojure.lang.Compiler.eval(Compiler.java:4179) >> 1: clojure.core$eval__3733.invoke(core.clj:1582) >> --more-- >> >> Regards, >> >> Hugh > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure Box, alpha
Sort of got distracted and stopped paying attention to getting that to run. I'll report when I get to it and learn more :). On Jan 5, 11:43 pm, "Shawn Hoover" wrote: > On Mon, Jan 5, 2009 at 4:24 PM, bOR_ wrote: > > > Just downloaded clojurebox and it installs like a charm here (windows > > vista business). It looks like I am stuck with windows at my new > > workspace (just had my first day of work there), so to have clojurebox > > was a nice thing. One question is how I would go about to setting up a > > emacs --daemon and emacsclient combination in clojurebox? Being able > > to detach and quit the emacs client and later on connect back to it > > saves me from accidentally stopping a long simulation in windows > > because I quitted the emacs program. > > > Currently if I try to C-x #, I get the message "No server editing > > buffers exist" > > The emacs that you start with the Clojure Box icon becomes a server, but it > has no clients waiting on it. If you later run c:\Program Files\Clojure > Box\emacs\emacs\bin\emacsclient.exe from the command line or as an editor > for a program like subversion, the file to edit will pop up in the Clojure > Box and you can use C-x #. Does that help? > > Shawn --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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 reduce a list of booleans?
On Jan 15, 2:05 pm, Daniel Jomphe wrote: > > (every? identity [true false true]) > > So obvious, yet so overlooked each time I read the function names in > the api! Hi Daniel, FYI, the reason "and" doesn't work is that it's a macro, not a function. Only functions can be used with "apply". If you had a hypothetical "and function" like this: (defn and-fn [& args] (every? identity args)) Then you could use apply: (apply and-fn [true true]) ;=> true (apply and-fn [true false true]) ;=> false But, obviously, just using "every?" in the first place is a lot simpler. -Stuart Sierra --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Macros in interaction with Functions
Stuart Sierra wrote: > FYI, the reason "and" doesn't work is that it's a macro, not a > function. Only functions can be used with "apply". When I found that out, I was surprised. My knowledge of lisp comes from reading, in the past few months: - ANSI Common Lisp - Practical Common Lisp and, some years ago, a few more things. And still, I wasn't prepared for the fact that macros don't mix 100% with functions. Either I overlooked an important section in these books, or they didn't really cover it much. Even now that I hurt myself against this limitation, I'm still to make complete sense out of it. I understand that macros aren't known to functions because functions only get to see their expansions, but it's fuzzy in my mind how some functions interact well with macros while some others don't. It's probably related to the fact one wouldn't want to rely on repeated macro-expansions while apply/reduce's implementation recurs/ iterates over a seq. So in some way, macros would be limited so that they are only valid if their call arguments are provided to them at compile time, not at run time. Yet, it's still hard to see the line between code-is-data and data-is-code. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Multiple hashing functions? (+ bug in PersistentHashMap.java?)
On Jan 14, 6:01 pm, Jason Wolfe wrote: > I've already posted here [1] and on the issue board [2] about > hashing. In particular, .hashCode for seqs/colls break the Java > contract that whenever (.equals x y), (= (.hashCode x) (.hashCode > y)). (let x = [1] and y = (seq [1])). As I've mentioned earlier, I > hope that eventually .hashCode and .equals will be brought into line. > Anyway, I won't rehash (ha ha) this issue further here. As I posted in the other thread, Rich just fixed this ... thanks! > Anyway, I've also since realized that .equals and = are not the same > thing, in particular with respect to numbers. So, it might be nice to > have a different hash function (i.e., Clojure's "hash"), that matches > the behavior of =, and allow the user to specify which hash function > they'd like to use when creating hash-sets and hash-maps. Following up, if the multiple-hash-function route is one that people like, it might also be nice to have the option to make Clojure identity hash-maps and sets, which use System.identityHashCode() and identical?. -Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Utilities for clojure.contrib?
> > Instead the first three might suggest corollaries: > > map-when map-when-not map-while > > Perfect. > On second thought, do you think map-when-not would actually be useful? Unless you're interested in the difference between nil and false, I think it's equivalent to (replicate (count (remove pred s)) nil). Also, can I do anything to help implement/integrate the changes we've agreed upon thus far? Thanks, Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Two errors building closure
I am trying to build Clojure on Fedora 10. When I first run ant, I get a message about the compliance level 1.4 not supporting target version 1.5. So I add source="1.5" to the javac task. Then I get a lot of warnings and the following 3 errors. [javac] 354. ERROR in /home/rdp/lisp/clj/clojure/src/jvm/clojure/ lang/Numbers.java (at line 900) [javac] : toBigDecimal(x).divide(toBigDecimal(y), mc); [javac] ^^ [javac] The method divide(BigDecimal, int) in the type BigDecimal is not applicable for the arguments (BigDecimal, MathCont ext) [javac] -- [javac] 355. ERROR in /home/rdp/lisp/clj/clojure/src/jvm/clojure/ lang/Numbers.java [javac] (at line 907) [javac] : toBigDecimal(x).divideToIntegralValue(toBigDecimal (y), mc); [javac] ^ [javac] The method divideToIntegralValue(BigDecimal) in the type BigDecimal is not applicable for the arguments (BigDecimal , MathContext) [javac] -- [javac] 356. ERROR in /home/rdp/lisp/clj/clojure/src/jvm/clojure/ lang/Numbers.java (at line 914) [javac] : toBigDecimal(x).remainder(toBigDecimal(y), mc); [javac] ^ [javac] The method remainder(BigDecimal) in the type BigDecimal is not applicable for the arguments (BigDecimal, MathContex t) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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 -~--~~~~--~~--~--~---
test-is reporting problem
The improved error reposting in test-is breaks some tests, e.g. from the book: (deftest test-lazy-index-of-any-with-match (is (with-out-str (is (zero? (index-of-any "zzabyycdxx" #{\z \a} "Iterating overz\n") (is (with-out-str (is (= 3 (index-of-any "zzabyycdxx" #{\b \y} "Iterating overz\nIterating over z\nIterating over a\n")) The problem is that it tries to take the value of with-out-str, not realizing that it is a macro. Should I (1) rewrite the test to not use a macro? (2) take a stab at fixing this in test-is? (3) get out of the way and let another Stuart handle it? :-) Stuart --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: A quasiquote for Clojure?
> >unquotewould not be defined by Clojure, so still an error if allowed > > to get evaluated. > > > Things like your sql would be macros that handled (unquotex) > > internally. > > SVN 1184 implements this. > > Feedback welcome on its utility for macro writers. > > Rich I like this a lot. Any chance of getting the same treatment for unquote-splicing? user> '~x (clojure.core/unquote x) user> '~...@x ; Exception: can't embed object in code ; Desired output: (clojure.core/unquote-splicing x) Or am I just doing this wrong? Thanks! Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Newbie question on *agent* here
Hi Came across Chouser's posting below: I know *agent* is for global designation. My question is how the first agent (agent nil) and *agent* used later in another nested send-off related? Also m after (fn is a function name so that it can be referred to later inside the same function? Thanks sun user=> (def z (atom 0)) #'user/z user=> (send-off (agent nil) (fn m [_] (Thread/sleep 500) (swap! z inc) (send-off *agent* m))) # user=> @z 3 user=> @z 8 user=> (swap! z + 1000) 1031 user=> @z 1035 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
(newbie) running clojure app without repl
Hi! I've had no experience in Lisp or clojure before. I've only worked with Java and Ruby, so this question may seem stupid. Is there any way to run a clojure app without REPL? For example something like: clojure my_app.clj I've read that you can compile clojure with the comile function, but this function must be called from a clojure application since it's a clojure function, am I right or wrong? Thanks, Linh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: (newbie) running clojure app without repl
> > > Hi! > I've had no experience in Lisp or clojure before. I've only worked > with Java and Ruby, so this question may seem stupid. Is there any way > to run a clojure app without REPL? > > For example something like: clojure my_app.clj > Something like this: java-cpclojure.jar:my_app_dirclojure.lang.Scriptmy_app.clj -- Education is what survives when what has been learned has been forgotten. - B. F. Skinner --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Example Java oriented SWT GUI application in Clojure
anyone able to get this going on a Mac yet? The main window comes up, but shortly after crashes. On Mon, Jan 12, 2009 at 5:24 PM, BerlinBrown wrote: > > Here is an example SWT application. It is a 'search' tool. Open a > file and the search term is highlighted. It has a java oriented > approach because I copied the java code verbatim. This might be > useful if you are still used to imperative programming. > > Main source: > > http://jvmnotebook.googlecode.com/svn/trunk/clojure/swt/search/src/octane_main.clj > > Additional Files (all you really need is what is in the lib directory) > http://jvmnotebook.googlecode.com/svn/trunk/clojure/swt/search > > But, I am all ears for suggestions (I am sure there are very, very > many) and if you want, send me a patch file, I will be glad to update > it. > > Might help for newbies like me. > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Example Java oriented SWT GUI application in Clojure
It's probably this: http://www.eclipse.org/swt/faq.php#carbonapp On Thu, Jan 15, 2009 at 9:20 PM, e wrote: > anyone able to get this going on a Mac yet? The main window comes up, but > shortly after crashes. > > > On Mon, Jan 12, 2009 at 5:24 PM, BerlinBrown wrote: > >> >> Here is an example SWT application. It is a 'search' tool. Open a >> file and the search term is highlighted. It has a java oriented >> approach because I copied the java code verbatim. This might be >> useful if you are still used to imperative programming. >> >> Main source: >> >> http://jvmnotebook.googlecode.com/svn/trunk/clojure/swt/search/src/octane_main.clj >> >> Additional Files (all you really need is what is in the lib directory) >> http://jvmnotebook.googlecode.com/svn/trunk/clojure/swt/search >> >> But, I am all ears for suggestions (I am sure there are very, very >> many) and if you want, send me a patch file, I will be glad to update >> it. >> >> Might help for newbies like me. >> >> > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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: Utilities for clojure.contrib?
On Jan 14, 1:03 pm, Jason Wolfe wrote: > > > (import '(java.util HashSet)) > > > (defn distinct-elts? "Are all of the elements of this sequence > > > distinct? Works on infinite sequences with repititions, making it > > > useful for, e.g., detecting cycles in graphs." > > > [s] > > > (let [hs (HashSet.)] > > > (loop [s (seq s)] > > > (cond (empty? s) true > > > (.contains hs (first s)) false > > > :else (do (.add hs (first s)) (recur (rest s))) > > > Is there any reason the builtin 'distinct?' couldn't handle these > > cases as well? What does "elts" stand for? > > I suppose this is the same as (apply distinct? s). Except that distinct? can't take 0 arguments, so (apply distinct? nil) fails rather than returning true. Does adding a 0-arg case to distinct? sound reasonable? -Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Synchronization Benchmarks
> Ah! but a mere hash table is not bi-directional :-) Right =) I got the idea in a Channel 9 video about MS' efforts with STM: http://channel9.msdn.com/shows/Going+Deep/Software-Transactional-Memory-The-Current-State-of-the-Art/(which reminds me, the spin-lock approach they try is probably fairly close to using an Atom in Clojure). I made the changes that Christophe suggested, and added type hints for the HashMaps used in CLJDict, and the speed improvement is very impressive. To see the scalability of the different approaches, I graphed with various numbers of threads and read percentages: http://github.com/stuhood/clojure-conc/tree/master/results Two conclusions: 1. The overhead for STM with low contention is very reasonable, 2. Optimism + MVCC + persistence fall down when faced with a majority of writes. (see the 100% write case in the writes graph.) Thanks, Stu On Thu, Jan 15, 2009 at 2:52 PM, Christian Vest Hansen wrote: > > On Thu, Jan 15, 2009 at 8:47 PM, Christian Vest Hansen > wrote: > > On Thu, Jan 15, 2009 at 8:35 PM, Mark H. wrote: > >> On Jan 15, 1:38 am, stuhood wrote: > >>> The benchmark contains 4 bi-directional dictionary implementations: > ... > >> > >> Doesn't Java already have a more optimized thread-safe hash table that > >> works by locking individual buckets, rather than the whole table? > >> Maybe I'm just confused ;-P > > Ah! but a mere hash table is not bi-directional :-) > > > -- > Venlig hilsen / Kind regards, > Christian Vest Hansen. > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: (newbie) running clojure app without repl
There is a standalone compiler that runs without the REPL: clojure.lang.Compile. The best examples of using it are the Ant build.xml files for Clojure and clojure-contrib. If I have time tomorrow I'll try to post a more detailed how-to. -Stuart Sierra On Jan 15, 6:53 pm, linh wrote: > Hi! > I've had no experience in Lisp or clojure before. I've only worked > with Java and Ruby, so this question may seem stupid. Is there any way > to run a clojure app without REPL? > > For example something like: clojure my_app.clj > > I've read that you can compile clojure with the comile function, but > this function must be called from a clojure application since it's a > clojure function, am I right or wrong? > > Thanks, > Linh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Macros in interaction with Functions
On Jan 15, 6:04 pm, Daniel Jomphe wrote: > And still, I wasn't prepared for the fact that macros don't mix 100% > with functions. Either I overlooked an important section in these > books, or they didn't really cover it much. It's not covered much. You get used to it. Think of it this way -- macros only exist during compilation. Functions like "apply" get evaluated at run-time. A macro like "and" has no value at run-time, so you can't use it as an argument to a function. -Stuart Sierra --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: test-is reporting problem
I was afraid that would happen. I'll fix it, probably tomorrow. -the other Stuart On Jan 15, 6:27 pm, Stuart Halloway wrote: > The improved error reposting in test-is breaks some tests, e.g. from > the book: > > (deftest test-lazy-index-of-any-with-match > (is (with-out-str (is (zero? (index-of-any "zzabyycdxx" #{\z \a} > "Iterating overz\n") > (is (with-out-str (is (= 3 (index-of-any "zzabyycdxx" #{\b \y} > "Iterating overz\nIterating over z\nIterating over a\n")) > > The problem is that it tries to take the value of with-out-str, not > realizing that it is a macro. > > Should I > > (1) rewrite the test to not use a macro? > (2) take a stab at fixing this in test-is? > (3) get out of the way and let another Stuart handle it? :-) > > Stuart --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: test-is reporting problem
You do that. -another Stuart On Thu, Jan 15, 2009 at 10:32 PM, Stuart Sierra wrote: > > I was afraid that would happen. I'll fix it, probably tomorrow. > -the other Stuart > > On Jan 15, 6:27 pm, Stuart Halloway wrote: > > The improved error reposting in test-is breaks some tests, e.g. from > > the book: > > > > (deftest test-lazy-index-of-any-with-match > > (is (with-out-str (is (zero? (index-of-any "zzabyycdxx" #{\z \a} > > "Iterating overz\n") > > (is (with-out-str (is (= 3 (index-of-any "zzabyycdxx" #{\b \y} > > "Iterating overz\nIterating over z\nIterating over a\n")) > > > > The problem is that it tries to take the value of with-out-str, not > > realizing that it is a macro. > > > > Should I > > > > (1) rewrite the test to not use a macro? > > (2) take a stab at fixing this in test-is? > > (3) get out of the way and let another Stuart handle it? :-) > > > > Stuart > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Example Java oriented SWT GUI application in Clojure
yeah. That fixed it. Thanks. On Thu, Jan 15, 2009 at 9:53 PM, Paul Barry wrote: > It's probably this: > http://www.eclipse.org/swt/faq.php#carbonapp > > > On Thu, Jan 15, 2009 at 9:20 PM, e wrote: > >> anyone able to get this going on a Mac yet? The main window comes up, but >> shortly after crashes. >> >> >> On Mon, Jan 12, 2009 at 5:24 PM, BerlinBrown wrote: >> >>> >>> Here is an example SWT application. It is a 'search' tool. Open a >>> file and the search term is highlighted. It has a java oriented >>> approach because I copied the java code verbatim. This might be >>> useful if you are still used to imperative programming. >>> >>> Main source: >>> >>> http://jvmnotebook.googlecode.com/svn/trunk/clojure/swt/search/src/octane_main.clj >>> >>> Additional Files (all you really need is what is in the lib directory) >>> http://jvmnotebook.googlecode.com/svn/trunk/clojure/swt/search >>> >>> But, I am all ears for suggestions (I am sure there are very, very >>> many) and if you want, send me a patch file, I will be glad to update >>> it. >>> >>> Might help for newbies like me. >>> >>> >> >> >> > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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 -~--~~~~--~~--~--~---
Mysterious performance anomalies
I was doing some microbenchmarking earlier, and I noticed some very very weird anomalies. If anyone could shed some light on what's going on that would be awesome. (I'm using the latest SVN, and have verified this on a totally clean repl). Simplified as much as possible, the heart of what I observed is: user> (prn (time (loop [i (int 0)] (if (< i (int 3000)) (recur (inc i)) i "Elapsed time: 4247.477 msecs" 3000 nil user> (time (loop [i (int 0)] (if (< i (int 3000)) (recur (inc i)) i))) "Elapsed time: 128.37 msecs" 3000 Weird, right? The prn is *outside* the loop, and yet it still affects the timing somehow. Maybe this is something specific to printing? Nope: user> (first (time (loop [i (int 0)] (if (< i (int 3000)) (recur (inc i)) [i] "Elapsed time: 4264.847 msecs" 3000 user> (time (loop [i (int 0)] (if (< i (int 3000)) (recur (inc i)) [i]))) "Elapsed time: 130.099 msecs" [3000] But, some other expressions around the "time" don't affect it in the same way: user> (when (time (loop [i (int 0)] (if (< i (int 3000)) (recur (inc i)) [i]))) 12) "Elapsed time: 130.236 msecs" 12 In case you were wondering, this has nothing to do with the "time" macro. user> (first (loop [i (int 0)] (if (< i (int 3000)) (recur (inc i)) [i]))) ; ... 4 seconds pass on my stopwatch ... 3000 And the slowness is by a multiplicative, not additive factor: user> (first (time (loop [i (int 0)] (if (< i (int 6000)) (recur (inc i)) [i] "Elapsed time: 8576.649 msecs" 6000 user> (time (loop [i (int 0)] (if (< i (int 6000)) (recur (inc i)) [i]))) "Elapsed time: 250.407 msecs" [6000] I'm at a total loss for what's going on. Anyway, I'll stop here for now in case I'm missing something stupid or obvious. Thanks for your help! Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Macros in interaction with Functions
> fuzzy in my mind how some functions interact well with macros while > some others don't. Good: (some-function (some-macro stuff)) Bad: (some-function some-macro stuff) For me I find it easiest to remember as "macros are not first class functions" ie: they cannot be passed to and executed by other functions. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Macros in interaction with Functions
On 16.01.2009, at 00:04, Daniel Jomphe wrote: > When I found that out, I was surprised. My knowledge of lisp comes > from reading, in the past few months: > - ANSI Common Lisp > - Practical Common Lisp > and, some years ago, a few more things. The best book to read about macros is in my opinion Paul Graham's "On Lisp", which is now available for free download: http://www.paulgraham.com/onlisp.html It covers mostly Common Lisp plus a bit of Scheme, but many of the ideas carry over very well to Clojure. > Even now that I hurt myself against this limitation, I'm still to make > complete sense out of it. I understand that macros aren't known to > functions because functions only get to see their expansions, but it's > fuzzy in my mind how some functions interact well with macros while > some others don't. The fundamental restriction is that you cannot pass macros to arguments as functions, and that is exactly what would be required to do a reduce over and. The universal workaround is to define a function that contains nothing but the macro, such as (fn [x y] (and x y)) which can also be written in Clojure using the shorthand notation #(and %1 %2) Here the macro gets expanded inside the function *body*, but what you pass around is the function *object*. Konrad. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---