Re: subtractng sequence?
How about (map - seq1 seq2) ? An example or two of the desired output would be helpful. --~--~-~--~~~---~--~~ You 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: subtractng sequence?
Christophe's solution seems to work. basically I just wanted to remove (4 6 8 10) from (2 3 4 5 6 7 8 9 10) so I end up with (2 3 5 7 9) On Wed, Jun 3, 2009 at 3:27 AM, kyle smith the1physic...@gmail.com wrote: How about (map - seq1 seq2) ? An example or two of the desired output would be helpful. -- Omnem crede diem tibi diluxisse supremum. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: subtractng sequence?
If what you really want to do is treat those sequences as sets, then you can use clojure.seq/difference: 1:1 user= (def seq1 (list 2 3 4 5 6 7 8 9 10)) #'user/seq1 1:2 user= (def seq2 (list 4 6 8 10)) #'user/seq2 1:3 user= (require 'clojure.set) nil 1:4 user= (clojure.set/difference (set seq1) (set seq2)) #{2 3 5 7 9} 1:5 user= (seq (clojure.set/difference (set seq1) (set seq2))) (2 3 5 7 9) 1:7 user= 2009/6/3 Wilson MacGyver wmacgy...@gmail.com: More newbie questions. :) If I have two sequences as follow: (2 3 4 5 6 7 8 9 10) (4 6 8 10) what's the best way to subtract the 2nd sequence from the first one? The best I can come up with was to do (first) on 2nd sequence and turn around and do a (remove) on the first sequence, etc until I exhaust the 2nd sequence. is there a better way? Thanks, -- Omnem crede diem tibi diluxisse supremum. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: subtractng sequence?
ah, that works too! thanks! On Wed, Jun 3, 2009 at 3:48 AM, Laurent PETIT laurent.pe...@gmail.com wrote: If what you really want to do is treat those sequences as sets, then you can use clojure.seq/difference: 1:1 user= (def seq1 (list 2 3 4 5 6 7 8 9 10)) #'user/seq1 1:2 user= (def seq2 (list 4 6 8 10)) #'user/seq2 1:3 user= (require 'clojure.set) nil 1:4 user= (clojure.set/difference (set seq1) (set seq2)) #{2 3 5 7 9} 1:5 user= (seq (clojure.set/difference (set seq1) (set seq2))) (2 3 5 7 9) 1:7 user= 2009/6/3 Wilson MacGyver wmacgy...@gmail.com: More newbie questions. :) If I have two sequences as follow: (2 3 4 5 6 7 8 9 10) (4 6 8 10) what's the best way to subtract the 2nd sequence from the first one? The best I can come up with was to do (first) on 2nd sequence and turn around and do a (remove) on the first sequence, etc until I exhaust the 2nd sequence. is there a better way? Thanks, -- Omnem crede diem tibi diluxisse supremum. -- Omnem crede diem tibi diluxisse supremum. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Macros applied to entire programs
Rich Hickey a écrit : On May 13, 9:57 am, Christophe Grand christo...@cgrand.net wrote: Mark Reid a écrit : In particular, it seems converting `(+ 1 2 3)` to `(+ 1 (+ 2 3))` can speed things up. Rich, would you accept a patch to make all arities inlinable for basic math ops? What does the patch do? Here is the patch, it breaks tests in contrib for (-) and (/) since both forms now throw an exception at compile-time. -- 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 -~--~~~~--~~--~--~--- diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 2f594af..6897e55 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -546,45 +546,46 @@ (reduce conj () coll)) ;;math stuff -(defn + +(defmacro + #^{:private true} def-left-op + [op docstring bodies] + (let [macro-fn (clojure.lang.Compiler/eval + `(fn + ~...@bodies + ([x# y# more#] `(~'~op (~'~op ~x# ~y#) ~...@more# + has-zero? (reduce #(or %1 (= [] (first %2))) false bodies) + x (gensym x) + y (gensym y)] + `(defn ~(with-meta op {:inline macro-fn}) + ~docstring + ~@(when has-zero? `(([] ~(macro-fn + ([~x] ~(macro-fn x)) + ([~x ~y] ~(macro-fn x y)) + ([x# y# more#] (reduce ~op (~op x# y#) more#) + +(def-left-op + Returns the sum of nums. (+) returns 0. - {:inline (fn [x y] `(. clojure.lang.Numbers (add ~x ~y))) - :inline-arities #{2}} ([] 0) - ([x] (cast Number x)) - ([x y] (. clojure.lang.Numbers (add x y))) - ([x y more] - (reduce + (+ x y) more))) + ([x] `(cast Number ~x)) + ([x y] `(. clojure.lang.Numbers (add ~x ~y -(defn * +(def-left-op * Returns the product of nums. (*) returns 1. - {:inline (fn [x y] `(. clojure.lang.Numbers (multiply ~x ~y))) - :inline-arities #{2}} ([] 1) - ([x] (cast Number x)) - ([x y] (. clojure.lang.Numbers (multiply x y))) - ([x y more] - (reduce * (* x y) more))) + ([x] `(cast Number ~x)) + ([x y] `(. clojure.lang.Numbers (multiply ~x ~y -(defn / +(def-left-op / If no denominators are supplied, returns 1/numerator, else returns numerator divided by all of the denominators. - {:inline (fn [x y] `(. clojure.lang.Numbers (divide ~x ~y))) - :inline-arities #{2}} - ([x] (/ 1 x)) - ([x y] (. clojure.lang.Numbers (divide x y))) - ([x y more] - (reduce / (/ x y) more))) + ([x] `(/ 1 ~x)) + ([x y] `(. clojure.lang.Numbers (divide ~x ~y -(defn - +(def-left-op - If no ys are supplied, returns the negation of x, else subtracts the ys from x and returns the result. - {:inline (fn [ args] `(. clojure.lang.Numbers (minus ~...@args))) - :inline-arities #{1 2}} - ([x] (. clojure.lang.Numbers (minus x))) - ([x y] (. clojure.lang.Numbers (minus x y))) - ([x y more] - (reduce - (- x y) more))) + ([x] `(. clojure.lang.Numbers (minus ~x))) + ([x y] `(. clojure.lang.Numbers (minus ~x ~y (defn Returns non-nil if nums are in monotonically increasing order,
Re: Macros applied to entire programs
I'm sure there's something wrong with my patch (the eval smell) and the fact that I'm assoc-ing a closure in the metadat map. I'll rework it if you agree with the idea of this patch Christophe Grand a écrit : Rich Hickey a écrit : On May 13, 9:57 am, Christophe Grand christo...@cgrand.net wrote: Mark Reid a écrit : In particular, it seems converting `(+ 1 2 3)` to `(+ 1 (+ 2 3))` can speed things up. Rich, would you accept a patch to make all arities inlinable for basic math ops? What does the patch do? Here is the patch, it breaks tests in contrib for (-) and (/) since both forms now throw an exception at compile-time. -- 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: You know you've been writing too much Clojure when...
Question: You know you've been writing too much Clojure when... (dorun Question) -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: unit testing private methods?
Well, of course this is a classic situation in OO, if you think about it. Googling around may shed some interesting light on the subject. Essentially, the question is: are you sure that's what you want to do? Why not concentrate your unit tests on the public interface in such a way that the private methods get exercised too. Then, when (not if) your implementation changes, your tests shouldn't have to. On Tue, Jun 2, 2009 at 11:57 PM, Allen Rohner aroh...@gmail.com wrote: I have a namespace with some public functions, and some private functions. I would like to write unit tests for the functions, and put them in a separate file from the main name space. I would also like to have an (ns) declaration in my tests file, because the tests require several libraries. Of course, if I have private methods in namespace A, I can't call them from namespace B. Right now, it seems I have several options: 1) put the unit tests in the same file 2) put the unit tests in a separate file, in the same namespace 3) make the private functions public 4) ??? I don't really like the first three options. Ideally, the private functions would remain private to every namespace except the testing name space. Is there a good solution for this? 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 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: unit testing private methods?
Hi Allen, Stu, I guess my first inclination would be one of: 1) put the unit tests in the same file using the with-test macro, or 2) put the unit tests in a separate file, in the same namespace Stu's suggestion of with-ns would also work. But you don't even need with-ns. You can refer a private function into the local namespace like this: (def private-function (ns-resolve 'other-namespace 'private-function)) You could even write a function that refers all the private symbols of a namespace: (defn refer-private [ns] (doseq [[symbol var] (ns-interns ns)] (when (:private (meta var)) (intern *ns* symbol var This is slightly evil, and I would never recommend it for any purpose except unit testing, but there it is. -Stuart Sierra On Wed, Jun 3, 2009 at 12:36 AM, Stuart Halloway stuart.hallo...@gmail.com wrote: Hi Allen, You could write a function that uses the clojure.contrib.with-ns/with-ns macro to dip into the namespace being tested and return the private function, assigning it to a local name in the test namespace. I need this too, and have been meaning to ping the other Stuart about either (a) adding something like this to test-is, or (b) creating a new test-helpers library in contrib that would include this function. Stu I have a namespace with some public functions, and some private functions. I would like to write unit tests for the functions, and put them in a separate file from the main name space. I would also like to have an (ns) declaration in my tests file, because the tests require several libraries. Of course, if I have private methods in namespace A, I can't call them from namespace B. Right now, it seems I have several options: 1) put the unit tests in the same file 2) put the unit tests in a separate file, in the same namespace 3) make the private functions public 4) ??? I don't really like the first three options. Ideally, the private functions would remain private to every namespace except the testing name space. Is there a good solution for this? 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 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 -~--~~~~--~~--~--~---
Fwd: Clojure at LispNYC, June 9th
This is the talk that was supposed to happen on May 12. And we're going to shoot video -- email me if you can volunteer to bring a camera. -Stuart -- Forwarded message -- Join us Tuesday, may 12th from 7:00-9:00 for Stuart Sierra's presentation: Implementing AltLaw.org in Clojure This talk demonstrates the power of combining Clojure with large Java frameworks, such as: * Hadoop - distributed map/reduce processing * Solr - text indexing/searching * Restlet - REST-oriented web framework * Jets3t - Amazon S3 Clojure http://clojure.org/ is a new Lisp dialect developed by Rich Hickey. Clojure takes lessons from the best of Common Lisp and Scheme, and adds new abstractions, a rich set of immutable data structures, software transactional memory, and tools for managing mutable state in a multithreaded environment. Clojure is compiled on-the-fly to Java bytecode, and offers direct and convenient access to any Java library. Stuart Sierra http://stuartsierra.com/ has contributed many modules to Clojure's standard library, including a testing framework, a code walker, and a macro-based template processor. AltLaw http://altlaw.org/ is a free, open-source, full-text database and search engine for federal court cases, developed at Columbia Law School. In the past, this information was only available in law libraries or commercial database costing hundreds of dollars per hour. Directions to Trinity: Trinity Lutheran 602 E. 9th St. Ave B., on Thomkins Square Park http://trinitylowereastside.org/ From N,R,Q,W (8th Street NYU Stop) and the 4,5 (Astor Street Stop): Walk East 4 blocks on St. Marks, cross Thomkins Square Park. From FV (2nd Ave Stop): Walk E one or two blocks, turn north for 8 short blocks From L (1st Ave Stop): Walk E one block, turn sounth for 5 short blocks The M9 bus line drops you off at the doorstep and the M15 is near get off on St. Marks 1st) To get there by car, take the FDR (East River Drive) to Houston then go NW till you're at 9th B. Week-night parking isn't bad at all, but if you're paranoid about your Caddy or in a hurry, there is a parking garage on 9th between 1st and 3rd Ave. ___ Lisp mailing list l...@lispnyc.org http://www.lispnyc.org:8080/mailman/listinfo/lisp --~--~-~--~~~---~--~~ You 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: unit testing private methods?
Stuart Sierra a écrit : Stu's suggestion of with-ns would also work. But you don't even need with-ns. You can refer a private function into the local namespace like this: (def private-function (ns-resolve 'other-namespace 'private-function)) And don't forget the good old @#'other-namespace/private-function to get the value of any private var :-) -- 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 -~--~~~~--~~--~--~---
Clojure Talk @ Philly Java Users Gropu Tonight
I realize this is late notice (didn't think of it till now), there is a Clojure talk tonight at the Philadelphia Java Users Group - to attend you'll need to RSVP (see: http://phillyjug.jsync.com/ to sign up). The announcement is below. Regards, Kyle Agenda: 6:30 – 7:00 Grab a good seat, some pizza, soft drinks, enjoy life 7:00 – 7:15 Announcements, raffles and giveaways, stretching exercises 7:15 - ?? Scott Fraser on Clojure Speaker Bio: Scott Fraser – co-founder, CTO of Portico Systems Scott has worked professionally in the information technology sector for more than twenty one years. One of the three original founders of Portico Systems, he continues to have hands-on involvement with the company’s Java-based platform. Previously he worked as an independent consultant specializing in UNIX/Windows C/C++ programming, and networking. Scott started working with Java in 1996, and looks forward to 10 more years with the language that single-handedly saved him from memory leaks, Win16/32 API’s, and General Protection Faults. He has a BS in Environmental Biology from Eastern University in St. David’s PA, and is an avid birder. Abstract: Scott has always known about the coming Robot Apocalypse. But only recently was he convinced, by a Functional Programming evangelist, that the deconstruction of the Imperative and Object Oriented programming paradigms that had dominated Scott's career for over 22 years might be imminent. Always paranoid about staying relevant, sure that the JVM was here to stay, and with many years of highly multithreaded high performance Java applications behind him, he sought a functional language that would work for him... and was led to Clojure. Clojure is an exciting lisp dialect with baked in concurrency support. It's creator, Rich Hickey, was inspired by Haskell and ML, and hopes the language will play as a dynamic language like Python, Ruby and Groovy, that is as accessible as those languages, but also as performant as Java and as useful in any context as you would Java. It sounded perfect. But could it subdue the robots? Join Scott to learn about Clojure, and what it's creator calls it's Four Legs: * functional programming * lisp * being hosted on the JVM * direct support for concurrency And finally, see Real World Examples (tm) of using Clojure to control robots, for purposes of self defense, amusement of conference attendees, and otherwise. --~--~-~--~~~---~--~~ You 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: You know you've been writing too much Clojure when...
... You know you've been writing too much Clojure when... You see a cartoon swearword @^#!! and you think it's clojure meta-data! -Adrian. --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Scoopler whispers that clojure is making a nice impression
Having fun watching scoopler these days, and seeing people twitter and whatnot about clojure at javaone. http://www.scoopler.com/search/#clojure --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: You know you've been writing too much Clojure when...
2009/6/3 Adrian Cuthbertson adrian.cuthbert...@gmail.com: ... You know you've been writing too much Clojure when... You see a cartoon swearword @^#!! and you think it's clojure meta-data! LOL ! :-) --~--~-~--~~~---~--~~ You 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: subtractng sequence?
On Jun 2, 2009, at 11:22 PM, Wilson MacGyver wrote: More newbie questions. :) If I have two sequences as follow: (2 3 4 5 6 7 8 9 10) (4 6 8 10) what's the best way to subtract the 2nd sequence from the first one? The best I can come up with was to do (first) on 2nd sequence and turn around and do a (remove) on the first sequence, etc until I exhaust the 2nd sequence. In Clojure, the set data structure is awesome. I have nothing to add to that. However, I had to do this the other day in Javascript (which lacks a decent set type) and the algorithm I came up with is this: sort both sequences walk down both sequences: if the remove list item is greater than the list item, add it to the result and increment the remove list index if the remove list item is less than the list item, increment the list index if they are equal, increment the remove list index I believe this algorithm to be O(n log n) because the subtraction operation should take O(MAX(n,m)) and that ought to be dominated by the O(n log n) for sorting whichever input list is bigger. The naive method ought to be O(n*m) because for each element of one list you have to do a complete traversal of the other list. If the lists are comparable in size it would start to resemble O(n^2). Pretty off-topic, I know, but the function I came up with is this: // returns the subtraction of two sorted lists function subtract(a1, a2) { var i = 0, j = 0, result = []; // walk down both lists while (i a1.length j a2.length) { // the list item is less than the remove item if (a1[i] a2[j]) { // stick it on the result and move along the list result.push(a1[i]); i++; } else if (a1[i] a2[j]) // the list item exceeds the remove item, so we need to move along the // remove items j++; else // the items are equal, so continue testing the list with this item of // the remove list i++; } // glob on the remainder of the list if (i a1.length) result = result.concat(a1.splice(i)); return result; } I'm sure Clojure's sets do this kind of thing more efficiently but if you have to do it in a language without a decent set data structure you can fall back on that algorithm. Of course, I don't think you'll notice an improvement over the naive method until you hit several thousand elements or have similarly sized input lists. — Daniel Lyons http://www.storytotell.org -- Tell 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 -~--~~~~--~~--~--~---
What's the function that checks if an object is sequence-able?
Hi, Is there a function that will return true iff calling seq on it's argument will not throw an error? I thought it was seq?, but (seq? [1 2 3]) returns false. -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: What's the function that checks if an object is sequence-able?
I don't know either, but you can use the following work around (defn my-seq[object] (instance? clojure.lang.Seqable object)) (my-seq []) =true (my-seq {}) =true (my-seq #{}) =true (my-seq '()) =true (my-seq :a) = false (my-seq 'a-symbol) = false Still, it would be nice to know the right way to do this... On Jun 3, 12:53 pm, CuppoJava patrickli_2...@hotmail.com wrote: Hi, Is there a function that will return true iff calling seq on it's argument will not throw an error? I thought it was seq?, but (seq? [1 2 3]) returns false. -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: Macro Writing Helper?
In case anybody else found defblockfn useful, here's the final version. The original didn't work when you used destructuring in the argument list of the function. (defn remove_destructuring [params] (map (fn [arg] (if (or (vector? arg) (map? arg)) (gensym) arg)) params)) (defmacro defblockfn [function params body] (let [tempfn (symbol (str function *)) macro_params (butlast (remove_destructuring params))] `(do (defn ~tempfn ~params ~...@body) (defmacro ~function [...@macro_params tail#] `(~'~tempfn ~...@macro_params (fn [] ~...@tail#)) -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: Macro Writing Helper?
Could you throw together some live examples and unit tests? On Jun 3, 1:10 pm, CuppoJava patrickli_2...@hotmail.com wrote: In case anybody else found defblockfn useful, here's the final version. The original didn't work when you used destructuring in the argument list of the function. (defn remove_destructuring [params] (map (fn [arg] (if (or (vector? arg) (map? arg)) (gensym) arg)) params)) (defmacro defblockfn [function params body] (let [tempfn (symbol (str function *)) macro_params (butlast (remove_destructuring params))] `(do (defn ~tempfn ~params ~...@body) (defmacro ~function [...@macro_params tail#] `(~'~tempfn ~...@macro_params (fn [] ~...@tail#)) -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: Macro Writing Helper?
Sure. Here's two plausible examples. I apologize for not providing any unit tests. I'm not quite sure what they are. I've never written one before. ;---EXAMPLE 1- (defblockfn surround_with_text [text block] (println text) (block) (println text)) (surround_with_text surrounding text (println this is surrounded with text) (println this is also surrounded with text)) ;---EXAMPLE 2--- (def *gravity*) (defblockfn with_gravity [gravity block] (binding [*gravity* gravity] (block))) (with_gravity 9.81 (println current gravity is: *gravity*)) -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: What's the function that checks if an object is sequence-able?
user= (seq? (seq [1])) true On 3 Jun 2009, at 17:53, CuppoJava wrote: Hi, Is there a function that will return true iff calling seq on it's argument will not throw an error? I thought it was seq?, but (seq? [1 2 3]) returns false. -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: What's the function that checks if an object is sequence-able?
oops, sorry, that's not what u meant On 3 Jun 2009, at 17:56, craig mcmillan wrote: user= (seq? (seq [1])) true On 3 Jun 2009, at 17:53, CuppoJava wrote: Hi, Is there a function that will return true iff calling seq on it's argument will not throw an error? I thought it was seq?, but (seq? [1 2 3]) returns false. -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 -~--~~~~--~~--~--~---
Using Clojure script as Spring beans
Hello Clojure gang. I am just wondering is there a way to 'magically' create Spring bean (eligible for injection) from Clojure scripts source, provided that Clojure code implements the existing Java interface? The approach similar to Spring dynamic language support: http://static.springframework.org/spring/docs/2.5.x/reference/dynamic-language.html Please, don't be harsh - I'm new to Clojure :-) Thanks, Dmitriy. --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Spring and Clojure
Hello. I'm just wondering is there a way to create Clojure beans and inject them into other Spring beans (given that Clojure code implements Java interface) inside Spring ApplicationContext, similar to other dynamic langs support: http://static.springframework.org/spring/docs/2.5.x/reference/dynamic-language.html ? Thanks, Dmitriy. --~--~-~--~~~---~--~~ You 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: What's the function that checks if an object is sequence-able?
It seems the consensus is that this function doesn't yet exist. I'll use the instance? Seqable workaround for now. Thanks for the help guys. -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: What's the function that checks if an object is sequence-able?
Hi, Am 03.06.2009 um 18:53 schrieb CuppoJava: Is there a function that will return true iff calling seq on it's argument will not throw an error? I thought it was seq?, but (seq? [1 2 3]) returns false. (or (coll? x) (seq? x)) should give a reasonable approximation. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: What's the function that checks if an object is sequence-able?
BDFL says: http://groups.google.com/group/clojure/browse_frm/thread/3826ba3a52ec8cf7/ea899cfd965744a8?lnk=gstq=hickey+seqable#ea899cfd965744a8 --~--~-~--~~~---~--~~ You 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: What's the function that checks if an object is sequence-able?
On Jun 3, 2009, at 12:53 PM, CuppoJava wrote: Is there a function that will return true iff calling seq on it's argument will not throw an error? I thought it was seq?, but (seq? [1 2 3]) returns false. Such a function might be called seqable?. As far as I know it doesn't exist currently. I've wanted it in the past as well. The seq function is implemented in Java as RT.seq: static public ISeq seq(Object coll){ if(coll instanceof ASeq) return (ASeq) coll; else if(coll instanceof LazySeq) return ((LazySeq) coll).seq(); else return seqFrom(coll); } which calls RT.seqFrom: static ISeq seqFrom(Object coll){ if(coll instanceof Seqable) return ((Seqable) coll).seq(); else if(coll == null) return null; else if(coll instanceof Iterable) return IteratorSeq.create(((Iterable) coll).iterator()); else if(coll.getClass().isArray()) return ArraySeq.createFromObject(coll); else if(coll instanceof String) return StringSeq.create((String) coll); else if(coll instanceof Map) return seq(((Map) coll).entrySet()); else { Class c = coll.getClass(); Class sc = c.getSuperclass(); throw new IllegalArgumentException(Don't know how to create ISeq from: + c.getSimpleName()); } } From that we could derive isSeqable in Java as static public bool isSeqable(Object coll){ return (coll instanceof ISeq) || (coll instanceof Seqable) || (coll == null) || (coll instanceof Iterable) || (coll.getClass().isArray()) || (coll instanceof String) || (coll instanceof Map); } (ASeq and LazySeq both implement ISeq so their two tests can be collapsed into one.) I've checked in a Clojure version to clojure.contrib.core: user= (doc seqable?) - clojure.contrib.core/seqable? ([x]) Returns true if (seq x) will succeed, false otherwise. nil user= The one critique I have of this is that one might expect (seqable? x) to return true only if (instance? clojure.lang.Seqable x) returns true. I think the name seqable? is ideal otherwise though, so I used it. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Spring and Clojure
Hi, Provided that the beans you would like to see implemented via clojure must conform to a preexisting interface, I guess there would be no need at all to leverage to dynamic-language part of spring. Here is a recipe (out of my head, not tested) for how this would work: 1. identify the interface you want to implement 2. create a namespace for this interface, with the correct :gen-class magic incantation on the (ns) form 3. create the corresponding classical bean declaration in your spring xml file (no possibility to generate classes with annotations yet) 4. make sure that your build process compiles the clojure namespace via AOT Then, all the real clojure code implementing the interface methods will be in regular clojure functions, that you can redefine at will from a REPL (so there's also intrinsically no need for an explicit refresh bean functionality. At least, it is as I understand that currently. Of course, being also able in clojure to implement interfaces at runtime via the 'proxy form, it could be interesting to have a better integration via a specific dynamic language extension, getting rid of step 4 in the above described process. HTH, -- Laurent 2009/6/3 Dmitriy Kopylenko dmitriy.kopyle...@gmail.com: Hello. I'm just wondering is there a way to create Clojure beans and inject them into other Spring beans (given that Clojure code implements Java interface) inside Spring ApplicationContext, similar to other dynamic langs support: http://static.springframework.org/spring/docs/2.5.x/reference/dynamic-language.html ? Thanks, Dmitriy. --~--~-~--~~~---~--~~ You 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: What's the function that checks if an object is sequence-able?
Thanks Steve. That's very useful for me. Personally I'm not too bothered by the clojure.lang.Seqable confusion. I've never had to deal directly with the Java interfaces for Clojure, and this is probably true for a lot of other users as well. The only use-case where I can see users being confused, is if they're writing Clojure libraries that are designed to be used from Java. Thanks again -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: unit testing private methods?
2) put the unit tests in a separate file, in the same namespace This works for me, but since it won't work with the normal use/require idiom, I would like to see a standard convention evolve to make it easy to read other people's code. Stu --~--~-~--~~~---~--~~ You 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: Spring and Clojure
Thanks Laurent. So it is indeed possible. I need to dive into Clojure to understand it better (I only started looking into Clojure few days ago). Are there any Maven plugins or Ant tasks for doing AOT compilation? Perhaps a small example of this set up (with Spring bean) would be terrific. Regards, Dmitriy. Sent from my iPhone On Jun 3, 2009, at 16:20, Laurent PETIT laurent.pe...@gmail.com wrote: Hi, Provided that the beans you would like to see implemented via clojure must conform to a preexisting interface, I guess there would be no need at all to leverage to dynamic-language part of spring. Here is a recipe (out of my head, not tested) for how this would work: 1. identify the interface you want to implement 2. create a namespace for this interface, with the correct :gen-class magic incantation on the (ns) form 3. create the corresponding classical bean declaration in your spring xml file (no possibility to generate classes with annotations yet) 4. make sure that your build process compiles the clojure namespace via AOT Then, all the real clojure code implementing the interface methods will be in regular clojure functions, that you can redefine at will from a REPL (so there's also intrinsically no need for an explicit refresh bean functionality. At least, it is as I understand that currently. Of course, being also able in clojure to implement interfaces at runtime via the 'proxy form, it could be interesting to have a better integration via a specific dynamic language extension, getting rid of step 4 in the above described process. HTH, -- Laurent 2009/6/3 Dmitriy Kopylenko dmitriy.kopyle...@gmail.com: Hello. I'm just wondering is there a way to create Clojure beans and inject them into other Spring beans (given that Clojure code implements Java interface) inside Spring ApplicationContext, similar to other dynamic langs support: http://static.springframework.org/spring/docs/2.5.x/reference/dynamic-language.html ? Thanks, Dmitriy. --~--~-~--~~~---~--~~ You 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: Spring and Clojure
This link might help. Came across this weblog titled Practical Clojure with SWT, JUnit and Spring: http://berlinbrowndev.blogspot.com/2009/04/practical-clojure-with-swt-junit-and.html -Al On Wed, Jun 3, 2009 at 6:02 PM, Dmitriy Kopylenko dmitriy.kopyle...@gmail.com wrote: Hello. I'm just wondering is there a way to create Clojure beans and inject them into other Spring beans (given that Clojure code implements Java interface) inside Spring ApplicationContext, similar to other dynamic langs support: http://static.springframework.org/spring/docs/2.5.x/reference/dynamic-language.html ? Thanks, Dmitriy. --~--~-~--~~~---~--~~ You 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: run macro for executable namespaces
On Jun 2, 2009, at 9:38 AM, Meikel Brandmeyer wrote: Did you further think about your previous suggestion to provide the functionality of calling a qualified function from the command line of clojure.main? I'd like to see a (:main...) clause supported by ns to name the main entry point for a namespace. In the absence of that, main itself is a decent substitute. I'd still like to suggest a '-E' flag, which basically specifies the entry point to call. So one could do clojure.main -E some.namespace/some-func I like that. Perhaps we could even leave out the -E resolving the namespace/filepath ambiguity by trying the namespace first and if it's not found, trying the filepath. This would require some.namespace to be on the classpath. clojure.main some/file.clj would just execute some/file.clj as a script. clojure.main does this one now. clojure.main -E some.namespace/some-func some/namespace.clj I like this too. would first read some/namespace.clj and then execute some.namespace/some-func. This would not require some.namespace to be on the classpath, because it could be defined in the given file. Right. very flexible. This would allow to make the loading of script files side-effect free, which would ease their use during debugging. And it would allow different entry points in a single script. Nice benefit. I like these changes. More discussion, especially from everyone interested in more flexible launching of Clojure via clojure.main would give us an indication of how important a change it is. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: subtractng sequence?
Thank you for such a detail email on the algorithm. I'll certainly keep that in mind. This is so far been the most impressive thing I've found about clojure. the community is very friendly and helpful. You've made a newbie feel much more comfortable. On Wed, Jun 3, 2009 at 12:33 PM, Daniel Lyons fus...@storytotell.org wrote: In Clojure, the set data structure is awesome. I have nothing to add to that. However, I had to do this the other day in Javascript (which lacks a decent set type) and the algorithm I came up with is this: sort both sequences walk down both sequences: if the remove list item is greater than the list item, add it to the result and increment the remove list index if the remove list item is less than the list item, increment the list index if they are equal, increment the remove list index -- Omnem crede diem tibi diluxisse supremum. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Spring and Clojure
We did the reverse (using Spring directly from Clojure) without any difficulty. Never thought about creating Clojure beans however. We had already some code to bootstrap Spring from Java. Just called it from Clojure. We wanted to drop Java as much as possible but did not want to loose some of the low level stuff we wrote in Java. Being curious, can you shed any light of the use you would make of Clojure beans ? Luc P. On Wed, 2009-06-03 at 09:02 -0700, Dmitriy Kopylenko wrote: Hello. I'm just wondering is there a way to create Clojure beans and inject them into other Spring beans (given that Clojure code implements Java interface) inside Spring ApplicationContext, similar to other dynamic langs support: http://static.springframework.org/spring/docs/2.5.x/reference/dynamic-language.html ? Thanks, Dmitriy. Luc Préfontaine Armageddon was yesterday, today we have a real problem... --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Where does the language end and the libraries begin?
Tonight Rich made a comment (related to distributed computing) about not wanting to include things in the language that should belong in libraries. This led me to wonder (only after leaving the meeting), where does that boundary live? Is clojure.core language or library? Is it the java implementation that separates the two? What happens when Clojure is written entirely in Clojure (as Rich also mentioned)? What does that really mean (other than that there won't be any .java files around)? I have no opinions here, it just seemed like a neat, quasi- philosophical issue, and I didn't have an answer. --~--~-~--~~~---~--~~ You 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 -~--~~~~--~~--~--~---
Help with Math Question
Hey guys, I'm really stuck on this math question, and I'm wondering if you guys know of any links that may help me. Given: f(x,y), a0, a list of numbers v. Find: g(x,y) and b0 such that: (reduce f a0 v) = (reduce g b0 (reverse v)) Thanks for your help -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: Where does the language end and the libraries begin?
I've always considered the core part of the language to be the portion that cannot be written in the language itself. I don't think you can write an Clojure if form in Clojure. When we talk about implementing Clojure entirely in Clojure, we don't actually mean implementing the language in itself. We mean something more along the lines of implementing Clojure v2 in Clojure v1. In case I'm mistaken, however, I would be absolutely fascinated by a language written in itself. -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 -~--~~~~--~~--~--~---