Re: Clojure quickstart maven archetype
On Tue, Sep 8, 2009 at 4:09 AM, Scott Fleckenstein wrote: > > On another note, it's surprising given that how easy creating the > archetype was how incredibly arcane writing a plugin is. Granted, > maven is new to me and I've got zero experience but the codebase, but > it seems amazing to me how complicated doing something as small as > launching a repl process can be. I must have gone through 20,000 > lines of various peoples code today to try and attempt building one > myself, from your plugin (which, was the nicest so far, BTW) to > antrun, to the exec plugin, to the clojureshell plugin. It's quite > comical considering the 8 line rake file I've got to do it. Oh well, > I'll figure it out eventually. > Agreed. The process of writing a maven plugin is really a lot more complicated than it ought to be. When I started on Clojureshell I couldn't really find any relevant javadocs anywhere and had to go through a lot of trial and error before I got classloading working. And running clojure inside the maven process wasn't really a serious design decision; it just seemed a lot easier than spawning a child process ;) BTW, you mentioned the official maven clojure repo, is that repo1.maven.orgor somewhere else? I can find clojure-1.0.0 there, but not clojure-contrib. Cheers, -- Fredrik == What am I up to? http://twitter.com/appelberg --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: minor grievance with arithmetic on characters
On Tue, Sep 8, 2009 at 23:35, Stephen C. Gilardi wrote: > > On Sep 8, 2009, at 2:14 AM, Timothy Pratley wrote: > >> According to the docstring compare returns -1, 0 or 1: >> user=> (compare \b \g) >> -5 > > We could fix the doc along the lines of: > > "Comparator. Returns a negative number, zero, or a positive number when x is > logically 'less than', 'equal to', or 'greater than' y. Same as Java > x.compareTo(y) except it also works for nil, and compares numbers and > collections in a type-independent manner. x must implement Comparable" > > or fix the implementation to conform to the current doc. > > My current thought is that we should fix the implementation and make a minor > mod to the doc to replace "Same as" with something like "Works like" because > compareTo only guarantees the sign of the return value. > > Other thoughts? I'd like to see the behavior of Java's built-in compareTo() followed and documented as such. This makes implementing compare by calling .compareTo when appropriate glueless. Also not promising that the result will be in teh set #{-1,0,1} has two other effects: 1) the implementation gains some freedom, which is occasionally useful. 2) the code pattern that naturally results from this: "a.compareTo(b) REL 0" is equivalent to "a REL b" where REL is one of #{ ==, !=, <, >, <=, >=}. Note how following this convention makes calls to compareTo easy to read because the programmer's intent is documented by REL and the relative order of a and b, which stays constant when mentally rewriting the expression. Yes, this is just as possible when compareTo() promises #{-1, 0, 1}, but such a promise does not lead the caller as inexorably to this solution, instead you end up with stupidities like this: [QUOTE source=Robert C. Martin, _Clean Code_, pg57] [...] In general it is better to find a way to make that argument or return value clear in its own right; but when its part of the standard library, or in code that you can not alter, then a helpful clarifying comment can be useful. public void testCompareTo() throws Exception { [...] assertTrue(a.compareTo(b) == -1); // a < b [...] assertTrue(b.compareTo(a) == 1); // b > a [...] } [/QUOTE] There are two problems with this code: (1) It's wrong. It's in violation of the actual contract of compareTo(), which only promises negative, positive or zero. (2) If it had been written to the *actual* behavior of the API, the expanatory comments, which this section is intended to demonstrate the usefulness of become redundant: assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); So, I guess the point of this diatribe is: please follow the behavior of Java's compareTo, and document this fact in (compare). // 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 -~--~~~~--~~--~--~---
Re: minor grievance with arithmetic on characters
Hello, Coming back to the original question: On Tue, Sep 8, 2009 at 6:50 AM, Timothy Pratley wrote: > > Is there a way to deal with this: > user=> (> \a \b) > java.lang.ClassCastException: java.lang.Character cannot be cast to > java.lang.Number (NO_SOURCE_FILE:0) > > So far the only things I know are to coerce or use interop eg: By 'coerce' I assume you mean something like: user=> (< (int \a) (int \b)) true What's wrong with it? (or this is what makes the grievance 'minor' ?) About the compare/compareTo discussion: the pain point here (for me) is that according to java docs, Character.compareTo does not use the locale information when comparing strings. Comparing as ints obviously doesn't help. So the internationally correct :-) way would be to use java.text.Collator for text-related comparisons. Maybe Clojure's compare should use java.text.Collator when comparing strings and chars - or add a textCompare function that would do that, to avoid slowing down compare? Thanks, > user=> (.compareTo \a \b) > -1 > -- Miron Brezuleanu --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: clojure-mode survey
On Wed, Sep 9, 2009 at 3:08 AM, Phil Hagelberg wrote: > This just resets the classpath to include target/dependency/ as well as > any jars in the lib/ directory of your project. I've included this in > the Emacs Starter Kit but haven't included it in clojure-mode yet since > I haven't quite decided if it's suitable for everyone. But it seems > there's a demand for it; so I guess I'll include it. It really does seem like there's a certain demand for it, I stumbled upon several blog posts and such where people have trouble setting up their Clojure projects. I definitely think that this would be a worthwhile addition to clojure-mode. Regards, 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 -~--~~~~--~~--~--~---
Re: minor grievance with arithmetic on characters
On Tue, Sep 8, 2009 at 8:18 PM, Timothy Pratley wrote: > > Hi Steve, > > I find the -1, 0, 1 result more useful, but am also wary it hides some > useful information. My preference would be to have the doc-string > changed to what you proposed and keep the neg/pos behaviour > of .compareTo in place. To get -1, 0, 1 requires a 'sign' operator > which is handy to have as a separate function - might be a candidate > for contrib? > > (defn sign > "Returns 1 if x is positive, -1 if x is negative, else 0" > [x] > (cond (pos? x) 1, (neg? x) -1, :else 0)) > (defn sign "Returns 1 if x is positive, -1 if x is negative, else 0" [x] (compare x 0)) If that doesn't work, then compare on numbers is likely to fail for widely-separated numbers due to integer underflow or overflow if the Java compareTo being called does so; compareTo is defined in interface Comparable as returning a Java int, which has 32 bit range; there's a reason it's recommended to implement compareTo using < or >, ==, ?:, and the literal values -1, 0, and 1. The char comparison using subtraction is safe since all differences between 16-bit numbers fit in an int, but this is not true for int, long, or bignum comparison by subtracting and then narrowing to int. For the native Java Integer, Long, and BigInteger types this is highly unlikely to be the case. I'm hoping Clojure's Ratio class's compareTo is also safe. This is assuming the Clojure compare function on numbers works by coercing them along the graph Byte-(Short,Character)-Int-Long-BigInteger-Ratio-BigDecimal, Float-Double-BigDecimal and then using compareTo, as seems likely. (I don't currently have my REPL or the source code handy to check.) --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: clojure-mode survey
2009/9/9 Phil Hagelberg : > > Rick Moynihan writes: > >> One problem I do have with clojure-mode/clojure is managing the >> classpaths for clojure projects... It seems that the typical elisp >> config only has one variable (which is then shared across all clojure >> files) for specifying the classpath... >> ... SNIP ... > The solution I've settled on is the clojure-project function: > > (defun clojure-project (path) > SNIP ... > > This just resets the classpath to include target/dependency/ as well as > any jars in the lib/ directory of your project. I've included this in > the Emacs Starter Kit but haven't included it in clojure-mode yet since > I haven't quite decided if it's suitable for everyone. But it seems > there's a demand for it; so I guess I'll include it. Yes, that looks like just what I'm after (I haven't yet tried it out - but will be sure to!)... This issue has got me thinking that the real problem appears to be that there isn't a standard or default way (script) to start up and run java/clojure projects... i.e. though this solves the problem when running clojure programs in emacs it doesn't do so for when you move into a different environment (perhaps staging or production) and want to run a REPL configured for your project or clojure program. I think there will always be a need for people to craft the JVM args for specific projects themselves, but it'd be nice if clojure could provide a default mechanism for specifying the basic JVM args etc in a way that meant it worked across environments, editors and environments... Is such a thing possible or even desirable... Personally I think finding a nice lightweight, default solution to this problem that can be supported by all environments/editors/IDE's would make clojure even more suited to rapid prototyping, experimental development and bootstrapping projects in a painless manner. Any thoughts? 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 -~--~~~~--~~--~--~---
Re: clojure-mode survey
On Sep 9, 11:02 am, Michael Kohl wrote: > On Wed, Sep 9, 2009 at 3:08 AM, Phil Hagelberg wrote: > > This just resets the classpath to include target/dependency/ as well as > > any jars in the lib/ directory of your project. I've included this in > > the Emacs Starter Kit but haven't included it in clojure-mode yet since > > I haven't quite decided if it's suitable for everyone. But it seems > > there's a demand for it; so I guess I'll include it. > > It really does seem like there's a certain demand for it, I stumbled > upon several blog posts and such where people have trouble setting up > their Clojure projects. I definitely think that this would be a > worthwhile addition to clojure-mode. I'd vote for it to go in. In my version I also include an extra setting for any native libraries I need for the project: (setq swank-clojure-library-paths (expand-file-name "lib/native" path)) Phil, it looks like you've abandoned your practice of exploding all jars into the lib directory. Any particular reason for that? Personally, I thought it was a heathen practice anyway :) --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Library problem: SWT and Emacs
I have had similar issues with swing. Going to the inferior lisp buffer and hitting return once or twice always resolved it. It only happens the first time a window is shown. --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Clojure quickstart maven archetype
When I said central repo, yes, I meant repo1.maven.org. Clojure contrib is only available as a SNAPSHOT there. My actual dependency element looks like: org.clojure clojure-contrib 1.0-SNAPSHOT -Scott On Sep 9, 12:42 am, Fredrik Appelberg wrote: > On Tue, Sep 8, 2009 at 4:09 AM, Scott Fleckenstein wrote: > > > > > On another note, it's surprising given that how easy creating the > > archetype was how incredibly arcane writing a plugin is. Granted, > > maven is new to me and I've got zero experience but the codebase, but > > it seems amazing to me how complicated doing something as small as > > launching a repl process can be. I must have gone through 20,000 > > lines of various peoples code today to try and attempt building one > > myself, from your plugin (which, was the nicest so far, BTW) to > > antrun, to the exec plugin, to the clojureshell plugin. It's quite > > comical considering the 8 line rake file I've got to do it. Oh well, > > I'll figure it out eventually. > > Agreed. The process of writing a maven plugin is really a lot more > complicated than it ought to be. When I started on Clojureshell I couldn't > really find any relevant javadocs anywhere and had to go through a lot of > trial and error before I got classloading working. And running clojure > inside the maven process wasn't really a serious design decision; it just > seemed a lot easier than spawning a child process ;) > > BTW, you mentioned the official maven clojure repo, is that > repo1.maven.orgor somewhere else? I can find clojure-1.0.0 there, but > not clojure-contrib. > > Cheers, > -- Fredrik > == > What am I up to?http://twitter.com/appelberg --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Clojure Golf – Episode 2: Largest Prime Factor
;; largest prime factor (defn lpf "Takes a number n and a starting number d > 1 and calculates the largest prime factor of n starting at number d. usage: (lpf 364362978 2) => 8675309" [n d] (if (> d n) (- d 1) (recur (#(if (zero? (rem % d)) (recur (/ % d)) %) n) (inc d This is the smallest `lpf` that I could come up with -- can you do better? Can you make it faster (shouldn't be too hard, considering mine is atrociously slow)? More information at: http://blog.fogus.me/2009/09/09/clojure-golf-episode-2-largest-prime-factor/ Have at it! -m --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Clojure Golf – Episode 2: Largest Prime Factor
Why did you define the problem as you did rather than simply "The largest prime factor of n?" On Sep 9, 1:39 pm, Fogus wrote: > ;; largest prime factor > (defn lpf > "Takes a number n and a starting number d > 1 > and calculates the largest prime factor of n > starting at number d. > > usage: (lpf 364362978 2) => 8675309" > [n d] > (if (> d n) > (- d 1) > (recur > (#(if (zero? (rem % d)) > (recur (/ % d)) > %) > n) > (inc d > > This is the smallest `lpf` that I could come up with -- can you do > better? Can you make it faster (shouldn't be too hard, considering > mine is atrociously slow)? > > More information > at:http://blog.fogus.me/2009/09/09/clojure-golf-episode-2-largest-prime-... > > Have at it! > > -m --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Clojure Golf – Episode 2: Largest Prime Factor
> (zero? (rem % d)) (= 0 (rem % d)) > (- d 1) presumably you chose this instead of (dec d) because it converts one real character into whitespace so if you make this: > (inc d (+ d 1) You can convert another whitespace! [arguably its a meaningful whitespace but lets ignore that for now] Oh and you could call your function l instead of lpf :) Ok so I don't have any useful suggestion sorry... but interesting to read your post, That recur inside a lambda was cute! --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: clojure-mode survey
Konrad Hinsen writes: > I work with the development branch regularly updated from github. Do I > conclude correctly that clojure-install is of no use for me? You can let clojure-install perform the initial setup and then simply issue a "git checkout master" from the clojure/ directory and recompile. But it's an extra step for you. I'd take patches to make (for instance) invoking it with the prefix arg have it check out master while it would work with 1.0 otherwise, but I'm probably not going to write that myself unless we start following master at work. >> I think the value-add here is pretty minimal. Before Clojure 1.0 if a >> change in Clojure broke swank-clojure, we'd have to scramble to get it >> fixed in swank-clojure, and everyone would update. But now that >> there's >> a stable target, I haven't been tracking master closely, so staying >> up-to-date is much less important. > > How stable is swank-clojure in practice with the changes that happened > since 1.0? I think we've only had one breakage, and it was fixed in a couple days. But I'm not making any guarantees. =) -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 -~--~~~~--~~--~--~---
Re: clojure-mode survey
On Sep 9, 7:44 am, "AndrewC." wrote: > > It really does seem like there's a certain demand for it, I stumbled > > upon several blog posts and such where people have trouble setting up > > their Clojure projects. I definitely think that this would be a > > worthwhile addition to clojure-mode. I'm going to add it to swank-clojure instead of clojure-mode since you need that to use it anyway. People who don't use slime don't need to bother with it. > I'd vote for it to go in. In my version I also include an extra > setting for any native libraries I need for the project: > > (setq swank-clojure-library-paths (expand-file-name "lib/native" > path)) I'll add a hook so you can perform these customizations yourself. > Phil, it looks like you've abandoned your practice of exploding all > jars into the lib directory. Any particular reason for that? I still expand all my jars into target/dependency. I just added lib/ for those people who still want to keep them there. The clojure- project supports both styles. -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 -~--~~~~--~~--~--~---
Re: clojure-mode survey
Rick Moynihan writes: > This issue has got me thinking that the real problem appears to be > that there isn't a standard or default way (script) to start up and > run java/clojure projects... i.e. though this solves the problem when > running clojure programs in emacs it doesn't do so for when you move > into a different environment (perhaps staging or production) and want > to run a REPL configured for your project or clojure program. Strongly agreed. Clojure would be much more approachable and obvious if it included a standard shell script. > Personally I think finding a nice lightweight, default solution to > this problem that can be supported by all environments/editors/IDE's > would make clojure even more suited to rapid prototyping, experimental > development and bootstrapping projects in a painless manner. I know there's one included in contrib now, but it's not quite the same. I suppose in order to be portable there'd need to be a batch file for windows too; it's a shame there's no good cross-platform way to handle that. -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 -~--~~~~--~~--~--~---
Content negotiation?
Would anyone have any interest in a content negotiation library making its way into contrib? That is, a library with a public function that takes an Accept: header from an HTTP request, and your server-side preferences, and spits out which Content-Type you should produce. This is important for "proper REST" apps. (I don't see any functionality like this in Compojure.) I have one about 80% done (compared to one I wrote in Python). Pure Clojure; the only dependency is on str-utils. If there's no interest in it getting into contrib, I'll just stick it on GitHub. --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Content negotiation?
Could you put it on GitHub anyway? It would be a good way to evaluate it. On Sep 10, 12:36 am, Richard Newman wrote: > Would anyone have any interest in a content negotiation library making > its way into contrib? > > That is, a library with a public function that takes an Accept: header > from an HTTP request, and your server-side preferences, and spits out > which Content-Type you should produce. > > This is important for "proper REST" apps. (I don't see any > functionality like this in Compojure.) > > I have one about 80% done (compared to one I wrote in Python). Pure > Clojure; the only dependency is on str-utils. > > If there's no interest in it getting into contrib, I'll just stick it > on GitHub. --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: How to use vimClojure?
This doesn't work for me. Here is what happens: > > 0. Start ng-server > > 1. Start a fresh vim. > > 2. :setfiletype clojure (a colon command like :w or :q) > > 3. \sr (should open a new window) > > 4. (to go back to first window) ( is Control+w, > > would be Alt+w) > > 5. Type in some function: (defn greet [] (println "Hello, World!")) > > 6. Make sure the cursor is in the function, eg. on the e of Hello. > > 7. \et (to send the function to the Repl) > > 8. A new window should open, containing #'user/greet. Type \p to close > > the window. It's all good up to this point. > > 9. Go to the Repl window, eg. with . > > 11. At the prompt type (gr and hit to complete the function > > name. > > 10. Submit (greet) by hitting return. (the Repl should now print > > "Hello, World!") This doesn't work. The new window opened up containing the right text. However, the REPL can not use the function. What's strange is that I can type (gr and CTRL-n and user/greet shows up! This tells me the REPL has the function, but it gives this error: # I've also tried (user/greet) but that doesn't work either - same error. I'm using vimclojure-2.1.2 with the latest clojure from git, java 6 on Ubuntu 9.04. Note: I have been copying/pasting using a mouse but that has a bug where comments get an 'x' character put in front of them on paste and the function won't compile. So I'd really like this to work! Thanks again for vimclojure! --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Content negotiation?
> Could you put it on GitHub anyway? It would be a good way to evaluate > it. +1 - I'd be interested in using it. - Adrian. On Thu, Sep 10, 2009 at 6:40 AM, Sean Devlin wrote: > > Could you put it on GitHub anyway? It would be a good way to evaluate > it. > > On Sep 10, 12:36 am, Richard Newman wrote: >> Would anyone have any interest in a content negotiation library making >> its way into contrib? >> >> That is, a library with a public function that takes an Accept: header >> from an HTTP request, and your server-side preferences, and spits out >> which Content-Type you should produce. >> >> This is important for "proper REST" apps. (I don't see any >> functionality like this in Compojure.) >> >> I have one about 80% done (compared to one I wrote in Python). Pure >> Clojure; the only dependency is on str-utils. >> >> If there's no interest in it getting into contrib, I'll just stick it >> on GitHub. > > > --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Content negotiation?
This might be good to integrate with ring as well? On Thu, Sep 10, 2009 at 12:46 AM, Adrian Cuthbertson wrote: > >> Could you put it on GitHub anyway? It would be a good way to evaluate >> it. > > +1 - I'd be interested in using it. > > - Adrian. > > On Thu, Sep 10, 2009 at 6:40 AM, Sean Devlin wrote: >> >> Could you put it on GitHub anyway? It would be a good way to evaluate >> it. >> >> On Sep 10, 12:36 am, Richard Newman wrote: >>> Would anyone have any interest in a content negotiation library making >>> its way into contrib? >>> >>> That is, a library with a public function that takes an Accept: header >>> from an HTTP request, and your server-side preferences, and spits out >>> which Content-Type you should produce. >>> >>> This is important for "proper REST" apps. (I don't see any >>> functionality like this in Compojure.) >>> >>> I have one about 80% done (compared to one I wrote in Python). Pure >>> Clojure; the only dependency is on str-utils. >>> >>> If there's no interest in it getting into contrib, I'll just stick it >>> on GitHub. >> > >> > > > > --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Content negotiation?
>> Could you put it on GitHub anyway? It would be a good way to >> evaluate >> it. > > +1 - I'd be interested in using it. Your wish is my command :) http://github.com/rnewman/clj-conneg/tree/master I haven't finished the complete sorting algorithm yet (it only uses q- vals, not level and 'completeness'), and I haven't implemented the filtering or server-side weights yet, but it's a damn sight better than searching for substrings. Bug reports welcome. This is literally minutes old. --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Content negotiation?
> This might be good to integrate with ring as well? I don't use Ring directly, if at all (just Compojure for now), so it needs to be upstream of that. I have no problem with Ring using it, though. (I imagine that would be trivial if it reached contrib.) --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Clojure Golf – Episode 2: Largest Prime Factor
I took a stab at it. I used: (set! *warn-on-reflection* true) but it didn't tell me anything. I found a Java class that did the same thing and created a Clojure implementation from that. I thought that perhaps if I could force the data types to be BigInteger Clojure would save time by not having to use reflection. However, this fails and I'm not sure why. The code: (defn lpf3 [#^bigint arg] (print (str "The prime factorization of " arg " is :")) (println (loop [i (bigint 2) n (bigint arg) ] ;(println (str "i:" i "n:" n)) (if (<= i (/ n i)) (recur (inc i) (loop [n2 (bigint n)] ;(println (str "n2:" n2)) (if (zero? (rem n2 i)) (recur (/ n2 i) ) n2 ))) n))) ) The error: The prime factorization of 234 is :# NOTE: Line 17 in this case looks like "n2 )))" I tried to create a version using long to see if that would help. It did as I received better compiler error messages. The end result: (too many casts perhaps...) (defn lpf6 [arg] (print (str "The prime factorization of " arg " is :")) (println (loop [i (long 2) n (long arg) ] (if (<= i (/ n i)) (recur (long (inc i)) (long (loop [n2 (long n)] (if (zero? (rem n2 i)) (recur (long (/ n2 i)) ) n2 (long n ) Clojure=> (time (lpf6 364362978)) The prime factorization of 364362978 is :8675309 "Elapsed time: 133.974784 msecs" Your code on the same machine gives: Clojure=> (time (lpf 364362978 2)) "Elapsed time: 1014.572527 msecs" 8675309 I suspect casting to long would speed things up a bit in your case. However, long doesn't have enough precision to handle the number you mentioned in your article: 1234567890123456789012345678901234567890 The correct solution would be to coerce the types to bigint. I've done this and the results are interesting. Strangely bigint is over 10x faster than long: Clojure=> (time (lpf6b 364362978)) The prime factorization of 364362978 is :8675309 "Elapsed time: 8.874452 msecs" The code: (defn lpf6b [arg] (print (str "The prime factorization of " arg " is :")) (println (loop [i (bigint 2) n (bigint arg) ] (if (<= i (/ n i)) (recur (bigint (inc i)) (bigint (loop [n2 (bigint n)] (if (zero? (rem n2 i)) (recur (bigint (/ n2 i)) ) n2 (bigint n ) I can only guess that bigint is faster here because I was not casting long correctly in enough (or in the correct) places and was actually causing the compiler more work. If this is obvious to anyone please post. I'm intrigued. My next stab would have been in GLSL with Clojure Penumbra. Purely for fun :-) But I'm out of time. Cheers. --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Clojure Golf – Episode 2: Largest Prime Factor
Just for fun I actually tried this: Clojure=> (time (lpf6b 1234567890123456789012345678901234567890)) The prime factorization of 1234567890123456789012345678901234567890 is :5964848081 "Elapsed time: 5519.278432 msecs" I can't confirm the answer is correct. 5.5 seconds sure beats 10 minutes. :-) --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Re: Clojure Golf – Episode 2: Largest Prime Factor
I propose to compute the score of a golf competition entry using this function: (defn score [expr] (count (tree-seq coll? #(if (map? %) (apply concat %) (seq %)) expr))) Thus, shorter names and literal anonymous closures won't change the score. On Thu, Sep 10, 2009 at 1:50 AM, Timothy Pratley wrote: > >> (zero? (rem % d)) > (= 0 (rem % d)) > >> (- d 1) > presumably you chose this instead of (dec d) because it converts one > real character into whitespace > > so if you make this: >> (inc d > (+ d 1) > You can convert another whitespace! [arguably its a meaningful > whitespace but lets ignore that for now] > > Oh and you could call your function l instead of lpf :) > Ok so I don't have any useful suggestion sorry... but interesting to > read your post, That recur inside a lambda was cute! > > > -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (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 -~--~~~~--~~--~--~---