Re: scoped local memoize
Ah, I think I have the solution: (defn foo [] (let [bar-memoized (memoize bar)] ; Do stuff with bar-memoized )) Seems to work -- to verify, this will GC the memoized cache for bar after each call to foo, right? On Mar 19, 1:56 am, Greg Fodor gfo...@gmail.com wrote: Hi there -- I am looking for a solution to a particular memoization pattern. I have a function foo that is the entry point of a caller that makes many thousands of calls to a function bar. In calling foo, bar will be called with many different args but there are many repeated calls to bar with the same args. I would like to memoize bar such that the memory used for memoization is GC'ed at the end of the call to foo, and additionally the cache used for memoization is thread local (so no need for heavyweight synchronization tools like atoms, etc.) In Ruby, I would implement this as a simple local hash with the ||= operator through each iteration of a loop inside foo that calls bar. This seems like a fairly common case, so I was wondering if there is an idiom/API to do this for me easily. Alternatively, my first guess is to write a macro that memoizes the function but allows the macro caller to name a dynamic var for the cache which can then be thread- locally bound from the caller side. When the caller var falls out of scope it should be GC'ed. If this makes sense, let me know. Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
clojure-mode-like syntax highlighting for the SLIME REPL
Hi Group, there was a Stack Overflow question recently re: syntax highlighting Clojure REPLs. This got me thinking that since I was going to tweak SLIME REPL font-lock for quite some time now (I find the default a bit too aggressive), I might as well do it now and have it use clojure-mode's font-lock settings too. Here's what I came up with: http://gist.github.com/337280 I've got some questions in connection with this. Firstly, I'd love to know whether this could be done in a simpler way. If not, then I wonder if clojure-mode could move the font-lock setup from the clojure-mode function itself to something like my clojure-font-lock-setup function and then just call that from clojure-mode? That way a usable syntax highlighting SLIME REPL would become a one hook affair. Then there's one thing I didn't try to tackle for now (because it would actually require me to write font-lock code, which is something that scares me to death), namely prompt highlighting (namespace appears in plain text for now). Is there a simple way to add this on top of clojure-mode font-lock settings? All the best, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Java method call irritation
Hi, In this particular case, his get-properties macros was a demonstration of how to write a macro, but could have been replaced with an out-of-the-box clojure.core/bean call. 2010/3/19 Per Vognsen per.vogn...@gmail.com: My experience as a newcomer to Clojure is that one of the most surprising things is the dichotomy between the Clojure and JVM world. I was reading one of Lau's blog posts on converting images to ASCII art: http://www.bestinclass.dk/index.php/2010/02/my-tribute-to-steve-ballmer His get-properties macro is only really needed because of this issue with methods. If .methods were wrapped up as clojures, you could write it directly like this: ;; General purpose function. Useful whenever you want to reverse the sense of function and arguments. (defn with-args [ args] #(apply % args)) (map (with-args (.getRGB image 10 10)) [.getRed .getGreen .getBlue]) -Per On Fri, Mar 19, 2010 at 4:30 AM, Michael Gardner gardne...@gmail.com wrote: On Mar 18, 2010, at 10:55 AM, Per Vognsen wrote: Is there any reason why a .method occurrence in non-operator position doesn't just do the closure wrapping automagically? I'd like to know this as well. Smooth Java interop is one of Clojure's selling points, but having to wrap Java methods in lambdas to use them as first-class functions feels awkward. Especially if the method in question has multiple arguments! -Michael -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: scoped local memoize
On Fri, Mar 19, 2010 at 06:56, Greg Fodor gfo...@gmail.com wrote: I would like to memoize bar such that the memory used for memoization is GC'ed at the end of the call to foo, and additionally the cache used for memoization is thread local (so no need for heavyweight synchronization tools like atoms, etc.) In Ruby, I would implement this as a simple local hash with the ||= operator through each iteration of a loop inside foo that calls bar. ;; the trick I found is to explicitly deref the var binding the ;; function to be memoized. This way fib's recursive calls will use ;; the memoized binding established in ;; use-fib-memoized-thread-locally. (defn fib [n] (if ( 2 n) n (+ (@#'fib (dec n)) (@#'fib (dec (dec n)) (defn use-fib-memoized-thread-locally [n] (binding [fib (memoize fib)] (fib n))) ;; user (time (fib 32)) ;; Elapsed time: 1755.796366 msecs ;; SLOW ;; 2178309 ;; ;; user (time (use-fib-memoized-thread-locally 32)) ;; Elapsed time: 1.514927 msecs ;; FAST ;; 2178309 ;; ;; user (time (fib 32)) ;; Elapsed time: 2024.836838 msecs ;; SLOW, again ;; 2178309 // Ben -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: scoped local memoize
Hi, On Mar 19, 7:05 am, Greg Fodor gfo...@gmail.com wrote: Ah, I think I have the solution: (defn foo [] (let [bar-memoized (memoize bar)] ; Do stuff with bar-memoized )) Seems to work -- to verify, this will GC the memoized cache for bar after each call to foo, right? Yes. I would think so. However, recursive calls in bar to itself will not be memoised! You could combine this technique however. (defn foo [] (binding [bar (memoize bar)] ...)) This will also catch recursive calls of bar to itself. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: scoped local memoize
Ah, is there any concern with pummeling that var? On Mar 19, 2:22 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On Mar 19, 7:05 am, Greg Fodor gfo...@gmail.com wrote: Ah, I think I have the solution: (defn foo [] (let [bar-memoized (memoize bar)] ; Do stuff with bar-memoized )) Seems to work -- to verify, this will GC the memoized cache for bar after each call to foo, right? Yes. I would think so. However, recursive calls in bar to itself will not be memoised! You could combine this technique however. (defn foo [] (binding [bar (memoize bar)] ...)) This will also catch recursive calls of bar to itself. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: scoped local memoize
No, it won't force a GC. But it should be eligible for GC, if that's what you mean. Hopefully the memo cache will stay in the generation-zero nursery, in which case it will incur effectively no GC cost since the nursery collector runs in time O(live objects in nursey) rather than O(total objects in nursery). In a Platonic paradise, the cache could even be allocated and freed without any GC involvement whatosever due to the magic of HotSpot's escape analysis. But that seldom works as widely in practice as one might hope and I expect it wouldn't in this example. -Per On Fri, Mar 19, 2010 at 1:05 PM, Greg Fodor gfo...@gmail.com wrote: Ah, I think I have the solution: (defn foo [] (let [bar-memoized (memoize bar)] ; Do stuff with bar-memoized )) Seems to work -- to verify, this will GC the memoized cache for bar after each call to foo, right? On Mar 19, 1:56 am, Greg Fodor gfo...@gmail.com wrote: Hi there -- I am looking for a solution to a particular memoization pattern. I have a function foo that is the entry point of a caller that makes many thousands of calls to a function bar. In calling foo, bar will be called with many different args but there are many repeated calls to bar with the same args. I would like to memoize bar such that the memory used for memoization is GC'ed at the end of the call to foo, and additionally the cache used for memoization is thread local (so no need for heavyweight synchronization tools like atoms, etc.) In Ruby, I would implement this as a simple local hash with the ||= operator through each iteration of a loop inside foo that calls bar. This seems like a fairly common case, so I was wondering if there is an idiom/API to do this for me easily. Alternatively, my first guess is to write a macro that memoizes the function but allows the macro caller to name a dynamic var for the cache which can then be thread- locally bound from the caller side. When the caller var falls out of scope it should be GC'ed. If this makes sense, let me know. Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Translation from Common Lisp 1
David, thank you. Your answer seems to be nearest possible to the origninal spirit. Obviousely the way syntax-quote is resolved qualified with a namespace makes the easier way impossible. Regards, alux On 18 Mrz., 22:17, David Nolen dnolen.li...@gmail.com wrote: On Thu, Mar 18, 2010 at 4:25 PM, alux alu...@googlemail.com wrote: Hello! I much enjoyed reading the tutorialhttp://www.lisperati.com/casting.html , mentioned by eyeris today. The most mind-extending thing (to me, having Java background) is the, admittedly non-idiomatic, use of symbols as data. But I have two translation problems, I want to pose before going to sleep (its pitch dark in Europe :). First the easy one: Common Lisp (defun describe-path (path) `(there is a ,(second path) going ,(first path) from here.)) You probably want (defn describe-path [path] `(~'there ~'is ~'a ~(second path) ~'going ~(first path) ~'from ~'here)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Translation from Common Lisp 1
But using symbols for something like this is a bit contrived anyway. Yes, But sometimes it needs contrived examples to get the message. Especially if you have misleading preconceptions. And to me, symbols had always been a way to refer to stuff. And only that. That had to be shaken an is now. (Like the old hastable example: A consistent implementation is returning a constant. Thats slow and doesnt scale, but it's consistent. To me thats been illuminating.) Many thanks to all for the discussion. alux On 18 Mrz., 23:21, Richard Newman holyg...@gmail.com wrote: But using symbols for something like this is a bit contrived anyway. Maybe, but I've seen it in other Common Lisp books/tutorials before. e.g. I'm sure PAIP was one of them. Part of the motivation is that CL symbols always compare with EQ and EQL, whilst strings are not required to do so: cl-user(9): (eq (concatenate 'string foo bar) foobar) nil This means you can use nice constructs such as CASE with symbols, but you need to roll your own using string-equal or string= to handle strings. (Using symbols also saves you typing all those double-quote characters, as well as saving memory and computation during comparison: symbols are interned, unlike strings.) In Clojure (thanks to Java's immutable interned strings) strings compare efficiently with = just like everything else, so there's less motivation. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Translation from Common Lisp 1
If you really wan't to go that way you can also choose to remove the namespaces: (defn describe-path [[where what]] (map (comp symbol name) `(there is a ~what going ~where from here.))) On Fri, Mar 19, 2010 at 8:17 AM, alux alu...@googlemail.com wrote: But using symbols for something like this is a bit contrived anyway. Yes, But sometimes it needs contrived examples to get the message. Especially if you have misleading preconceptions. And to me, symbols had always been a way to refer to stuff. And only that. That had to be shaken an is now. (Like the old hastable example: A consistent implementation is returning a constant. Thats slow and doesnt scale, but it's consistent. To me thats been illuminating.) Many thanks to all for the discussion. alux On 18 Mrz., 23:21, Richard Newman holyg...@gmail.com wrote: But using symbols for something like this is a bit contrived anyway. Maybe, but I've seen it in other Common Lisp books/tutorials before. e.g. I'm sure PAIP was one of them. Part of the motivation is that CL symbols always compare with EQ and EQL, whilst strings are not required to do so: cl-user(9): (eq (concatenate 'string foo bar) foobar) nil This means you can use nice constructs such as CASE with symbols, but you need to roll your own using string-equal or string= to handle strings. (Using symbols also saves you typing all those double-quote characters, as well as saving memory and computation during comparison: symbols are interned, unlike strings.) In Clojure (thanks to Java's immutable interned strings) strings compare efficiently with = just like everything else, so there's less motivation. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+ unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.cgrand.net/ (en) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Java method call irritation
On 18 Mar 2010, at 16:55, Per Vognsen wrote: Is there any reason why a .method occurrence in non-operator position doesn't just do the closure wrapping automagically? There is two reasons I can think of, though of course I can't know if they are the real ones. First, a technical reason: .method is handled as part of macro expansion: user (macroexpand-1 '(.hashCode 3)) (. 3 hashCode) The result is a special form for Java interop. Symbols in non-operator positions are not macro-expanded, so some other mechanism would have to be invented to handle them in a special way. It would in fact create a first special symbol category, complicating the semantics of the language, so this is not just a technical reason. Second, a semantic reason: Java method calls are resolved statically if possible (you can use reflection warnings to find out where this fails), making them very fast. Creating and calling a closure is a much slower operation. Rich has stated at several occasions that he considers performance in important part of the interface of a function, so making a clear syntactic distinction between a fast and a slow operation would fit well with that point of view. Konrad. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Java method call irritation
On Fri, Mar 19, 2010 at 2:46 PM, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 18 Mar 2010, at 16:55, Per Vognsen wrote: Is there any reason why a .method occurrence in non-operator position doesn't just do the closure wrapping automagically? There is two reasons I can think of, though of course I can't know if they are the real ones. First, a technical reason: .method is handled as part of macro expansion: user (macroexpand-1 '(.hashCode 3)) (. 3 hashCode) The result is a special form for Java interop. Symbols in non-operator positions are not macro-expanded, so some other mechanism would have to be invented to handle them in a special way. It would in fact create a first special symbol category, complicating the semantics of the language, so this is not just a technical reason. Interesting. I had tacitly assumed there was already some special symbol magic going on and so did not know it was a simple case of macro expansion with a little reader support. Second, a semantic reason: Java method calls are resolved statically if possible (you can use reflection warnings to find out where this fails), making them very fast. Creating and calling a closure is a much slower operation. Rich has stated at several occasions that he considers performance in important part of the interface of a function, so making a clear syntactic distinction between a fast and a slow operation would fit well with that point of view. I thought of this as well before posting. A few comments: 1. Creation: You only need to create one closure per function, once and for all; the closure does not close over anything in the surrounding scope, it's just a wrapper. 2. Calling: This is such a straightforward case of inlining that HotSpot will eat it for breakfast. Clojure is full of idioms that would be death to performance if not for such behavior from HotSpot. 3. Type hinting: This is a deeper problem with first-class methods. The current manner of type hinting does not work well here. If you could write SomeClass.someMethod to refer to a specific class's method and perhaps supply further signature hints in the case of same-arity overloads, e.g. #^([Integer]) ResultSet.getObject, then this could be resolved. -Per Konrad. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Java method call irritation
Konrad, Im not following where this would be a problem in terms of optimization. In the definition for map, all that needs to be added is a check for a symbol? and the resulting sequence could look and act exactly like it would, had you manually added the #(.method %) right? If the technical obstacle can be overcome, which Im confident that it can, then regarding semantics this have come up several times, where people intuitively assume that it works, which I completely understand and think it should, so it wouldn't be adding a layer of complexity. Lau On 19 Mar., 08:46, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 18 Mar 2010, at 16:55, Per Vognsen wrote: Is there any reason why a .method occurrence in non-operator position doesn't just do the closure wrapping automagically? There is two reasons I can think of, though of course I can't know if they are the real ones. First, a technical reason: .method is handled as part of macro expansion: user (macroexpand-1 '(.hashCode 3)) (. 3 hashCode) The result is a special form for Java interop. Symbols in non-operator positions are not macro-expanded, so some other mechanism would have to be invented to handle them in a special way. It would in fact create a first special symbol category, complicating the semantics of the language, so this is not just a technical reason. Second, a semantic reason: Java method calls are resolved statically if possible (you can use reflection warnings to find out where this fails), making them very fast. Creating and calling a closure is a much slower operation. Rich has stated at several occasions that he considers performance in important part of the interface of a function, so making a clear syntactic distinction between a fast and a slow operation would fit well with that point of view. Konrad. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Java method call irritation
I don't think passing symbols around and having special case behavior scattered around different functions is going to help beginners. If anything, it would confuse them when they try to treat .methods as first-class functions in their own code and discover that it doesn't work. -Per On Fri, Mar 19, 2010 at 3:10 PM, LauJensen lau.jen...@bestinclass.dk wrote: Konrad, Im not following where this would be a problem in terms of optimization. In the definition for map, all that needs to be added is a check for a symbol? and the resulting sequence could look and act exactly like it would, had you manually added the #(.method %) right? If the technical obstacle can be overcome, which Im confident that it can, then regarding semantics this have come up several times, where people intuitively assume that it works, which I completely understand and think it should, so it wouldn't be adding a layer of complexity. Lau On 19 Mar., 08:46, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 18 Mar 2010, at 16:55, Per Vognsen wrote: Is there any reason why a .method occurrence in non-operator position doesn't just do the closure wrapping automagically? There is two reasons I can think of, though of course I can't know if they are the real ones. First, a technical reason: .method is handled as part of macro expansion: user (macroexpand-1 '(.hashCode 3)) (. 3 hashCode) The result is a special form for Java interop. Symbols in non-operator positions are not macro-expanded, so some other mechanism would have to be invented to handle them in a special way. It would in fact create a first special symbol category, complicating the semantics of the language, so this is not just a technical reason. Second, a semantic reason: Java method calls are resolved statically if possible (you can use reflection warnings to find out where this fails), making them very fast. Creating and calling a closure is a much slower operation. Rich has stated at several occasions that he considers performance in important part of the interface of a function, so making a clear syntactic distinction between a fast and a slow operation would fit well with that point of view. Konrad. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Clojure 101 - Slime installation
To avoid confusion Im pasting from another thread: Getting ready: http://www.bestinclass.dk/index.php/2009/12/clojure-101-getting-cloju... Doing simple pages: http://www.bestinclass.dk/index.php/2009/12/beating-the-arc-challenge... Including SQL: http://www.bestinclass.dk/index.php/2009/12/dynamic-interactive-webde... Making a simple Reddit clone: http://www.bestinclass.dk/index.php/2010/02/reddit-clone-in-10-minute... ..and extending that with a user database: http://www.bestinclass.dk/index.php/2010/02/reddit-clone-with-user-re... I wrote them in a style which targets new-comers, so I hope it will be of some help. Lau On 18 Mar., 19:56, Tim Johnson t...@johnsons-web.com wrote: Seehttp://vimeo.com/8398020 Great video! But, it would be great if I could capture the *text* of the video, (if available) that would be very helpful in referrencing Lau's instructions Anyone know how to do that? thanks -- Tim t...@johnsons-web.comhttp://www.akwebsoft.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Parser irritation
Hello, is this a bug or a feature? (And how could I know.) spels= (macroexpand `(huhu huhu.)) (spels/huhu huhu.) If the symbol ends with a dot, it doesnt get resolved with name space. I suspect thats because it will get special interpretation as Java constructor. But what kind of magic is at work here? Thank you, alux -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Translation from Common Lisp 2
Hello Michael, hello Dave, its actually been the parenthesis. Thank you. (Now I still have to understand it ;-) On 18 Mrz., 22:43, Michael Wood esiot...@gmail.com wrote: On 18 March 2010 23:40, Dave M damncan...@gmail.com wrote: ... (game-action weld chain bucket attic (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn ^ Your if-condition is nested one form too deeply; try (if (and (have 'bucket) ...) ...) I haven't tried it, so there might be other problems. Oh right, yes, I didn't notice before your message that he had (if ((and ... in his game-action macro :) -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Parser irritation
Hi, On Mar 19, 9:16 am, alux alu...@googlemail.com wrote: is this a bug or a feature? (And how could I know.) spels= (macroexpand `(huhu huhu.)) (spels/huhu huhu.) If the symbol ends with a dot, it doesnt get resolved with name space. I suspect thats because it will get special interpretation as Java constructor. But what kind of magic is at work here? This is exactly the case. The magic is `. It either expands the classname to the full qualified version, if the class is exported. Or it leaves it alone otherwise. The reason is, that you can have a class frobnicator.Foo imported in the namespace where you define your macro. However the user may use your macro in a namespace which imports yoyodyne.Foo. If the Foo. in your macro was left alone, it would now refer to yoyodyne.Foo instead of the intended frobnicator.Foo. If the class is not imported it must be by definition fully qualified. And hence ` leaves the symbol with trailing . alone. Note that something similar happens to the .method notation. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Parser irritation
Ah. Interesting. (btw the exported in you second line certainly should be imported) So it interprets huhu. as full qualified class name and leaves it alone. Thank you for the explanation. Regards, alux On 19 Mrz., 09:38, Meikel Brandmeyer m...@kotka.de wrote: Hi, On Mar 19, 9:16 am, alux alu...@googlemail.com wrote: is this a bug or a feature? (And how could I know.) spels= (macroexpand `(huhu huhu.)) (spels/huhu huhu.) If the symbol ends with a dot, it doesnt get resolved with name space. I suspect thats because it will get special interpretation as Java constructor. But what kind of magic is at work here? This is exactly the case. The magic is `. It either expands the classname to the full qualified version, if the class is exported. Or it leaves it alone otherwise. The reason is, that you can have a class frobnicator.Foo imported in the namespace where you define your macro. However the user may use your macro in a namespace which imports yoyodyne.Foo. If the Foo. in your macro was left alone, it would now refer to yoyodyne.Foo instead of the intended frobnicator.Foo. If the class is not imported it must be by definition fully qualified. And hence ` leaves the symbol with trailing . alone. Note that something similar happens to the .method notation. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Translation from Common Lisp 2
By the way, you may find a working version at http://paste.lisp.org/+22IH/1 Kind regards, alux On 19 Mrz., 09:18, alux alu...@googlemail.com wrote: Hello Michael, hello Dave, its actually been the parenthesis. Thank you. (Now I still have to understand it ;-) On 18 Mrz., 22:43, Michael Wood esiot...@gmail.com wrote: On 18 March 2010 23:40, Dave M damncan...@gmail.com wrote: ... (game-action weld chain bucket attic (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn ^ Your if-condition is nested one form too deeply; try (if (and (have 'bucket) ...) ...) I haven't tried it, so there might be other problems. Oh right, yes, I didn't notice before your message that he had (if ((and ... in his game-action macro :) -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: clj-sandbox
I'm ecstatic about this. I've been writing a Clojure IRC bot over the last week or so, and this will really help me get sandboxed Clojure evaluation working. Thanks. On Mar 15, 5:22 am, Heinz Nikolaus Gies he...@licenser.net wrote: My brain is a sive, I forgot the github link o.Ohttp://github.com/Licenser/clj-sandboxsorry for the smap. Best regards, Heinz -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Parser irritation
Hi, On Mar 19, 9:49 am, alux alu...@googlemail.com wrote: (btw the exported in you second line certainly should be imported) Woops. Yes. You are right. Should be imported. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
REPL behaviour / time / lazyness
Hello, I played a bit with Fibonacci again. The slow and inefficient way ;-) (defn fib0 [n] (if ( n 1) 1 (+ (fib0 (- n 1)) (fib0 (- n 2) user= (time (fib0 35)) Elapsed time: 20874.18345 msecs 24157817 I use (set! *print-length* 10) and tried some mapping: user= (time (map fib0 (iterate inc 1))) Elapsed time: 0.913524 msecs (2 3 5 8 13 21 34 55 89 144 ...) Everything fine. Now what puzzles me: user= (time (map fib0 (range 100))) Elapsed time: 1.248203 msecs The time is printed immediately, but the result waits about 8 seconds to print! (1 2 3 5 8 13 21 34 55 89 ...) Can you tell whats happening here? Especially comparing to the (iterate inc 1) version .. Thank you and regards, alux -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: REPL behaviour / time / lazyness
Hi, On Mar 19, 11:27 am, alux alu...@googlemail.com wrote: user= (time (fib0 35)) Elapsed time: 20874.18345 msecs 24157817 user= (time (map fib0 (iterate inc 1))) Elapsed time: 0.913524 msecs (2 3 5 8 13 21 34 55 89 144 ...) Everything fine. Now what puzzles me: user= (time (map fib0 (range 100))) Elapsed time: 1.248203 msecs As you write in your subject. You are caught by laziness. Wrap the map in a doall. (time (doall (map fib0 (iterate inc 1))) (time (doall (map fib0 (range 100))) (Don't forget to set print-length!) What happens? The map returns not a list of sorts but an object, which computes the result when it is requested. So it completes very fast, hence the short time reported by the time call. Now outside the time call the object is received by the Repl which triggers the suspended computation and prints the result. So the actual work happens outside the time call. On the other hand, wrapping the map into a doall will realise the computation immediately (that is inside the time call) and work will actually show up in form of a longer time reported by time. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
getRuntime exec call?
(defn cmdresult [cmdstr] (let [args (into [] (seq (.split cmdstr )))] (BufferedReader. (InputStreamReader. (. (. (. Runtime (getRuntime)) (exec args)) (getInputStream)) (defn readLine [cmdresult] (. cmdresult (readLine))) (def a (cmdresult ls *.o)) This fails claiming: No matching method found: exec for class java.lang.Runtime If I replace the Runtime line with: (. (. (. Runtime (getRuntime)) (exec ls)) (getInputStream)) it works and gives me the result of the ls system call. If I replace the Runtime line with (. (. (. Runtime (getRuntime)) (exec ls *.o)) (getInputStream)) it fails even though it has a string argument. Suggestions? Tim Daly -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Instance predicates for deftyped types
It looks like there isn't a way to get at the class behind a deftyped type other than constructing a dummy instance and taking its class, because the generated class has a gensymmed name. I was doing something where I needed to test when something was an instance of a deftype, so I added this to the `(do ...) block in deftype's implementation: (defn ~(symbol (str name ?)) [x#] (instance? ~classname x#)) It would also be nice if the class itself was exposed under some standardized name, e.g. (symbol (str ~name -class))). Any reason this isn't done right now? -Per -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: getRuntime exec call?
The call to a static method is special, try (.exec (Runtime/getRuntime) ls) Regards, alux TimDaly schrieb: (defn cmdresult [cmdstr] (let [args (into [] (seq (.split cmdstr )))] (BufferedReader. (InputStreamReader. (. (. (. Runtime (getRuntime)) (exec args)) (getInputStream)) (defn readLine [cmdresult] (. cmdresult (readLine))) (def a (cmdresult ls *.o)) This fails claiming: No matching method found: exec for class java.lang.Runtime If I replace the Runtime line with: (. (. (. Runtime (getRuntime)) (exec ls)) (getInputStream)) it works and gives me the result of the ls system call. If I replace the Runtime line with (. (. (. Runtime (getRuntime)) (exec ls *.o)) (getInputStream)) it fails even though it has a string argument. Suggestions? Tim Daly -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: web starting clojure apps without Java code
That would be great! Please post the link here when you're done. On Mar 18, 5:15 pm, LauJensen lau.jen...@bestinclass.dk wrote: Eugen, Fantastic insight - I cant wait to work that into a blogpost :) Lau On 17 Mar., 15:56, Eugen Dück eu...@dueck.org wrote: All, Developing in clojure is a lot of fun, at least it was for me and a project of mine - except for one thing: Deploying the app as Java Web Start app, that took me a bit of time to figure out, and not only because Java Web Start is broken in debian squeeze (for a workaround, see bugs.debian.org/560056 ). Java Web Start has been discussed in this group some time ago (http://groups.google.com/group/clojure/browse_thread/thread/f0c69735c... ), and the proposed solution at that time contained one Java class that did some static initialization (to propagate the necessary permissions to clojure's own classloader) and then went on to call RT to load a clj file, after fiddling around with PushBackReaders and so forth. I would like to stay away from RT, as it can change, and I don't want to depend on RT staying the way it is. Now it turns out that Web Start is actually pretty easy if you just AOT your whole app and gen-class your main entry point. That way you don't need any Java code. My clj file that contains the entry point starts like this: (ns kanshiki.swing (:gen-class)) Then I compile the app and create the jar file: mkdir classes java -cp clojure.jar:clojure-contrib-slim.jar:classes:. clojure.main - e (compile 'kanshiki.swing) (cd classes; jar cf ../kanshiki-boom.jar *) jarsigner kanshiki-boom.jar And the jnlp contains these tags to make it work: ... resources j2se version=1.6*/ jar href=clojure.jar/ jar href=kanshiki-boom.jar main=true/ /resources application-desc main-class=kanshiki.swing/ ... The complete jnlp can be found athttp://dueck.org/kanshiki-boom/. I plan to introduce and document this beta-grade app soon, but if there's any Japanese learner out there interested in or in need of Kanji handwriting recognition, check it out, but please hold back with any bug reports etc. until I have introduced it. Only one quick note: Kanjis you click will automatically be copied to the clipboard, so if you use it together with a kanji dictionary that can search the clipboard like kiten (yes, that's the KDE kanji dictionary with the hge memory leak, the other day it grew to 6GB before I killed it), it is actually useful to look up kanjis or words. Oh, and did I mention lately that clojure is pure fun? Thanks again Rich! You've done (and are still doing) a terrific job! Eugen -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: clojure-mode-like syntax highlighting for the SLIME REPL
On 19 March 2010 06:08, Michał Marczyk michal.marc...@gmail.com wrote: Hi Group, there was a Stack Overflow question recently re: syntax highlighting Clojure REPLs. This got me thinking that since I was going to tweak SLIME REPL font-lock for quite some time now (I find the default a bit too aggressive), I might as well do it now and have it use clojure-mode's font-lock settings too. Here's what I came up with: http://gist.github.com/337280 Very cute! I'd love to see this integrated into clojure-mode! R. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: REPL behaviour / time / lazyness
Hi, On Mar 19, 12:34 pm, alux alu...@googlemail.com wrote: You didnt try this, as I can judge, because you responded in finite time ;-) Ah, yes. Intersperse with (take 10 ...) at will. :) My main irritation is still: Why do my range and my iterate version differer in their print beheavior? Because with range you get as first argument to fib0 a 0, while with iterate you get a 1 as first parameter to fib0. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: REPL behaviour / time / lazyness
;-) Still, I dont believe. I get the same difference with user= (time (map fib0 (range 100))) Elapsed time: 1.916445 msecs more than 5 seconds (0 1 1 2 3 5 8 13 21 34 ...) user= (time (map fib0 (iterate inc 0))) Elapsed time: 0.104203 msecs (0 1 1 2 3 5 8 13 21 34 ...) Hm. Regards, alux Meikel Brandmeyer schrieb: Hi, On Mar 19, 12:34 pm, alux alu...@googlemail.com wrote: You didnt try this, as I can judge, because you responded in finite time ;-) Ah, yes. Intersperse with (take 10 ...) at will. :) My main irritation is still: Why do my range and my iterate version differer in their print beheavior? Because with range you get as first argument to fib0 a 0, while with iterate you get a 1 as first parameter to fib0. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Instance predicates for deftyped types
On 19.03.2010, at 12:09, Per Vognsen wrote: It looks like there isn't a way to get at the class behind a deftyped type other than constructing a dummy instance and taking its class, because the generated class has a gensymmed name. I was doing something where I needed to test when something was an instance of a deftype, so I added this to the `(do ...) block in deftype's implementation: The official approach is to check for type rather than class, the type being the namespace-qualified keyword version of the type name. The class is considered an implementation detail. Considering that there is already an alternative implementation of Clojure (ClojureCLR) and that there might be more in the future, this is pretty reasonable in my opinion. Here's an (untested) example: (deftype Foo [bar]) (defn is-this-a-foo? [x] (identical? (type x) ::Foo)) Konrad. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Instance predicates for deftyped types
Hi, On Mar 19, 12:09 pm, Per Vognsen per.vogn...@gmail.com wrote: It looks like there isn't a way to get at the class behind a deftyped type other than constructing a dummy instance and taking its class, because the generated class has a gensymmed name. I was doing something where I needed to test when something was an instance of a deftype, so I added this to the `(do ...) block in deftype's implementation: (defn ~(symbol (str name ?)) [x#] (instance? ~classname x#)) It would also be nice if the class itself was exposed under some standardized name, e.g. (symbol (str ~name -class))). Any reason this isn't done right now? I would not rely on class but on type, which will return the type tag of the type. Unfortunately the tag does currently not work with instance?. (defn general-instance? [t o] (isa? (type o) t)) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Simple functional programming lexicon?
You might want to check out: http://peepcode.com/products/functional-programming-with-clojure -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Wrapping a java api...
Hi, I'm trying to wrap the apfloat (arbitrary precision float, http://www.apfloat.org/apfloat_java) java library for a small project. The idea is that the parameters of apfloat calculations get automatically converted to the Apfloat class. My test function is sqrtf (square root float) and the automatic conversion will allow me to write (sqrtf 5) without converting the 5 to an Apfloat object first. sqrtf uses a multimethod apf (apfloat) that takes care of the conversion. I wonder if this is the correct way of handling this in clojure or if I'm off track here? apfloat.clj: (ns apfloat) (import '(org.apfloat Apfloat Apint ApfloatMath)) (set! *warn-on-reflection* true) ; default precision (def *precision* 20) (def infinite Apfloat/INFINITE) (declare apf) (defn sqrtf [a] sqrt of apfloat a (ApfloatMath/sqrt (apf a))) (defmulti apf creates an Apfloat. class) (defmethod apf Apfloat [#^Apfloat a] a) (defmethod apf Apint [#^Apint a] (if (= Apfloat/INFINITE (.precision a)) (.precision a (long *precision*)) a)) (defmethod apf Integer ([#^Integer a] (Apfloat. (.longValue a) (long *precision* -- Martin -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
overrding function from other namespace
Hi, I trying to use clojure.contrib.mock. It says to override the function report-problem to integrate it into other test framework like clojure.test. I've got this working, but the namespace switching looks a bit ugly. Is there a better way to handle this? Maybe something like (ns clojure.contrib.mock (defn... the override) ) which avoids the extra code to switch back to the original namespace? (ns apfloattest (:use apfloat clojure.test clojure.contrib.mock)) (ns clojure.contrib.mock (:use clojure.test)) ; delegate mock reporting to clojure.test (defn report-problem ([function expected actual message] (is (= expected actual) (str message Function name: function (ns apfloattest) (deftest test-sqrtf (expect [apf (times 1 (returns (apf 5)))] (sqrtf 5))) -- Martin -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Quines
Ok, I golfed it. (def s[(def s%s)(printf(s 0)s)])(printf(s 0)s) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Simple functional programming lexicon?
Also the Learn you a Haskell for Great Good tutorial is a pretty nice and light-hearted introduction to FP with Haskell which might also help you to understand some of the concepts better: http://learnyouahaskell.com/ If you don't mind taking a detour into the Haskell world, the book Real World Haskell also does a very good job of explaining key functional vocabulary using pragmatic examples (for the most part). I may never use Haskell in anger, but I found learning the language and reading this one book a very good exploration of the functional programming space. -- Perhaps people don't believe this, but throughout all of the discussions of entering China our focus has really been what's best for the Chinese people. It's not been about our revenue or profit or whatnot. --Sergey Brin, demonstrating the emptiness of the don't be evil mantra. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Name suggestions
clojure + native = clotive On Thu, Mar 18, 2010 at 10:36 AM, Alexandre Patry patry...@iro.umontreal.ca wrote: On Wed, Mar 17, 2010 at 3:08 AM, mac markus.gustavs...@gmail.com wrote: After just a little more test and polish I plan on calling clj-native 1.0. But clj-native is a *really* boring name so I want to change it before 1.0 and I don't have very good imagination when it comes to these things. So I need your help. It doesn't have to have anything to do with anything, could just be something that sounds funny, like sasquatch, that's a funny word. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Clojure Koans?
On a recent Java Ranch, Dick Wall mentioned that he was working with Clojure and F# people on functional language Koans that are like the Ruby Koans at http://github.com/relevance/functional-koans/ the branch for clojure is: at http://github.com/relevance/functional-koans/tree/clojure There are 9 koans so far, with the last contributions some time in February. On Wed, Dec 2, 2009 at 2:39 PM, Matthew Williams matthew.d.willi...@gmail.com wrote: The folks over at http://edgecase.com put together a great project for people interested in Ruby to really get a grasp of the standard library as well as introduce them to the idea of unit testing. The project is up on Github: http://github.com/edgecase/ruby_koans The basic idea is you run Rake which then guides you through exercises taking you throughout almost the entire standard library. For example, a problem might look like the following: def test_double_quoted_strings_are_strings string = Hello, World assert_equal __, string.is_a?(String) end The __ represents the expected the result of the second argument on assert_equal. Once you fill in the correct answer, run rake, and it will guide you to the next set of koans. They exercise almost every method for the major data types, blocks, exceptions, etc etc. It's a really great project. Could something like this come from the Clojure community? I've just started Stuart's Clojure PragProg book and I'm finding it to be a great resource. But I'm also finding myself struggling a bit on a few items that might have a single example or a brief explanation and then I'm off searching through docs and trying to come up with some practical examples on my own that really drill down how the given form should be used, or how recur works, or let, do, etc etc. Would this be something worth while, especially for those joining the community? I discovered the Ruby Koans with a few years of Ruby under my belt and found them to be a really refreshing set of exercises. And now that I'm entering a new community, it's something I think I would benefit from greatly. Does anyone have any input on how best to accomplish this? Or even some starter koans? On a side note, it's been really refreshing working with Clojure. I haven't yet begun implementing anything other than what I'm finding in example material, but I'm getting there. Having been doing OOP for such a long time, I'm still slowly taking in the functional approach and I'm seeing more and more benefits as the days go by. Thanks for being such an great community! -Matthew Williams @mwilliams -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Long post with some questions about getting started...
I want to learn Clojure and the first idea for a simple app that popped into my head was some sort of roguelike (because I'm a gamer and this is what I like to do...) I could go on making hello world apps and tiny test apps that serve little purpose, but the way I learn is by setting an end goal and going for it. I don't intend on making this in the first shot, but like I said, there's the goal. I've read quite a bit on Clojure, done some simple stuff like the Hello World apps and such already. I get the idea of the list structure (though I'm still VERY green on this.) A little background: I have an extensive background (10+ years professional, many more non-pro) in OOP and Procedural Programing using everything from Javascript/Actionscript to C# and even the gross VB4-6 in my early years and a little known Aspect Scripting (which I've totally forgotten by now.) I've only really dealt with threaded applications in C# because, let's face it... it's dead simple even using mutex locking. Non-professionally I started on an old TRS-80 then moved to a 80386 with GWBASIC/QBASIC and dabbled in C/C++ (but mainly I've just read tons of books on C/C++...) So, I'm trying to put all that aside and think Functional for this. I'm really trying, and it's mind bending to put all that aside... but I learn by example so here's where I ask some clues. I've downloaded Netbeans and an addon and played with it a little bit, but it seems to require a _main entry method and from the various tutorials around, I see that's not the norm. I'm having an interesting (to me) question around a using REPL. Once it's shut down, where does this code go? I feel like I'm in the old TRS-80 volatile coding days where you write some code, and if you shut down you've lost it all. Is this the case? So how do you save your code in a REPL? I understand these could be unique per editor so I understand if you get irate at me for asking such a silly question... I understand a list from ( to ) has the potential to be a function in separate threads because I poked my head into a tutorial I should have probably stayed clear of. If I create a function that I want to execute first on start up to check for a file and load it, but if it doesn't exist, create it and populate some array for world data. That's fairly straight forward, but in a game environment, this gets you nowhere but RAM full of data. About this point I'd then call a function create a player that would read in data from this world within a local proximity and act upon it. There's two ways I can see going about this. One is threading it off to act on it's own (which is what I'd love to do) and the other is appending it to the end of this creation function (have that function call the player on completion) but this is where I'm lost. Is it as simple as calling said method at the end of the list or is that filling up a stack of pain that I don't want to deal with when it all crashes? So I thought, I just need to do it. Just put it to silicon and start making something then I stared at the screen... A part of me would approach this as a client/server model which I'm not certain is right for functional programming. You have to have some communication method, or is the world data stored in a global location that is accessible to this player? Am I thinking about this all wrong? Would the player spawn the world load/creation only when it was needed? What if you wanted more than one actor? (would be a boring game if there were no enemies...) How does each actor access this world data? I realize some of this sounds totally noobish. Forgive me, but this is new territory for me. With OOP and functional languages I could scope a simple array of an array and reference it within it's scope. Is all Clojure scoped globally for data or am I supposed to go find something to handle that? I would figure with the nature of functional programming I could have it store data in a simple file format for the time being. That might not scale well, or it just may. I don't know. Sorry for the length of this post, the rambling, and the incoherent thought process. I realize I'm probably asking too many questions at once... :-\ -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
ANN: clj-facebook, a Clojure client library for Facebook apps
I'd like to announce the initial release of clj-facebook, a Facebook client library in Clojure. The code can be found here: http://github.com/rnewman/clj-facebook We welcome comments and proposed code improvements. Don -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Translation from Common Lisp 2
You just needed to edit your translation from CL a bit more, there were some extra brackets in your if statements. The following should work: (defspel game-action [command subj obj place rest] `(defspel ~command [subject# object#] `(if (and (= *location* '~'~place) (= '~subject# '~'~subj) (= '~object# '~'~obj) (have '~'~subj)) ~@'~rest '(i cant ~'~command like that. (game-action weld chain bucket attic (if (and (have 'bucket) (alter-var-root (var *chain-welded*) (fn [_] true))) '(the chain is now securely welded to the bucket.) '(you do not have a bucket.))) On Thu, Mar 18, 2010 at 4:38 PM, alux alu...@googlemail.com wrote: Again, from my translation of the http://www.lisperati.com/casting.html tutorial. I completely lost track at the macro generating macro (defspel game- action .. In short, Barski writes a very simple (and neat) text adventure. To avoid wrong assumtions he doesnt talk about macros but SPELs, using CL (defmacro defspel (rest rest) `(defmacro ,@rest)) Clj (defmacro defspel [ rest] `(defmacro ~...@rest)) I translated everything up to the last page http://www.lisperati.com/actions.html, then he arrives at (defspel game-action (command subj obj place rest rest) `(defspel ,command (subject object) `(cond ((and (eq *location* ',',place) (eq ',subject ',',subj) (eq ',object ',',obj) (have ',',subj)) ,@',rest) (t '(i cant ,',command like that.) Without CL knowledge, I dont really understand whats going on, but gave a try (please dont lough to hard :) (defspel game-action [command subj obj place rest] `(defspel ~command [subject# object#] `(if ((and (= *location* '~'~place) (= '~subject# '~'~subj) (= '~object# '~'~obj) (have '~'~subj)) ~@'~rest) '(i cant ~'~command like that. use (game-action weld chain bucket attic (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn [_] true))) '(the chain is now securely welded to the bucket.)) '(you do not have a bucket.))) If I try it, I get spels= (weld chain bucket) java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.I Fn (NO_SOURCE_FILE:0) And I'm stuck. My whole try is here: http://paste.lisp.org/+22IH Many thanks and a good night. alux -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
zipentry-seq based on clojure.core/resultset-seq
Hi, I want a function that takes byte array in zip format and returns sequence of included ZipEntrys. I wrote zipentry-seq based on clojure.core/resultset-seq as below. (entries) returns sequence of included ZipEntrys and many nils, so I added ad-hoc filter at the last. Please advice me to make it more better. pre (defn zipentry-seq [zip-byte-array] (let [zip-stream (ZipInputStream. (ByteArrayInputStream. zip-byte- array)) entries (fn thisfn [] (when (not= 0 (.available zip-stream)) (cons (.getNextEntry zip-stream) (lazy-seq (thisfn)] (filter #(not (nil? %)) (entries /pre -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
ANN: clj-facebook, a Clojure client library for Facebook apps
I'd like to announce the initial release of clj-facebook, a Facebook client library in Clojure. The code can be found here: http://github.com/rnewman/clj-facebook We welcome comments and proposed code improvements. Don -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
How to use Clojure with Robocode
Hi, Has anyone been able to use Clojure with Robocode? I've followed this http://www.fatvat.co.uk/2009/05/clojure-and-robocode.html but got the error Round 1 initializing.. Let the games begin! java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java: 39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java: 27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at net.sf.robocode.host.security.RobotClassLoader.createRobotInstance(RobotClassLoader.java: 272) at net.sf.robocode.host.proxies.HostingRobotProxy.loadRobotRound(HostingRobotProxy.java: 201) at net.sf.robocode.host.proxies.HostingRobotProxy.run(HostingRobotProxy.java: 242) at java.lang.Thread.run(Thread.java:637) Caused by: java.lang.NullPointerException at clojure.lang.Var.setMeta(Var.java:179) at clojure.lang.Var.internPrivate(Var.java:96) at ubolonton.MyRobot.clinit(Unknown Source) ... 10 more Thanks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Instance predicates for deftyped types
Thanks, I had seen that ::Foo use and was a bit confused. Now it all makes sense. It would still be nice to have an auto-generated name?-style predicate in deftype, I think. -Per On Fri, Mar 19, 2010 at 7:44 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, On Mar 19, 12:09 pm, Per Vognsen per.vogn...@gmail.com wrote: It looks like there isn't a way to get at the class behind a deftyped type other than constructing a dummy instance and taking its class, because the generated class has a gensymmed name. I was doing something where I needed to test when something was an instance of a deftype, so I added this to the `(do ...) block in deftype's implementation: (defn ~(symbol (str name ?)) [x#] (instance? ~classname x#)) It would also be nice if the class itself was exposed under some standardized name, e.g. (symbol (str ~name -class))). Any reason this isn't done right now? I would not rely on class but on type, which will return the type tag of the type. Unfortunately the tag does currently not work with instance?. (defn general-instance? [t o] (isa? (type o) t)) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: REPL behaviour / time / lazyness
2010/3/19 alux alu...@googlemail.com: ;-) Still, I dont believe. I get the same difference with user= (time (map fib0 (range 100))) Elapsed time: 1.916445 msecs more than 5 seconds (0 1 1 2 3 5 8 13 21 34 ...) user= (time (map fib0 (iterate inc 0))) Elapsed time: 0.104203 msecs (0 1 1 2 3 5 8 13 21 34 ...) Hm. Regards, alux Could chunked seqs explain something here ? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: REPL behaviour / time / lazyness
Hi, On Mar 19, 1:39 pm, alux alu...@googlemail.com wrote: Still, I dont believe. You should... I get the same difference with user= (time (map fib0 (range 100))) Elapsed time: 1.916445 msecs more than 5 seconds (0 1 1 2 3 5 8 13 21 34 ...) user= (time (map fib0 (iterate inc 0))) Elapsed time: 0.104203 msecs (0 1 1 2 3 5 8 13 21 34 ...) How does this fit to following? user= (time (map fib0 (iterate inc 1))) Elapsed time: 0.913524 msecs (2 3 5 8 13 21 34 55 89 144 ...) ^^^ The example you posted can't be. With the fib0 you posted you get: (fib0 0) = 1 (fib0 1) = (+ (fib0 0) (fib0 -1)) = (+ 1 1) = 2 So what you posted above can't be true. At least not with the fib0 you gave in your original post. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Instance predicates for deftyped types
On 19.03.2010, at 13:50, Per Vognsen wrote: It would still be nice to have an auto-generated name?-style predicate in deftype, I think. I haven't yet made my mind up about this. I have used such auto-generated predicates in my unit library (http://code.google.com/p/clj-units/) for dimension testing, but I may take them out again. What I dislike about this approach is def-ing a symbol inside a macro that is not spelled out explicitly by the user of that macro. This can easily cause namespace pollution of invisible origin. Konrad. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Translation from Common Lisp 2
JC Petkovich, thank you. I couldnt see your message before March 19, 6:00 group time, i.e. 13:00 UTC, but thats exactly the solution that was needed. Regards, alux JC Petkovich schrieb: You just needed to edit your translation from CL a bit more, there were some extra brackets in your if statements. The following should work: (defspel game-action [command subj obj place rest] `(defspel ~command [subject# object#] `(if (and (= *location* '~'~place) (= '~subject# '~'~subj) (= '~object# '~'~obj) (have '~'~subj)) ~@'~rest '(i cant ~'~command like that. (game-action weld chain bucket attic (if (and (have 'bucket) (alter-var-root (var *chain-welded*) (fn [_] true))) '(the chain is now securely welded to the bucket.) '(you do not have a bucket.))) On Thu, Mar 18, 2010 at 4:38 PM, alux alu...@googlemail.com wrote: Again, from my translation of the http://www.lisperati.com/casting.html tutorial. I completely lost track at the macro generating macro (defspel game- action .. In short, Barski writes a very simple (and neat) text adventure. To avoid wrong assumtions he doesnt talk about macros but SPELs, using CL (defmacro defspel (rest rest) `(defmacro ,@rest)) Clj (defmacro defspel [ rest] `(defmacro ~...@rest)) I translated everything up to the last page http://www.lisperati.com/actions.html, then he arrives at (defspel game-action (command subj obj place rest rest) `(defspel ,command (subject object) `(cond ((and (eq *location* ',',place) (eq ',subject ',',subj) (eq ',object ',',obj) (have ',',subj)) ,@',rest) (t '(i cant ,',command like that.) Without CL knowledge, I dont really understand whats going on, but gave a try (please dont lough to hard :) (defspel game-action [command subj obj place rest] `(defspel ~command [subject# object#] `(if ((and (= *location* '~'~place) (= '~subject# '~'~subj) (= '~object# '~'~obj) (have '~'~subj)) ~@'~rest) '(i cant ~'~command like that. use (game-action weld chain bucket attic (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn [_] true))) '(the chain is now securely welded to the bucket.)) '(you do not have a bucket.))) If I try it, I get spels= (weld chain bucket) java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.I Fn (NO_SOURCE_FILE:0) And I'm stuck. My whole try is here: http://paste.lisp.org/+22IH Many thanks and a good night. alux -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Java method call irritation
Where would you place the type hint needed to avoid reflection ? 2010/3/19 LauJensen lau.jen...@bestinclass.dk: Konrad, Im not following where this would be a problem in terms of optimization. In the definition for map, all that needs to be added is a check for a symbol? and the resulting sequence could look and act exactly like it would, had you manually added the #(.method %) right? If the technical obstacle can be overcome, which Im confident that it can, then regarding semantics this have come up several times, where people intuitively assume that it works, which I completely understand and think it should, so it wouldn't be adding a layer of complexity. Lau On 19 Mar., 08:46, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 18 Mar 2010, at 16:55, Per Vognsen wrote: Is there any reason why a .method occurrence in non-operator position doesn't just do the closure wrapping automagically? There is two reasons I can think of, though of course I can't know if they are the real ones. First, a technical reason: .method is handled as part of macro expansion: user (macroexpand-1 '(.hashCode 3)) (. 3 hashCode) The result is a special form for Java interop. Symbols in non-operator positions are not macro-expanded, so some other mechanism would have to be invented to handle them in a special way. It would in fact create a first special symbol category, complicating the semantics of the language, so this is not just a technical reason. Second, a semantic reason: Java method calls are resolved statically if possible (you can use reflection warnings to find out where this fails), making them very fast. Creating and calling a closure is a much slower operation. Rich has stated at several occasions that he considers performance in important part of the interface of a function, so making a clear syntactic distinction between a fast and a slow operation would fit well with that point of view. Konrad. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Instance predicates for deftyped types
It's pretty common in the Lisp world at large. For example, Common Lisp's (defstruct foo ...) automatically defines a foo-p predicate. -Per On Fri, Mar 19, 2010 at 7:53 PM, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 19.03.2010, at 13:50, Per Vognsen wrote: It would still be nice to have an auto-generated name?-style predicate in deftype, I think. I haven't yet made my mind up about this. I have used such auto-generated predicates in my unit library (http://code.google.com/p/clj-units/) for dimension testing, but I may take them out again. What I dislike about this approach is def-ing a symbol inside a macro that is not spelled out explicitly by the user of that macro. This can easily cause namespace pollution of invisible origin. Konrad. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: REPL behaviour / time / lazyness
Meikel, you are right, I changed horses, uh, definitions inbetween. So the REPL interaction of my last response should read Clojure 1.1.0 user= (set! *print-length* 10) 10 user= (defn fib0 [n] (if ( n 1) 1 (+ (fib0 (- n 1)) (fib0 (- n 2) #'user/fib0 user= (time (map fib0 (range 100))) Elapsed time: 1.979022 msecs (1 2 3 5 8 13 21 34 55 89 ...) user= (time (map fib0 (iterate inc 0))) Elapsed time: 0.969677 msecs (1 2 3 5 8 13 21 34 55 89 ...) user= Despite this, the text I wrote seems still valid to me; note that I changed the start point for the iterate as response to your mail. Thats why now both starts with 0 as argument, and 1 as result. But the range one waits some five sec, the iterate doesnt. Sorry for the confusion. And thanks for the patience ;-) Kind regards, alux PS.: A correct Fibonacci sequence would use ( n 2) instead of ( n 1). Just to mention it. Meikel Brandmeyer schrieb: Hi, On Mar 19, 1:39 pm, alux alu...@googlemail.com wrote: Still, I dont believe. You should... I get the same difference with user= (time (map fib0 (range 100))) Elapsed time: 1.916445 msecs more than 5 seconds (0 1 1 2 3 5 8 13 21 34 ...) user= (time (map fib0 (iterate inc 0))) Elapsed time: 0.104203 msecs (0 1 1 2 3 5 8 13 21 34 ...) How does this fit to following? user= (time (map fib0 (iterate inc 1))) Elapsed time: 0.913524 msecs (2 3 5 8 13 21 34 55 89 144 ...) ^^^ The example you posted can't be. With the fib0 you posted you get: (fib0 0) = 1 (fib0 1) = (+ (fib0 0) (fib0 -1)) = (+ 1 1) = 2 So what you posted above can't be true. At least not with the fib0 you gave in your original post. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Name suggestions
Frank Hale wrote: clojure + native = clotive or clo-jive, like clojure dancing with another language. 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Translation from Common Lisp 2
Yeah, the Clojure namespacing does make translating symbol references in my game-action macro a bit cumbersome... But I think Clojure's straight-forward approach to namespacing is well worth this small inconvenience :-) On Mar 19, 8:54 am, alux alu...@googlemail.com wrote: JC Petkovich, thank you. I couldnt see your message before March 19, 6:00 group time, i.e. 13:00 UTC, but thats exactly the solution that was needed. Regards, alux JC Petkovich schrieb: You just needed to edit your translation from CL a bit more, there were some extra brackets in your if statements. The following should work: (defspel game-action [command subj obj place rest] `(defspel ~command [subject# object#] `(if (and (= *location* '~'~place) (= '~subject# '~'~subj) (= '~object# '~'~obj) (have '~'~subj)) ~@'~rest '(i cant ~'~command like that. (game-action weld chain bucket attic (if (and (have 'bucket) (alter-var-root (var *chain-welded*) (fn [_] true))) '(the chain is now securely welded to the bucket.) '(you do not have a bucket.))) On Thu, Mar 18, 2010 at 4:38 PM, alux alu...@googlemail.com wrote: Again, from my translation of thehttp://www.lisperati.com/casting.html tutorial. I completely lost track at the macro generating macro (defspel game- action .. In short, Barski writes a very simple (and neat) text adventure. To avoid wrong assumtions he doesnt talk about macros but SPELs, using CL (defmacro defspel (rest rest) `(defmacro ,@rest)) Clj (defmacro defspel [ rest] `(defmacro ~...@rest)) I translated everything up to the last pagehttp://www.lisperati.com/actions.html, then he arrives at (defspel game-action (command subj obj place rest rest) `(defspel ,command (subject object) `(cond ((and (eq *location* ',',place) (eq ',subject ',',subj) (eq ',object ',',obj) (have ',',subj)) ,@',rest) (t '(i cant ,',command like that.) Without CL knowledge, I dont really understand whats going on, but gave a try (please dont lough to hard :) (defspel game-action [command subj obj place rest] `(defspel ~command [subject# object#] `(if ((and (= *location* '~'~place) (= '~subject# '~'~subj) (= '~object# '~'~obj) (have '~'~subj)) ~@'~rest) '(i cant ~'~command like that. use (game-action weld chain bucket attic (if ((and (have 'bucket) (alter-var-root (var *chain-welded*) (fn [_] true))) '(the chain is now securely welded to the bucket.)) '(you do not have a bucket.))) If I try it, I get spels= (weld chain bucket) java.lang.ClassCastException: java.lang.Boolean cannot be cast to clojure.lang.I Fn (NO_SOURCE_FILE:0) And I'm stuck. My whole try is here:http://paste.lisp.org/+22IH Many thanks and a good night. alux -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: How to use Clojure with Robocode
Could you post the source code? On Mar 19, 7:56 am, ubolonton ubolon...@gmail.com wrote: Hi, Has anyone been able to use Clojure with Robocode? I've followed thishttp://www.fatvat.co.uk/2009/05/clojure-and-robocode.html but got the error Round 1 initializing.. Let the games begin! java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAcce ssorImpl.java: 39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstru ctorAccessorImpl.java: 27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at net.sf.robocode.host.security.RobotClassLoader.createRobotInstance(RobotCla ssLoader.java: 272) at net.sf.robocode.host.proxies.HostingRobotProxy.loadRobotRound(HostingRobotP roxy.java: 201) at net.sf.robocode.host.proxies.HostingRobotProxy.run(HostingRobotProxy.java: 242) at java.lang.Thread.run(Thread.java:637) Caused by: java.lang.NullPointerException at clojure.lang.Var.setMeta(Var.java:179) at clojure.lang.Var.internPrivate(Var.java:96) at ubolonton.MyRobot.clinit(Unknown Source) ... 10 more Thanks -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Java method call irritation
On Fri, Mar 19, 2010 at 4:04 AM, Per Vognsen per.vogn...@gmail.com wrote: On Fri, Mar 19, 2010 at 2:46 PM, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 18 Mar 2010, at 16:55, Per Vognsen wrote: Is there any reason why a .method occurrence in non-operator position doesn't just do the closure wrapping automagically? There is two reasons I can think of, though of course I can't know if they are the real ones. First, a technical reason: .method is handled as part of macro expansion: user (macroexpand-1 '(.hashCode 3)) (. 3 hashCode) The result is a special form for Java interop. Symbols in non-operator positions are not macro-expanded, so some other mechanism would have to be invented to handle them in a special way. It would in fact create a first special symbol category, complicating the semantics of the language, so this is not just a technical reason. Interesting. I had tacitly assumed there was already some special symbol magic going on and so did not know it was a simple case of macro expansion with a little reader support. Second, a semantic reason: Java method calls are resolved statically if possible (you can use reflection warnings to find out where this fails), making them very fast. Creating and calling a closure is a much slower operation. Rich has stated at several occasions that he considers performance in important part of the interface of a function, so making a clear syntactic distinction between a fast and a slow operation would fit well with that point of view. I thought of this as well before posting. A few comments: 1. Creation: You only need to create one closure per function, once and for all; the closure does not close over anything in the surrounding scope, it's just a wrapper. 2. Calling: This is such a straightforward case of inlining that HotSpot will eat it for breakfast. Clojure is full of idioms that would be death to performance if not for such behavior from HotSpot. 3. Type hinting: This is a deeper problem with first-class methods. The current manner of type hinting does not work well here. If you could write SomeClass.someMethod to refer to a specific class's method and perhaps supply further signature hints in the case of same-arity overloads, e.g. #^([Integer]) ResultSet.getObject, then this could be resolved. This has been discussed some, including alternate hinting syntaxes not entirely unlike what you suggest: http://clojure-log.n01se.net/date/2010-01-21.html#08:34 --Chouser http://joyofclojure.com/ -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: REPL behaviour / time / lazyness
Laurent, Could chunked seqs explain something here ? sounds possible. If I only knew what this is ;-) Regards, alux Laurent PETIT schrieb: 2010/3/19 alux alu...@googlemail.com: ;-) Still, I dont believe. I get the same difference with user= (time (map fib0 (range 100))) Elapsed time: 1.916445 msecs more than 5 seconds (0 1 1 2 3 5 8 13 21 34 ...) user= (time (map fib0 (iterate inc 0))) Elapsed time: 0.104203 msecs (0 1 1 2 3 5 8 13 21 34 ...) Hm. Regards, alux Could chunked seqs explain something here ? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Long post with some questions about getting started...
Nick, Welcome to Clojure! On Mar 18, 5:04 pm, Nick nschub...@gmail.com wrote: I want to learn Clojure and the first idea for a simple app that popped into my head was some sort of roguelike (because I'm a gamer and this is what I like to do...) I could go on making hello world apps and tiny test apps that serve little purpose, but the way I learn is by setting an end goal and going for it. I don't intend on making this in the first shot, but like I said, there's the goal. I've read quite a bit on Clojure, done some simple stuff like the Hello World apps and such already. I get the idea of the list structure (though I'm still VERY green on this.) A little background: I have an extensive background (10+ years professional, many more non-pro) in OOP and Procedural Programing using everything from Javascript/Actionscript to C# and even the gross VB4-6 in my early years and a little known Aspect Scripting (which I've totally forgotten by now.) I've only really dealt with threaded applications in C# because, let's face it... it's dead simple even using mutex locking. Non-professionally I started on an old TRS-80 then moved to a 80386 with GWBASIC/QBASIC and dabbled in C/C++ (but mainly I've just read tons of books on C/C++...) So, I'm trying to put all that aside and think Functional for this. I'm really trying, and it's mind bending to put all that aside... but I learn by example so here's where I ask some clues. I've downloaded Netbeans and an addon and played with it a little bit, but it seems to require a _main entry method and from the various tutorials around, I see that's not the norm. I'm having an interesting (to me) question around a using REPL. Once it's shut down, where does this code go? I feel like I'm in the old TRS-80 volatile coding days where you write some code, and if you shut down you've lost it all. Is this the case? So how do you save your code in a REPL? I understand these could be unique per editor so I understand if you get irate at me for asking such a silly question... To answer your question about the REPL, yes everything is lost when you close it. However, this isn't the whole story. Once you create a new project w/ Enclojure, you can send code from a file too the REPL either from a context menu or keyboard shortcut (Alt+E in windows). It's standard practice to edit your file, and send the code to the REPL dynamically. This gets you out of the 1960s and back to 2010. I understand a list from ( to ) has the potential to be a function in separate threads because I poked my head into a tutorial I should have probably stayed clear of. If I create a function that I want to execute first on start up to check for a file and load it, but if it doesn't exist, create it and populate some array for world data. That's fairly straight forward, but in a game environment, this gets you nowhere but RAM full of data. About this point I'd then call a function create a player that would read in data from this world within a local proximity and act upon it. There's two ways I can see going about this. One is threading it off to act on it's own (which is what I'd love to do) and the other is appending it to the end of this creation function (have that function call the player on completion) but this is where I'm lost. Is it as simple as calling said method at the end of the list or is that filling up a stack of pain that I don't want to deal with when it all crashes? So I thought, I just need to do it. Just put it to silicon and start making something then I stared at the screen... A part of me would approach this as a client/server model which I'm not certain is right for functional programming. You have to have some communication method, or is the world data stored in a global location that is accessible to this player? Am I thinking about this all wrong? Would the player spawn the world load/creation only when it was needed? What if you wanted more than one actor? (would be a boring game if there were no enemies...) How does each actor access this world data? I realize some of this sounds totally noobish. Forgive me, but this is new territory for me. With OOP and functional languages I could scope a simple array of an array and reference it within it's scope. Is all Clojure scoped globally for data or am I supposed to go find something to handle that? I would figure with the nature of functional programming I could have it store data in a simple file format for the time being. That might not scale well, or it just may. I don't know. Sorry for the length of this post, the rambling, and the incoherent thought process. I realize I'm probably asking too many questions at once... :-\ You're probably asking several questions at once because you're trying to learn a lot at once. It's understandable. It sounds to me like you would benefit from learning a bit more about the language before jumping
Re: type hint puzzler
That was it. I was fixated on the ResultSet object and didn't consider overloading. Adding the (int) hint sped things up considerably. Thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: scoped local memoize
For recursive one-shot memoized functions, I've been using this: (defmacro memoized-fn [name args body] `(let [a# (atom {})] (fn ~name ~args (let [m# @a# args# ~args] (if-let [[_# v#] (find m# args#)] v# (let [v# (do ~...@body)] (swap! a# assoc args# v#) v#)) e.g., (memoized-fn fib [x] (if ( n 2) 1 (+ (fib (- n 1)) (fib (- n 2) If you need every last bit of performance, you can replace the atom- map combination with a mutable Java HashMap. -Jason On Mar 18, 11:17 pm, B Smith-Mannschott bsmith.o...@gmail.com wrote: On Fri, Mar 19, 2010 at 06:56, Greg Fodor gfo...@gmail.com wrote: I would like to memoize bar such that the memory used for memoization is GC'ed at the end of the call to foo, and additionally the cache used for memoization is thread local (so no need for heavyweight synchronization tools like atoms, etc.) In Ruby, I would implement this as a simple local hash with the ||= operator through each iteration of a loop inside foo that calls bar. ;; the trick I found is to explicitly deref the var binding the ;; function to be memoized. This way fib's recursive calls will use ;; the memoized binding established in ;; use-fib-memoized-thread-locally. (defn fib [n] (if ( 2 n) n (+ (@#'fib (dec n)) (@#'fib (dec (dec n)) (defn use-fib-memoized-thread-locally [n] (binding [fib (memoize fib)] (fib n))) ;; user (time (fib 32)) ;; Elapsed time: 1755.796366 msecs ;; SLOW ;; 2178309 ;; ;; user (time (use-fib-memoized-thread-locally 32)) ;; Elapsed time: 1.514927 msecs ;; FAST ;; 2178309 ;; ;; user (time (fib 32)) ;; Elapsed time: 2024.836838 msecs ;; SLOW, again ;; 2178309 // Ben -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Name suggestions
ffinagle (Merriam-Webster says: to obtain by indirect or involved means, to obtain by trickery, to use devious or dishonest methods to achieve one's ends) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: scoped local memoize
Excellent -- thanks all. The binding approach works very well. On Mar 19, 11:40 am, Jason Wolfe jawo...@berkeley.edu wrote: For recursive one-shot memoized functions, I've been using this: (defmacro memoized-fn [name args body] `(let [a# (atom {})] (fn ~name ~args (let [m# @a# args# ~args] (if-let [[_# v#] (find m# args#)] v# (let [v# (do ~...@body)] (swap! a# assoc args# v#) v#)) e.g., (memoized-fn fib [x] (if ( n 2) 1 (+ (fib (- n 1)) (fib (- n 2) If you need every last bit of performance, you can replace the atom- map combination with a mutable Java HashMap. -Jason On Mar 18, 11:17 pm, B Smith-Mannschott bsmith.o...@gmail.com wrote: On Fri, Mar 19, 2010 at 06:56, Greg Fodor gfo...@gmail.com wrote: I would like to memoize bar such that the memory used for memoization is GC'ed at the end of the call to foo, and additionally the cache used for memoization is thread local (so no need for heavyweight synchronization tools like atoms, etc.) In Ruby, I would implement this as a simple local hash with the ||= operator through each iteration of a loop inside foo that calls bar. ;; the trick I found is to explicitly deref the var binding the ;; function to be memoized. This way fib's recursive calls will use ;; the memoized binding established in ;; use-fib-memoized-thread-locally. (defn fib [n] (if ( 2 n) n (+ (@#'fib (dec n)) (@#'fib (dec (dec n)) (defn use-fib-memoized-thread-locally [n] (binding [fib (memoize fib)] (fib n))) ;; user (time (fib 32)) ;; Elapsed time: 1755.796366 msecs ;; SLOW ;; 2178309 ;; ;; user (time (use-fib-memoized-thread-locally 32)) ;; Elapsed time: 1.514927 msecs ;; FAST ;; 2178309 ;; ;; user (time (fib 32)) ;; Elapsed time: 2024.836838 msecs ;; SLOW, again ;; 2178309 // Ben -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Sequential vs. divide and conquer algorithm
I've been toying with various implementations of reduce-like functions, trying to do something smarter than a simple iteration over a collection of data. This hasn't worked out very well, my implementation is a lot (~50x) slower than a simple loop. Could anyone point out any bottlenecks in this algorithm and advise me on possible ways of improving it? ;-- simple (sequential) implementation (defn- sum_seq_int [val vec] (if (empty? vec) val (recur (+ val (first vec)) (rest vec (defn sum_seq [vec] (sum_seq_int 0 vec)) ;-- divideconquer approach (defn- split [vec] (let [c (count vec) c2 (/ c 2)] (list (subvec vec 0 c2) (subvec vec c2 c (defn- sum_tree_int [val vec1 vec2] (cond (and (empty? vec1) (= (count vec2) 1)) (+ val (first vec2)) (and (empty? vec2) (= (count vec1) 1)) (+ val (first vec1)) :else (let [s1 (split vec1) s2 (split vec2)] (recur (sum_tree_int val (first s1) (second s1)) (first s2) (second s2) (defn sum_tree [vec] (let [s (split vec)] (sum_tree_int 0 (first s) (second s ;-- some tests (def l1 (range 1 10)) (def l2 (range 1 1000)) (def l3 (range 1 10)) (time (sum_seq (vec l1))) Elapsed time: 0.040508 msecs 45 (time (sum_seq (vec l2))) Elapsed time: 0.297523 msecs 499500 (time (sum_seq (vec l3))) Elapsed time: 29.381109 msecs 45 (time (sum_tree (vec l1))) Elapsed time: 0.181308 msecs 45 (time (sum_tree (vec l2))) Elapsed time: 13.529094 msecs 499500 (time (sum_tree (vec l3))) Elapsed time: 1387.68363 msecs 45 What is the most likely cause of the slowdown? 1. split function, 2. non-tail-recursive function call, 3. general overhead. As for (1), how to split the collection so that no data copying is required and resulting subvectors are more or less balanced? Or, how to query the underlying data structure whether, or where, such a convenient position exists? Andrzej -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: getRuntime exec call?
The call I coded works if you only pass a string with no spaces. However, if the string has spaces there is no result. If you break the string into String[] then clojure cannot match the appropriate exec(String[]) method in Runtime. I do not know how to convince clojure to call this method. alux wrote: The call to a static method is special, try (.exec (Runtime/getRuntime) ls) Regards, alux TimDaly schrieb: (defn cmdresult [cmdstr] (let [args (into [] (seq (.split cmdstr )))] (BufferedReader. (InputStreamReader. (. (. (. Runtime (getRuntime)) (exec args)) (getInputStream)) (defn readLine [cmdresult] (. cmdresult (readLine))) (def a (cmdresult ls *.o)) This fails claiming: No matching method found: exec for class java.lang.Runtime If I replace the Runtime line with: (. (. (. Runtime (getRuntime)) (exec ls)) (getInputStream)) it works and gives me the result of the ls system call. If I replace the Runtime line with (. (. (. Runtime (getRuntime)) (exec ls *.o)) (getInputStream)) it fails even though it has a string argument. Suggestions? Tim Daly -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: clojure-mode-like syntax highlighting for the SLIME REPL
On Thu, Mar 18, 2010 at 11:08 PM, Michał Marczyk michal.marc...@gmail.com wrote: there was a Stack Overflow question recently re: syntax highlighting Clojure REPLs. This got me thinking that since I was going to tweak SLIME REPL font-lock for quite some time now (I find the default a bit too aggressive), I might as well do it now and have it use clojure-mode's font-lock settings too. Here's what I came up with: http://gist.github.com/337280 I've got some questions in connection with this. Firstly, I'd love to know whether this could be done in a simpler way. If not, then I wonder if clojure-mode could move the font-lock setup from the clojure-mode function itself to something like my clojure-font-lock-setup function and then just call that from clojure-mode? That way a usable syntax highlighting SLIME REPL would become a one hook affair. Awesome. Yeah, that sounds great. Could you submit an issue to clojure-mode to do this? http://github.com/technomancy/clojure-mode/issues A patch would be even better, of course. Then there's one thing I didn't try to tackle for now (because it would actually require me to write font-lock code, which is something that scares me to death), namely prompt highlighting (namespace appears in plain text for now). Is there a simple way to add this on top of clojure-mode font-lock settings? This would belong in swank-clojure actually. clojure-mode doesn't with slime at all by itself; it's just for highlighting, indentation, etc. (though it can spawn simplistic repl subprocesses.) -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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Sequential vs. divide and conquer algorithm
What type of improvement are you expecting to see? 1. A linear improvement based on throwing more cores at the problem? In this case you would need to use pmap to compute items in parallel. Your implementation appears to be single threaded. 2. An algorithmic improvement, like going from a DFT to an FFT? In this case, is there any theoretical reason the algorithm does less work? Are you making a time/memory trade off? This would make it easier to provide suggestions. Sean On Mar 19, 12:53 pm, Andrzej ndrwr...@googlemail.com wrote: I've been toying with various implementations of reduce-like functions, trying to do something smarter than a simple iteration over a collection of data. This hasn't worked out very well, my implementation is a lot (~50x) slower than a simple loop. Could anyone point out any bottlenecks in this algorithm and advise me on possible ways of improving it? ;-- simple (sequential) implementation (defn- sum_seq_int [val vec] (if (empty? vec) val (recur (+ val (first vec)) (rest vec (defn sum_seq [vec] (sum_seq_int 0 vec)) ;-- divideconquer approach (defn- split [vec] (let [c (count vec) c2 (/ c 2)] (list (subvec vec 0 c2) (subvec vec c2 c (defn- sum_tree_int [val vec1 vec2] (cond (and (empty? vec1) (= (count vec2) 1)) (+ val (first vec2)) (and (empty? vec2) (= (count vec1) 1)) (+ val (first vec1)) :else (let [s1 (split vec1) s2 (split vec2)] (recur (sum_tree_int val (first s1) (second s1)) (first s2) (second s2) (defn sum_tree [vec] (let [s (split vec)] (sum_tree_int 0 (first s) (second s ;-- some tests (def l1 (range 1 10)) (def l2 (range 1 1000)) (def l3 (range 1 10)) (time (sum_seq (vec l1))) Elapsed time: 0.040508 msecs 45 (time (sum_seq (vec l2))) Elapsed time: 0.297523 msecs 499500 (time (sum_seq (vec l3))) Elapsed time: 29.381109 msecs 45 (time (sum_tree (vec l1))) Elapsed time: 0.181308 msecs 45 (time (sum_tree (vec l2))) Elapsed time: 13.529094 msecs 499500 (time (sum_tree (vec l3))) Elapsed time: 1387.68363 msecs 45 What is the most likely cause of the slowdown? 1. split function, 2. non-tail-recursive function call, 3. general overhead. As for (1), how to split the collection so that no data copying is required and resulting subvectors are more or less balanced? Or, how to query the underlying data structure whether, or where, such a convenient position exists? Andrzej -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
map-filter, is this in the API?
Very simple function: (defn map-filter [f coll] (map f (filter f (coll))) Is there an API function for this that I am missing? For example, it is useful for pulling out all values in a list of maps of a certain key that is optional: Clojure= (map-filter :k [{:a :b :c :d :k :found} {:a :b :c :d} {:a :b :c :d :k :other}]) (:found :other) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Ensure
On Mon, Mar 15, 2010 at 3:34 PM, Raoul Duke rao...@gmail.com wrote: On Mon, Mar 15, 2010 at 1:13 AM, Christophe Grand christo...@cgrand.net wrote: It hasn't blocked in the sense of wait and continue: it retries the transaction after growing the history of the ref (refs have an adaptive history): i'm confused about being able to set :max-history, does that not run the risk of breaking the correctness of things? No, my understanding is that correctness is guaranteed by the retry. The adaptive history is an optimization so that the retry doesn't need to happen. As Christophe demonstrated, the first transaction essentially ran with a :max-history of 0 and the transaction had to retry. The next time around, the ref had adequate history to store its previous state so that a retry was not needed. Jim -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: getRuntime exec call?
Sorry, I'm a bit in a hurry ;-) You give a vector, it needs an array. Try something like: spels= (make-array (.getClass ) 2 ) #String[] [Ljava.lang.String;@ad8659 spels= (def arr (make-array (.getClass ) 2 )) #'spels/arr spels= (aset arr 0 write) write spels= (aset arr 1 c:\\config.sys) c:\\config.sys spels= (.exec (Runtime/getRuntime) arr) Greezs, alux Tim Daly schrieb: The call I coded works if you only pass a string with no spaces. However, if the string has spaces there is no result. If you break the string into String[] then clojure cannot match the appropriate exec(String[]) method in Runtime. I do not know how to convince clojure to call this method. alux wrote: The call to a static method is special, try (.exec (Runtime/getRuntime) ls) Regards, alux TimDaly schrieb: (defn cmdresult [cmdstr] (let [args (into [] (seq (.split cmdstr )))] (BufferedReader. (InputStreamReader. (. (. (. Runtime (getRuntime)) (exec args)) (getInputStream)) (defn readLine [cmdresult] (. cmdresult (readLine))) (def a (cmdresult ls *.o)) This fails claiming: No matching method found: exec for class java.lang.Runtime If I replace the Runtime line with: (. (. (. Runtime (getRuntime)) (exec ls)) (getInputStream)) it works and gives me the result of the ls system call. If I replace the Runtime line with (. (. (. Runtime (getRuntime)) (exec ls *.o)) (getInputStream)) it fails even though it has a string argument. Suggestions? Tim Daly -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: getRuntime exec call?
On Mar 19, 2010, at 6:07 AM, TimDaly wrote: (defn cmdresult [cmdstr] (let [args (into [] (seq (.split cmdstr )))] (BufferedReader. (InputStreamReader. (. (. (. Runtime (getRuntime)) (exec args)) (getInputStream)) Why do (into [])? .exec expects a String[], exactly what .split gives you. I wrote something similar recently (included below, in case you're interested). You could easily wrap it with a .split to get similar functionality, though personally I prefer passing the args as a list because that way you can deal with paths with spaces in them. -Michael (defn cmd [command args] Runs command with args and returns its stdout, stderr, and exit status. (let [process (.start (ProcessBuilder. (into-array (cons command args] (.waitFor process) (hash-map :output (line-seq (java.io.BufferedReader. (java.io.InputStreamReader. (.getInputStream process :error (line-seq (java.io.BufferedReader. (java.io.InputStreamReader. (.getErrorStream process :status (.exitValue process (defn do-cmd [command args] Runs command with args and returns its stdout as a seq of lines. Throws exception on failure. (let [command (apply cmd command args)] (if (zero? (:status command)) (:output command) (throw (Exception. (str Command failed: (apply str (interpose \n (:error command) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: map-filter, is this in the API?
Nope. (map f (filter f ...)) is currently the way to go. On Mar 19, 1:54 pm, Greg Fodor gfo...@gmail.com wrote: Very simple function: (defn map-filter [f coll] (map f (filter f (coll))) Is there an API function for this that I am missing? For example, it is useful for pulling out all values in a list of maps of a certain key that is optional: Clojure= (map-filter :k [{:a :b :c :d :k :found} {:a :b :c :d} {:a :b :c :d :k :other}]) (:found :other) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: map-filter, is this in the API?
On Mar 19, 2010, at 12:54 PM, Greg Fodor wrote: Very simple function: (defn map-filter [f coll] (map f (filter f (coll))) You have an extra parenthesis before coll. Is there an API function for this that I am missing? For example, it is useful for pulling out all values in a list of maps of a certain key that is optional: Clojure= (map-filter :k [{:a :b :c :d :k :found} {:a :b :c :d} {:a :b :c :d :k :other}]) (:found :other) I don't think so. But note that you can do the filter after the map, to avoid applying f twice per element: (defn map-filter-2 [f coll] (filter identity (map f coll))) -Michael -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Sequential vs. divide and conquer algorithm
On Sat, Mar 20, 2010 at 2:15 AM, Sean Devlin francoisdev...@gmail.com wrote: What type of improvement are you expecting to see? 1. A linear improvement based on throwing more cores at the problem? Yes. In this case you would need to use pmap to compute items in parallel. I haven't looked at pmap yet. Thanks for the clue, it might prove more useful indeed. Your implementation appears to be single threaded. Yes, that's just a test. I guess I should have also chosen a more realistic worker function. As all clojure's persistent data collections are built on top of tree structures I thought this kind of destructuring could be both straightforward to implement and efficient. I wonder if a built-in partition function, aware of the internal representation of the collection data, could help here. 2. An algorithmic improvement, like going from a DFT to an FFT? In this case, is there any theoretical reason the algorithm does less work? Are you making a time/memory trade off? No, although balancing the operations could potentially help with some second order effects (e.g. numerical errors). Thanks, Andrzej -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Long post with some questions about getting started...
On Mar 18, 2010, at 2:04 PM, Nick wrote: I'm having an interesting (to me) question around a using REPL. Once it's shut down, where does this code go? I feel like I'm in the old TRS-80 volatile coding days where you write some code, and if you shut down you've lost it all. Is this the case? So how do you save your code in a REPL? I understand these could be unique per editor so I understand if you get irate at me for asking such a silly question... I mostly use the repl for executing tests, preferring to write and evaluate Clojure definitions from a lisp editor. For example, in the MCLIDE lisp editor, I evaluate lisp code in the editor by placing the cursor at the opening or closing parenthesis of an expression then hit the Enter key. Alternatively, I use a menu shortcut to (re) evaluate all definitions in the file I am editing. -- Terje Norderhaug te...@in-progress.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: getRuntime exec call?
Also, have a look at http://richhickey.github.com/clojure-contrib/shell-api.html /Patrik On Mar 19, 7:00 pm, Michael Gardner gardne...@gmail.com wrote: On Mar 19, 2010, at 6:07 AM, TimDaly wrote: (defn cmdresult [cmdstr] (let [args (into [] (seq (.split cmdstr )))] (BufferedReader. (InputStreamReader. (. (. (. Runtime (getRuntime)) (exec args)) (getInputStream)) Why do (into [])? .exec expects a String[], exactly what .split gives you. I wrote something similar recently (included below, in case you're interested). You could easily wrap it with a .split to get similar functionality, though personally I prefer passing the args as a list because that way you can deal with paths with spaces in them. -Michael (defn cmd [command args] Runs command with args and returns its stdout, stderr, and exit status. (let [process (.start (ProcessBuilder. (into-array (cons command args] (.waitFor process) (hash-map :output (line-seq (java.io.BufferedReader. (java.io.InputStreamReader. (.getInputStream process :error (line-seq (java.io.BufferedReader. (java.io.InputStreamReader. (.getErrorStream process :status (.exitValue process (defn do-cmd [command args] Runs command with args and returns its stdout as a seq of lines. Throws exception on failure. (let [command (apply cmd command args)] (if (zero? (:status command)) (:output command) (throw (Exception. (str Command failed: (apply str (interpose \n (:error command) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: getRuntime exec call?
Hi, On Fri, Mar 19, 2010 at 11:00:34AM -0700, alux wrote: spels= (make-array (.getClass ) 2 ) #String[] [Ljava.lang.String;@ad8659 spels= (def arr (make-array (.getClass ) 2 )) #'spels/arr spels= (aset arr 0 write) write spels= (aset arr 1 c:\\config.sys) c:\\config.sys spels= (.exec (Runtime/getRuntime) arr) It's easier to use into-array: (.exec (Runtime/getRuntime) (into-array [write c:\\config.sys])) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: getRuntime exec call?
;-) I'm still at letter b in clojure.core. Grin. Regards, a. Meikel Brandmeyer schrieb: Hi, On Fri, Mar 19, 2010 at 11:00:34AM -0700, alux wrote: spels= (make-array (.getClass ) 2 ) #String[] [Ljava.lang.String;@ad8659 spels= (def arr (make-array (.getClass ) 2 )) #'spels/arr spels= (aset arr 0 write) write spels= (aset arr 1 c:\\config.sys) c:\\config.sys spels= (.exec (Runtime/getRuntime) arr) It's easier to use into-array: (.exec (Runtime/getRuntime) (into-array [write c:\\config.sys])) Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Java method call irritation
On Mar 18, 11:55 am, Per Vognsen per.vogn...@gmail.com wrote: Is there any reason why a .method occurrence in non-operator position doesn't just do the closure wrapping automagically? It's been discussed as a possibility; it may be added to Clojure in the future. -SS -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Name suggestions
On Mar 17, 3:08 am, mac markus.gustavs...@gmail.com wrote: After just a little more test and polish I plan on calling clj-native 1.0. But clj-native is a *really* boring name so I want to change it before 1.0 and I don't have very good imagination when it comes to these things. Personally, I much prefer library names that are descriptive rather than creative. Give your kids cute names, not your libraries. -SS -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
clojure.walk
This post has two parts. Part 1. I know that the API is trying to hit the sweet spot on the brevity vs. information curve, but there are several areas where more information is needed; one of these is clojure.walk. Let's say that I have some nested set of vectors: (def nestV [ [0 [0] ] [0 0] ]) and I want to apply #(+ % 3) to each element and get out a nested set of vectors with the same shape as nestV [ [3 [3] ] [3 3]]. The overview to clojure.walk says the following: It takes any data structure (list, vector, map, set, seq), calls a function on every element, and uses the return value of the function in place of the original. This sounds like I will find a function within this namespace that will do what I want. I tried prewalk and postwalk, which, from the their usage examples would appear to be what I want. But when I try to test them I find the following: user= (prewalk #(+ 3 %) nestV) #CompilerException java.lang.ClassCastException: clojure.lang.PersistentVector (NO_SOURCE_FILE:0) user= (postwalk #(+ 3 %) nestV) #CompilerException java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.PersistentVector (NO_SOURCE_FILE:0) The problem with the usage examples is that they don't actually show what the outcome will be. Further, there is no documentation other than the API on clojure.walk. Part 2 Is there a function in the API that allows me to do the type of calculation I described above? user= (some-function #(+ % 3) nestV) (((3(3))(3 3)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Long post with some questions about getting started...
On Fri, 19 Mar 2010 07:21:50 -0700 (PDT) Sean Devlin francoisdev...@gmail.com wrote: I'm having an interesting (to me) question around a using REPL. Once it's shut down, where does this code go? I feel like I'm in the old TRS-80 volatile coding days where you write some code, and if you shut down you've lost it all. Is this the case? So how do you save your code in a REPL? I understand these could be unique per editor so I understand if you get irate at me for asking such a silly question... To answer your question about the REPL, yes everything is lost when you close it. However, this isn't the whole story. Once you create a new project w/ Enclojure, you can send code from a file too the REPL either from a context menu or keyboard shortcut (Alt+E in windows). It's standard practice to edit your file, and send the code to the REPL dynamically. This gets you out of the 1960s and back to 2010. Most clojure-aware environments will have similar functionality: SLIME+SWANK, Eclipse, etc. It's not clear this really gets you out of the 60s, though - it's been standard practice for (file-based *) LISP development for as long as I can remember. Nuts, it worked with Scheme2C and mg on the Amiga in the 80s. mike *) InterLISP and some others were more like SmallTalk, or MS BASIC, in that you edited code at the REPL and saved the entire workspace. That did add power - I've never seen a file-based LISP whose error handler would let me fix the code on the fly and continue execution. -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O ascii ribbon campaign - stop html mail - www.asciiribbon.org -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: clojure.walk
I'm not overly familiar with clojure.walk, but I think you'll find the output of (prewalk #(doto % prn) [[3 [3]] [3 3]]) very illuminating. On Fri, Mar 19, 2010 at 2:13 PM, cej38 junkerme...@gmail.com wrote: This post has two parts. Part 1. I know that the API is trying to hit the sweet spot on the brevity vs. information curve, but there are several areas where more information is needed; one of these is clojure.walk. Let's say that I have some nested set of vectors: (def nestV [ [0 [0] ] [0 0] ]) and I want to apply #(+ % 3) to each element and get out a nested set of vectors with the same shape as nestV [ [3 [3] ] [3 3]]. The overview to clojure.walk says the following: It takes any data structure (list, vector, map, set, seq), calls a function on every element, and uses the return value of the function in place of the original. This sounds like I will find a function within this namespace that will do what I want. I tried prewalk and postwalk, which, from the their usage examples would appear to be what I want. But when I try to test them I find the following: user= (prewalk #(+ 3 %) nestV) #CompilerException java.lang.ClassCastException: clojure.lang.PersistentVector (NO_SOURCE_FILE:0) user= (postwalk #(+ 3 %) nestV) #CompilerException java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.PersistentVector (NO_SOURCE_FILE:0) The problem with the usage examples is that they don't actually show what the outcome will be. Further, there is no documentation other than the API on clojure.walk. Part 2 Is there a function in the API that allows me to do the type of calculation I described above? user= (some-function #(+ % 3) nestV) (((3(3))(3 3)) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Installation issues on slack 13.0 (ant?)
FYI: I'm using slackware 13.0, 32-bit slack has much to redeem it, but there is no apt-get, synaptic and aptitude. Thus when I unzip clojure-1.1.0.zip, the closest I can find to installation instructions are at readme.txt. Looks like a very simple process, except that I am unfamiliar with `ant'. Looks like I need to install it. So what am I looking for? Is it apache-ant, or some other system? And where do I download it? Note: slack has very good build tools for applications with C as the source, so if ant is written in C, source would be fine Thanks -- Tim t...@johnsons-web.com http://www.akwebsoft.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: overrding function from other namespace
why are you def'ing your functions in the mock namespace? why are you juggling namespaces at all? On Wed, Mar 17, 2010 at 3:12 PM, Martin Hauner martin.hau...@gmx.net wrote: Hi, I trying to use clojure.contrib.mock. It says to override the function report-problem to integrate it into other test framework like clojure.test. I've got this working, but the namespace switching looks a bit ugly. Is there a better way to handle this? Maybe something like (ns clojure.contrib.mock (defn... the override) ) which avoids the extra code to switch back to the original namespace? (ns apfloattest (:use apfloat clojure.test clojure.contrib.mock)) (ns clojure.contrib.mock (:use clojure.test)) ; delegate mock reporting to clojure.test (defn report-problem ([function expected actual message] (is (= expected actual) (str message Function name: function (ns apfloattest) (deftest test-sqrtf (expect [apf (times 1 (returns (apf 5)))] (sqrtf 5))) -- Martin -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject. -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
clojure naming convention for accessors vs. local variables
If am creating accessors to access structures, how should they be named? (defstruct employer :employee) (defstruct employee :employer) (def employee-name (accessor employee :employer)) (def employer-name (accessor employer :employee)) In a situation where one struct is pointing to the other, is that the best accessor name? Since structs are lower case do they clash with variables and accessors ever? I could easily see myself doing (def employee (...)) Here, I assume it won't have any problems, but does it become problematic later? Especially since it seems that accessors can be in either order. (defstruct vert :id :edgeId) (defstruct edge :id :vertId) (def vert (accessor edge :vert)) (def edge (accessor vert :edge)) I know this could be easily resolved by changing the accessor definitions to get-vert and get-edge, but I was hoping it wouldn't be necessary. Once again, I'm bound to have a variable somewhere in my code called vert and edge. Java and Scala don't seem to have this problem. Especially using Scala's builtin getter setter feature, which has strick ordering like edge.vert // returns the vert for this edge vert.edge // returns the edge for this vert Is there a better naming convention to follow? get-vert and get- edge? Should structures ever be uppercase to distinguish them? That doesn't seem to be the lisp convention. In these cases it seems the struct name would never be a problem, but it seems I'm stuck between making a convenient accessor name and easily stomping over if making a convenient variable name. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: clojure-mode-like syntax highlighting for the SLIME REPL
On 19 March 2010 18:12, Phil Hagelberg p...@hagelb.org wrote: On Thu, Mar 18, 2010 at 11:08 PM, Michał Marczyk Awesome. Yeah, that sounds great. Could you submit an issue to clojure-mode to do this? http://github.com/technomancy/clojure-mode/issues A patch would be even better, of course. Sure thing, I'll send you a patch / pull request sometime this weekend. :-) Then there's one thing I didn't try to tackle for now (because it would actually require me to write font-lock code, which is something that scares me to death), namely prompt highlighting (namespace appears in plain text for now). Is there a simple way to add this on top of clojure-mode font-lock settings? This would belong in swank-clojure actually. clojure-mode doesn't with slime at all by itself; it's just for highlighting, indentation, etc. (though it can spawn simplistic repl subprocesses.) Yes, I realise that's not something to put in clojure-mode. What I meant is that I haven't yet investigated how slime-repl swank-clojure (?) go about putting those custom text properties on things captured on the standard output of the Lisp process (so things like (doc foo) or the output of (println :foo) have their own subdued colour). Basically I'd like to try to use whatever mechanism is in place for distinguishing printouts from return values and combine that with clojure-mode highlighting for the perfect Clojure-oriented SLIME REPL experience. ;-) Hopefully I'll be able to do that in the next few days; I'll post it for your consideration as soon as I have it ready. (Note that as far as font-lock is concerned, I hardly know what I'm doing. Perhaps someone who knows what they're doing will post the elisp incantation to accomplish the above before I get started on it. :-)) All the best, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: clojure-mode-like syntax highlighting for the SLIME REPL
On 19 March 2010 12:58, Rick Moynihan rick.moyni...@gmail.com wrote: Very cute! I'd love to see this integrated into clojure-mode! Glad you like it! As mentioned above, I'll try to polish it a bit further. Sincerely, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Installation issues on slack 13.0 (ant?)
On 20 March 2010 00:32, Tim Johnson t...@johnsons-web.com wrote: So what am I looking for? Is it apache-ant, or some other system? And where do I download it? Yes, it's Apache Ant: http://ant.apache.org/ Note: slack has very good build tools for applications with C as the source, so if ant is written in C, source would be fine It's written in Java. You should be able to get a jar, from the project page or perhaps a Maven repo (e.g. http://repo1.maven.org/maven2/ant/ant/1.6.5/). Sincerely, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Installation issues on slack 13.0 (ant?)
* Micha?? Marczyk michal.marc...@gmail.com [100319 15:56]: On 20 March 2010 00:32, Tim Johnson t...@johnsons-web.com wrote: So what am I looking for? Is it apache-ant, or some other system? And where do I download it? Yes, it's Apache Ant: http://ant.apache.org/ Thanks. I got it. Installed it as per instructions at http://ant.apache.org/manual/index.html Now i have the following error messages: ## = t...@bart:~$ echo $PATH /usr/local/bin/ant/bin:/usr/local/bin/ant:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/java/bin:/usr/lib/kde4/libexec:/usr/lib/qt/bin:/usr/share/texmf/bin:. t...@bart:~$ ant Exception in thread main java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit. ## = More paths: t...@bart:~$ echo $ANT_HOME /usr/local/bin/ant/bin $JAVA_HOME /usr/lib/java -- Tim t...@johnsons-web.com http://www.akwebsoft.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Installation issues on slack 13.0 (ant?)
I would guess that you need the ant-launcher jar too: http://repo1.maven.org/maven2/ant/ant-launcher/1.6.5/ If you find there might be something else missing, check out the whole ant group: http://repo1.maven.org/maven2/ant/ HTH. Sincerely, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Installation issues on slack 13.0 (ant?)
* Micha?? Marczyk michal.marc...@gmail.com [100319 16:46]: I would guess that you need the ant-launcher jar too: http://repo1.maven.org/maven2/ant/ant-launcher/1.6.5/ If you find there might be something else missing, check out the whole ant group: http://repo1.maven.org/maven2/ant/ I'm looking at that URL now. --- where is the .jar file to be installed? (Feel free to point me to documentation) --- Example - on my machine the java binary is at: /usr/lib/java/bin/java thanks -- Tim t...@johnsons-web.com http://www.akwebsoft.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Long post with some questions about getting started...
On Mar 19, 2010, at 4:17 PM, Mike Meyer wrote: On Fri, 19 Mar 2010 07:21:50 -0700 (PDT) Sean Devlin francoisdev...@gmail.com wrote: I'm having an interesting (to me) question around a using REPL. Once it's shut down, where does this code go? I feel like I'm in the old TRS-80 volatile coding days where you write some code, and if you shut down you've lost it all. Is this the case? So how do you save your code in a REPL? I understand these could be unique per editor so I understand if you get irate at me for asking such a silly question... To answer your question about the REPL, yes everything is lost when you close it. However, this isn't the whole story. Once you create a new project w/ Enclojure, you can send code from a file too the REPL either from a context menu or keyboard shortcut (Alt+E in windows). It's standard practice to edit your file, and send the code to the REPL dynamically. This gets you out of the 1960s and back to 2010. Most clojure-aware environments will have similar functionality: SLIME+SWANK, Eclipse, etc. It's not clear this really gets you out of the 60s, though - it's been standard practice for (file-based *) LISP development for as long as I can remember. Nuts, it worked with Scheme2C and mg on the Amiga in the 80s. *) InterLISP and some others were more like SmallTalk, or MS BASIC, in that you edited code at the REPL and saved the entire workspace. That did add power - I've never seen a file-based LISP whose error handler would let me fix the code on the fly and continue execution. Possibly I am misunderstanding I've never seen a file-based LISP whose error handler would let me fix the code on the fly and continue execution but that sounds like common practice in the REPL break loop for many lisps. -- Terje Norderhaug te...@in-progress.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: clojure naming convention for accessors vs. local variables
As the doc for 'accessor notes, you should really eschew this stuff altogether, and be more idiomatic by just using the keyword. If you absolutely know that you need that (slightly) more efficient access, then naming the struct with an uppercase first letter works, and isn't too uncommon; besides this is a special-case performance issue, right? On Mar 19, 4:36 pm, strattonbrazil strattonbra...@gmail.com wrote: If am creating accessors to access structures, how should they be named? (defstruct employer :employee) (defstruct employee :employer) (def employee-name (accessor employee :employer)) (def employer-name (accessor employer :employee)) In a situation where one struct is pointing to the other, is that the best accessor name? Since structs are lower case do they clash with variables and accessors ever? I could easily see myself doing (def employee (...)) Here, I assume it won't have any problems, but does it become problematic later? Especially since it seems that accessors can be in either order. (defstruct vert :id :edgeId) (defstruct edge :id :vertId) (def vert (accessor edge :vert)) (def edge (accessor vert :edge)) I know this could be easily resolved by changing the accessor definitions to get-vert and get-edge, but I was hoping it wouldn't be necessary. Once again, I'm bound to have a variable somewhere in my code called vert and edge. Java and Scala don't seem to have this problem. Especially using Scala's builtin getter setter feature, which has strick ordering like edge.vert // returns the vert for this edge vert.edge // returns the edge for this vert Is there a better naming convention to follow? get-vert and get- edge? Should structures ever be uppercase to distinguish them? That doesn't seem to be the lisp convention. In these cases it seems the struct name would never be a problem, but it seems I'm stuck between making a convenient accessor name and easily stomping over if making a convenient variable name. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: clojure.walk
Kevin, thank you for your example. Ok here is what I get: (prewalk #(doto % prn) [[3 [3]] [3 3]]) [[3 [3]] [3 3]] [3 [3]] 3 [3] 3 [3 3] 3 3 [[3 [3]] [3 3]] Thus, it appears that an element of my nested vectors isn't just the values within the vectors, but also stands for the inner vectors as well. I agree that this is a (maybe THE) proper way of reading the quoted API text from my earlier post. But this goes to the first part of my earlier post, given this small example I have a much better idea of what is going on. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: overrding function from other namespace
I'd imagine you should be using with-bindings: user= (ns foo) nil foo= (defn bar [x] (inc x)) #'foo/bar foo= (ns user) nil user= (foo/bar 5) 6 user= (with-bindings {#'foo/bar #(dec %)} (foo/bar 5)) 4 On Mar 17, 3:12 pm, Martin Hauner martin.hau...@gmx.net wrote: Hi, I trying to use clojure.contrib.mock. It says to override the function report-problem to integrate it into other test framework like clojure.test. I've got this working, but the namespace switching looks a bit ugly. Is there a better way to handle this? Maybe something like (ns clojure.contrib.mock (defn... the override) ) which avoids the extra code to switch back to the original namespace? (ns apfloattest (:use apfloat clojure.test clojure.contrib.mock)) (ns clojure.contrib.mock (:use clojure.test)) ; delegate mock reporting to clojure.test (defn report-problem ([function expected actual message] (is (= expected actual) (str message Function name: function (ns apfloattest) (deftest test-sqrtf (expect [apf (times 1 (returns (apf 5)))] (sqrtf 5))) -- Martin -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Simple functional programming lexicon?
On 18 March 2010 20:56, Ben Armstrong synerg...@gmail.com wrote: On 18/03/10 06:57 AM, Michael Kohl wrote: There's a really nice article series on monads in Clojure: http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/ Oh, wow! Lucidly written. And it gives me something, maybe-m, that I can't believe I got along without before. I'm eager now to continue with part 2 Agreed. :-) Well, I almost gave in to an urge to go on musing about FP in general, but I decided to suppress it for now and to post instead my own short bibliography of monad-related Web resources. Clojure-based stuff comes first, though I'm also including two Haskell links of particular interest. Michael has already mentioned Konrad's tutorial, but it is still included below so that I can use this posting as a self-contained reference. Clearly it is true that there is no need to learn about monads to programme in Clojure (and to be productive and have fun while doing so), but they do make for a very interesting approach to structuring computations, so if one is already curious about them, then one cannot go wrong with some monadic food for thought. ;-) (The full immersion programme is run in Haskell, of course, but the Clojure experience is very enlightening too.) All the best, Michał Monads: A Bibliography = First, the above mentioned tutorial by Konrad Hinsen: [A Monad Tutorial For Clojure Programmers][1] The following articles by Jim Duey are also very good (and they do take a somewhat different approach to Konrad's tutorial, so it's worth while to read both series): [Monads in Clojure][2] [Higher Level Monads][3] [Why Use Monads][4] [The Continuation Monad in Clojure][5] [Sessions for Compojure][6] There's also a very good Haskell resource on the most frequently used monads: [All About Monads][7] The example code is in Haskell, but each monad's section includes some motivating discussion. Then there are [Philip Wadler's monad-related papers][8]. IIRC, Monads for functional programming is a bit of a tutorial paper, so that may be worth skimming. And just for the pleasure of reading through the numerous displays of breathtaking FP brilliance collected therein, take a look at [Oleg Kiselyov's site][9]. The section labelled Computation has a subsection devoted to monads. [1]: http://onclojure.com/2009/03/05/a-monad-tutorial-for-clojure-programmers-part-1/ [2]: http://intensivesystems.net/tutorials/monads_101.html [3]: http://intensivesystems.net/tutorials/monads_201.html [4]: http://intensivesystems.net/tutorials/why_monads.html [5]: http://intensivesystems.net/tutorials/cont_m.html [6]: http://intensivesystems.net/tutorials/web_sessions.html [7]: http://www.haskell.org/all_about_monads/html/index.html [8]: http://homepages.inf.ed.ac.uk/wadler/topics/monads.html [9]: http://okmij.org/ftp/ -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
Re: Installation issues on slack 13.0 (ant?)
Actually that Maven repo suggestion strikes me as misguided now, seeing how your purpose is to have a usable ant command and not access ant as a library... You'll probably be better of with the latest ant distribution from their webpage. The installation docs are here: http://ant.apache.org/manual/index.html This page does include instructions on where to put things. Sincerely, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.
lazy-xml returns 503 from w3.org
Hi, In trying to use clojure.cotrib.lazy-xml to parse a xml file. I get java.io.IOException: Server returned HTTP response code: 503 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd because w3c blocks access to that dtd now. Is there any work around? Thanks, -- Omnem crede diem tibi diluxisse supremum. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words REMOVE ME as the subject.