Re: Quick slime/emacs questions
Mark Engelberg writes: Hi Mark, > Also, where can I look up the names of various commands to rebind to > different keys? For example, I want to remap C-s to do what C-x-C-s > currently does, and I wan to remap C-f to do what C-s currently does, > to make behavior more consistent with other programs I use. (After > using emacs for a while, I inevitably find myself hitting C-x-C-s to > save in other programs :) ) If you want the usual C-s saves, C-x cuts, C-v pastes bindings, you can enable CUA mode: ,[ C-h f cua-mode RET ] | cua-mode is an interactive autoloaded Lisp function in `cua-base.el'. | | It is bound to , | . | | (cua-mode &optional arg) | | Toggle CUA key-binding mode. | When enabled, using shifted movement keys will activate the | region (and highlight the region using `transient-mark-mode'), | and typed text replaces the active selection. | | Also when enabled, you can use C-z, C-x, C-c, and C-v to undo, | cut, copy, and paste in addition to the normal Emacs bindings. | The C-x and C-c keys only do cut and copy when the region is | active, so in most cases, they do not conflict with the normal | function of these prefix keys. | | If you really need to perform a command which starts with one of | the prefix keys even when the region is active, you have three | options: | - press the prefix key twice very quickly (within 0.2 seconds), | - press the prefix key and the following key within 0.2 seconds, or | - use the SHIFT key with the prefix key, i.e. C-S-x or C-S-c. | | You can customize `cua-enable-cua-keys' to completely disable the | CUA bindings, or `cua-prefix-override-inhibit-delay' to change | the prefix fallback behavior. | | CUA mode manages Transient Mark mode internally. Trying to disable | Transient Mark mode while CUA mode is enabled does not work; if you | only want to highlight the region when it is selected using a | shifted movement key, set `cua-highlight-region-shift-only'. ` But I'd suggest to try the standard bindings for some time first. As others already said, if you use Emacs efficiently you'll isearch much more than you'll save, and C-s is isearch by default. (There's no faster navigation/movement than isearching.) Bye, Tassilo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: file io
sweet :) - Korny On Fri, Mar 27, 2009 at 4:34 AM, Victor Rodriguez wrote: > > On Tue, Mar 24, 2009 at 11:05 PM, Korny Sietsma wrote: > > It'd be nice to have a macro that worked more like the first example - > > "spit" is great for one-liners, but the fact that it opens and closes the > > file each time you call it seems a bit painful for anything more complex. > > Something that ends up working like: > > > > (with-out-as "test.txt" > >(println "hello") > >(println "world")) > > WARNING: spoilers ahead: > > (use 'clojure.contrib.duck-streams) > > (defmacro with-out-as > [f & body] > `(with-open [w# (writer ~f)] > (binding [*out* w#] > ~...@body))) > > (with-out-as "/tmp/test.txt" > (print "hola,") > (println " crayola")) > > > Cheers, > > Victor Rodriguez. > > > Hmm - I've never written a macro, maybe I should give this a try... > > > > - Korny > > > > On Wed, Mar 25, 2009 at 5:10 AM, Stuart Sierra < > the.stuart.sie...@gmail.com> > > wrote: > >> > >> On Mar 24, 12:42 pm, Parth Malwankar > >> wrote: > >> > user=> (with-open [f (writer (file "test.txt"))] > >> > (binding [*out* f] > >> >(println "hello world !!!"))) > >> > >> Or even more simply: > >> > >> (use 'clojure.contrib.duck-streams) > >> (spit "test.txt" "Hello, world!\n") > >> > >> -Stuart Sierra > >> > > > > > > > > -- > > Kornelis Sietsma korny at my surname dot com > > "Every jumbled pile of person has a thinking part > > that wonders what the part that isn't thinking > > isn't thinking of" > > > > > > > > > > > -- Kornelis Sietsma korny at my surname dot com "Every jumbled pile of person has a thinking part that wonders what the part that isn't thinking isn't thinking of" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Suggest patch to math.clj - integer-length
I changed "integer-length" to use numberOfLeadingZeros or bitLength methods. It reduces execution time a bit. So that of "exact-integer-sqrt" too. ;; test with name integer-length-new (defmulti ;; #^{:private true} integer-length-new class) (defmethod integer-length-new java.lang.Integer [n] (- 32 (Integer/numberOfLeadingZeros n))) (defmethod integer-length-new java.lang.Long [n] (- 64 (Long/numberOfLeadingZeros n))) (defmethod integer-length-new java.math.BigInteger [n] (.bitLength n)) (defn time-f [f start length] (time (dorun (map f (range start (+ start length)) ;; Integer case (time-f integer-length (expt 2 10) (expt 10 6)) "Elapsed time: 435.079883 msecs" (time-f integer-length-new (expt 2 10) (expt 10 6)) "Elapsed time: 415.858854 msecs" ;; Long case (time-f integer-length (expt 2 40) (expt 10 6)) "Elapsed time: 746.825107 msecs" (time-f integer-length-new (expt 2 40) (expt 10 6)) "Elapsed time: 612.915711 msecs" ;; BigInteger case (time-f integer-length (expt 2 70) (expt 10 5)) "Elapsed time: 1263.520978 msecs" (time-f integer-length-new (expt 2 70) (expt 10 5)) "Elapsed time: 1006.090455 msecs" --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~--- --- math.clj.~master~ 2009-03-30 10:37:00.0 +0900 +++ math.clj 2009-03-30 11:04:02.0 +0900 @@ -134,11 +134,11 @@ ; Length of integer in binary, used as helper function for sqrt. (defmulti #^{:private true} integer-length class) (defmethod integer-length java.lang.Integer [n] - (count (Integer/toBinaryString n))) + (- 32 (Integer/numberOfLeadingZeros n))) (defmethod integer-length java.lang.Long [n] - (count (Long/toBinaryString n))) + (- 64 (Long/numberOfLeadingZeros n))) (defmethod integer-length java.math.BigInteger [n] - (count (. n toString 2))) + (.bitLength n)) ;; Produces the largest integer less than or equal to the square root of n ;; Input n must be a non-negative integer
inconsistency with ref & get
I noticed an inconsistency with refs and get: (def ref-map (ref {:a 1, :b 2})) (ref-map :a) => 1 (get ref-map :a) => nil Now I haven't seen any documentation that getting the value of a ref without a @/deref is supported at all, so maybe this isn't supported. But if those forms are supported, both forms should return the same value, and if it isn't supported, I think they should throw exceptions. I'm willing to write patches either way. Allen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Fresh Clojure Tutorial
Looks great, thanks a bunch. I'm not coming from a Java background so any swing example I can get my hands on is great. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: bug in clojure.contrib.math/exact-integer-sqrt
I know I can ignore leftover part, but my concern is that exact- integer-sqrt will calculate leftover if needed or not. Why not 2 public functions? like mzscheme's "integer-sqrt" and "integer-sqrt/remainder" On Mar 30, 9:16 am, Mark Engelberg wrote: > If you don't care about the "leftover" portion that exact-integer-sqrt > returns, you can do something like: > (let [[floor-sqrt _] (exact-integer-sqrt n)] ...) > or (first (exact-integer-sqrt n)) > > so I didn't want to expose another function which returns only half of > the information that this one does. > > On Sun, Mar 29, 2009 at 4:34 PM, hjlee wrote: > > I'm not sure, I think there might be cases the error part not needed. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Quick slime/emacs questions
Something like this in your ~/.emacs might do the job: (define-key global-map (kbd "C-x C-b") (lambda () (interactive) (select-window (call-interactively 'list-buffers Cheers, Mark On Mar 30, 7:41 am, Mark Engelberg wrote: > When I have two windows open, and hit C-x-C-b, it pops up a list of > buffers in the OTHER window from where the current focus is. Any idea > why it's doing that, and how I can alter the behavior so it pops up > the list of buffers in the current window? > > Also, where can I look up the names of various commands to rebind to > different keys? For example, I want to remap C-s to do what C-x-C-s > currently does, and I wan to remap C-f to do what C-s currently does, > to make behavior more consistent with other programs I use. (After > using emacs for a while, I inevitably find myself hitting C-x-C-s to > save in other programs :) ) > > Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Quick slime/emacs questions
On Sun, Mar 29, 2009 at 4:41 PM, Mark Engelberg wrote: > > When I have two windows open, and hit C-x-C-b, it pops up a list of > buffers in the OTHER window from where the current focus is. Any idea > why it's doing that, and how I can alter the behavior so it pops up > the list of buffers in the current window? I'm afraid I can't help you with C-x X-b, but I highly recommend anything.el, which can do much more than chaging buffers, as a replacement. It is so useful I have it binded to C-o: http://www.emacswiki.org/cgi-bin/wiki/Anything > Also, where can I look up the names of various commands to rebind to > different keys? For example, I want to remap C-s to do what C-x-C-s > currently does, and I wan to remap C-f to do what C-s currently does, > to make behavior more consistent with other programs I use. (After > using emacs for a while, I inevitably find myself hitting C-x-C-s to > save in other programs :) ) Ouch, you are going to rebind two of the most useful Emacs commands: search forward and move forward. If you don't know about search-forward and are still using the arrow keys to move the cursor around, you are missing opportunities to be much more productive. Emacs is an amazing tool, it pays to spend some time becoming proficient with it. A good place to start is emacswiki.org. Cheers, Victor Rodriguez. > Thanks! > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Does anyone have a simple example of making a JPopupMenu in Clojure?
I'm one of the ones who /didn't/ come from Java to Clojure. I can only get myself so far looking at Java examples. I need to make a context menu that will pop up when I right click inside of a JEditorPane. I'd appreciate it if anyone could whip me up a simple example of doing something like that in Clojure. Thanks in advance! -Anthony --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: bug in clojure.contrib.math/exact-integer-sqrt
If you don't care about the "leftover" portion that exact-integer-sqrt returns, you can do something like: (let [[floor-sqrt _] (exact-integer-sqrt n)] ...) or (first (exact-integer-sqrt n)) so I didn't want to expose another function which returns only half of the information that this one does. On Sun, Mar 29, 2009 at 4:34 PM, hjlee wrote: > I'm not sure, I think there might be cases the error part not needed. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Status of Eclipse plug-in and OSGi compatibility
Hi *, I just came back from EclipseCON 2009. There was a short talk about Clojure (that I unfortunaltely missed) but the slides are available here http://www.eclipsecon.org/2009/sessions?id=630, click though to gpublication. Interesting, two questions: 1. What is the state of the Eclipse plug-in? Does it offer an Emacs- like REPL? 2. What is the status of the OSGi compatibility? I saw some discussions in the group archive but my question is where is this today? Frank. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: bug in clojure.contrib.math/exact-integer-sqrt
Thank you! And sorry, I made serious typo in last question. I had to write "private" instead of "public". (I want to pull my hairs.) I'm not sure, I think there might be cases the error part not needed. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: oo
On Mar 29, 4:40 pm, David Nolen wrote: > I see, thanks for the clarification. It does seem like you are purposefully > creating a situation in which type will fail since something more likely: > (type (proxy [clojure.lang.IRef][])) > > works fine. > > I'm wondering if a CLOS-like system would really have to handle such a > degenerate (in the technical sense :) case as the one you've pointed out? > I'm interested in hearing reasons if there is one. Because the design domain of CLOS is the values of the language for which it's implemented. If Rich says that an object like the one I created is not a Clojure value--that constructing such a value is an error--then it makes sense to implement a version of CLOS that traps them on input and raises an informative exception. Otherwise, we have to accept that such values, no matter what we may think of them, are Clojure values, and any implementation of CLOS for Clojure must do something sensible with them. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: oo
On Mar 29, 7:22 am, Konrad Hinsen wrote: > On 29.03.2009, at 07:25, mikel wrote: > > >> Enjoying the thread. Out of curiosity for which Clojure values is > >> the return > >> value of the type function undefined? > > > Try this: > > > (type (proxy [clojure.lang.IMeta clojure.lang.IRef][])) > > > java.lang.UnsupportedOperationException: meta (NO_SOURCE_FILE:0) > > [Thrown class clojure.lang.Compiler$CompilerException] > > > No doubt someone is going to point out that the proxy object I created > > there is useless; that's true, but beside the point. > > Not entirely. Your example object is not only useless, it is as close > as possible to an object created intentionally to cause trouble. You > create an object that derives from IMeta, thus claiming that it > handles metadata, but then don't provide an implementation that would > actually make metadata work. Sure, that's right. Maybe constructing such a value in the first place is an error. The fact remains that it's a Clojure value. If you want to write a Clojure implementation of CLOS, then you need your dispatching code to be able to handle all Clojure values. If it doesn't, you have not written a Clojure implementation of CLOS. This "pathological object" is a Clojure value. Clojure's "type" function doesn't presently return a type for such values, so, in order to implement CLOS, you're going to need to write another type-returning function. Discussions of whether such values make sense is beside the point. As long as Clojure allows you to make them, any implementation of CLOS for Clojure needs to deal with them. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: oo
I see, thanks for the clarification. It does seem like you are purposefully creating a situation in which type will fail since something more likely: (type (proxy [clojure.lang.IRef][])) works fine. I'm wondering if a CLOS-like system would really have to handle such a degenerate (in the technical sense :) case as the one you've pointed out? I'm interested in hearing reasons if there is one. David On Sun, Mar 29, 2009 at 5:22 PM, mikel wrote: > > > > On Mar 29, 1:34 am, David Nolen wrote: > > On Sun, Mar 29, 2009 at 1:25 AM, mikel wrote: > > > > > (type (proxy [clojure.lang.IMeta clojure.lang.IRef][])) > > > > > java.lang.UnsupportedOperationException: meta (NO_SOURCE_FILE:0) > > > [Thrown class clojure.lang.Compiler$CompilerException] > > > > > No doubt someone is going to point out that the proxy object I created > > > there is useless; that's true, but beside the point. The point is that > > > it's straightforward to create some value v for which (type v) is > > > undefined. In order to make a Clojure-friendly version of CLOS, you > > > need some concept of object type such that you can define a function > > > that returns a sensible type for any value. > > > > Not totally following you here as: > > > > (proxy [clojure.lang.IMeta clojure.lang.IRef][]) > > > > immediately throws an error. I can't think of a situation in Clojure > where > > the type function does not return a usable value. Let me know if I'm > wrong, > > but your example is not a case as far as I can tell. > > If you type that expression at the REPL, it throws for the same reason > that calling type on it throws: because the print method for it calls > meta, which is not implemented. > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Fresh Clojure Tutorial
Oh, I should point out that it looks like your abs examples, under "Learning basic clojure" got mangled. On Sun, Mar 29, 2009 at 3:34 PM, Curran Kelleher wrote: > > Hello, > > I've created an introductory tutorial for Clojure and Emacs here: > > http://lifeofaprogrammergeek.blogspot.com/2009/03/learning-clojure-and-emacs.html > > I just wanted to let the community know, maybe it should be linked to > in the wiki? > > Best, > Curran > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Fresh Clojure Tutorial
Excellent tutorial. I pretty much zipped right through it, even though I'm on osx and had to figure out the right way to get a git client for myself. Thanks! On Sun, Mar 29, 2009 at 3:34 PM, Curran Kelleher wrote: > > Hello, > > I've created an introductory tutorial for Clojure and Emacs here: > > http://lifeofaprogrammergeek.blogspot.com/2009/03/learning-clojure-and-emacs.html > > I just wanted to let the community know, maybe it should be linked to > in the wiki? > > Best, > Curran > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Fresh Clojure Tutorial
Is link broken? blogpost return pagen not found message. -- Krešimir Šojat --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Quick slime/emacs questions
describe-key (usually C-h k) followed by a key will tell you what a key is currently bound to. On my setup C-x C-b is bound to ido-switch-buffer--it is not immediately obvious how to make it pop the buffer list in the current window. You might find "What You Can Learn From ido.el" (http://www.vimeo.com/1013263 ) interesting. (Note the correction from Ed Singleton in the comments, too.) Stu > > When I have two windows open, and hit C-x-C-b, it pops up a list of > buffers in the OTHER window from where the current focus is. Any idea > why it's doing that, and how I can alter the behavior so it pops up > the list of buffers in the current window? > > Also, where can I look up the names of various commands to rebind to > different keys? For example, I want to remap C-s to do what C-x-C-s > currently does, and I wan to remap C-f to do what C-s currently does, > to make behavior more consistent with other programs I use. (After > using emacs for a while, I inevitably find myself hitting C-x-C-s to > save in other programs :) ) > > Thanks! > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: oo
On Mar 29, 1:34 am, David Nolen wrote: > On Sun, Mar 29, 2009 at 1:25 AM, mikel wrote: > > > (type (proxy [clojure.lang.IMeta clojure.lang.IRef][])) > > > java.lang.UnsupportedOperationException: meta (NO_SOURCE_FILE:0) > > [Thrown class clojure.lang.Compiler$CompilerException] > > > No doubt someone is going to point out that the proxy object I created > > there is useless; that's true, but beside the point. The point is that > > it's straightforward to create some value v for which (type v) is > > undefined. In order to make a Clojure-friendly version of CLOS, you > > need some concept of object type such that you can define a function > > that returns a sensible type for any value. > > Not totally following you here as: > > (proxy [clojure.lang.IMeta clojure.lang.IRef][]) > > immediately throws an error. I can't think of a situation in Clojure where > the type function does not return a usable value. Let me know if I'm wrong, > but your example is not a case as far as I can tell. If you type that expression at the REPL, it throws for the same reason that calling type on it throws: because the print method for it calls meta, which is not implemented. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Quick slime/emacs questions
When I have two windows open, and hit C-x-C-b, it pops up a list of buffers in the OTHER window from where the current focus is. Any idea why it's doing that, and how I can alter the behavior so it pops up the list of buffers in the current window? Also, where can I look up the names of various commands to rebind to different keys? For example, I want to remap C-s to do what C-x-C-s currently does, and I wan to remap C-f to do what C-s currently does, to make behavior more consistent with other programs I use. (After using emacs for a while, I inevitably find myself hitting C-x-C-s to save in other programs :) ) Thanks! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Fresh Clojure Tutorial
Hello, I've created an introductory tutorial for Clojure and Emacs here: http://lifeofaprogrammergeek.blogspot.com/2009/03/learning-clojure-and-emacs.html I just wanted to let the community know, maybe it should be linked to in the wiki? Best, Curran --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: new in contrib.test-is: fixtures
On Sat, Mar 28, 2009 at 10:24 PM, Stuart Sierra wrote: > (defn my-fixture [f] > ;; Perform setup, establish bindings, whatever. > (f) ;; Then call the function we were passed. > ;; Tear-down / clean-up code here. > ) This is a cool functional way of defining these, but I think I'd prefer to just call the fixture function from the tests needing common setup because of the standard problems with shared setup in unit tests. (In brief, the test doesn't stand on its own to express what it's about, so you have to scroll around to figure out what context the test runs in.) For clj-record's db-connected tests I defined a macro called "defdbtest" [1] that created and rolled back a transaction around each test. For something less common but still shared among multiple tests I might prefer something like the following (using a fixture function called "with-valid-foo") over a fixture declaration that worked on the whole namespace: (deftest foo-bars-like-its-supposed-to (with-valid-foo (fn [foo] (is ( ... something about foo barring) with-valid-foo is similar to one of your fixtures, but it passes any needed stuff to the given function as args rather than using thread-local bindings. On the other hand, I might just prefer this: (deftest foo-bars-like-its-supposed-to (let [foo (valid-foo)] (is ( ... something about foo barring) Either of these approaches make each test a little more wordy, but the two big advantages are * each test lets you know what context it's interested in and how it got it * not all tests in the namespace have to use the same fixtures. If you agree it would be nice for individual tests to pick and choose fixtures but you're a fan of using thread-local bindings, maybe you could enhance deftest to let it say what fixtures it wants instead of a namespace-wide declaration. -hume. [1] http://github.com/duelinmarkers/clj-record/blob/master/src/clj_record/test/test_helper.clj -- http://elhumidor.blogspot.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: bug in clojure.contrib.math/exact-integer-sqrt
Fixed. Thanks for the report. Aside from being a helper function for sqrt, exact-integer-sqrt is available in some Lisp and Scheme implementations. At first glance, you might think that calling (floor (sqrt n)) is sufficient, and no special function is needed. But for large integers which are not square, sqrt converts them to a double, and precision is lost. So if you really need to know the (floor (sqrt n)), something like exact-integer-sqrt is needed. I don't know how commonly used this is, but since it is needed anyway internally, and might be useful externally, I think that's why many implementations expose it. On Sun, Mar 29, 2009 at 7:00 AM, 이휘재 wrote: > Hi, all. > > (clojure.contrib.math/exact-integer-sqrt 1) > => [65536 995705032704] > > due to typo in "integer-length". > > must be: > (clojure.contrib.math/exact-integer-sqrt 1) > => [100 0] > > -- > aside, > does "integer-sqrt" need to be public? > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
System.loadLibrary() does not work
I'm trying to use Clojure to call a library via JNI. Here's a working piece of Java code that I'm trying to convert to Clojure: import libfoo.Foo; // A GlueGen-generated wrapper class Test { static { System.loadLibrary("foo"); // The original library System.loadLibrary("foojni"); // A GlueGen-generated wrapper } public static void main(String[] args) { Foo.do_nothing(); } } Here's my Clojure conversion: (import '(libfoo Foo)) (System/loadLibrary "foo") (System/loadLibrary "foojni") (Foo/do_nothing) Running this Clojure program results in: java.lang.UnsatisfiedLinkError: libfoo.Foo.do_nothing()V (test.clj:0) as if the library wasn't dynamically linked at all. The Clojure code works if I copy the static block from my Java client code into the GlueGen generated Java class, and remove the System/loadLibrary calls from the Clojure client. If the libraries are loaded in the static block of the Java wrapper class, calling System/loadLibrary in Clojure results in: java.lang.UnsatisfiedLinkError: Native Library /libfoo.so already loaded in another classloader (test.clj:0) Is there a working equivalent of System.loadLibrary() in the Clojure API? I tried to google for it, but couldn't find anything. Thanks, -- Timo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Request for improved error reporting
Mark Volkmann writes: Hi Mark, >> The long list of stuff you get is called a Stack Trace. It will save >> your life someday. > > Definitely having the ability to see the full stack trace is be > useful. I wonder though if that should be the default output. Maybe by > default only lines from the stack trace that are not part of the > Clojure implementation should be output. I'd say filtering traces is something an IDE may provide with some user options. A compiler/interpreter/VM of any language should provide as much information as it can get. Bye, Tassilo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Java code example for loading clojure code
Here is an example for loading clojure code. I had trouble with this before. I believe that once the script is loaded, it is loaded per JVM instance. http://clojure.googlegroups.com/web/TestLoadClojureFromJava.java?gsc=PMri4QsAAABqmMyUtnF_kwfBAZY6oRfS Also, any suggestions are welcome. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Request for improved error reporting
On 29 Mrz., 01:55, Glen Stampoultzis wrote: > Hi, I've been really enjoying getting to know clojure. It's an awesome > language that has got me very interested in learning more. One thing that > hasn't left me impressed is the error reporting. > [...] > There are a few things wrong here and with clojure error reporting in > general: > > 1. I'm not getting a line number for some reason. > 2. I don't get any indication what the nature of the error is. > 3. I get a big (nested) stack trace that has more to do with clojure > compiler internals than my program. I would like to make a comment that does not directly talk about your specific issue, but about error reporting in general. I would love to hear more opinions about Gradual Typing for Clojure. That would allow the compiler to catch errors before the program is actually run. Your example that you gave at some other point in this thread could have been caught during compilation. Please have a look at this thread: http://groups.google.com/group/clojure/browse_thread/thread/7a48f48e4b197a15 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: What's a convenient way of calling super.method()?
Glad to be of help. To be totally honest I hadn't really tested it too much, so I don't know ;) One obvious limitation here is that it doesn't work with multiple inheritance (it only looks at the first item in the parents set). As long you're sticking with a Java-style single inheritance model this doesn't really present much of a problem. I'll clean it up when I have some extra time and add some test cases, provide a small readme listing limitations, and host it on GitHub for anyone else that needs this behavior. David On Sun, Mar 29, 2009 at 8:20 AM, CuppoJava wrote: > > Thanks a lot for that David, > It works perfectly for me. > > Are there any circumstances where it doesn't work? I haven't run into > any yet, but if there are, I'll design my program around it. > -Patrick > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
bug in clojure.contrib.math/exact-integer-sqrt
Hi, all. (clojure.contrib.math/exact-integer-sqrt 1) => [65536 995705032704] due to typo in "integer-length". must be: (clojure.contrib.math/exact-integer-sqrt 1) => [100 0] -- aside, does "integer-sqrt" need to be public? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~--- --- math.clj.old 2009-03-29 22:22:25.0 +0900 +++ math.clj 2009-03-29 21:59:48.0 +0900 @@ -136,7 +136,7 @@ (defmethod integer-length java.lang.Integer [n] (count (Integer/toBinaryString n))) (defmethod integer-length java.lang.Long [n] - (count (Integer/toBinaryString n))) + (count (Long/toBinaryString n))) (defmethod integer-length java.math.BigInteger [n] (count (. n toString 2)))
Re: Request for improved error reporting
On Sun, Mar 29, 2009 at 4:26 AM, Rayne wrote: > > The long list of stuff you get is called a Stack Trace. It will save > your life someday. Definitely having the ability to see the full stack trace is be useful. I wonder though if that should be the default output. Maybe by default only lines from the stack trace that are not part of the Clojure implementation should be output. If you want a full stace trace, maybe there could be a flag you have to set to get that. If this were the case then Glen's output would have been: java.lang.IllegalArgumentException: Wrong number of args passed to: user$testing (test.clj:0) Caused by: java.lang.IllegalArgumentException: Wrong number of args passed to: user$testing at user$eval__4.invoke(test.clj:2) This could be achieved by simply filtering out all lines that begin with "at clojure.". I understand there are utilities available that make stack traces more readable, but I'm talking about what should happen by default. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: oo
On 29.03.2009, at 07:25, mikel wrote: >> Enjoying the thread. Out of curiosity for which Clojure values is >> the return >> value of the type function undefined? > > Try this: > > (type (proxy [clojure.lang.IMeta clojure.lang.IRef][])) > > java.lang.UnsupportedOperationException: meta (NO_SOURCE_FILE:0) > [Thrown class clojure.lang.Compiler$CompilerException] > > > No doubt someone is going to point out that the proxy object I created > there is useless; that's true, but beside the point. Not entirely. Your example object is not only useless, it is as close as possible to an object created intentionally to cause trouble. You create an object that derives from IMeta, thus claiming that it handles metadata, but then don't provide an implementation that would actually make metadata work. BTW, the function type could easily be fixed to handle your problem. At the moment it does (or (:type (meta x)) (class x)) Adding an exception handler that returns (class x) whenever (meta x) fails would take care of your pathological object. I can't say if this would add much runtime overhead, not being much of a JVM expert. Konrad. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: What's a convenient way of calling super.method()?
Thanks a lot for that David, It works perfectly for me. Are there any circumstances where it doesn't work? I haven't run into any yet, but if there are, I'll design my program around it. -Patrick --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: oo
Hi, Am 27.03.2009 um 09:25 schrieb Mark Engelberg: I may come along and want to extend test-prefer to a type ::d which derives from ::c and ::e, where ::e provides an alternative implementation. ab (a and b are intended to be hidden from end-user) | | -- | c e | | | d (derive ::d ::c) (derive ::d ::e) (defmethod test-prefer ::e [h] "e") Now, as an external user, I know nothing about where test-prefer on ::c gets its behavior. Obviously, I have to disambiguate between whether test-prefer chooses ::c over ::e, so I may try something like this: (prefer-method test-prefer ::c ::e) But this will not work. I still get an error saying I need to disambiguate between ::a and ::e. And not knowing anything about ::a, I could be very confused, and not know how to provide this information. Is there some special reason, why choosing ::c is not enough in prefer-method? As soon as I preferred ::c over ::e. Why should I then need to go further up the tree? Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: oo
Hi, Am 29.03.2009 um 08:34 schrieb David Nolen: Not totally following you here as: (proxy [clojure.lang.IMeta clojure.lang.IRef][]) immediately throws an error. I can't think of a situation in Clojure where the type function does not return a usable value. Let me know if I'm wrong, but your example is not a case as far as I can tell. The point that Mikel wants to make is, that you can easily provide a proxy, which implements clojure.lang.IMeta. But when you don't provide a "meta" implementation, the proxy will throw a UnsupportedOperation exception. Hence type will not work. I personally consider this a non-issue. What is the point of providing an interface and then yell "I WONT DO IT" at the system, when it tries to do the advertised action? In my opinion, you should provide the advertised methods. What's the point of the interface otherwise? Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Request for improved error reporting
The long list of stuff you get is called a Stack Trace. It will save your life someday. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---