Re: Slime buffer ns is always user
On Wed, Jan 7, 2009 at 11:49 PM, Zak Wilson wrote: > >> First, compile the buffer with C-c >> C-k. Then, evaluate new definitions in the same source file and they >> will be evaluated in the correct namespace (regardless of what >> namespace is active in the repl). > > That's what I expected, but it doesn't work; new definitions are > evaluated in user. It shows user/foo when I evaluate (def foo 'bar). > It shows # when I evaluate *ns*. > > I would think this is a bug, but it seems to work for everyone else, > so it's probably some sort of misconfiguration. Aside from the REPL > fix, my configuration is straight out of the readme. I'm not sure what > could be wrong. Try adding the following code to your .emacs file and let me know if this fixes the problem for you: (setq slime-find-buffer-package-function 'slime-clojure-search-buffer-package) (defun slime-clojure-search-buffer-package () (let ((case-fold-search t) (regexp1 (concat "^(\\(clojure.core/\\)?in-ns\\>[ \t']*" "\\([^)]+\\)[ \t]*)")) (regexp2 (concat "^(\\(clojure.core/\\)?ns\\>[ \t']*" "\\([^)]+\\)[ \t]*)"))) (save-excursion (when (or (re-search-backward regexp1 nil t) (re-search-forward regexp1 nil t) (re-search-backward regexp2 nil t) (re-search-forward regexp2 nil t)) (match-string-no-properties 2) -- 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: Slime buffer ns is always user
> First, compile the buffer with C-c > C-k. Then, evaluate new definitions in the same source file and they > will be evaluated in the correct namespace (regardless of what > namespace is active in the repl). That's what I expected, but it doesn't work; new definitions are evaluated in user. It shows user/foo when I evaluate (def foo 'bar). It shows # when I evaluate *ns*. I would think this is a bug, but it seems to work for everyone else, so it's probably some sort of misconfiguration. Aside from the REPL fix, my configuration is straight out of the readme. I'm not sure what could be wrong. --~--~-~--~~~---~--~~ 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: Slime buffer ns is always user
On Wed, Jan 7, 2009 at 7:25 PM, Zak Wilson wrote: > > I'm using the latest Slime, swank-clojure and Clojure, with a fix from > Chousuke to start up the REPL properly. I have no problem setting the > namespace in the REPL, but anything I eval directly from a file (i.e. > with C-x C-e) gets evaluated in the user ns. > > The ns in the *inferior-lisp* buffer remains user regardless of the > active file or setting the ns in the slime-repl, however, setting it > to something else manually seems to have no effect on the problem. > > The file's namespace is set up properly. I can load it with require. > > I heard this was a problem with an older version of swank-clojure, but > I'm quite certain You may have multiple source files open and the namespace can be different for each source buffer. First, compile the buffer with C-c C-k. Then, evaluate new definitions in the same source file and they will be evaluated in the correct namespace (regardless of what namespace is active in the repl). -- 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: sort behavior question
I wonder if the root cause might be clearer if you were to review the documentation for the sort function and then apply what it says to a smaller dataset, e.g. a pair of lists. Bill --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Gen-interface signature
I'm playing around with gen-interface, and compiled the following: (ns mypkg.compiletest) (gen-interface :name mypkg.ICompileTest :methods [['foo [] []]]) I then used a java .class decompiler to look at the resulting .class file expecting to see an interface with a single method called "foo" but instead I see this: package mypkg; public interface ICompileTest { public abstract _5B__5D_ _28_quote_20_foo_29_(); } My questions: 1. Why is the method name "_5B__5D_ _28_quote_20_foo_29_" instead of "foo"? 2. Why is the method abstract? I'm not aware of any meaning for the abstract keyword in an interface - not that that means there isn't a meaning... :-) -Greg --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Slime buffer ns is always user
I'm using the latest Slime, swank-clojure and Clojure, with a fix from Chousuke to start up the REPL properly. I have no problem setting the namespace in the REPL, but anything I eval directly from a file (i.e. with C-x C-e) gets evaluated in the user ns. The ns in the *inferior-lisp* buffer remains user regardless of the active file or setting the ns in the slime-repl, however, setting it to something else manually seems to have no effect on the problem. The file's namespace is set up properly. I can load it with require. I heard this was a problem with an older version of swank-clojure, but I'm quite certain --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
update in place for unique references
I am new to clojure, but it seems very interesting. Has anyone thought about allowing "update in place" for situations where it is safe? Suppose you have (def y (tripleit x)) and you know that there is only a single reference to x at this point, then it would be safe to implement it as "y takes on the storage of x and this is multiplied by 3 in-place". Well, I should say it's safe as long as "x" loses scope at this point. The fact that y has gained its storage and done an update in place shouldn't bother anyone or cause any loss in purity. This is what "uniqueness types" are used for in the "Clean" functional lanugage. (And logic language Mercury uses "unique modes".) Now I realize there is the question in Clojure of "how do we know whether it's unique". Clean does it via the type system. But one could have other mechanisms for ensuring uniqueness. One would be to keep a runtime track of references and only allow an update-in-place primitive in the case of a single reference. If this were attempted when multiple references existed, a runtime error would occur. Has anyone thought about this kind of update-in-place methodology? It seems to be one of the reasons why both Clean and Mercury achieve good performance. Perhaps there are good reasons why this approach is not workable in clojure (or not useful), but I'd be interested to hear why. Thanks, 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 -~--~~~~--~~--~--~---
sort behavior question
I noticed strange behavior in the sort function, I was sorting key value tuples and ran into the following: when sorting 2 item vectors such as [1 [1 2 3]] sort works fine: (println (sort (map (fn [x] [(int (* (Math/random) 10)) x]) (for [x (range 4)] [1 2 3] output: ([6 [1 2 3]] [6 [1 2 3]] [6 [1 2 3]] [6 [1 2 3]]) however, if the second item is a list, e.g: (println (sort (map (fn [x] [(int (* (Math/random) 10)) x]) (for [x (range 100)] `(1 2 3) the following exception can occur, this happens more frequently for larger ranges, for range of 4, it may or may run and produce the result, however with a range of 100 the exception occurs consistently: Exception in thread "main" java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.LazyCons (gen.clj:60) at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2684) at clojure.lang.Compiler.compile(Compiler.java:4564) at clojure.lang.RT.compile(RT.java:362) at clojure.lang.RT.load(RT.java:404) at clojure.lang.RT.load(RT.java:376) --~--~-~--~~~---~--~~ 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: Simple example of using postgresql with contrib.sql...
On Jan 7, 2009, at 6:20 PM, ssecorp wrote: I tried to use connection in internal to get resultSetMetadata but I never succeeded with it. In the current svn version of clojure.contrib, connection is available without using sql.internal. Also, there's now an example of getting connection metadata in sql.test. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: re-find
On Jan 7, 2009, at 6:21 PM, Jeff Foster wrote: Looking at the code, re-find uses re-groups which explicitly says that it either returns a vector or a string. This is clunky to deal with - is there any reason it doesn't always return a vector? Whether it returns a vector or string depends on the structure of the regular expression you're searching for, not the input data. At the time you write the code you can know which it will return. Returning just a string from a "simple" regex is a convenience when when using a regex search in a chain of operations. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: re-find
On Wednesday 07 January 2009 15:21, Jeff Foster wrote: > I'm not understanding re-find. > > (re-find #"bar" "bar") => "bar" > > whereas > > (re-find #"(foo)|(bar)" "foo bar") => ["foo" "foo" nil] > > Why does one return a vector and one just the result directly? The use of capturing parentheses in the latter. > ... is there any reason it doesn't always return a vector? 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-find
I'm not understanding re-find. (re-find #"bar" "bar") => "bar" whereas (re-find #"(foo)|(bar)" "foo bar") => ["foo" "foo" nil] Why does one return a vector and one just the result directly? Looking at the code, re-find uses re-groups which explicitly says that it either returns a vector or a string. This is clunky to deal with - is there any reason it doesn't always return a vector? --~--~-~--~~~---~--~~ 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: yet another Clojure snake
As a complete clojure newbie (hi folks!) from a Ruby/Java background, I kind-of don't like either - I'd pull out a named function like: (def add-mix-and-beat [bowl, dry-ingredients wet-ingredients] ... and then use your second example, but now it's: (def make-cookies-2a [flower baking-soda salt button sugar eggs] (bake (make-dough-balls (find-baking-sheet) (add-mix-and-beat (find-bowl) '(flower baking-soda salt) '(eggs flour))) - I'm trying to follow the "if it does more than 7 things, it's too complex" model. (Apologies if my syntax is broken - I'm still completely new to lisp/clojure (ok, I did lisp at uni, but that's an embarrassingly long time ago!)) - Korny On Thu, Jan 8, 2009 at 8:17 AM, Mark Volkmann wrote: > > On Wed, Jan 7, 2009 at 3:05 PM, Tom Ayerst wrote: >> Honestly? The second one, but I did say I didn't like the 'big let' style, >> maybe that is why. > > I think I may be in the minority on this. I suspect there are more > people currently using Clojure who came to it from a Lisp background > than a Java background. I had exposure to Lisp in college, but that > was a long time ago. My recent experience has been more with Java and > Ruby. Maybe that's why I find deeply nested function calls difficult > to read. After three or four levels of nesting, the code is no longer > obvious to me. The second option below is six levels deep. > >> Cheers >> >> Tom >> >> 2009/1/7 Mark Volkmann >>> >>> On Wed, Jan 7, 2009 at 3:13 AM, Tom Ayerst wrote: >>> > Hi Mark, >>> > >>> I agree they could be inlined, but I find that style easier to read. >>> For example, these are equivalent. >>> >>> (defn make-cookies-1 [flower baking-soda salt button sugar eggs] >>> ; let describes the step-by-step process for making cookies. >>> (let [bowl (find-bowl :small) >>> bowl (add-ingredients bowl flower baking-soda salt) >>> batter (mix bowl) >>> batter (add-and-beat batter eggs flour) >>> baking-sheet (find-baking-sheet) >>> baking-sheet (make-dough-balls baking-sheet batter)] >>>(bake baking-sheet))) >>> >>> (def make-cookies-2 [flower baking-soda salt button sugar eggs] >>> (bake (make-dough-balls >>>(find-baking-sheet) >>>(add-and-beat (mix (add-ingredients (find-bowl) flower baking-soda >>> salt) eggs flour >>> >>> Which of these is easier to understand? > > -- > R. Mark Volkmann > Object Computing, Inc. > > > > -- Kornelis Sietsma korny at my surname dot com kornys at gmail dot com on google chat -- kornys on skype "Every jumbled pile of person has a thinking part that wonders what the part that isn't thinking isn't thinking of" --~--~-~--~~~---~--~~ 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: Simple example of using postgresql with contrib.sql...
and user.clj function wasn't avilable without importing it when I try to access them if I put a file ina namespace. On Jan 7, 8:27 pm, "Stephen C. Gilardi" wrote: > On Jan 7, 2009, at 12:11 PM, ssecorp wrote: > > > > > This was going to be a question but I solved it before I finished the > > post :) > > Figured I might post the solution then, hopefully it will help someone > > else. > > Very cool. > > > > > (ns progs.netflix.db > > (:require (clojure.contrib [sql :as sql])) > > (:require (clojure.contrib.sql [internal :as internal]))) > > (load-file "C:/clojure/user.clj") > > > (def db {:classname "org.postgresql.Driver" > > :subprotocol "postgresql" > > :subname "//localhost/flonk" > > :user "postgres" > > :password "1234qwer" > > }) > > > (defn drop-deleta [] > > (try > > (sql/drop-table :deleta) > > (catch Exception e))) > > > (defn create-and-drop-previous [] > > (sql/with-connection db > > (sql/transaction > > (drop-deleta > > The goal is for you not to need "sql.internal". I made a recent change > that makes "(connection)" available without it. If you're still using > it, please let me know why and I'll try to fix it. > > If C:/clojure is in your classpath, user.clj will be loaded at the > time you launch the repl or script. You shouldn't need to load it in > code you deploy. If you're doing it at the repl, I would prefer to use > (require 'user.clj :reload) and avoid load-file in nearly every case. > > --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 -~--~~~~--~~--~--~---
Re: Simple example of using postgresql with contrib.sql...
I tried to use connection in internal to get resultSetMetadata but I never succeeded with it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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: File organization & bootstrapping
Craig McDaniel writes: > Connect to your running app from emacs by using "M-x slime-connect" > rather than "M-x slime". When you're done, use "M-x slime- > disconnect" (or from the REPL, "," then "disconnect") to leave your > process running. In addtion, including swank in your running > production app is a real benefit since you can connect to it from > emacs at any later time for diagnosis, debugging, etc... That's good to know; thanks. I'm still a little uneasy about introducing swank as an external dependency. It's not a big deal for stuff you'd use internally, but for open-source projects I like to keep the installation process to a couple lines. I guess I could bundle a copy of swank-clojure to streamline things. Or I could wait until I actually have something to release before I obsess about making installation and distribution easy. =) -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: contrib/sql with postgresql, problem inserting into column of type date
The sample code for the book now includes a clojure.contrib.sql example with date handling that may be helpful [1]. I tested with HSQLDB, please let me know if it doesn't work with postgresql. Cheers, Stuart [1] http://github.com/stuarthalloway/programming-clojure/tree/master/examples/snippet.clj > > (defn inse [] > (sql/with-connection db >(sql/transaction > (insert-rows :r [[1 2 "date '2008-12-03'" 3]]))) > nil) > > I have tried all kinds of variations. it works perfectly with another > table, like (int,int,int,int) and passing [1,2,3,4] > so it is the type of column 3 that is the problem. > > "2008-12-03" > "'2008-12-03'" > "date 2008-12-03" > etc > tried all combos. > > > > java.lang.Exception: transaction rolled back: Batch entry 0 insert > into reviews values (1488844,1,2005-09-06,3) was aborted. Call > getNextException to see the cause. (parsing.clj:0) > user=> java.lang.Exception: transaction rolled back: Batch entry 0 > insert into reviews values (1,2,2008-12-02,3) was aborted. Call > getNextException to see the cause. (pg.clj:0) > user=> java.lang.Exception: transaction rolled back: Batch entry 0 > insert into reviews values (1,2,2008-12-02,3) was aborted. Call > getNextException to see the cause. (pg.clj:0) > user=> (.getNextException) > java.lang.IllegalArgumentException: Malformed member expression, > expecting (.member target ...) (NO_SOURCE_FILE:50) > user=> (.getNextException 1) > java.lang.IllegalArgumentException: No matching field found: > getNextException for class java.lang.Integer (NO_SOURCE_FILE:0) > user=> (.getNextException java.lang.Exception) > java.lang.IllegalArgumentException: No matching field found: > getNextException for class java.lang.Class (NO_SOURCE_FILE:0) > user=> (.getNextException e) > java.lang.Exception: Unable to resolve symbol: e in this context > (NO_SOURCE_FILE:53) > user=> (printStackTrace) > java.lang.Exception: Unable to resolve symbol: printStackTrace in this > context (NO_SOURCE_FILE:54) > user=> (.printStackTrace) > java.lang.IllegalArgumentException: Malformed member expression, > expecting (.member target ...) (NO_SOURCE_FILE:55) > user=> .printStackTrace > java.lang.Exception: Unable to resolve symbol: .printStackTrace in > this context (NO_SOURCE_FILE:0) > user=> (System/getProperty "java.vm.version") > > "10.0-b22" > user=> java.lang.Exception: transaction rolled back: Batch entry 0 > insert into r values (1,2,2008-12-02,3) was aborted. Call > getNextException to see the cause. (pg.clj:0) > user=> ("2008-12") > java.lang.ClassCastException: java.lang.String cannot be cast to > clojure.lang.IFn (NO_SOURCE_FILE:0) > user=> java.lang.Exception: transaction rolled back: Batch entry 0 > insert into r values (1,2,"2008-12-02",3) was aborted. Call > getNextException to see the cause. (pg.clj:0) > user=> java.lang.Exception: Unsupported escape character: \' (pg.clj: > 59) > user=> java.lang.NumberFormatException: Invalid number: 2008-12-02 > (pg.clj:59) > user=> java.lang.Exception: transaction rolled back: Batch entry 0 > insert into r values (1,2,'2008-12-02',3) was aborted. Call > getNextException to see the cause. (pg.clj:0) > user=> (System/getNextException) > java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:65) > user=> java.lang.Exception: transaction rolled back: Batch entry 0 > insert into r values (1,2,2008-12-02,3) was aborted. Call > getNextException to see the cause. (pg.clj:0) > user=> (System/getNextException) > java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:67) > user=> (System/getNextException) > java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:68) > user=> (System/getNextException) > java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:69) > user=> (System/getNextException) > java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:70) > user=> nil > user=> nil > user=> java.lang.Exception: transaction rolled back: Batch entry 0 > insert into r values (1,2,NULL,3) was aborted. Call getNextException > to see the cause. (pg.clj:0) > user=> java.lang.Exception: Unsupported escape character: \' (pg.clj: > 59) > user=> (.replace '2008-12-025' "5" "") > java.lang.NumberFormatException: Invalid number: 2008-12-025 > user=> "5" > user=> "" > user=> java.lang.Exception: Unmatched delimiter: ) > user=> (.replace "2008-12-025" "5" "") > "2008-12-02" > user=> java.lang.Exception: transaction rolled back: Batch entry 0 > insert into r values (1,2,'2008-12-03',3) was aborted. Call > getNextException to see the cause. (pg.clj:0) > user=> java.lang.Exception: transaction rolled back: Batch entry 0 > insert into r values (1,2,date '2008-12-03',3) was aborted. Call > getNextException to see the cause. (pg.clj:0) > user=> > > --~--~-~--~~~---~--~~ 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
contrib/sql with postgresql, problem inserting into column of type date
(defn inse [] (sql/with-connection db (sql/transaction (insert-rows :r [[1 2 "date '2008-12-03'" 3]]))) nil) I have tried all kinds of variations. it works perfectly with another table, like (int,int,int,int) and passing [1,2,3,4] so it is the type of column 3 that is the problem. "2008-12-03" "'2008-12-03'" "date 2008-12-03" etc tried all combos. java.lang.Exception: transaction rolled back: Batch entry 0 insert into reviews values (1488844,1,2005-09-06,3) was aborted. Call getNextException to see the cause. (parsing.clj:0) user=> java.lang.Exception: transaction rolled back: Batch entry 0 insert into reviews values (1,2,2008-12-02,3) was aborted. Call getNextException to see the cause. (pg.clj:0) user=> java.lang.Exception: transaction rolled back: Batch entry 0 insert into reviews values (1,2,2008-12-02,3) was aborted. Call getNextException to see the cause. (pg.clj:0) user=> (.getNextException) java.lang.IllegalArgumentException: Malformed member expression, expecting (.member target ...) (NO_SOURCE_FILE:50) user=> (.getNextException 1) java.lang.IllegalArgumentException: No matching field found: getNextException for class java.lang.Integer (NO_SOURCE_FILE:0) user=> (.getNextException java.lang.Exception) java.lang.IllegalArgumentException: No matching field found: getNextException for class java.lang.Class (NO_SOURCE_FILE:0) user=> (.getNextException e) java.lang.Exception: Unable to resolve symbol: e in this context (NO_SOURCE_FILE:53) user=> (printStackTrace) java.lang.Exception: Unable to resolve symbol: printStackTrace in this context (NO_SOURCE_FILE:54) user=> (.printStackTrace) java.lang.IllegalArgumentException: Malformed member expression, expecting (.member target ...) (NO_SOURCE_FILE:55) user=> .printStackTrace java.lang.Exception: Unable to resolve symbol: .printStackTrace in this context (NO_SOURCE_FILE:0) user=> (System/getProperty "java.vm.version") "10.0-b22" user=> java.lang.Exception: transaction rolled back: Batch entry 0 insert into r values (1,2,2008-12-02,3) was aborted. Call getNextException to see the cause. (pg.clj:0) user=> ("2008-12") java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0) user=> java.lang.Exception: transaction rolled back: Batch entry 0 insert into r values (1,2,"2008-12-02",3) was aborted. Call getNextException to see the cause. (pg.clj:0) user=> java.lang.Exception: Unsupported escape character: \' (pg.clj: 59) user=> java.lang.NumberFormatException: Invalid number: 2008-12-02 (pg.clj:59) user=> java.lang.Exception: transaction rolled back: Batch entry 0 insert into r values (1,2,'2008-12-02',3) was aborted. Call getNextException to see the cause. (pg.clj:0) user=> (System/getNextException) java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:65) user=> java.lang.Exception: transaction rolled back: Batch entry 0 insert into r values (1,2,2008-12-02,3) was aborted. Call getNextException to see the cause. (pg.clj:0) user=> (System/getNextException) java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:67) user=> (System/getNextException) java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:68) user=> (System/getNextException) java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:69) user=> (System/getNextException) java.lang.NoSuchFieldException: getNextException (NO_SOURCE_FILE:70) user=> nil user=> nil user=> java.lang.Exception: transaction rolled back: Batch entry 0 insert into r values (1,2,NULL,3) was aborted. Call getNextException to see the cause. (pg.clj:0) user=> java.lang.Exception: Unsupported escape character: \' (pg.clj: 59) user=> (.replace '2008-12-025' "5" "") java.lang.NumberFormatException: Invalid number: 2008-12-025 user=> "5" user=> "" user=> java.lang.Exception: Unmatched delimiter: ) user=> (.replace "2008-12-025" "5" "") "2008-12-02" user=> java.lang.Exception: transaction rolled back: Batch entry 0 insert into r values (1,2,'2008-12-03',3) was aborted. Call getNextException to see the cause. (pg.clj:0) user=> java.lang.Exception: transaction rolled back: Batch entry 0 insert into r values (1,2,date '2008-12-03',3) was aborted. Call getNextException to see the cause. (pg.clj:0) user=> --~--~-~--~~~---~--~~ 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: yet another Clojure snake
On Wed, Jan 7, 2009 at 3:05 PM, Tom Ayerst wrote: > Honestly? The second one, but I did say I didn't like the 'big let' style, > maybe that is why. I think I may be in the minority on this. I suspect there are more people currently using Clojure who came to it from a Lisp background than a Java background. I had exposure to Lisp in college, but that was a long time ago. My recent experience has been more with Java and Ruby. Maybe that's why I find deeply nested function calls difficult to read. After three or four levels of nesting, the code is no longer obvious to me. The second option below is six levels deep. > Cheers > > Tom > > 2009/1/7 Mark Volkmann >> >> On Wed, Jan 7, 2009 at 3:13 AM, Tom Ayerst wrote: >> > Hi Mark, >> > >> I agree they could be inlined, but I find that style easier to read. >> For example, these are equivalent. >> >> (defn make-cookies-1 [flower baking-soda salt button sugar eggs] >> ; let describes the step-by-step process for making cookies. >> (let [bowl (find-bowl :small) >> bowl (add-ingredients bowl flower baking-soda salt) >> batter (mix bowl) >> batter (add-and-beat batter eggs flour) >> baking-sheet (find-baking-sheet) >> baking-sheet (make-dough-balls baking-sheet batter)] >>(bake baking-sheet))) >> >> (def make-cookies-2 [flower baking-soda salt button sugar eggs] >> (bake (make-dough-balls >>(find-baking-sheet) >>(add-and-beat (mix (add-ingredients (find-bowl) flower baking-soda >> salt) eggs flour >> >> Which of these is easier to understand? -- 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: Adding user-defined state to classes created with (proxy ...)
> You're calling my bluff, eh? Well, no I don't yet. Although I have been known to do some bluff-calling, in this case I was actually hoping you had done it because I need this for a project I'm working on. :-) > I think the problem with your example is trying to work with classes > or namespaces without any package names. This sometimes works a bit, > but it's not really supported. So I put your example code into a file > named "my_ns/compiletest.clj", and changed it to: > > (ns my-ns.compiletest) > (gen-interface :name my_ns.ICompileTest) > (proxy [java.io.InputStream] []) ; Just to make sure proxy works by > itself (line 3) > (proxy [my_ns.ICompileTest] []) ; Line 4 > > Now compiling works fine for me: > > user=> (compile 'my-ns.compiletest) > my-ns.compiletest Yep, that works for me too. Thx. -Greg --~--~-~--~~~---~--~~ 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: yet another Clojure snake
Honestly? The second one, but I did say I didn't like the 'big let' style, maybe that is why. Cheers Tom 2009/1/7 Mark Volkmann > > On Wed, Jan 7, 2009 at 3:13 AM, Tom Ayerst wrote: > > Hi Mark, > > > I agree they could be inlined, but I find that style easier to read. > For example, these are equivalent. > > (defn make-cookies-1 [flower baking-soda salt button sugar eggs] > ; let describes the step-by-step process for making cookies. > (let [bowl (find-bowl :small) > bowl (add-ingredients bowl flower baking-soda salt) > batter (mix bowl) > batter (add-and-beat batter eggs flour) > baking-sheet (find-baking-sheet) > baking-sheet (make-dough-balls baking-sheet batter)] >(bake baking-sheet))) > > (def make-cookies-2 [flower baking-soda salt button sugar eggs] > (bake (make-dough-balls >(find-baking-sheet) >(add-and-beat (mix (add-ingredients (find-bowl) flower aking-soda > salt) eggs flour > > Which of these is easier to understand? > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
AOT compilation and reloading of namespaces
Dear Clojurians, I found an issue with (require :reload ...) and AOT compilation. Files "load"ed in a multi-file namespace get not correctly reloaded when AOT compiled. user=> (compile 'foo) foo user=> (require :reload-all :verbose 'foo) (clojure.core/load "/foo") (clojure.core/load "/bar") nil user=> (require :reload-all :verbose 'foo) (clojure.core/load "/foo") nil I added an issue on Google Code: http://code.google.com/p/clojure/issues/detail?id=38 Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Adding user-defined state to classes created with (proxy ...)
On Wed, Jan 7, 2009 at 3:18 PM, Greg Harman wrote: > > Do you have an example of gen-interface + proxy working together? You're calling my bluff, eh? Well, no I don't yet. I'm doing ugly hacky things instead, to avoid the compile step. But since you've thrown down the gauntlet, to mix some metaphors... I think the problem with your example is trying to work with classes or namespaces without any package names. This sometimes works a bit, but it's not really supported. So I put your example code into a file named "my_ns/compiletest.clj", and changed it to: (ns my-ns.compiletest) (gen-interface :name my_ns.ICompileTest) (proxy [java.io.InputStream] []) ; Just to make sure proxy works by itself (line 3) (proxy [my_ns.ICompileTest] []) ; Line 4 Now compiling works fine for me: user=> (compile 'my-ns.compiletest) my-ns.compiletest --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: yet another Clojure snake
On Jan 7, 7:01 am, "Mark Volkmann" wrote: > On Wed, Jan 7, 2009 at 3:13 AM, Tom Ayerst wrote: > > Hi Mark, > > > I'm afraid I don't like the "big let" style and I found it hard to follow > > some of your code, that may just be a personal thing but a lot of the vars > > defined in let are only used once and could be inlined. > > I agree they could be inlined, but I find that style easier to read. > For example, these are equivalent. > > (defn make-cookies-1 [flower baking-soda salt button sugar eggs] > ; let describes the step-by-step process for making cookies. > (let [bowl (find-bowl :small) > bowl (add-ingredients bowl flower baking-soda salt) > batter (mix bowl) > batter (add-and-beat batter eggs flour) > baking-sheet (find-baking-sheet) > baking-sheet (make-dough-balls baking-sheet batter)] > (bake baking-sheet))) > > (def make-cookies-2 [flower baking-soda salt button sugar eggs] > (bake (make-dough-balls > (find-baking-sheet) > (add-and-beat (mix (add-ingredients (find-bowl) flower aking-soda > salt) eggs flour > > Which of these is easier to understand? You can avoid the big let while still keeping the order of operations clear by using the -> macro: (defn make-cookies [flour baking-soda salt butter sugar eggs] (let [batter (-> (find-bowl :small) (add ingredients flour baking-soda salt) (mix) (add-and-beat eggs flour))] (-> (find-baking-sheet) (make-dough-balls batter) (bake In my opinion, this little macro is a brilliant idea. -- Nathan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: File organization & bootstrapping
Getting back to Phil Hagelberg's comment that maintaining a project's classpath in both a SLIME config and shell script for each project/ application is a "Don't Repeat Yourself" violation, there is a way to avoid that: Don't bother with swank-clojure-extra-classpaths. Instead, include / path/to/swank-clojure in the classpath of each of your project's startup shell scripts. Each project starts up a swank server using something like the following in its initialization code, using a unique port for each project: (require 'swank.swank) (swank.swank/ignore-protocol-version "2009-01-01") (swank.swank/start-server "/dev/null" :port :encoding "iso- latin-1-unix") Connect to your running app from emacs by using "M-x slime-connect" rather than "M-x slime". When you're done, use "M-x slime- disconnect" (or from the REPL, "," then "disconnect") to leave your process running. In addtion, including swank in your running production app is a real benefit since you can connect to it from emacs at any later time for diagnosis, debugging, etc... -Craig --~--~-~--~~~---~--~~ 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: Adding user-defined state to classes created with (proxy ...)
Chouser, Do you have an example of gen-interface + proxy working together? Take a look at the following. Proxy works fine for a Java-provided interface, but not for the generated one (ICompileTest.class is being generated and is in the filesystem/classpath where expected.) (ns compiletest) (gen-interface :name ICompileTest) (proxy [java.io.InputStream] []) ; Just to make sure proxy works by itself (line 3) (proxy [ICompileTest] []) ; Line 4 --- user=> (binding [*compile-path* *fusion-compile-path*] (compile 'compiletest)) java.lang.NullPointerException (compiletest.clj:4) thanks, Greg On Jan 4, 11:39 am, Chouser wrote: > It may be, but let me again mention the option of gen-interface plus > proxy. Sometimes you need to produce a physical .class files of > concrete types (for servlet containers, for use with android, etc.). > But if that's not the case, you may prefer the simplicity of > gen-interface. Then you can implement your interface in as many ways > as needed using 'proxy'. --~--~-~--~~~---~--~~ 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: atom swap! and retry
On Wed, Jan 7, 2009 at 11:21 AM, Rich Hickey wrote: > > On Jan 7, 12:11 pm, "Mark Volkmann" wrote: >> What is it that triggers the function passed to swap! to be retried? >> Is it that some other thread has modified the atom since swap! was >> invoked, but before the function passed to swap! returns? >> >> -- > > I think that's described pretty well here: > > http://clojure.org/atoms Right. Somehow I had skipped over this part: "Since another thread may have changed the value in the intervening time, it may have to retry, and does so in a spin loop." Thanks! -- 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: Simple example of using postgresql with contrib.sql...
On Jan 7, 2009, at 12:11 PM, ssecorp wrote: This was going to be a question but I solved it before I finished the post :) Figured I might post the solution then, hopefully it will help someone else. Very cool. (ns progs.netflix.db (:require (clojure.contrib [sql :as sql])) (:require (clojure.contrib.sql [internal :as internal]))) (load-file "C:/clojure/user.clj") (def db {:classname "org.postgresql.Driver" :subprotocol "postgresql" :subname "//localhost/flonk" :user "postgres" :password "1234qwer" }) (defn drop-deleta [] (try (sql/drop-table :deleta) (catch Exception e))) (defn create-and-drop-previous [] (sql/with-connection db (sql/transaction (drop-deleta The goal is for you not to need "sql.internal". I made a recent change that makes "(connection)" available without it. If you're still using it, please let me know why and I'll try to fix it. If C:/clojure is in your classpath, user.clj will be loaded at the time you launch the repl or script. You shouldn't need to load it in code you deploy. If you're doing it at the repl, I would prefer to use (require 'user.clj :reload) and avoid load-file in nearly every case. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: writing bytes to a file
Looks like spit is for printing just text. On Wed, Jan 7, 2009 at 12:20 PM, Paul Barry wrote: > clojure.contrib.duck_streams/spit? > > > On Wed, Jan 7, 2009 at 2:14 PM, Brian Doyle wrote: > >> I couldn't find anything in core or contrib that wrote out >> bytes to a file so I wrote something to do it. Is this >> functionality already implemented and I just couldn't find >> it? If there isn't anything already, would this be something >> good to put in contrib somewhere? Thanks. >> >>(defn write-bytes >> "Writes the bytes from the in-stream to the given filename." >> [#^java.io.InputStream in-stream #^String filename] >> (with-open [out-stream (new FileOutputStream filename)] >>(let [buffer (make-array (Byte/TYPE) 4096)] >> (loop [bytes (.read in-stream buffer)] >>(if (not (neg? bytes)) >> (do >>(.write out-stream buffer 0 bytes) >>(recur (.read in-stream buffer >> >> >> >> > > > > --~--~-~--~~~---~--~~ 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: File organization & bootstrapping
On Jan 7, 2009, at 2:04 PM, Shawn Hoover wrote: Clojure developers, would it be a good idea for Compiler.java or clojure.core/compile to check if *compile-path* exists, else throw an exception specific to that problem? I like the idea. There is a subtle problem I don't think it will catch though. The JRE appears to scan CLASSPATH only once at startup checking whether each item in it is actually a viable jar file or directory. If a path appears in CLASSPATH, but does not exist at JRE startup, but does exist at compile time, compilation will still fail and it will still be very hard to figure out why. Perhaps this is a case for speculation in the error message: - Exception: Compilation target directory doesn't exist - Exception: Compilation target directory exists, but load-after- compile failed, did it exist when the JVM was launched? (assuming the latter is detectable) --Steve smime.p7s Description: S/MIME cryptographic signature
Re: writing bytes to a file
clojure.contrib.duck_streams/spit? On Wed, Jan 7, 2009 at 2:14 PM, Brian Doyle wrote: > I couldn't find anything in core or contrib that wrote out > bytes to a file so I wrote something to do it. Is this > functionality already implemented and I just couldn't find > it? If there isn't anything already, would this be something > good to put in contrib somewhere? Thanks. > >(defn write-bytes > "Writes the bytes from the in-stream to the given filename." > [#^java.io.InputStream in-stream #^String filename] > (with-open [out-stream (new FileOutputStream filename)] >(let [buffer (make-array (Byte/TYPE) 4096)] > (loop [bytes (.read in-stream buffer)] >(if (not (neg? bytes)) > (do >(.write out-stream buffer 0 bytes) >(recur (.read in-stream buffer > > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
writing bytes to a file
I couldn't find anything in core or contrib that wrote out bytes to a file so I wrote something to do it. Is this functionality already implemented and I just couldn't find it? If there isn't anything already, would this be something good to put in contrib somewhere? Thanks. (defn write-bytes "Writes the bytes from the in-stream to the given filename." [#^java.io.InputStream in-stream #^String filename] (with-open [out-stream (new FileOutputStream filename)] (let [buffer (make-array (Byte/TYPE) 4096)] (loop [bytes (.read in-stream buffer)] (if (not (neg? bytes)) (do (.write out-stream buffer 0 bytes) (recur (.read in-stream buffer --~--~-~--~~~---~--~~ 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: File organization & bootstrapping
On Wed, Jan 7, 2009 at 1:45 PM, Greg Harman wrote: > > Bingo - *compile-path* was a relative dir. Defining it as the full > path did the trick. > > Thanks! > > > Also, make sure the directory named by *compile-path* exists on the file > > system. Compilation creates subdirs, but not *compile-path* itself. > You're welcome! Clojure developers, would it be a good idea for Compiler.java or clojure.core/compile to check if *compile-path* exists, else throw an exception specific to that problem? 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: File organization & bootstrapping
Bingo - *compile-path* was a relative dir. Defining it as the full path did the trick. Thanks! > Also, make sure the directory named by *compile-path* exists on the file > system. Compilation creates subdirs, but not *compile-path* itself. --~--~-~--~~~---~--~~ 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: delimiter and capitalization for clojure-contrib?
Works for me. I am going to go with clojure-contrib if nobody pushes strongly for something else. Maybe I'll even commit a README file. :-) Stuart > On Wed, Jan 7, 2009 at 9:45 AM, Stuart Halloway > wrote: >> >> Is there a definitive delimiter and capitalization for the name >> "clojure-contrib"? I have seen space, hyphen, and dot as a delimiter, >> plus several different takes on capitalization. >> >> Sorry to be a pedant, but copyeditors are tough opponents. :-) > > I make no claims that this is Correct, but I use "clojure-contrib" as > the project name, which matches the URL of the project, the name of > the directory where I check out the repo, the title at the top of the > code.google page, etc. But of course the namespace is > "clojure.contrib" and the files are in "clojure/contrib" (in my case > "clojure-contrib/src/clojure/contrib") I've never felt the urge to > capitalize any of it. > > --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: File organization & bootstrapping
On Wed, Jan 7, 2009 at 12:34 PM, Greg Harman wrote: > > This is frustrating - with a fresh REPL I'm back to the compile > problem. I can't think of anything I changed that would cause it to > work intermittently, and I don't know what file it's looking for... > the source files are on the classpath (it "require"s just fine) and > the directory in *compile-path* is also on the cp (via add- > classpath). > > It's not the "load" operation that caused it - I removed that entirely > and just put a placeholder (defn foo [] true), and the compilation > still crashes on this line. > Are your files still called package1/foo.clj and package2/bar.clj? If so you would need to (compile 'package1.foo) and (compile 'package2.bar). Also, make sure the directory named by *compile-path* exists on the file system. Compilation creates subdirs, but not *compile-path* itself. 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: nested transactions
So nested transactions only keep track of nesting level similar to that in Sybase? Sun On Jan 7, 12:18 pm, Rich Hickey wrote: > On Jan 7, 12:07 pm, "Mark Volkmann" wrote: > > > Are there any particular issues with using nested transactions ... > > dosync inside a dosync ... in Clojure? > > Nope. Just note that nested transactions 'join' the enclosing > transaction - they commit with it. Essentially there is only the > outermost transaction. > > 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 -~--~~~~--~~--~--~---
Re: File organization & bootstrapping
> One solution would be to load a single file and then have that file use > add-classpath to set the classpath, but add-classpath is unreliable; > I've had problems getting it to work consistently and have been told in > #clojure that I shouldn't be using it. Possibly the cause of the compile problem I had in my last message(s)? I'll dig around and see if I can find that thread & understand what the issue with add-classpath is. > My solution for the time being is to always launch via SLIME and > consider that method of launching it canonical, essentially deprecating > the method of launching it from the shell. But obviously this is not > ideal because for some reason not everyone uses Emacs. =) Clearly the > classpath belongs in the codebase so it can be used independently of how > the application was launched. Beyond not using emacs, if you want something that's deployable in a server environment and not just on a development box it has to run with no human intervention ala emacs bootstrapping. I realize that emacs could be configured to automatically launch the clojure app, but that seems too hokey for a real production deployment. -Greg --~--~-~--~~~---~--~~ 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: File organization & bootstrapping
This is frustrating - with a fresh REPL I'm back to the compile problem. I can't think of anything I changed that would cause it to work intermittently, and I don't know what file it's looking for... the source files are on the classpath (it "require"s just fine) and the directory in *compile-path* is also on the cp (via add- classpath). It's not the "load" operation that caused it - I removed that entirely and just put a placeholder (defn foo [] true), and the compilation still crashes on this line. On Jan 7, 10:17 am, Greg Harman wrote: > Nevermind, with a fresh start today (and perhaps more importantly, > perhaps, a fresh environment) compiling seems to work fine. --~--~-~--~~~---~--~~ 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: atom swap! and retry
On Jan 7, 12:11 pm, "Mark Volkmann" wrote: > What is it that triggers the function passed to swap! to be retried? > Is it that some other thread has modified the atom since swap! was > invoked, but before the function passed to swap! returns? > > -- I think that's described pretty well here: http://clojure.org/atoms 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 -~--~~~~--~~--~--~---
Re: nested transactions
On Jan 7, 12:07 pm, "Mark Volkmann" wrote: > Are there any particular issues with using nested transactions ... > dosync inside a dosync ... in Clojure? > Nope. Just note that nested transactions 'join' the enclosing transaction - they commit with it. Essentially there is only the outermost transaction. 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 -~--~~~~--~~--~--~---
atom swap! and retry
What is it that triggers the function passed to swap! to be retried? Is it that some other thread has modified the atom since swap! was invoked, but before the function passed to swap! returns? -- 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 -~--~~~~--~~--~--~---
Simple example of using postgresql with contrib.sql...
This was going to be a question but I solved it before I finished the post :) Figured I might post the solution then, hopefully it will help someone else. (import '(java.sql Connection DriverManager ResultSet SQLException Statement ResultSetMetaData)) (import '(org.postgresql Driver)) (defn connect-postgresql [] (let [name "jdbc:postgresql://localhost:5432/flonk"] (DriverManager/getConnection name "postgres" "qwerasdf"))) (defn connect-postgresql2 [] (let [name "jdbc:postgresql://localhost/test"] (DriverManager/getConnection name "postgres" "qwerasdf"))) (connect-postgresql) that establishes a connection(both examples work). How would I do it with contrib.sql? First create a db with with postgresql(pgadmin3 makes this very easy). then connect and manipulate with the following, given that you named the database flonk. (ns progs.netflix.db (:require (clojure.contrib [sql :as sql])) (:require (clojure.contrib.sql [internal :as internal]))) (load-file "C:/clojure/user.clj") (def db {:classname "org.postgresql.Driver" :subprotocol "postgresql" :subname "//localhost/flonk" :user "postgres" :password "1234qwer" }) (defn drop-deleta [] (try (sql/drop-table :deleta) (catch Exception e))) (defn create-and-drop-previous [] (sql/with-connection db (sql/transaction (drop-deleta --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
nested transactions
Are there any particular issues with using nested transactions ... dosync inside a dosync ... in Clojure? -- 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: metadata question
On Jan 7, 10:37 am, Rich Hickey wrote: > On Jan 7, 1:01 am, "rzeze...@gmail.com" wrote: > > > Looking at how the #^ macro is used in core.clj confuses me even more. > > > For example: > > > user=> (def #^{:arglist '([name]) :doc "Say hello."} hello (fn hello > > [name] (println (str "Hello, " name > > #'user/hello > > user=> (hello "ryan") > > Hello, ryan > > nil > > > I mean I kind of follow it, but not totally. Is this macro explained > > somewhere? > > This might help: > > http://groups.google.com/group/clojure/msg/919455504c57659e > > Rich Perfect! Thanks Rich. I actually read over this thread before but completely forgot about it (this group has really picked up steam over the last couple of months). Next time I'll try searching the group more, rather than adding more noise. However, I will reiterate the last threads conclusion. #^ is not a macro for with-meta. That is what I think tripped me up. I may still not understand the full power of #^, but as long as I remember it's not sugar for with-meta than I should at least avoid shooting myself in the foot. -Ryan --~--~-~--~~~---~--~~ 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: per-defmulti hierarchies
Hi Rich, Am 07.01.2009 um 17:10 schrieb Rich Hickey: Thanks Meikel. I have a couple of points: First, making derive and underive act on vars instead of the hierarchies directly is not good - it reduces the generality needlessly. Good practice is to make pure fns, then do the reference part, not mix the two. Second, there's no reason to bind MultiFn to Var - any IRef will do. Then people can put their hierarchies in Atoms/Refs or whatever. Third, I don't see the need for defhierarchy at this point. Ok. My problem is, that passing the hierarchy directly doesn't allow adding further derivations. The only idea I had, was to use Vars. I didn't like the idea, but I couldn't come up with another one. The solution is again an abstraction: IRef. Changing (un)derive and adding defhierarchy, was just some try to help the user with the limitations of this approach. But (dosync (alter ref-to-hierarchy derive ::Foo ::Bar)) works perfectly. :) Much cleaner indeed. This shows again: ugly solutions and special cases are a sign, that one does it wrong... Please find attached another patch going for IRef instead of Var directly. And without the other cruft. Sincerely Meikel issue-8b.diff Description: Binary data smime.p7s Description: S/MIME cryptographic signature
Re: delimiter and capitalization for clojure-contrib?
On Wed, Jan 7, 2009 at 9:45 AM, Stuart Halloway wrote: > > Is there a definitive delimiter and capitalization for the name > "clojure-contrib"? I have seen space, hyphen, and dot as a delimiter, > plus several different takes on capitalization. > > Sorry to be a pedant, but copyeditors are tough opponents. :-) I make no claims that this is Correct, but I use "clojure-contrib" as the project name, which matches the URL of the project, the name of the directory where I check out the repo, the title at the top of the code.google page, etc. But of course the namespace is "clojure.contrib" and the files are in "clojure/contrib" (in my case "clojure-contrib/src/clojure/contrib") I've never felt the urge to capitalize any of it. --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: per-defmulti hierarchies
On Jan 5, 4:56 pm, Meikel Brandmeyer wrote: > Dear Clojurians, > > This patch allows multimethods to use different hierarchies, than > the global hierarchy for use with isa?. Currently only the global > hierarchy is possible. > > The patch extends the MultiFn class to accept also a Var pointing > to a hierarchy. The rationale is, that otherwise the multimethod > cannot be extended with derivation after it's definition. Hence > it cannot receive the hierarchy directly. > > To promote that every hierarchy must be a Var, derive and underive > are modified to act on vars instead of the hierarchies directly. > Furthermore the convenience macros defhierarchy and defhierarchy- > are provided, which define new hierarchies with optional docstring > support and automatic initialisation with make-hierarchy. > > This is listed as a "hot" item in the Todo list and is connected > tohttp://code.google.com/p/clojure/issues/detail?id=8. > In fact the patch there is needed as a prerequisite. > > Example of usage: > > (defhierarchy our-hierarchy >"This is a dedicated hierarchy for our own purposes!") > > ; Note: here we need the Var, hence the #'. > ; Should this be handled via a macro? > (derive #'our-hierarchy :xxx :yyy) > > (defmulti foo identity :hierarchy our-hierarchy) > > (defmethod foo :yyy >[x] >(println "We are in" :yyy "but got" x)) > > Comments and feedback appreciated. > Thanks Meikel. I have a couple of points: First, making derive and underive act on vars instead of the hierarchies directly is not good - it reduces the generality needlessly. Good practice is to make pure fns, then do the reference part, not mix the two. Second, there's no reason to bind MultiFn to Var - any IRef will do. Then people can put their hierarchies in Atoms/Refs or whatever. Third, I don't see the need for defhierarchy at this point. 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 -~--~~~~--~~--~--~---
Re: what's wrong with this?
typo... and looks working... should be (println (format "%s %d" s i))) On Jan 7, 10:44 am, wubbie wrote: > Hi all, > > I'm attempting to provide 2 type hints here and not working... > > (defn my-fn [#^String s #^Integer i] (println format("%s %d" s i))) > (my-fn "hello" (new Integer 123)) > > Thanks > Sun --~--~-~--~~~---~--~~ 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's wrong with this?
Try: (defn my-fn [#^String s #^Integer i] (println (format"%s %d" s i))) #'user/my-fn user=> (my-fn 1 "foo") java.util.IllegalFormatConversionException: d != java.lang.String (NO_SOURCE_FILE:0) user=> (my-fn "foo" 1) foo 1 Stuart > > Hi all, > > I'm attempting to provide 2 type hints here and not working... > > (defn my-fn [#^String s #^Integer i] (println format("%s %d" s i))) > (my-fn "hello" (new Integer 123)) > > Thanks > Sun > > > --~--~-~--~~~---~--~~ 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: Agent thread pool OOM
On Jan 7, 2:14 am, durka wrote: > I ran to into some strange agent behavior today that may be a bug. An > agent apparently exhausted the JVM available memory and threw an > OutOfMemoryError -- but it didn't go anywhere. I saw the error in the > console, but I couldn't get at it from the REPL: agent-errors still > returned nil and .getQueueCount still returned 1. > clojure.contrib.stacktrace/e did not report it as the most recent > exception. What's more, the agent is now a "zombie" in that subsequent > sends fail silently (they do inc the queue count, but it seems the > memory-eating action is stuck). Chouser has a succinct test case > athttp://paste.lisp.org/display/73224, with my annotations. > Fixed (svn 1198) - thanks for the report. 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 -~--~~~~--~~--~--~---
what's wrong with this?
Hi all, I'm attempting to provide 2 type hints here and not working... (defn my-fn [#^String s #^Integer i] (println format("%s %d" s i))) (my-fn "hello" (new Integer 123)) Thanks Sun --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Agent thread pool OOM
I ran to into some strange agent behavior today that may be a bug. An agent apparently exhausted the JVM available memory and threw an OutOfMemoryError -- but it didn't go anywhere. I saw the error in the console, but I couldn't get at it from the REPL: agent-errors still returned nil and .getQueueCount still returned 1. clojure.contrib.stacktrace/e did not report it as the most recent exception. What's more, the agent is now a "zombie" in that subsequent sends fail silently (they do inc the queue count, but it seems the memory-eating action is stuck). Chouser has a succinct test case at http://paste.lisp.org/display/73224, with my annotations. Alex --~--~-~--~~~---~--~~ 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: File organization & bootstrapping
> I think you may be working at too low a level with "load". You should > be able to accomplish the same thing with: > > (ns my-app > (:require package1 package2)) > > (package2/start-app) > > my_app, package1, and package2 all need to be immediately under a > directory (or JAR file) on the Java classpath. Also check out the Ant > build.xml files from Clojure core and clojure-contrib. The problem with this is that now you have to repeat your classpath in two places: your SLIME config and the shell script that you use to launch your app. This is a DRY[1] violation. One solution would be to load a single file and then have that file use add-classpath to set the classpath, but add-classpath is unreliable; I've had problems getting it to work consistently and have been told in #clojure that I shouldn't be using it. My solution for the time being is to always launch via SLIME and consider that method of launching it canonical, essentially deprecating the method of launching it from the shell. But obviously this is not ideal because for some reason not everyone uses Emacs. =) Clearly the classpath belongs in the codebase so it can be used independently of how the application was launched. There's got to be a way around this problem, but I haven't found it yet. -Phil [1] - http://en.wikipedia.org/wiki/Don%27t_repeat_yourself --~--~-~--~~~---~--~~ 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: metadata question
On Jan 7, 1:01 am, "rzeze...@gmail.com" wrote: > Looking at how the #^ macro is used in core.clj confuses me even more. > > For example: > > user=> (def #^{:arglist '([name]) :doc "Say hello."} hello (fn hello > [name] (println (str "Hello, " name > #'user/hello > user=> (hello "ryan") > Hello, ryan > nil > > I mean I kind of follow it, but not totally. Is this macro explained > somewhere? > This might help: http://groups.google.com/group/clojure/msg/919455504c57659e 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 -~--~~~~--~~--~--~---
Re: yet another Clojure snake
On Wed, Jan 7, 2009 at 8:52 AM, Christophe Grand wrote: > > Mark Volkmann a écrit : >> I'd >> really like to find a way to get rid of that global variable, but I >> haven't been able to. > You can pass an atom (locally defined in main) to create-panel, and pass > it to your step function. Thanks! I've made that change. See http://www.ociweb.com/mark/programming/ClojureSnake.html. No more globals! -- 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: File organization & bootstrapping
Nevermind, with a fresh start today (and perhaps more importantly, perhaps, a fresh environment) compiling seems to work fine. > It works for "require" and for calling functions in the package(s), > but the problem now is that it doesn't work for AOT from the REPL. > > (compile 'package1) crashes with: > > java.io.IOException: No such file or directory (package.clj:4) > > Where line 4 is the first "load" operation (and the load works fine if > I execute it directly). If I remove the load operation altogether as a > test (making a single-file package), now I get: > > java.io.IOException: No such file or directory (NO_SOURCE_FILE:0) > > As far as I can tell, this is now identical to the example that Rich > gave in one of the two threads that I referenced in my earlier post. > I'm not really sure how go about tracing "NO_SOURCE_FILE:0"... --~--~-~--~~~---~--~~ 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: yet another Clojure snake
On Wed, Jan 7, 2009 at 3:13 AM, Tom Ayerst wrote: > Hi Mark, > > I'm afraid I don't like the "big let" style and I found it hard to follow > some of your code, that may just be a personal thing but a lot of the vars > defined in let are only used once and could be inlined. I agree they could be inlined, but I find that style easier to read. For example, these are equivalent. (defn make-cookies-1 [flower baking-soda salt button sugar eggs] ; let describes the step-by-step process for making cookies. (let [bowl (find-bowl :small) bowl (add-ingredients bowl flower baking-soda salt) batter (mix bowl) batter (add-and-beat batter eggs flour) baking-sheet (find-baking-sheet) baking-sheet (make-dough-balls baking-sheet batter)] (bake baking-sheet))) (def make-cookies-2 [flower baking-soda salt button sugar eggs] (bake (make-dough-balls (find-baking-sheet) (add-and-beat (mix (add-ingredients (find-bowl) flower aking-soda salt) eggs flour Which of these is easier to understand? > I do like the state loop approach but I don't see why you need that global. If you see a way to get rid of it, I'd gladly do that. I just don't see a way yet. -- 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: yet another Clojure snake
Mark Volkmann a écrit : > I'd > really like to find a way to get rid of that global variable, but I > haven't been able to. You can pass an atom (locally defined in main) to create-panel, and pass it to your step function. 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: yet another Clojure snake
On Wed, Jan 7, 2009 at 3:13 AM, Tom Ayerst wrote: > Hi Mark, > > I think the def inside a defn has to go, it looks like an accident in waiting. I'm not sure about that. The value last-key-code is only set in the keyPressed method which is invoked when Swing/AWT detects that the user pressed a key. It is only used in the snake-with-key-direction function. After using the value, that function resets it to nil. I understand the desire to avoid global variables whenever possible. I'd really like to find a way to get rid of that global variable, but I haven't been able to. However, in this case I'm having trouble imagining a scenario where something bad can happen. Can anyone think of such a scenario? What would be a better way to capture and use the last key code? -- 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: yet another Clojure snake
On Wed, Jan 7, 2009 at 3:13 AM, Tom Ayerst wrote: > Hi Mark, > > I think you are replacing globals with a "god" structure (game) which passed > to every function, I think you need to abstract more. That's definitely what I'm doing and I don't like it either. I just haven't worked out a better alternative yet. Some of the functions use many parts of the game state, so for those it seems appropriate to just pass the game rather than a large number of arguments extracted from the game. For other functions that don't use very many pars of game, maybe I should use more parameters. For example, (defn win? [game] (let [snake (game :snake) body (snake :body)] (= (count body) (game :length-to-win Would you recommend that I change it to this and make the caller pass two parameters? (defn win? [snake length-to-win] (= (count (snake :body) (game length-to-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: Cons.count overflows stack (with patch)
On Wed, Jan 7, 2009 at 2:10 PM, Chouser wrote: > > On Wed, Jan 7, 2009 at 2:41 AM, Christian Vest Hansen > wrote: >> >> On Wed, Jan 7, 2009 at 5:26 AM, Chouser wrote: >>> Since I couldn't find any other class that uses this kind of >>> recursion for count(), it may be impossible to build a seq that >>> would still cause Cons.count() to overflow the stack, but I'm not >>> completely certain. >> >> We're all allowed to implement our own IPersistentCollections, but if >> they break 'count, then that would be a different bug, no? > > Good question. > > If your new collection (FooColl) implements seq() by returning a new > kind of Seq (FooColl$Seq) which in turn implements FooColl$Seq.count() > recursively as Cons did, it will break for long chains of FooColl$Seq. > This already strikes me as very unlikely, because it would only be > tempting to do in collections that accept an unmodified ISeq as part > of their contents. But regardless, this would be entirely your own > new code and there's nothing I can do about it. > > However, if FooColl$Seq avoids that error by using code like in this > patch, then we would have a more subtle issue. A FooColl$Seq that > includes a Cons which in turn was cons'ed onto a FooColl$Seq that > includes a Cons ... and continues alternating like that for sufficient > depth would defeat this patch's fix. Cons.count() would see that it's > 'rest' is not a Cons, and would delegate to RT.count(). FooColl$Seq, > doing the same, would create a mutual recursion situation that could > overflow the stack. > > I think we're now firmly off in the weeds far enough to declare "we > can cross that bridge when we get to it," happy in the belief that we > never will. But even so, FooColl$Seq could push things a little > further by checking for Cons *or* FooColl$Seq and avoid recursing into > either one. This would then postpone the problem until someone makes > an alternating chain of FooColl$Seq and BarColl$Seq. Or those people doing tricksy stuff like this could make a careful and considered decision to design their Seq types such that they are kinds of Cons, which, logically, I'd say they are. But considering your patch, my spidey-senses have also failed to unearth a way to use this approach to blow the stack. > > I suppose the right way to handle this would be a signal Interface (or > perhaps just a method?) declaring if a seq's count() is "fast" or not. > Then Cons.count() could check this: if 'rest' is fast, defer to > RT.count(), otherwise inc in it's own loop. This sounds to me like a > lot of work and a big patch for a problem nobody's likely to have. And when it does happen in a couple of years time, we can point to this discussion and ask the guy to kindly provide a patch :-P it reminds of a JRE bug that remain undescovered for something like five years, until someone had the audacity to try and Arrays.sort an array larger than half of Integer.MAX_VALUE :) > > --Chouser > > > > -- 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 -~--~~~~--~~--~--~---
delimiter and capitalization for clojure-contrib?
Is there a definitive delimiter and capitalization for the name "clojure-contrib"? I have seen space, hyphen, and dot as a delimiter, plus several different takes on capitalization. Sorry to be a pedant, but copyeditors are tough opponents. :-) Thanks, 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: yet another Clojure snake
On Wed, Jan 7, 2009 at 12:55 AM, Emeka wrote: > > Hello, > > Why not changing defns create-apple and create-snake to defs create-apple > and snake-create.Your defns have no args that why I feel strongly that they > should def, well I may be wrong. The newest version of my code only has one defn that takes no arguments and that is main. You can't just change defn to def when their are no arguments. def only defines a function if you write it something like this. (def millis (fn [] (System/currentTimeMillis))) -- 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: Very noob file reading and printing question
Oops, sorry Paul (In your favour I expect people can probably pronounce your surname! ;-) Cheers Tom 2009/1/7 Paul Barry > No Problem Ayerst :) Just kidding, people call me Barry all the time, even > though my first name is Paul. That's the curse of having 2 first names I > guess. > > > On Wed, Jan 7, 2009 at 8:17 AM, Tom Ayerst wrote: > >> Thanks Barry, I now see what I did. >> >> I tried doseq early but it didn't print anything. I had: >> (with-open [r (reader "doc.txt")] >>(doseq [line (line-seq r)] println line)) >> >> so I wasn't evaluating the println. >> >> Cheers >> >> Tom >> >> 2009/1/7 Paul Barry >> >> Here's a little cleaner version using doseq: >>> (use 'clojure.contrib.duck-streams) >>> >>> (with-open [r (reader "doc.txt")] >>> (doseq [line (line-seq r)] (println line))) >>> >>> >>> On Wed, Jan 7, 2009 at 7:27 AM, Tom Ayerst wrote: >>> Thanks Brian. I finally nailed it with: (use '[clojure.contrib.duck-streams :only (reader)]) (with-open [r (reader "doc.txt")] (dorun (for [line (line-seq r)] (do (println line) Cheers Tom 2009/1/6 Brian Doyle > On Tue, Jan 6, 2009 at 4:47 PM, Tom Ayerst wrote: > >> Its not the println, nor getting a reader (duckstreams is fine, I can >> do that). Its the converting it to a seq and stepping through it printing >> each element (which should be a line). Its the loopy, steppy bit, just >> for a >> side effect; that I am messing up. >> >> Cheers >> >> Tom > > > I've done this type of thing and it worked great for me. > >(with-open [r (clojure.contrib.duck-streams/reader > "filename.txt")] >(doseq [line (line-seq r)] >; do stuff with the line here > )) > > Basically you'll want to use the line-seq function. Hopefully that > helps. > > >> 2009/1/6 Mark Volkmann >> >> >>> On Tue, Jan 6, 2009 at 5:26 PM, Tom Ayerst >>> wrote: >>> > Hi, >>> > >>> > How do I read and print a text file? I can read it, its the >>> printing that >>> > is the problem, I feel it should be obvious but I keep tripping >>> myself up. >>> > (The context is I need to extract data line by line, translate the >>> line >>> > format and save it for a legacy app) >>> >>> Do you just need to print to stdout? >>> The println function does that. It puts a space between the output of >>> each of its arguments. If you don't want that you can use the str >>> function to concatenate a bunch of string values together. >>> If you need something fancier, don't forget that you can access >>> everything in java.io from Clojure. >>> >>> -- >>> 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: Very noob file reading and printing question
No Problem Ayerst :) Just kidding, people call me Barry all the time, even though my first name is Paul. That's the curse of having 2 first names I guess. On Wed, Jan 7, 2009 at 8:17 AM, Tom Ayerst wrote: > Thanks Barry, I now see what I did. > > I tried doseq early but it didn't print anything. I had: > (with-open [r (reader "doc.txt")] >(doseq [line (line-seq r)] println line)) > > so I wasn't evaluating the println. > > Cheers > > Tom > > 2009/1/7 Paul Barry > > Here's a little cleaner version using doseq: >> (use 'clojure.contrib.duck-streams) >> >> (with-open [r (reader "doc.txt")] >> (doseq [line (line-seq r)] (println line))) >> >> >> On Wed, Jan 7, 2009 at 7:27 AM, Tom Ayerst wrote: >> >>> Thanks Brian. >>> >>> I finally nailed it with: >>> >>> (use '[clojure.contrib.duck-streams :only (reader)]) >>> >>> (with-open [r (reader "doc.txt")] >>>(dorun >>> (for [line (line-seq r)] (do (println line) >>> >>> Cheers >>> >>> Tom >>> >>> 2009/1/6 Brian Doyle >>> >>> On Tue, Jan 6, 2009 at 4:47 PM, Tom Ayerst wrote: > Its not the println, nor getting a reader (duckstreams is fine, I can > do that). Its the converting it to a seq and stepping through it printing > each element (which should be a line). Its the loopy, steppy bit, just > for a > side effect; that I am messing up. > > Cheers > > Tom I've done this type of thing and it worked great for me. (with-open [r (clojure.contrib.duck-streams/reader "filename.txt")] (doseq [line (line-seq r)] ; do stuff with the line here )) Basically you'll want to use the line-seq function. Hopefully that helps. > 2009/1/6 Mark Volkmann > > >> On Tue, Jan 6, 2009 at 5:26 PM, Tom Ayerst >> wrote: >> > Hi, >> > >> > How do I read and print a text file? I can read it, its the >> printing that >> > is the problem, I feel it should be obvious but I keep tripping >> myself up. >> > (The context is I need to extract data line by line, translate the >> line >> > format and save it for a legacy app) >> >> Do you just need to print to stdout? >> The println function does that. It puts a space between the output of >> each of its arguments. If you don't want that you can use the str >> function to concatenate a bunch of string values together. >> If you need something fancier, don't forget that you can access >> everything in java.io from Clojure. >> >> -- >> 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: Very noob file reading and printing question
Thanks Barry, I now see what I did. I tried doseq early but it didn't print anything. I had: (with-open [r (reader "doc.txt")] (doseq [line (line-seq r)] println line)) so I wasn't evaluating the println. Cheers Tom 2009/1/7 Paul Barry > Here's a little cleaner version using doseq: > (use 'clojure.contrib.duck-streams) > > (with-open [r (reader "doc.txt")] > (doseq [line (line-seq r)] (println line))) > > > On Wed, Jan 7, 2009 at 7:27 AM, Tom Ayerst wrote: > >> Thanks Brian. >> >> I finally nailed it with: >> >> (use '[clojure.contrib.duck-streams :only (reader)]) >> >> (with-open [r (reader "doc.txt")] >>(dorun >> (for [line (line-seq r)] (do (println line) >> >> Cheers >> >> Tom >> >> 2009/1/6 Brian Doyle >> >> >>> On Tue, Jan 6, 2009 at 4:47 PM, Tom Ayerst wrote: >>> Its not the println, nor getting a reader (duckstreams is fine, I can do that). Its the converting it to a seq and stepping through it printing each element (which should be a line). Its the loopy, steppy bit, just for a side effect; that I am messing up. Cheers Tom >>> >>> >>> I've done this type of thing and it worked great for me. >>> >>>(with-open [r (clojure.contrib.duck-streams/reader >>> "filename.txt")] >>>(doseq [line (line-seq r)] >>>; do stuff with the line here >>> )) >>> >>> Basically you'll want to use the line-seq function. Hopefully that >>> helps. >>> >>> 2009/1/6 Mark Volkmann > On Tue, Jan 6, 2009 at 5:26 PM, Tom Ayerst > wrote: > > Hi, > > > > How do I read and print a text file? I can read it, its the printing > that > > is the problem, I feel it should be obvious but I keep tripping > myself up. > > (The context is I need to extract data line by line, translate the > line > > format and save it for a legacy app) > > Do you just need to print to stdout? > The println function does that. It puts a space between the output of > each of its arguments. If you don't want that you can use the str > function to concatenate a bunch of string values together. > If you need something fancier, don't forget that you can access > everything in java.io from Clojure. > > -- > 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: Very noob file reading and printing question
Here's a little cleaner version using doseq: (use 'clojure.contrib.duck-streams) (with-open [r (reader "doc.txt")] (doseq [line (line-seq r)] (println line))) On Wed, Jan 7, 2009 at 7:27 AM, Tom Ayerst wrote: > Thanks Brian. > > I finally nailed it with: > > (use '[clojure.contrib.duck-streams :only (reader)]) > > (with-open [r (reader "doc.txt")] >(dorun > (for [line (line-seq r)] (do (println line) > > Cheers > > Tom > > 2009/1/6 Brian Doyle > > >> On Tue, Jan 6, 2009 at 4:47 PM, Tom Ayerst wrote: >> >>> Its not the println, nor getting a reader (duckstreams is fine, I can do >>> that). Its the converting it to a seq and stepping through it printing each >>> element (which should be a line). Its the loopy, steppy bit, just for a side >>> effect; that I am messing up. >>> >>> Cheers >>> >>> Tom >> >> >> I've done this type of thing and it worked great for me. >> >>(with-open [r (clojure.contrib.duck-streams/reader "filename.txt")] >>(doseq [line (line-seq r)] >>; do stuff with the line here >> )) >> >> Basically you'll want to use the line-seq function. Hopefully that helps. >> >> >>> 2009/1/6 Mark Volkmann >>> >>> On Tue, Jan 6, 2009 at 5:26 PM, Tom Ayerst wrote: > Hi, > > How do I read and print a text file? I can read it, its the printing that > is the problem, I feel it should be obvious but I keep tripping myself up. > (The context is I need to extract data line by line, translate the line > format and save it for a legacy app) Do you just need to print to stdout? The println function does that. It puts a space between the output of each of its arguments. If you don't want that you can use the str function to concatenate a bunch of string values together. If you need something fancier, don't forget that you can access everything in java.io from Clojure. -- 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: Cons.count overflows stack (with patch)
On Wed, Jan 7, 2009 at 2:41 AM, Christian Vest Hansen wrote: > > On Wed, Jan 7, 2009 at 5:26 AM, Chouser wrote: >> Since I couldn't find any other class that uses this kind of >> recursion for count(), it may be impossible to build a seq that >> would still cause Cons.count() to overflow the stack, but I'm not >> completely certain. > > We're all allowed to implement our own IPersistentCollections, but if > they break 'count, then that would be a different bug, no? Good question. If your new collection (FooColl) implements seq() by returning a new kind of Seq (FooColl$Seq) which in turn implements FooColl$Seq.count() recursively as Cons did, it will break for long chains of FooColl$Seq. This already strikes me as very unlikely, because it would only be tempting to do in collections that accept an unmodified ISeq as part of their contents. But regardless, this would be entirely your own new code and there's nothing I can do about it. However, if FooColl$Seq avoids that error by using code like in this patch, then we would have a more subtle issue. A FooColl$Seq that includes a Cons which in turn was cons'ed onto a FooColl$Seq that includes a Cons ... and continues alternating like that for sufficient depth would defeat this patch's fix. Cons.count() would see that it's 'rest' is not a Cons, and would delegate to RT.count(). FooColl$Seq, doing the same, would create a mutual recursion situation that could overflow the stack. I think we're now firmly off in the weeds far enough to declare "we can cross that bridge when we get to it," happy in the belief that we never will. But even so, FooColl$Seq could push things a little further by checking for Cons *or* FooColl$Seq and avoid recursing into either one. This would then postpone the problem until someone makes an alternating chain of FooColl$Seq and BarColl$Seq. I suppose the right way to handle this would be a signal Interface (or perhaps just a method?) declaring if a seq's count() is "fast" or not. Then Cons.count() could check this: if 'rest' is fast, defer to RT.count(), otherwise inc in it's own loop. This sounds to me like a lot of work and a big patch for a problem nobody's likely to have. --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: Very noob file reading and printing question
Thanks Brian. I finally nailed it with: (use '[clojure.contrib.duck-streams :only (reader)]) (with-open [r (reader "doc.txt")] (dorun (for [line (line-seq r)] (do (println line) Cheers Tom 2009/1/6 Brian Doyle > > On Tue, Jan 6, 2009 at 4:47 PM, Tom Ayerst wrote: > >> Its not the println, nor getting a reader (duckstreams is fine, I can do >> that). Its the converting it to a seq and stepping through it printing each >> element (which should be a line). Its the loopy, steppy bit, just for a side >> effect; that I am messing up. >> >> Cheers >> >> Tom > > > I've done this type of thing and it worked great for me. > >(with-open [r (clojure.contrib.duck-streams/reader "filename.txt")] >(doseq [line (line-seq r)] >; do stuff with the line here > )) > > Basically you'll want to use the line-seq function. Hopefully that helps. > > >> 2009/1/6 Mark Volkmann >> >> >>> On Tue, Jan 6, 2009 at 5:26 PM, Tom Ayerst wrote: >>> > Hi, >>> > >>> > How do I read and print a text file? I can read it, its the printing >>> that >>> > is the problem, I feel it should be obvious but I keep tripping myself >>> up. >>> > (The context is I need to extract data line by line, translate the line >>> > format and save it for a legacy app) >>> >>> Do you just need to print to stdout? >>> The println function does that. It puts a space between the output of >>> each of its arguments. If you don't want that you can use the str >>> function to concatenate a bunch of string values together. >>> If you need something fancier, don't forget that you can access >>> everything in java.io from Clojure. >>> >>> -- >>> 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: Support for new bee
Chris and Chris Thanks On Wed, Jan 7, 2009 at 9:09 AM, Christophe Grand wrote: > > janus a écrit : > > It can't figure out why this is not working or was I sleeping while > > trying it out. > > > > (apply #(println %) [2 3]) > > > This line is equivalent to (#(println %) 2 3) which errors since > #(println %) takes only one argument. > user=> (macroexpand '#(println %)) > (fn* [p1__3493] (println p1__3493)) > > Depending on what you were trying to achieve, you could have written: > (apply println [2 3]) ; same as (println 2 3) > (apply #(println %) [2 3] nil) ; same as (#(println %) [2 3]) or > (println [2 3]) > (map #(println %) [2 3]) ; roughly equivalent to [(#(println %) 2) > (#(println %) 3)] or [(println 2) (println 3)] > (map println [2 3]) ; roughly equivalent to [(println 2) (println 3)] > (doseq [i [2 3]] (print i)) ; same as (do (println 2) (println 3)) > > > And, why is it that I can't do this? > > > > Instead of (let [{coin :coin :as snake}{...}][coin > > snake]) > > I tried this (let [{:coin coin :as snake}{...}][coin > > snake]) and got failure. Why is it so?(just changed the position of > > the key :coin) > > > See http://clojure.org/special_forms#toc4 "Map binding-forms [...] > consists of a map of binding-form-key pairs." > coin :coin is a binding-form-key pair while :coin coin is > key-binding-form pair. > Some pairs start with a keyword (:as, :or, :keys, :strs and :syms) but > they have a special meaning. > > Hope this helps. > > 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: yet another Clojure snake
Hi Mark, I think the def inside a defn has to go, it looks like an accident in waiting. I think you are replacing globals with a "god" structure (game) which passed to every function, I think you need to abstract more. I'm afraid I don't like the "big let" style and I found it hard to follow some of your code, that may just be a personal thing but a lot of the vars defined in let are only used once and could be inlined. I do like the state loop approach but I don't see why you need that global. Cheers Tom 2009/1/7 Mark Volkmann > > On Tue, Jan 6, 2009 at 3:07 PM, Mark Engelberg > wrote: > > > > One way to approach this without mutation is as follows: > > > > Decide on a data representation that represents the entire state of > > the game world at a given instant. > > > > Write a function which can draw this state. > > Write a function which takes the state and player keypresses as input, > > and returns a new updated state. > > Write a function which takes the state and returns the new state just > > from time elapsing. > > > > Note that none of the above functions mutate anything. It's all about > > returning fresh states, which fits well with Clojure's standard > > handling of data structures. > > > > Then write a loop that consumes an initial state, and creates a game > > experience by repeatedly applying the above functions. No globals or > > refs are required, just keep passing the new states back into the loop > > for further processing. > > > > This is an outline of the strategy employed by the "world" teachpack > > that accompanies the "How to Design Programs" curriculum that uses PLT > > Scheme. Students routinely develop the snake program as a homework > > assignment, using this approach. > > Excellent suggestions! I spent many hours today rewriting my snake > program to do this. The new version is at > http://www.ociweb.com/mark/programming/ClojureSnake.html. It doesn't > use any refs or transactions. Parts of it are greatly simplified over > what I had before. For example, creation of the JPanel proxy is > shorter. > > I only have one global remaining and can't figure out how to get rid > of it. It is the key code of the last key pressed. That gets set in > the keyPressed method of the JPanel which is a KeyListener. > > I know we're beating this into the ground, but feedback is still > welcomed. If you see anything in the code that you would do > differently, I'd be interested in hearing about it. > > -- > 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: metadata question
rzeze...@gmail.com a écrit : > Looking at how the #^ macro is used in core.clj confuses me even more. > > For example: > > user=> (def #^{:arglist '([name]) :doc "Say hello."} hello (fn hello > [name] (println (str "Hello, " name > #'user/hello > user=> (hello "ryan") > Hello, ryan > nil > > I mean I kind of follow it, but not totally. Is this macro explained > somewhere? > #^{:arglist '([name]) :doc "Say hello."} hello indeed adds the metadata to the symbol but def copies the symbol metadata to make the var metadata. http://code.google.com/p/clojure/source/browse/trunk/src/jvm/clojure/lang/Compiler.java#363 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: Support for new bee
janus a écrit : > It can't figure out why this is not working or was I sleeping while > trying it out. > > (apply #(println %) [2 3]) > This line is equivalent to (#(println %) 2 3) which errors since #(println %) takes only one argument. user=> (macroexpand '#(println %)) (fn* [p1__3493] (println p1__3493)) Depending on what you were trying to achieve, you could have written: (apply println [2 3]) ; same as (println 2 3) (apply #(println %) [2 3] nil) ; same as (#(println %) [2 3]) or (println [2 3]) (map #(println %) [2 3]) ; roughly equivalent to [(#(println %) 2) (#(println %) 3)] or [(println 2) (println 3)] (map println [2 3]) ; roughly equivalent to [(println 2) (println 3)] (doseq [i [2 3]] (print i)) ; same as (do (println 2) (println 3)) > And, why is it that I can't do this? > > Instead of (let [{coin :coin :as snake}{...}][coin > snake]) > I tried this (let [{:coin coin :as snake}{...}][coin > snake]) and got failure. Why is it so?(just changed the position of > the key :coin) > See http://clojure.org/special_forms#toc4 "Map binding-forms [...] consists of a map of binding-form-key pairs." coin :coin is a binding-form-key pair while :coin coin is key-binding-form pair. Some pairs start with a keyword (:as, :or, :keys, :strs and :syms) but they have a special meaning. Hope this helps. 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: Support for new bee
On Wed, Jan 7, 2009 at 9:03 AM, Christian Vest Hansen wrote: > You are effectively trying to do (#(println %) 1 2). Typo. I meant to write (#(println %) 2 3). -- 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: Support for new bee
On Wed, Jan 7, 2009 at 8:26 AM, janus wrote: > > It can't figure out why this is not working or was I sleeping while > trying it out. > > (apply #(println %) [2 3]) The #(println %) procedure takes only one argument (because you only have that one % in there) and you are applying it to two, namely 2 and 3. You are effectively trying to do (#(println %) 1 2). Maybe try this instead: (apply println [2 3]) > > And, why is it that I can't do this? > > Instead of (let [{coin :coin :as snake}{...}][coin > snake]) > I tried this (let [{:coin coin :as snake}{...}][coin > snake]) and got failure. Why is it so?(just changed the position of > the key :coin) Because the binding-form goes before the key when you use map-binding forms, and a keyword (:coin) cannot be used as a binding-form. > > Emeka > > > -- 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 -~--~~~~--~~--~--~---