New library: BigInteger random numbers other PRNG utils
I've written a pseudorandom number generator for arbitrarily large integers, as well as a number of other utilities for pseudorandom numbers. Features: * Everything is a lazy seq * Gaussian (mean 0, variance 1) - pseudorandom doubles * Arbitrarily large pseudorandom uniformly distributed integers on [L, U) * Lazy seq transforms from integer pseudorandom number generators to uniformly distributed bytes, longs, doubles (on [0, 1)) It's available for download as a Git repository at http://www.cs.berkeley.edu/~mhoemmen/gits/clojure-prng.git I'm releasing the code under a modified BSD license (use as you like but give attribution and don't sue me if it breaks something). Please let me know if you find any bugs as I've only done some informal tests. In particular, feel free to feed it into some serious PRNG test suite. 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: New library: BigInteger random numbers other PRNG utils
On Jan 2, 12:46 am, Mark H. mark.hoem...@gmail.com wrote: I've written a pseudorandom number generator for arbitrarily large integers, as well as a number of other utilities for pseudorandom numbers. Other features: * Function to generate a random seed, using either Java's SecureRandom or your own entropy source (treated as a file -- e.g., /dev/random) * Gratuitous comments (not so much inline) that explain the algorithms and some potential pitfalls btw the test code uses Java's PRNG (not (rand) -- it creates a new java.util.Random object and calls the appropriate methods), but this was only for testing convenience, and should not be construed as an approval of said PRNG algorithm. 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: update-values for clojure.contrib.sql
Well, one thing that sticks out (particularly to me) is the fact that you forgot to put your doc-string *before* your [params*] list :) (ahem) On Fri, Jan 2, 2009 at 8:21 AM, budu nbudu...@gmail.com wrote: Hi, I was experimenting with clojure-contrib's sql features and found that there wasn't any update-values function. I've written my own and I'm sharing it here: (defn update-values [table where column-names values] Update columns of a table with values. columns-names is a vector of column names (strings or keywords) and the rest of arguments are the values for those columns. (let [columns (map #(str (the-str %) = ?) column-names) template (if (seq column-names) (apply str (interpose , columns)) )] (apply do-prepared (format update %s set %s where %s (the-str table) template where) [values]))) It only send one set of values to do-prepared because of the where clause that would have to change according to each sets. I'm ready for your commentaries and/or suggestions. -- 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: macro trouble
Hi, Am 02.01.2009 um 03:37 schrieb Eric Tschetter: When you look at the backtrace of the exception you will find (very far down the trace) lines like caused by... There you normally find more useful information than ExceptionInInitializer. user= (defmacro tracefn [function-name] Creates trace logging of calls to a function. `(def ~function-name (let [old-function# ~(eval function-name)] You don't want eval here. Only ~function-name. If you use eval somewhere it's almost always wrong. There are uses for eval, but they are veeery rare. (fn [ args#] (println args#) (print ) (let [ret-val# (apply old-function# args#)] (println ret-val#) ret-val#) Maybe you want to use prn instead of println? user= (defn poor-mans-multiply [x y] (if ( x 0) (+ y (poor-mans-multiply (dec x) y)) 0)) Also not related and I suspect this to be just an example, but nevertheless: the JVM does not support tail call optimisation. So this function will blow up the stack for sufficiently large values of x. You might want to look at the trampoline utility function. Hmm.. or just for fun rewrite it using the sequence library of Clojure. :) (defn poor-mans-multiply [x y] (apply + (take x (repeat y And finally you might find this useful: http://groups.google.com/group/clojure/browse_frm/thread/3ea8777880231e18/6fd1b352ac1a6744?lnk=gstq=trace#6fd1b352ac1a6744 Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: macro trouble
Hi again, Am 02.01.2009 um 03:37 schrieb Eric Tschetter: user= (defmacro tracefn [function-name] Creates trace logging of calls to a function. And another minor issue: the docstring goes in front of the argument vector, because Clojure allows also variable arity. (defn foo docstring here ([x] ...) ([x y] ...)) Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Patch: Detect overflow in IntegerOps.Negate
Issue 28 created with patch attached: http://code.google.com/p/clojure/issues/detail?id=28 On Dec 14 2008, 12:42 am, Olov Lassus olov.las...@gmail.com wrote: Hi, thanks for Clojure! Here's my first contribution (CA filled out and will arrive next week): Negating Integer.MIN_VALUE overflows but should return a BigInteger. It also affects binary subtraction since Clojure implements it using negation and addition. The overflow occurs silently without throwing an exception. These examples trigger the flaw: user= (- -2147483648) -2147483648 user= (- -1 -2147483648) -2147483649 The attached patch is created against trunk r1159. Same examples after applying it: user= (- -2147483648) 2147483648 user= (- -1 -2147483648) 2147483647 /Olov Lassus detect_negate_overflow.patch 1KViewDownload --~--~-~--~~~---~--~~ You 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: Patch: Large negative range overflows
Issue 29 created with patch attached: http://code.google.com/p/clojure/issues/detail?id=29 On Dec 14 2008, 1:29 am, Olov Lassus olov.las...@gmail.com wrote: Hi, Here's another patch from me: The clojure.lang.Range type is implemented with integer type start and end indices. The core.clj range function should detect when an index doesn't fit inside an int and create an increasing sequence using iterate instead. The current implementation detects too large positive, but not too large negative ranges. The overflow occurs silently without throwing an exception. Before: user= (take 1 (range -2147483649 0)) (2147483647) After applying the patch (created against trunk r1159): user= (take 1 (range -2147483649 0)) (-2147483649) I also made the range function slightly less conservative vs = wise. This shouldn't affect correctness but (range 0 2147483647) will now return a Range (after patch) instead of a LazyCons (before). /Olov Lassus support_large_negative_range.patch 1KViewDownload --~--~-~--~~~---~--~~ You 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: What is this function called?
On Thu, Jan 1, 2009 at 10:14 PM, Andrew Baine andrew.ba...@gmail.com wrote: I want to get a seq of successive rests of the given seq: user (defn f [seq] (if (empty? seq) nil (lazy-cons seq (f (rest seq) #'user/f user (f '(1 2 3 4)) ((1 2 3 4) (2 3 4) (3 4) (4)) That's very similar to tails in Haskell: http://www.zvon.org/other/haskell/Outputlist/tails_f.html user (take 10 (map #(take 5 %) (f (iterate inc 1 ((1 2 3 4 5) (2 3 4 5 6) (3 4 5 6 7) (4 5 6 7 8) (5 6 7 8 9) (6 7 8 9 10) (7 8 9 10 11) (8 9 10 11 12) (9 10 11 12 13) (10 11 12 13 14)) For this particular example, you could use 'partition': (take 10 (partition 5 1 (iterate inc 1))) Does this fn already exist in clojure? If not what would an idiomatic name be for it from Haskell or CL? I don't think it exists in clojure.core or clojure.contrib. --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: What is this function called?
On Thu, Jan 1, 2009 at 10:14 PM, Andrew Baine andrew.ba...@gmail.com wrote: I want to get a seq of successive rests of the given seq: user (defn f [seq] (if (empty? seq) nil (lazy-cons seq (f (rest seq) #'user/f user (f '(1 2 3 4)) ((1 2 3 4) (2 3 4) (3 4) (4)) Hi, Haskell has tails in the Data.List module which is similar, though it includes a null-list as a final value: *Main Data.List.tails [1..4] [[1,2,3,4],[2,3,4],[3,4],[4],[]] *Main take 10 . map (take 5) . Data.List.tails $ iterate (+1) 1 [[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8],[5,6,7,8,9],[6,7,8,9,10],[7,8,9,10,11],[8,9,10,11,12],[9,10,11,12,13],[10,11,12,13,14]] Rests makes good sense as a Clojure-name, IMO, as does not including a null-value at the end. Graham user (take 10 (map #(take 5 %) (f (iterate inc 1 ((1 2 3 4 5) (2 3 4 5 6) (3 4 5 6 7) (4 5 6 7 8) (5 6 7 8 9) (6 7 8 9 10) (7 8 9 10 11) (8 9 10 11 12) (9 10 11 12 13) (10 11 12 13 14)) Does this fn already exist in clojure? If not what would an idiomatic name be for it from Haskell or CL? Andrew --~--~-~--~~~---~--~~ You 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: reduction
On Dec 12 2008, 3:35 pm, Christophe Grand christo...@cgrand.net wrote: I was sure it was a job for iterate: (defn reductions Returns a lazy seq of the intermediate values of the reduction (as per reduce) of coll by f, starting with init. ([f coll] (if (seq coll) (for [s (iterate (fn [[x s]] (if s (lazy-cons (f x (first s)) (rest s coll) :while s] (first s)) (list (f ([f val coll] (reductions f (cons val coll This isn't in clojure.core yet (any reason why not?) so would you mind if I add it to clojure.contrib.seq-utils? Or of course you can do it if you prefer. :-) --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: Release of VimClojure 1.3.0
Hi Meikel, I am running Vim 7.2 on Windows XP and am not able to get the completion working in VimClojure. I get errors when trying to edit a .clj file. These errors always occur unless I comment out the code in clojure.vim that adds the completions. The errors I'm getting with VimClojure 1.3.0 are below. I got similar errors in the previous version of VimClojure as well (though not identical due to the addition of AddCompletion), so this isn't new to 1.3.0. Error detected while processing function vimcloj...@addcompletions. .vimcloj...@addpathtooption: line 7: E539: Illegal character F: complete+=kC:\Program\ Files\Vim\vimfiles\ftplugin\clojure\completions-clojure.core.txt E539: Illegal character F: complete+=kC:\Program\ Files\Vim\vimfiles\ftplugin\clojure\completions-clojure.set.txt E539: Illegal character F: complete+=kC:\Program\ Files\Vim\vimfiles\ftplugin\clojure\completions-clojure.xml.txt E539: Illegal character F: complete+=kC:\Program\ Files\Vim\vimfiles\ftplugin\clojure\completions-clojure.zip.txt Do you have any idea what the problem is? Thanks, Justin On Thu, Jan 1, 2009 at 10:23 AM, Meikel Brandmeyer m...@kotka.de wrote: Dear vimming Clojurians, a long overdue release of VimClojure is available. This is mainly a bugfix and maintenance release. It brings the highlighting, indenting and completion up-to-date with current Clojure. Highlighting for contrib is there for a few modules, but it's far from being complete. One new feature worth mentioning is the conditional highlighting. Vim tries to figure at, which namespaces are required/used and dynamically adds highlighting for the included commands. Example: (ns foo.bar (:use [clojure.contrib.def :only (defvar)])) This adds highlighting for: - clojure.contrib.def/defvar and - defvar (But not for eg. defvar-!) (ns foo.bar (:require [clojure.contrib.def :as d])) This adds highlighting for: - clojure.contrib.def/defvar and - d/defvar and - d/defvar- (But not for defvar!) For multiple-file namespaces a similar :use/:require directive must be put in a comment at the file header for now. So it's still experimental. Thanks for all the feedback on issues and improvements! The release may be found at the usual spot: http://kotka.de/projects/clojure/vimclojure.html Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: What is this function called?
I did something similar using (iterate rest coll), which I called iter- rest: (defn iter-rest Takes the first (count coll) items from call to (iterate rest coll). If passed function as first argument, calls it on each invocation of rest, i.e. (iterate #(func (rest %)) coll). ([coll] (take (count coll) (iterate rest coll))) ([func coll] (take (count coll) (iterate #(func (rest %)) coll user= (iter-rest (range 3)) ((0 1 2) (1 2) (2)) I now realize a key difference is that, by using (count coll), iter- rest fully realizes anything lazy; for Andrew's lazy version above, I second the name rests. Perry --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
detecting running as script
I have a file of Clojure code that I'd like to experiment with in the REPL. I use (load file-path) to do that and then I can try out the functions it defines. At the bottom of the file it calls the functions required to run my application. Is there a way I can write the code so it only runs my application when I run it outside the REPL? For example, this should run the application: clj myapp.clj and this should not: clj user= (load-file myapp.clj) Ruby has something like this. You surround the code that runs the app like this: if $PROGRAM_NAME == __FILE__ # code to run application goes here end -- 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 -~--~~~~--~~--~--~---
Compilation problems
I already made a post about problems compiling with emacs, but I suppose I'm the only one whos having this problem and no one knows how to fix it. I was testing out compilation into class files with clojure a little while ago. I put (ns rayne (:gen-class)) (defn -main [ args] (println(HI))) into a file called rayne.clj and started it clojure, and typed (compile 'rayne). The compilation produced 2 different class files, but it gave me a class not found error saying it couldn't find rayne $_main__32.class. It produced the class files, but gave me an error.. O_o. I'm on a windows vista PC by the way, thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Compilation problems
On Jan 2, 2009, at 11:37 AM, Rayne wrote: into a file called rayne.clj and started it clojure, and typed (compile 'rayne). The compilation produced 2 different class files, but it gave me a class not found error saying it couldn't find rayne $_main__32.class. It produced the class files, but gave me an error.. O_o. I'm on a windows vista PC by the way, thanks. To compile successfully, Clojure requires that both the source file and the directory where the files will be stored (*compile-path*) be in Classpath at the time Clojure is launched. The error you're getting sounds like that condition is not met in your case. Please check that. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Compilation problems
On Jan 2, 10:44 am, Stephen C. Gilardi squee...@mac.com wrote: On Jan 2, 2009, at 11:37 AM, Rayne wrote: into a file called rayne.clj and started it clojure, and typed (compile 'rayne). The compilation produced 2 different class files, but it gave me a class not found error saying it couldn't find rayne $_main__32.class. It produced the class files, but gave me an error.. O_o. I'm on a windows vista PC by the way, thanks. To compile successfully, Clojure requires that both the source file and the directory where the files will be stored (*compile-path*) be in Classpath at the time Clojure is launched. The error you're getting sounds like that condition is not met in your case. Please check that. --Steve smime.p7s 3KViewDownload I checked, and the classpath (compile-path) is the classes directory in my clojure folder, so I put the file in there, and tried to compile it, it gave me java.io.FileNotFoundException: Could not locate rayne__init.class or rayne.clj on classpath: (NO_SOURCE_FILE:0) but when I placed the file back into the clojure directory, it gave me the old error, but still produced 2 class files. --~--~-~--~~~---~--~~ You 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: Release of VimClojure 1.3.0
On Thu, Jan 1, 2009 at 11:23 AM, Meikel Brandmeyer m...@kotka.de wrote: a long overdue release of VimClojure is available. Thanks, works great! --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: Release of VimClojure 1.3.0
Hi Justin, Am 02.01.2009 um 17:00 schrieb Justin Johnson: E539: Illegal character F: complete+=kC:\Program\ Files\Vim \vimfiles\ftplugin\clojure\completions-clojure.core.txt The problem is the space in Program Files. I'm not sure, whether this can be fixed at all on my side, or whether this is a Vim bug. I will investigate on #vim tonight, whether this can be solved. Until then: * Disable the code as you already mentioned. * Or avoid whitespace in pathnames. These are the only workarounds I can think of at the moment. Please stay tuned for an update. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: macro trouble
When you look at the backtrace of the exception you will find (very far down the trace) lines like caused by... There you normally find more useful information than ExceptionInInitializer. I don't get a backtrace, all I get is what I put in the original message. How do I turn on full backtraces? user= (defmacro tracefn [function-name] Creates trace logging of calls to a function. `(def ~function-name (let [old-function# ~(eval function-name)] You don't want eval here. Only ~function-name. If you use eval somewhere it's almost always wrong. There are uses for eval, but they are veeery rare. The thing is, I want to store the actual *function* not the symbol referencing the function (the symbol's reference changes after the macro is evaluated). (fn [ args#] (println args#) (print ) (let [ret-val# (apply old-function# args#)] (println ret-val#) ret-val#) Maybe you want to use prn instead of println? Is that just to give the user flexibility on whether they want to flush on new line? Or is there some other reason to choose prn over println? user= (defn poor-mans-multiply [x y] (if ( x 0) (+ y (poor-mans-multiply (dec x) y)) 0)) Also not related and I suspect this to be just an example, but nevertheless: the JVM does not support tail call optimisation. So this function will blow up the stack for sufficiently large values of x. You might want to look at the trampoline utility function. Oh yeah, it's just a stupid function that I wrote up to help me verify tracing. And finally you might find this useful: http://groups.google.com/group/clojure/browse_frm/thread/3ea8777880231e18/6fd1b352ac1a6744?lnk=gstq=trace#6fd1b352ac1a6744 I looked at the trace.clj in clojure.contrib and it looks like it will resolve my current wants for trace functionality, but I chose to post this anyway because I wanted to know if clojure can handle AOP-esque macros that wrap function and replace its base definition (that's basically what I'm doing). --Eric --~--~-~--~~~---~--~~ You 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: Compilation problems
On Jan 2, 11:02 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 02.01.2009 um 17:37 schrieb Rayne: The compilation produced 2 different class files, but it gave me a class not found error saying it couldn't find rayne $_main__32.class. It produced the class files, but gave me an error.. O_o. I'm on a windows vista PC by the way, thanks. Make sure the source directory and directory where the .class files are stored after compilation are both in the classpath. Sincerely Meikel smime.p7s 5KViewDownload I don't know how to check the classpath or change it, I just suppose it's the classes directory because *compile-path* shows that it's that. I'm not used to JVM languages, I don't have much clue about how this kind of thing works. --~--~-~--~~~---~--~~ You 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: Compilation problems
On Jan 2, 2009, at 11:51 AM, Rayne wrote: I checked, and the classpath (compile-path) is the classes directory in my clojure folder, so I put the file in there, and tried to compile it, it gave me You'll need to learn a bit about Classpath to work with Clojure. Basically, Classpath is a list of root directories within which Java and Clojure files exist. By making the location of source files classpath-relative, Java and Clojure can find them on a particular machine even if its directory structure is not identical to that of another machine. By controlling what is and is not in the Classpath list, you can control what is and is not visible to a Java virtual machine. In the case of compiling with Clojure, the Classpath set up at Clojure launch time must include the root directory that contains your source file and the root directory that will contain your compiled files and both of those directories must already exist. Here's an example of setting classpath for compilation using the -cp option to java on unix: % mkdir source dest % # use an editor to create source/rayne.clj % ls -R source dest dest: source: rayne.clj % cat source/rayne.clj (ns rayne) (defn hi [] (prn hi)) % java -cp clojure.jar:source:dest clojure.main Clojure user= (binding [*compile-path* dest] (compile 'rayne)) rayne user= % ls -R source dest dest: rayne$hi__4.class rayne__init.class source: rayne.clj % This example is for Mac OS X/Unix and I know you're on Windows. I recommend using Google to search for Classpath on Windows to get some examples there. Java examples will probably be enough for you to adapt what I've shown to work in your case. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: macro trouble
Hi, Am 02.01.2009 um 18:00 schrieb Eric Tschetter: From the Repl try: (.printStackTrace *e) The thing is, I want to store the actual *function* not the symbol referencing the function (the symbol's reference changes after the macro is evaluated). 1:10 user= (defmacro tracefn Creates trace logging of calls to a function. [function-name] `(def ~function-name (let [old-function# ~function-name] (fn [ args#] (println args#) (print ) (let [ret-val# (apply old-function# args#)] (println ret-val#) ret-val#) nil 1:21 user= (defn foo [x] (inc x)) #'user/foo 1:22 user= (macroexpand-1 '(tracefn foo)) (def foo (clojure.core/let [old-function__28__auto__ foo] (clojure.core/fn [ args__29__auto__] (clojure.core/println args__29__auto__) (clojure.core/print ) (clojure.core/let [ret- val__30__auto__ (clojure.core/apply old-function__28__auto__ args__29__auto__)] (clojure.core/println ret-val__30__auto__) ret- val__30__auto__ 1:23 user= (foo 1) 2 1:24 user= (tracefn foo) #'user/foo 1:25 user= (foo 1) (1) 2 2 Is that just to give the user flexibility on whether they want to flush on new line? Or is there some other reason to choose prn over println? 1:6 user= (println foo) foo nil 1:7 user= (prn foo) foo nil 1:8 user= (println \space) nil 1:9 user= (prn \space) \space nil I would prefer prn. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
How to interpret nested back quote in Macro?
Hi all, Here is the code from Stu's CL translation. (defmacro check [ forms] `(do ~@(map (fn [f] `(report-result ~f '~f)) forms))) And report-result is: (defn report-result [result form] (println (format %s: %s (if result pass FAIL) (pr-str form An example run is: (check (= (+ 1 2) 3) (= (+ 3 4) 8))) --~--~-~--~~~---~--~~ You 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: macro trouble
From the Repl try: (.printStackTrace *e) Thanks! The thing is, I want to store the actual *function* not the symbol referencing the function (the symbol's reference changes after the macro is evaluated). 1:10 user= (defmacro tracefn Creates trace logging of calls to a function. [function-name] `(def ~function-name (let [old-function# ~function-name] (fn [ args#] (println args#) (print ) (let [ret-val# (apply old-function# args#)] (println ret-val#) ret-val#) nil 1:21 user= (defn foo [x] (inc x)) #'user/foo 1:22 user= (macroexpand-1 '(tracefn foo)) (def foo (clojure.core/let [old-function__28__auto__ foo] (clojure.core/fn [ args__29__auto__] (clojure.core/println args__29__auto__) (clojure.core/print ) (clojure.core/let [ret-val__30__auto__ (clojure.core/apply old-function__28__auto__ args__29__auto__)] (clojure.core/println ret-val__30__auto__) ret-val__30__auto__ Ok, so I guess it was the eval that was tripping it up. Do function objects not resolve to themselves in clojure? I think I'll try printing the stacktrace and looking at why the code was breaking on the eval'd value. Is that just to give the user flexibility on whether they want to flush on new line? Or is there some other reason to choose prn over println? 1:6 user= (println foo) foo nil 1:7 user= (prn foo) foo nil 1:8 user= (println \space) nil 1:9 user= (prn \space) \space nil I would prefer prn. Point taken :). Thank you! --Eric Tschetter --~--~-~--~~~---~--~~ You 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: What is this function called?
On Fri, Jan 2, 2009 at 8:09 AM, Perry Trolard trol...@gmail.com wrote: I did something similar using (iterate rest coll), which I called iter- rest: (defn iter-rest Takes the first (count coll) items from call to (iterate rest coll). If passed function as first argument, calls it on each invocation of rest, i.e. (iterate #(func (rest %)) coll). ([coll] (take (count coll) (iterate rest coll))) ([func coll] (take (count coll) (iterate #(func (rest %)) coll user= (iter-rest (range 3)) ((0 1 2) (1 2) (2)) I now realize a key difference is that, by using (count coll), iter- rest fully realizes anything lazy; for Andrew's lazy version above, I second the name rests. Perry Okay, great, I'm using it and calling it rests. Thanks all. --~--~-~--~~~---~--~~ You 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: Compilation problems
On Jan 2, 11:27 am, Stephen C. Gilardi squee...@mac.com wrote: On Jan 2, 2009, at 11:51 AM, Rayne wrote: I checked, and the classpath (compile-path) is the classes directory in my clojure folder, so I put the file in there, and tried to compile it, it gave me You'll need to learn a bit about Classpath to work with Clojure. Basically, Classpath is a list of root directories within which Java and Clojure files exist. By making the location of source files classpath-relative, Java and Clojure can find them on a particular machine even if its directory structure is not identical to that of another machine. By controlling what is and is not in the Classpath list, you can control what is and is not visible to a Java virtual machine. In the case of compiling with Clojure, the Classpath set up at Clojure launch time must include the root directory that contains your source file and the root directory that will contain your compiled files and both of those directories must already exist. Here's an example of setting classpath for compilation using the -cp option to java on unix: % mkdir source dest % # use an editor to create source/rayne.clj % ls -R source dest dest: source: rayne.clj % cat source/rayne.clj (ns rayne) (defn hi [] (prn hi)) % java -cp clojure.jar:source:dest clojure.main Clojure user= (binding [*compile-path* dest] (compile 'rayne)) rayne user= % ls -R source dest dest: rayne$hi__4.class rayne__init.class source: rayne.clj % This example is for Mac OS X/Unix and I know you're on Windows. I recommend using Google to search for Classpath on Windows to get some examples there. Java examples will probably be enough for you to adapt what I've shown to work in your case. --Steve smime.p7s 3KViewDownload Thanks I managed to get it to compile, now the only trouble I'm having is packaging it into a .jar, guess I might just have to wait until there is more windows documentation for Clojure. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from 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: update-values for clojure.contrib.sql
D'oh! I have a hard time kicking out that old habit. And changing code after testing it too! On Jan 2, 4:21 am, Christian Vest Hansen karmazi...@gmail.com wrote: Well, one thing that sticks out (particularly to me) is the fact that you forgot to put your doc-string *before* your [params*] list :) (ahem) On Fri, Jan 2, 2009 at 8:21 AM, budu nbudu...@gmail.com wrote: Hi, I was experimenting with clojure-contrib's sql features and found that there wasn't any update-values function. I've written my own and I'm sharing it here: (defn update-values [table where column-names values] Update columns of a table with values. columns-names is a vector of column names (strings or keywords) and the rest of arguments are the values for those columns. (let [columns (map #(str (the-str %) = ?) column-names) template (if (seq column-names) (apply str (interpose , columns)) )] (apply do-prepared (format update %s set %s where %s (the-str table) template where) [values]))) It only send one set of values to do-prepared because of the where clause that would have to change according to each sets. I'm ready for your commentaries and/or suggestions. -- 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: What is this function called?
I don't know if the function exists on its own in Common Lisp, but in Common Lisp there is maplist that does what you get by combining map and rests : http://www.lispworks.com/documentation/HyperSpec/Body/f_mapc_.htm HTH, -- Laurent On Jan 2, 7:21 pm, Andrew Baine andrew.ba...@gmail.com wrote: On Fri, Jan 2, 2009 at 8:09 AM, Perry Trolard trol...@gmail.com wrote: I did something similar using (iterate rest coll), which I called iter- rest: (defn iter-rest Takes the first (count coll) items from call to (iterate rest coll). If passed function as first argument, calls it on each invocation of rest, i.e. (iterate #(func (rest %)) coll). ([coll] (take (count coll) (iterate rest coll))) ([func coll] (take (count coll) (iterate #(func (rest %)) coll user= (iter-rest (range 3)) ((0 1 2) (1 2) (2)) I now realize a key difference is that, by using (count coll), iter- rest fully realizes anything lazy; for Andrew's lazy version above, I second the name rests. Perry Okay, great, I'm using it and calling it rests. Thanks all. --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
literate snake
I've written a new version of the snake program that uses a more literate style and therefore, to my eyes, calls for far fewer comments. I think this code is very readable. Check it out at http://www.ociweb.com/mark/programming/ClojureLiterateSnake.html. Feedback is welcomed! The most controversial thing about this code is probably my use of def to change the state of the snake and the apple. It's not yet clear to me that using atoms is needed here, but I need to think about that more. This version has some features that weren't in the original such as: - automatically turning the snake in the clockwise direction when a board edge is reached - changing the color of the snake to black when it overlaps itself - announcing a win when the length of the snake reaches 10 - automatically restarting the game after an overlap or a win -- 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: Release of VimClojure 1.3.0
I got it working by adding double quotes around the path, as can be seen in the let line of the function below. function! vimclojure#AddCompletions(ns) let completions = split(globpath(\ . rtp, ftplugin/clojure/completions- . a:ns . .txt\), '\n') if completions != [] call vimclojure#AddPathToOption('k' . completions[0], 'complete') endif endfunction On Fri, Jan 2, 2009 at 10:58 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi Justin, Am 02.01.2009 um 17:00 schrieb Justin Johnson: E539: Illegal character F: complete+=kC:\Program\ Files\Vim\vimfiles\ftplugin\clojure\completions-clojure.core.txt The problem is the space in Program Files. I'm not sure, whether this can be fixed at all on my side, or whether this is a Vim bug. I will investigate on #vim tonight, whether this can be solved. Until then: * Disable the code as you already mentioned. * Or avoid whitespace in pathnames. These are the only workarounds I can think of at the moment. Please stay tuned for an update. Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Release of VimClojure 1.3.0
It looks like my change below just got rid of the errors. However the completion functionality is not working. :( On Fri, Jan 2, 2009 at 1:13 PM, Justin Johnson ajustinjohn...@gmail.comwrote: I got it working by adding double quotes around the path, as can be seen in the let line of the function below. function! vimclojure#AddCompletions(ns) let completions = split(globpath(\ . rtp, ftplugin/clojure/completions- . a:ns . .txt\), '\n') if completions != [] call vimclojure#AddPathToOption('k' . completions[0], 'complete') endif endfunction On Fri, Jan 2, 2009 at 10:58 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi Justin, Am 02.01.2009 um 17:00 schrieb Justin Johnson: E539: Illegal character F: complete+=kC:\Program\ Files\Vim\vimfiles\ftplugin\clojure\completions-clojure.core.txt The problem is the space in Program Files. I'm not sure, whether this can be fixed at all on my side, or whether this is a Vim bug. I will investigate on #vim tonight, whether this can be solved. Until then: * Disable the code as you already mentioned. * Or avoid whitespace in pathnames. These are the only workarounds I can think of at the moment. Please stay tuned for an update. Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Release of VimClojure 1.3.0
I reinstalled Vim to C:\Vim and reinstalled VimClojure as well. This time I don't get the errors while opening a .clj file, but completion still is not working. Control-N completes things based on what's already in my file but not using anything from Clojure. Am I doing something wrong, or is it just not working on Windows. Justin On Fri, Jan 2, 2009 at 1:22 PM, Justin Johnson ajustinjohn...@gmail.comwrote: It looks like my change below just got rid of the errors. However the completion functionality is not working. :( On Fri, Jan 2, 2009 at 1:13 PM, Justin Johnson ajustinjohn...@gmail.comwrote: I got it working by adding double quotes around the path, as can be seen in the let line of the function below. function! vimclojure#AddCompletions(ns) let completions = split(globpath(\ . rtp, ftplugin/clojure/completions- . a:ns . .txt\), '\n') if completions != [] call vimclojure#AddPathToOption('k' . completions[0], 'complete') endif endfunction On Fri, Jan 2, 2009 at 10:58 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi Justin, Am 02.01.2009 um 17:00 schrieb Justin Johnson: E539: Illegal character F: complete+=kC:\Program\ Files\Vim\vimfiles\ftplugin\clojure\completions-clojure.core.txt The problem is the space in Program Files. I'm not sure, whether this can be fixed at all on my side, or whether this is a Vim bug. I will investigate on #vim tonight, whether this can be solved. Until then: * Disable the code as you already mentioned. * Or avoid whitespace in pathnames. These are the only workarounds I can think of at the moment. Please stay tuned for an update. Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: literate snake
On Jan 2, 11:07 am, Mark Volkmann r.mark.volkm...@gmail.com wrote: The most controversial thing about this code is probably my use of def to change the state of the snake and the apple. It's not yet clear to me that using atoms is needed here, but I need to think about that more. Not atoms, refs. Or agents for that matter -- the snake can be naturally modeled as an agent, because it responds to events coming from different sources: * the movement update * user input * encountering objects 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: Release of VimClojure 1.3.0
Hi, Am 02.01.2009 um 21:06 schrieb Justin Johnson: I reinstalled Vim to C:\Vim and reinstalled VimClojure as well. This time I don't get the errors while opening a .clj file, but completion still is not working. Control-N completes things based on what's already in my file but not using anything from Clojure. Am I doing something wrong, or is it just not working on Windows. Aargh. Another problem. Now this should work. At least it did before. Unfortunately I have no access to a Win box at the moment. So I can't really investigate this for the next two weeks. For the original problem: Could you please try the following manually? setlocal complete+=kC:\Program\\\ Files\Vim\vimfiles\ftplugin\clojure \completions-clojure.core.txt It seems whitespace really needs hardcore escapeing... :| Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Release of VimClojure 1.3.0
I found the cause of the second problem. All of the backslashes needed to be escaped. I tried a manual setlocal and then the value of complete didn't have any backslashes. It works if I escape the backslashes or if I use forward slashes though. So if I can change the code to just use forward slashes that would fix it, though I don't know vimscript. :-( On Fri, Jan 2, 2009 at 2:33 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 02.01.2009 um 21:06 schrieb Justin Johnson: I reinstalled Vim to C:\Vim and reinstalled VimClojure as well. This time I don't get the errors while opening a .clj file, but completion still is not working. Control-N completes things based on what's already in my file but not using anything from Clojure. Am I doing something wrong, or is it just not working on Windows. Aargh. Another problem. Now this should work. At least it did before. Unfortunately I have no access to a Win box at the moment. So I can't really investigate this for the next two weeks. For the original problem: Could you please try the following manually? setlocal complete+=kC:\Program\\\ Files\Vim\vimfiles\ftplugin\clojure\completions-clojure.core.txt It seems whitespace really needs hardcore escapeing... :| Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: literate snake
That def inside a function doesn't look right but I'm a noob at this too. I managed to run the snake off the board which suggests the concurrency is not quite right. I would use 'cell' instead of 'grid'. Cheers Tom 2009/1/2 Mark Volkmann r.mark.volkm...@gmail.com I've written a new version of the snake program that uses a more literate style and therefore, to my eyes, calls for far fewer comments. I think this code is very readable. Check it out at http://www.ociweb.com/mark/programming/ClojureLiterateSnake.html. Feedback is welcomed! The most controversial thing about this code is probably my use of def to change the state of the snake and the apple. It's not yet clear to me that using atoms is needed here, but I need to think about that more. This version has some features that weren't in the original such as: - automatically turning the snake in the clockwise direction when a board edge is reached - changing the color of the snake to black when it overlaps itself - announcing a win when the length of the snake reaches 10 - automatically restarting the game after an overlap or a win -- 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: literate snake
Also; I think the 'get' is necessary on the get-snake-head and get-snake-body. 2009/1/2 Tom Ayerst tom.aye...@gmail.com That def inside a function doesn't look right but I'm a noob at this too. I managed to run the snake off the board which suggests the concurrency is not quite right. I would use 'cell' instead of 'grid'. Cheers Tom 2009/1/2 Mark Volkmann r.mark.volkm...@gmail.com I've written a new version of the snake program that uses a more literate style and therefore, to my eyes, calls for far fewer comments. I think this code is very readable. Check it out at http://www.ociweb.com/mark/programming/ClojureLiterateSnake.html. Feedback is welcomed! The most controversial thing about this code is probably my use of def to change the state of the snake and the apple. It's not yet clear to me that using atoms is needed here, but I need to think about that more. This version has some features that weren't in the original such as: - automatically turning the snake in the clockwise direction when a board edge is reached - changing the color of the snake to black when it overlaps itself - announcing a win when the length of the snake reaches 10 - automatically restarting the game after an overlap or a win -- 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: literate snake
On Fri, Jan 2, 2009 at 4:05 PM, Tom Ayerst tom.aye...@gmail.com wrote: That def inside a function doesn't look right but I'm a noob at this too. I managed to run the snake off the board which suggests the concurrency is not quite right. Calling 'def' to like this is much worse than a lack of comments, especially in code meant to teach. --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: clj-backtrace: more readable backtraces for Clojure
Hi, I don't have Clojure in front of me right now to try this out, but from the looks of the README let me be the first to give you an emphatic *Thank you*. This is looking rather useful. Nice work. My one concern with this is how brittle is this with respect to Clojure's development? Have you had any trouble getting reasonable output on various revisions of Clojure? /mike. On Thu, Jan 1, 2009 at 9:30 PM, Mark McGranaghan mmcgr...@gmail.com wrote: Hi all, I'm happy to announce an alpha release of clj-backtrace, a library for processing backtraces generated by Clojure programs. The library works by separating useful backtrace information from the noise generated by the Clojure compilation process, and also provides functions for pretty-printing these cleaned backtraces. You can see simple usage instructions and example backtrace output on the library's README page: http://github.com/mmcgrana/clj-backtrace/tree/master/README.textile If you've ever felt that backtraces in Clojure were difficult to read, I hope you'll give this library a try and let me know if it helps! - Mark --~--~-~--~~~---~--~~ You 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: literate snake
On Fri, Jan 2, 2009 at 3:09 PM, Chouser chou...@gmail.com wrote: On Fri, Jan 2, 2009 at 4:05 PM, Tom Ayerst tom.aye...@gmail.com wrote: That def inside a function doesn't look right but I'm a noob at this too. I managed to run the snake off the board which suggests the concurrency is not quite right. Calling 'def' to like this is much worse than a lack of comments, especially in code meant to teach. Thanks for the feedback! I'll gladly change it to use atoms or agents or refs. I'm just not sure which one is most appropriate. What do you think I should use? -- 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: literate snake
n Fri, Jan 2, 2009 at 4:47 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 2, 2009 at 3:09 PM, Chouser chou...@gmail.com wrote: On Fri, Jan 2, 2009 at 4:05 PM, Tom Ayerst tom.aye...@gmail.com wrote: That def inside a function doesn't look right but I'm a noob at this too. I managed to run the snake off the board which suggests the concurrency is not quite right. Calling 'def' to like this is much worse than a lack of comments, especially in code meant to teach. Thanks for the feedback! I'll gladly change it to use atoms or agents or refs. I'm just not sure which one is most appropriate. What do you think I should use? I don't feel I have much authority in the realm of designing concurrent programs, but here are a couple thoughts: It seems to me that 'apple' and 'snake' together describe the state of the game, and therefore need their changes coordinated. This suggests they should both be refs. I think it might also be very natural to use a single agent with Thread/sleep and send-off to itself instead of the Timer. This would detangle the actionPerformed method from the panel, and allow you to give the action function a meaningful name instead. --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 -~--~~~~--~~--~--~---
Debian/Ubuntu clojure package
Hello, I have recently put together a Debian package for clojure. The package may also work on Ubuntu however this is untested. It may be downloaded from: http://www.pcc.me.uk/~peter/debian/clojure_0.0.20081217-1_all.deb You may also be interested in the source package which is downloadable using: dget http://www.pcc.me.uk/~peter/debian/clojure_0.0.20081217-1.dsc Comments are much appreciated. Thanks, -- Peter signature.asc Description: Digital signature
Re: literate snake
On Fri, Jan 2, 2009 at 4:04 PM, Chouser chou...@gmail.com wrote: n Fri, Jan 2, 2009 at 4:47 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 2, 2009 at 3:09 PM, Chouser chou...@gmail.com wrote: On Fri, Jan 2, 2009 at 4:05 PM, Tom Ayerst tom.aye...@gmail.com wrote: That def inside a function doesn't look right but I'm a noob at this too. I managed to run the snake off the board which suggests the concurrency is not quite right. Calling 'def' to like this is much worse than a lack of comments, especially in code meant to teach. Thanks for the feedback! I'll gladly change it to use atoms or agents or refs. I'm just not sure which one is most appropriate. What do you think I should use? I don't feel I have much authority in the realm of designing concurrent programs, but here are a couple thoughts: It seems to me that 'apple' and 'snake' together describe the state of the game, and therefore need their changes coordinated. I'm thinking their changes don't need to be coordinated. Here's why. The only state for an apple is it's color and cell. The color never changes. The cell only changes when the snake eats it. That is determined in the actionPerformed method which is also responsible for triggering movement of the snake, thus changing its state. actionPerformed is called on the Swing event dispatch thread. That means there can never multiple threads running actionPerformed concurrently. I think this is why my code works using def, despite it being bad form. This suggests they should both be refs. I think it might also be very natural to use a single agent with Thread/sleep and send-off to itself instead of the Timer. This would detangle the actionPerformed method from the panel, and allow you to give the action function a meaningful name instead. It would also invalidate what I said above about knowing that the actionPerformed code was always being executed from a single thread. Do you think it's a good idea to do that anyway? -- 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: detecting running as script
I suspect that *command-line-arguments* would have myapp.clj as the 0th element in the clj myapp.clj Can't test right now though sorry. On Jan 3, 3:34 am, Mark Volkmann r.mark.volkm...@gmail.com wrote: I have a file of Clojure code that I'd like to experiment with in the REPL. I use (load file-path) to do that and then I can try out the functions it defines. At the bottom of the file it calls the functions required to run my application. Is there a way I can write the code so it only runs my application when I run it outside the REPL? For example, this should run the application: clj myapp.clj and this should not: clj user= (load-file myapp.clj) Ruby has something like this. You surround the code that runs the app like this: if $PROGRAM_NAME == __FILE__ # code to run application goes here end -- 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: literate snake
What is it that makes this code literate? On Fri, Jan 2, 2009 at 8:07 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: I've written a new version of the snake program that uses a more literate style and therefore, to my eyes, calls for far fewer comments. I think this code is very readable. Check it out at http://www.ociweb.com/mark/programming/ClojureLiterateSnake.html. Feedback is welcomed! The most controversial thing about this code is probably my use of def to change the state of the snake and the apple. It's not yet clear to me that using atoms is needed here, but I need to think about that more. This version has some features that weren't in the original such as: - automatically turning the snake in the clockwise direction when a board edge is reached - changing the color of the snake to black when it overlaps itself - announcing a win when the length of the snake reaches 10 - automatically restarting the game after an overlap or a win -- R. Mark Volkmann Object Computing, Inc. -- 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: literate snake
On Fri, Jan 2, 2009 at 4:23 PM, Christian Vest Hansen karmazi...@gmail.com wrote: What is it that makes this code literate? Perhaps my understanding of the term is a bit off. What makes this code different from most Clojure code I see is that the functions tend to be very short and focused. I think this makes reading the code much easier. I don't feel like I have to think as hard to figure out what each piece is doing. This makes me more comfortable with including almost no comments. For example, my previous version contained this: (paintComponent [graphics] (proxy-super paintComponent graphics) (paint graphics @apple (colors :apple)) (doseq [point (:body @snake)] (paint graphics point (colors :snake My new version contains this: (paintComponent [graphics] (proxy-super paintComponent graphics) (paint-apple graphics) (paint-snake graphics)) This is a style that is strongly encouraged in Smalltalk, and perhaps in many other programming communities. It's really just lots of application of the extract method refactoring pattern. -- 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 -~--~~~~--~~--~--~---
implementing the Hofstadter Male and Female sequences
How would you implement the Hofstadter Male and Female sequences *elegantly* in Clojure? Here's a starting point: (declare h-male h-female) (defn h-male [n] (if (= n 0) 0 (- n (h-female (h-male (dec n)) (defn h-female [n] (if (= n 0) 1 (- n (h-male (h-female (dec n)) (def h-male (memoize h-male)) (def h-female (memoize h-female)) (def h-male-seq (map h-male (iterate inc 0))) (def h-female-seq (map h-female (iterate inc 0))) 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: literate snake
On Friday 02 January 2009 14:23, Christian Vest Hansen wrote: What is it that makes this code literate? I don't know whether or not you're familiar with the concept of Literate Programming. If you are, then you can judge for yourself whether that code qualifies as literate. If not, check out some of these references: - http://www-cs-faculty.stanford.edu/~knuth/lp.html - http://en.wikipedia.org/wiki/Literate_programming - http://www.literateprogramming.com/ - http://www.literateprogramming.com/knuthweb.pdf - http://vasc.ri.cmu.edu/old_help/Programming/Literate/literate.html Many more are out there. Randall Schulz --~--~-~--~~~---~--~~ You 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: detecting running as script
On Fri, Jan 2, 2009 at 4:20 PM, Timothy Pratley timothyprat...@gmail.com wrote: I suspect that *command-line-arguments* would have myapp.clj as the 0th element in the clj myapp.clj Can't test right now though sorry. Good idea! Unfortunately it seems that *command-line-args* is nil regardless of whether I load the code in a REPL or run it as a script. It doesn't include the name of the script, just arguments that follow it. On Jan 3, 3:34 am, Mark Volkmann r.mark.volkm...@gmail.com wrote: I have a file of Clojure code that I'd like to experiment with in the REPL. I use (load file-path) to do that and then I can try out the functions it defines. At the bottom of the file it calls the functions required to run my application. Is there a way I can write the code so it only runs my application when I run it outside the REPL? For example, this should run the application: clj myapp.clj and this should not: clj user= (load-file myapp.clj) Ruby has something like this. You surround the code that runs the app like this: if $PROGRAM_NAME == __FILE__ # code to run application goes here end -- 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: literate snake
On Fri, Jan 2, 2009 at 5:20 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 2, 2009 at 4:04 PM, Chouser chou...@gmail.com wrote: I don't feel I have much authority in the realm of designing concurrent programs, but here are a couple thoughts: It seems to me that 'apple' and 'snake' together describe the state of the game, and therefore need their changes coordinated. I'm thinking their changes don't need to be coordinated. Here's why. The only state for an apple is it's color and cell. The color never changes. The cell only changes when the snake eats it. That is determined in the actionPerformed method which is also responsible for triggering movement of the snake, thus changing its state. But if any other thread were to observe apple and snake immediately after the apple has been moved (because of a collision), it might be surprised to find that a moment later the snake has grown even though the apple was nowhere near it (having already been moved). Worse yet, suppose some other thread moves the apple, perhaps because the player is taking too long in driving the snake to it. If this were to happen after the collision detection but before the apple is moved, you'd again get unexpected results. You can know of course that neither of these will happen because there are no other threads doing any such thing. But (1) that may change in a future version of the program and (2) even as it is this requires you to reason about the *entire* program, not just the part you're dealing with at the moment. Thus I'd argue that for a correct and robust program, you should use refs for apple and snake, and think carefully about the appropriate scope for the dosync(s) that you use to modify them. actionPerformed is called on the Swing event dispatch thread. This means that while the application logic part of the program is running, the UI will not respond to user interaction. Again, this hardly matters for a toy program, but is something you'd want to avoid when demonstrating the right way to do things. I think it might also be very natural to use a single agent with Thread/sleep and send-off to itself instead of the Timer. This would detangle the actionPerformed method from the panel, and allow you to give the action function a meaningful name instead. It would also invalidate what I said above about knowing that the actionPerformed code was always being executed from a single thread. Do you think it's a good idea to do that anyway? actionPerformed would no longer be run in the Swing thread, and might indeed be run in different threads at different times, but as long as it was always run on the same agent, you're guaranteed that no two actionPerformed would be run at the same time. Actions are serialized for a given agent. So yes, I'd still say it's a good idea. Though you would want to use invokeLater in your new-game function. --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: literate snake
On Fri, Jan 2, 2009 at 4:38 PM, Randall R Schulz rsch...@sonic.net wrote: On Friday 02 January 2009 14:23, Christian Vest Hansen wrote: What is it that makes this code literate? I don't know whether or not you're familiar with the concept of Literate Programming. If you are, then you can judge for yourself whether that code qualifies as literate. If not, check out some of these references: - http://www-cs-faculty.stanford.edu/~knuth/lp.html - http://en.wikipedia.org/wiki/Literate_programming - http://www.literateprogramming.com/ - http://www.literateprogramming.com/knuthweb.pdf - http://vasc.ri.cmu.edu/old_help/Programming/Literate/literate.html Many more are out there. Thanks Randall! Clearly what I'm doing doesn't fit the definition of literate programming. Maybe I can claim that it's literate style based on this part of the definition: The main idea is to treat a program as a piece of literature, addressed to human beings rather than to a computer. What I'm trying to do is break the code up into a number of helper functions so the the functions that use them are easier to read. For example, here's a snippet of my code (including a questionable use of def that will be changed soon): (if (snake :alive) (if (adjacent-or-same-cell? (snake-head) (apple :cell)) (do (def apple (make-apple)) (move-snake true) (if (= (snake-length) *length-to-win*) (new-game You win!))) (move-snake false)) (new-game You killed the snake!)) I should probably change the arguments to move-snake to be more meaningful. You get the idea though. What I'm trying to avoid is deeply nested function definitions with lots of long argument lists and anonymous functions. -- 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: literate snake
On Fri, Jan 2, 2009 at 4:48 PM, Chouser chou...@gmail.com wrote: On Fri, Jan 2, 2009 at 5:20 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 2, 2009 at 4:04 PM, Chouser chou...@gmail.com wrote: I don't feel I have much authority in the realm of designing concurrent programs, but here are a couple thoughts: It seems to me that 'apple' and 'snake' together describe the state of the game, and therefore need their changes coordinated. I'm thinking their changes don't need to be coordinated. Here's why. The only state for an apple is it's color and cell. The color never changes. The cell only changes when the snake eats it. That is determined in the actionPerformed method which is also responsible for triggering movement of the snake, thus changing its state. But if any other thread were to observe apple and snake immediately after the apple has been moved (because of a collision), it might be surprised to find that a moment later the snake has grown even though the apple was nowhere near it (having already been moved). Worse yet, suppose some other thread moves the apple, perhaps because the player is taking too long in driving the snake to it. If this were to happen after the collision detection but before the apple is moved, you'd again get unexpected results. You can know of course that neither of these will happen because there are no other threads doing any such thing. But (1) that may change in a future version of the program and (2) even as it is this requires you to reason about the *entire* program, not just the part you're dealing with at the moment. Thus I'd argue that for a correct and robust program, you should use refs for apple and snake, and think carefully about the appropriate scope for the dosync(s) that you use to modify them. actionPerformed is called on the Swing event dispatch thread. This means that while the application logic part of the program is running, the UI will not respond to user interaction. Again, this hardly matters for a toy program, but is something you'd want to avoid when demonstrating the right way to do things. I think it might also be very natural to use a single agent with Thread/sleep and send-off to itself instead of the Timer. This would detangle the actionPerformed method from the panel, and allow you to give the action function a meaningful name instead. It would also invalidate what I said above about knowing that the actionPerformed code was always being executed from a single thread. Do you think it's a good idea to do that anyway? actionPerformed would no longer be run in the Swing thread, and might indeed be run in different threads at different times, but as long as it was always run on the same agent, you're guaranteed that no two actionPerformed would be run at the same time. Actions are serialized for a given agent. So yes, I'd still say it's a good idea. Though you would want to use invokeLater in your new-game function. Thanks Chris! Your explanation makes a lot of sense. I'll change the code as you suggested and put up a new version soon. -- 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: clj-backtrace: more readable backtraces for Clojure
Hi Mike, Thanks for your interest. clj-backtrace is developed and tested against Clojure head, though it should work with reasonably recent versions of Clojure. I hope that you and other Clojure users have a chance to try it out in your environments and report the results back to the group. I wouldn't normally rely on the exposed implementation details like clj-backtrace does, but these details are exactly the problem that the library is trying to fix, so AFAIK there is no way around it. A patch proving otherwise would of course be welcome. Looking forward to your reports, - Mark On Fri, Jan 2, 2009 at 4:10 PM, Michael Reid kid.me...@gmail.com wrote: Hi, I don't have Clojure in front of me right now to try this out, but from the looks of the README let me be the first to give you an emphatic *Thank you*. This is looking rather useful. Nice work. My one concern with this is how brittle is this with respect to Clojure's development? Have you had any trouble getting reasonable output on various revisions of Clojure? /mike. On Thu, Jan 1, 2009 at 9:30 PM, Mark McGranaghan mmcgr...@gmail.com wrote: Hi all, I'm happy to announce an alpha release of clj-backtrace, a library for processing backtraces generated by Clojure programs. The library works by separating useful backtrace information from the noise generated by the Clojure compilation process, and also provides functions for pretty-printing these cleaned backtraces. You can see simple usage instructions and example backtrace output on the library's README page: http://github.com/mmcgrana/clj-backtrace/tree/master/README.textile If you've ever felt that backtraces in Clojure were difficult to read, I hope you'll give this library a try and let me know if it helps! - Mark --~--~-~--~~~---~--~~ You 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: literate snake
Yes, what you did should certainly be called Intentional programming (or Intention revealing programming) instead of literate programming. This style of programming is for example encouraged by the book Clean Code of Robert C. Martin. I like this style of programming, I too think it is clear, and makes a good use of the compiler that prevents any comment (considering the function names are the old comments) from being not up to date ! :-) The difficulty, as always, is in finding the right balance ! HTH, -- Laurent On Jan 2, 11:51 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 2, 2009 at 4:38 PM, Randall R Schulz rsch...@sonic.net wrote: On Friday 02 January 2009 14:23, Christian Vest Hansen wrote: What is it that makes this code literate? I don't know whether or not you're familiar with the concept of Literate Programming. If you are, then you can judge for yourself whether that code qualifies as literate. If not, check out some of these references: - http://www-cs-faculty.stanford.edu/~knuth/lp.html - http://en.wikipedia.org/wiki/Literate_programming - http://www.literateprogramming.com/ - http://www.literateprogramming.com/knuthweb.pdf - http://vasc.ri.cmu.edu/old_help/Programming/Literate/literate.html Many more are out there. Thanks Randall! Clearly what I'm doing doesn't fit the definition of literate programming. Maybe I can claim that it's literate style based on this part of the definition: The main idea is to treat a program as a piece of literature, addressed to human beings rather than to a computer. What I'm trying to do is break the code up into a number of helper functions so the the functions that use them are easier to read. For example, here's a snippet of my code (including a questionable use of def that will be changed soon): (if (snake :alive) (if (adjacent-or-same-cell? (snake-head) (apple :cell)) (do (def apple (make-apple)) (move-snake true) (if (= (snake-length) *length-to-win*) (new-game You win!))) (move-snake false)) (new-game You killed the snake!)) I should probably change the arguments to move-snake to be more meaningful. You get the idea though. What I'm trying to avoid is deeply nested function definitions with lots of long argument lists and anonymous functions. -- 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 -~--~~~~--~~--~--~---
Java arrays caveat -- why?
From http://clojure.org/java_interop#toc27 : Clojure supports the creation, reading and modification of Java arrays. It is recommended that you limit use of arrays to interop with Java libraries that require them as arguments or use them as return values. What are the reasons for this caveat? If I receive a float array from some Java function, and want to pass it on to the rest of my program, should I think about copying it to a persistent vector? Sounds expensive. What do I give up by not doing so? Thanks, 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: literate snake
Hello, here are some feedbacks : I suggest you should create a namespace for the code of the game ('cause you want to show clojure good coding practices, as well as good coding conventions, won't you ;-) Could it make sense to use even fewer def's than currently ? I guess it could be made not mandatory to have apple, snake, as global vars ? And the JFrame too ? It could be great to have just defn's (and defstruct's and defmacro's), and a single defn entry point for starting the game ? HTH, -- Laurent Mark Volkmann wrote: I've written a new version of the snake program that uses a more literate style and therefore, to my eyes, calls for far fewer comments. I think this code is very readable. Check it out at http://www.ociweb.com/mark/programming/ClojureLiterateSnake.html. Feedback is welcomed! The most controversial thing about this code is probably my use of def to change the state of the snake and the apple. It's not yet clear to me that using atoms is needed here, but I need to think about that more. This version has some features that weren't in the original such as: - automatically turning the snake in the clockwise direction when a board edge is reached - changing the color of the snake to black when it overlaps itself - announcing a win when the length of the snake reaches 10 - automatically restarting the game after an overlap or a win -- 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: Java arrays caveat -- why?
Java arrays are mutable. If you pass them around, everything in Clojure that relies on the assumption of immutability stops working. How big is your array? Does the Java API continue to hold on to it? Stuart From http://clojure.org/java_interop#toc27 : Clojure supports the creation, reading and modification of Java arrays. It is recommended that you limit use of arrays to interop with Java libraries that require them as arguments or use them as return values. What are the reasons for this caveat? If I receive a float array from some Java function, and want to pass it on to the rest of my program, should I think about copying it to a persistent vector? Sounds expensive. What do I give up by not doing so? Thanks, 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: literate snake
On Fri, Jan 2, 2009 at 5:29 PM, lpetit laurent.pe...@gmail.com wrote: Yes, what you did should certainly be called Intentional programming (or Intention revealing programming) instead of literate programming. I was considering referring to intentional rather than literate until I saw this in the Wikipedia description of intentional programming. 'Key to the benefits of IP is that source code is not stored in text files, but in a binary file that bears a resemblance to XML. This style of programming is for example encouraged by the book Clean Code of Robert C. Martin. I like this style of programming, I too think it is clear, and makes a good use of the compiler that prevents any comment (considering the function names are the old comments) from being not up to date ! :-) The difficulty, as always, is in finding the right balance ! Thanks for the feedback! On Jan 2, 11:51 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Jan 2, 2009 at 4:38 PM, Randall R Schulz rsch...@sonic.net wrote: On Friday 02 January 2009 14:23, Christian Vest Hansen wrote: What is it that makes this code literate? I don't know whether or not you're familiar with the concept of Literate Programming. If you are, then you can judge for yourself whether that code qualifies as literate. If not, check out some of these references: - http://www-cs-faculty.stanford.edu/~knuth/lp.html - http://en.wikipedia.org/wiki/Literate_programming - http://www.literateprogramming.com/ - http://www.literateprogramming.com/knuthweb.pdf - http://vasc.ri.cmu.edu/old_help/Programming/Literate/literate.html Many more are out there. Thanks Randall! Clearly what I'm doing doesn't fit the definition of literate programming. Maybe I can claim that it's literate style based on this part of the definition: The main idea is to treat a program as a piece of literature, addressed to human beings rather than to a computer. What I'm trying to do is break the code up into a number of helper functions so the the functions that use them are easier to read. For example, here's a snippet of my code (including a questionable use of def that will be changed soon): (if (snake :alive) (if (adjacent-or-same-cell? (snake-head) (apple :cell)) (do (def apple (make-apple)) (move-snake true) (if (= (snake-length) *length-to-win*) (new-game You win!))) (move-snake false)) (new-game You killed the snake!)) I should probably change the arguments to move-snake to be more meaningful. You get the idea though. What I'm trying to avoid is deeply nested function definitions with lots of long argument lists and anonymous functions. -- R. Mark Volkmann Object Computing, Inc. -- 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: shelling out, convenience function for Runtime.exec()
Chouser chou...@gmail.com writes: I've added shell-out to clojure-contrib, with an 'sh' function that allows usage like: This is great; I was wondering where such a function was a couple weeks ago. Thanks! -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: implementing the Hofstadter Male and Female sequences
I don't think you need the declare line in your example, since the recursive references are inside of closures. I think your code is already very elegant, in the sense that it almost directly mirrors the mathematical definition of the sequences. There are probably ways to make it more efficient (for example, you could create a custom memoization for these functions that stores things internally in a vector, taking advantage of the fact that these inputs are numbers, and are always being generated sequentially. But this would certainly make the code less elegant. The only thing I can think of that is more elegant would be to combine the sequence/generating function/memoization into one thing: (def natural-numbers (iterate inc 1)) (declare hmale-seq hfemale-seq) (def hmale-seq (cons 0 (for [n natural-numbers] (- n (nth hfemale-seq (nth hmale-seq (dec n))) (def hfemale-seq (cons 1 (for [n natural-numbers] (- n (nth hmale-seq (nth hfemale-seq (dec n))) But this is going to be less efficient than your version, because it has to do a linear seek through the sequence to find the cached value. --~--~-~--~~~---~--~~ You 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: literate snake
For anyone still following this, the latest code that incorporates many of the suggestions I've received here is at http://www.ociweb.com/mark/programming/ClojureSnake.html, replacing my original version. It now uses refs. I think I have the dosyncs optimally placed. Feedback still welcomed! Can I / should I further reduce the number of defs I have? -- 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: Some code review for clj-record?
John, I was looking around at your tests just to get a feel for using the test-is stuff in the contrib library. I noticed that when I ran main.clj it would run not only the tests in clj-record, but all of the tests in the clojure.contrib as well. I was curious so I attempted to figure out what was going on and what to do to only run the tests in clj-record.test.*. I changed the end of the clj-record/test/main.clj script to this: main.clj (def files [core-test validation-test associations-test]) (doseq [file files] (load file)) (def base-ns (re-find #^\w*.*\. (str *ns*))) (apply test-is/run-tests (map #(symbol (str base-ns %)) files)) main.clj I also had to change the ns function in the associations-test.clj file to match the name of the file. The word 'associations' in the namespace was just misspelled. On Wed, Dec 31, 2008 at 9:39 AM, John D. Hume duelin.mark...@gmail.comwrote: Hi Brian, On Tue, Dec 30, 2008 at 11:41 AM, Brian Doyle brianpdo...@gmail.com wrote: (ns com.example.user) (clj-record.core/init-model) but when I do that I get the error: java.lang.ClassNotFoundException: clj-record.core ... (first (reverse (re-split #\. (name (ns-name *ns*) and could be changed to: (last (re-split #\. (name (ns-name *ns* Those changes have been incorporated, along with stuff in the README about validation. I'm confused as to how I ended up with (first (reverse ...)) since I remember looking at the doc for (last seq), but anyway, it's there now. -hume. -- http://elhumidor.blogspot.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: literate snake
On Jan 2, 5:39 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: For anyone still following this, the latest code that incorporates many of the suggestions I've received here is athttp://www.ociweb.com/mark/programming/ClojureSnake.html, replacing my original version. It now uses refs. I think I have the dosyncs optimally placed. I noticed that the new-game function which is called in a transaction does IO (it displays You killed the snake!). Transactions may be retried (see http://clojure.org/refs) so that message might get displayed more than once. There's an io! macro (doesn't seem to be documented on the web page, but it's in core.clj in the Clojure source with a nice docstring) which serves only to help programmers avoid putting IO in their transactions -- it doesn't magically make IO work right in a transaction. (Refs and transactions don't solve the problem that IO is inherently stateful and destructive -- Clojure relies on the IO system itself to handle that, which it should nicely in your case.) 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 -~--~~~~--~~--~--~---