Re: Clojure Golf – Episode 2: Largest Prime Factor
What about a golf competition on the golf competition scorer? Then we can evaluate that using; (defmacro score-scorer [scorer] ... ) :) - Adrian On Thu, Sep 10, 2009 at 8:12 AM, Christophe Grand wrote: > > 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 -~--~~~~--~~--~--~---
Re: Library problem: SWT and Emacs
srolls and Laurent, Thanks for your replies. I still can't figure it out and I'm switching to eclipse. On Sep 10, 12:45 am, srolls wrote: > 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-mode survey
2009/9/10 Phil Hagelberg : > > 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. Glad I'm not the only one :-) >> 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 As I'm sure you and many others know, this problem exists in the Java community also... A few years ago I found a solution in Apache Commons Launcher: http://commons.apache.org/launcher/ It uses a lot of the infrastructure from ant and is pretty powerful, providing a cross platform way of specifying jvm args, classpaths, library paths etc... Sadly the project is largely moribund but other than being poorly documented it worked pretty well... I could imagine a pure clojure implementation of this (perhaps based on lancet?) that would use a clojure DSL instead of ant xml to configure the VM in a cross platform manner. The only problem I ran into with commons launcher was to do with System.in being passed through the VMs... It worked but its implementation was inefficient and resulted in excessive CPU consumption unless you switched it off... This was an easy work around for me, as I didn't need to read from System.in, but I can imagine it being a problem if you're running a REPL. I suspect however that it was just a bug, rather than a larger design flaw. 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 Golf – Episode 2: Largest Prime Factor
Hi, On Sep 10, 3:52 pm, MarkSwanson wrote: > 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. :-) Just thought you would like to know that Wolfram|Alpha agrees (in roughly the same time): http://www.wolframalpha.com/input/?i=factor+1234567890123456789012345678901234567890 Regards, Mark. -- http://mark.reid.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 -~--~~~~--~~--~--~---
Re: Clojure Golf – Episode 2: Largest Prime Factor
> Just thought you would like to know that Wolfram|Alpha agrees (in > roughly the same time): > > http://www.wolframalpha.com/input/?i=factor+1234567890123456789012345... 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 -~--~~~~--~~--~--~---
Re: clojure-mode survey
I still use clojure-mode and it's basic LISP interaction features. I've installed SLIME once and went through the hassle of getting it working, but it didn't (seem) to offer much more. It also made quitting an infinite loop difficult (C-c C-c didn't work for me in SLIME). So eventually i just moved back to clojure-mode. What features of SLIME do people use it for? I like the function argument lookup, but it only works for functions already def'd in the REPL, so it's functionality is limited. -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 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: Printing to be read
On Wed, Sep 9, 2009 at 00:16, Richard Newman wrote: > >> So, my question is this: is there a way to print a structure out in >> a fashion that it can be read back in correctly (i.e. with strings >> being quoted), and without having to write my own print function? > > prn. > > user=> (prn {:foo ["bar" 5.0]}) > {:foo ["bar" 5.0]} > nil > If you want the results to be more pleasing to read (i.e. not one giant line) have a look at: http://richhickey.github.com/clojure-contrib/pprint-api.html // 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: Printing to be read
2009/9/9 Brian Hurt : [...] > So, my question is this: is there a way to print a structure out in a > fashion that it can be read back in correctly (i.e. with strings being > quoted), and without having to write my own print function? To go along with the other answers, you will want to bind *read-eval* to false: http://clojure.org/api#toc26 -- Michael Wood --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Class function alwayrs returns java.lang.class??
Hello. I'm trying to use (class String) to get the class object for the String class. However, nomatter what class typ ei pass, i always get java.lang.Class back. Is this the way its supposed to work? Thx! --~--~-~--~~~---~--~~ You 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: Class function alwayrs returns java.lang.class??
You need to pass the object to (class, e.g... user=> (class "a") java.lang.String user=> (class String) java.lang.Class user=> (class 1) java.lang.Integer (So String is actually a Class object). Rgds, Adrian. On Thu, Sep 10, 2009 at 5:00 PM, Gorsal wrote: > > Hello. I'm trying to use (class String) to get the class object for > the String class. However, nomatter what class typ ei pass, i always > get java.lang.Class back. Is this the way its supposed to work? > > Thx! > > > > --~--~-~--~~~---~--~~ You 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: Class function alwayrs returns java.lang.class??
Yes. (class "an instance of Stirng") will return java.lang.String Now the clojure symbol String is bound to a java.lang.Class instance giving information on the java.lang.String class (as if you had issued "kljlkjk".getClass()). 2009/9/10 Gorsal > > Hello. I'm trying to use (class String) to get the class object for > the String class. However, nomatter what class typ ei pass, i always > get java.lang.Class back. Is this the way its supposed to work? > > Thx! > > > > --~--~-~--~~~---~--~~ You 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: Class function alwayrs returns java.lang.class??
What you're getting is the class of the String class, which is Class. What you want is just plain "String". On Thu, Sep 10, 2009 at 11:00 AM, Gorsal wrote: > > Hello. I'm trying to use (class String) to get the class object for > the String class. However, nomatter what class typ ei pass, i always > get java.lang.Class back. Is this the way its supposed to work? > > Thx! > > > > --~--~-~--~~~---~--~~ You 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 and SOAP
Hello, I am looking to write a SOAP client in Clojure and was wondering if there are any good existing libraries/clients in Java. After a bit of searching i came across Apache Axis and JAX-WS, though i am not sure how useful they will be and JAX-WS uses annotations. Has anyone had any experience dealing with SOAP and Clojure? Are there any more useful libraries out there, or anything on clojure.contrib that could be of help? --regards Adityo --~--~-~--~~~---~--~~ You 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 : > > The solution I've settled on is the clojure-project function: > > (defun clojure-project (path) > "Setup classpaths for a clojure project and starts a new SLIME session. > Kills existing SLIME session, if any." > (interactive (list > (ido-read-directory-name > "Project root: " > (locate-dominating-file default-directory "src" > (require 'swank-clojure) > (when (get-buffer "*inferior-lisp*") > (kill-buffer "*inferior-lisp*")) > (add-to-list 'swank-clojure-extra-vm-args > (format "-Dclojure.compile.path=%s" > (expand-file-name "target/classes/" path))) > (setq swank-clojure-binary nil > swank-clojure-jar-path (expand-file-name "target/dependency/" path) > swank-clojure-extra-classpaths > (append (mapcar (lambda (d) (expand-file-name d path)) > '("src/" "target/classes/" "test/")) > (let ((lib (expand-file-name "lib" path))) > (if (file-exists-p lib) > (directory-files lib t ".jar$" > slime-lisp-implementations > (cons `(clojure ,(swank-clojure-cmd) :init swank-clojure-init) > (remove-if #'(lambda (x) (eq (car x) 'clojure)) > slime-lisp-implementations))) > (save-window-excursion > (slime))) I've tried getting this to work but it keeps it failing after I call the function and interactively tell it my project direcotory it seems to repeatedly poll with the following message: Polling "/var/folders/mY/mY1Jdd-YEAW-N77HgxpP6k+++TI/-Tmp-/slime.53923".. (Abort with `M-x slime-abort-connection'.) [15 times] Any ideas? 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: Class function alwayrs returns java.lang.class??
Ah. So class returns the class of the instance, and does not find the class with the name given. So , if I wanted to get the class of a ExecutionEvent, I would Have to go (Class/forName "org.eclipse.core.commands.ExecutionEvent")? Preferrably, I would like to simply go (Class/forName "ExecutionEvent") since I have already done: (import (java.lang.reflect Modifier Method) (org.eclipse.core.commands ExecutionEvent)) Is there a way? From: clojure@googlegroups.com [mailto:cloj...@googlegroups.com] On Behalf Of Laurent PETIT Sent: Thursday, September 10, 2009 10:06 AM To: clojure@googlegroups.com Subject: Re: Class function alwayrs returns java.lang.class?? Yes. (class "an instance of Stirng") will return java.lang.String Now the clojure symbol String is bound to a java.lang.Class instance giving information on the java.lang.String class (as if you had issued "kljlkjk".getClass()). 2009/9/10 Gorsal Hello. I'm trying to use (class String) to get the class object for the String class. However, nomatter what class typ ei pass, i always get java.lang.Class back. Is this the way its supposed to work? Thx! --~--~-~--~~~---~--~~ You 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: Class function alwayrs returns java.lang.class??
On Thu, Sep 10, 2009 at 1:20 PM, Seth Burleigh wrote: > Ah. So class returns the class of the instance, and does not find the > class with the name given. > Yes. > So , if I wanted to get the class of a ExecutionEvent, I would > > Have to go (Class/forName "org.eclipse.core.commands.ExecutionEvent")? > Nope, you would just have to type "ExecutionEvent", without quotes. Symbols that are class names are evaluated directly as instances of Class for the class they name. user=> (import 'java.util.HashMap) java.util.HashMap user=> (= HashMap (Class/forName "java.util.HashMap")) true Hope that helps, - J. --~--~-~--~~~---~--~~ You 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 and SOAP
I've been working on a project (both client and server) for the last few weeks using Clojure and SOAP. I looked around for anything SOAP related and didn't find much. I ended up just using the Apache Axis library. Their WSDL2Java saved me quite a bit of time. Right now I have more java code than I was hoping for, but I didn't write most of it. All in all, I'm reasonably happy with how the project is going. If you do find anything interesting, please let me know. ~jeff On Thu, Sep 10, 2009 at 8:49 AM, Adie wrote: > > Hello, > > I am looking to write a SOAP client in Clojure and was wondering if > there are any good existing libraries/clients in Java. After a bit of > searching i came across Apache Axis and JAX-WS, though i am not sure > how useful they will be and JAX-WS uses annotations. > > Has anyone had any experience dealing with SOAP and Clojure? > Are there any more useful libraries out there, or anything on > clojure.contrib that could be of help? > > --regards > Adityo > > > > --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
How to define multiple methods at once
Hi, I'd like to know whether there is already something in clojure.contrib that installs a method with multiple dispatch-values, i.e. given a multimethod like: (defmulti some-multi identity) instead of installing several methods with different dispatch values that do the same thing: (defmethod some-multi :a [arg] (do-something)) (defmethod some-multi :b [arg] (do-something)) I'd like to have something like this: (hypothetic-defmethods some-multi [:a :b] [arg] (do-something)) Is this already somehow in clojure.contrib (if so, I'm unable to find it)? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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 define multiple methods at once
> (hypothetic-defmethods some-multi [:a :b] [arg] (do-something)) Multimethods are dispatched using isa?. The idiomatic Clojure way of doing what you want is to define *one* method against something higher up in the hierarchy than both :a and :b. For example, if your two values are ::get and ::head, perhaps you should be defining a handler for ::idempotent-http-method. --~--~-~--~~~---~--~~ You 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 define multiple methods at once
> The idiomatic Clojure way of doing what you want is to define *one* > method against something higher up in the hierarchy than both :a and :b. > > For example, if your two values are ::get and ::head, perhaps you > should be defining a handler for ::idempotent-http-method. Thanks; fits perfectly into my domain. I knew about isa?, but it seems I was stuck in a hierarchy-is-for-classes-only mindset. --~--~-~--~~~---~--~~ You 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?
http://github.com/rnewman/clj-conneg/tree/master This is now pretty much finished, apart from more detailed sorting. E.g., you can ask: (conneg/best-allowed-content-type "image/*; q=0.9, text/html; q=0.1, text/plain; q=0.8" #{"image/jpeg"}) => ("image" "jpeg") i.e., it computes the most acceptable concrete type if it can. Comments 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 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 -~--~~~~--~~--~--~---
Lisp indenter for Kate
I wrote a Kate script to make lisp development on Kate a little more pleasant. It was written primarily with Clojure in mind, so it should work best with this language, but it's pretty generic. If you use Kate, please try it and feel free to add a comment to the kde bug report (see below). You can find the script here (read my first comment carefully): http://bugs.kde.org/show_bug.cgi?id=207002 Just place it under ~/.kde4/share/apps/katepart/script (you might need to create this directory) and choose "LISP" from "Tools > Indentation". This overrides the default lisp indenter. 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 -~--~~~~--~~--~--~---
Re: clojure-mode survey
Tom Faulhaber writes: > Also, one thing that I (and others) have noticed is that clojure mode > chokes on the #^{} form metadata on namespaces. (See any of the files > in clojure-contrib for an example.) I'm not able to reproduce the > problem now, so if you don't already know what it is, I'll keep my eye > out for it and send you a proper report when I have it happening. So I just found out that you can add regular docstrings to namespaces as per http://code.google.com/p/clojure/issues/detail?id=30, which was actually news to me (I thought it was targeted for 1.1). Anyway, given that you can do docstrings with nicer syntax now and git supports far more detailed authorship data, is there any reason to still use the #^{} syntax for namespaces? I must confess I've never liked the way it looks. -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: minor grievance with arithmetic on characters
I'd like to second all of this. The very first time I had to fix someone else's bug was when the dev used "a.compareTo(b) == -1". On Sep 9, 1:37 am, B Smith-Mannschott wrote: > 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: Looping idiom
uau cutting the Gordian knot On 8 sep, 05:39, Timothy Pratley wrote: > Yet another way :) > > user=> (map + (rest a) a) > (3 5 7 9 11) --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---