Re: Why does (= [] (range)) not terminate?

2012-02-17 Thread Michael Gardner
On Feb 17, 2012, at 2:29 PM, Alan Malloy wrote: Lazy sequences implement java.util.List, which has a .size method. clojure.lang.APersistentVector/doEquiv (and doEquals) attempts to optimize when it sees it is being compared to something with a .size or .count method, by comparing sizes before

Re: How to be lazy…

2012-02-16 Thread Michael Gardner
partition-by is lazy in that it only splits its argument into as many subseqs as requested; the subseqs themselves are not lazy. So when you partition-by the result of (replace-subseq-with-sentinel [1 2] sentinel (range)) and then request the infinite third subseq thereof, partition-by won't

Re: How to be lazy…

2012-02-16 Thread Michael Gardner
On Feb 16, 2012, at 11:08 AM, Wolodja Wentland wrote: Thanks for the explanation. What would be a good way to ensure that the subseqeuence are lazy too? I can't think of a good way to do this with higher-order functions, so you'll probably have to write a recursive function that manually

Re: stack overflow vs scheme

2011-12-01 Thread Michael Gardner
Try increasing the JVM's stack size with -Xss. -- 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

Re: need help eliminating ordinary recursion/thinking the Clojure way

2011-11-11 Thread Michael Gardner
Since you're given a sorted list of intervals, you don't actually need to restart the whole merging process from the start after each merge; you can just replace the last interval in your output with the new, merged interval and continue from there. So `reduce' is the perfect tool for the job;

Re: anyone interested in a small game?

2011-10-31 Thread Michael Gardner
On Oct 31, 2011, at 2:03 PM, Timothy Baldridge wrote: This is what Clojure excels at...de-coupling, or as Rich put it in his recent talk Simple made Easy: don't assume things about your code. Don't assume that all models will always fit into the concept of a polygon...don't assume that you'll

Re: When to use mutable state

2011-10-14 Thread Michael Gardner
On Oct 14, 2011, at 8:48 AM, Timothy Baldridge wrote: On Fri, Oct 14, 2011 at 7:58 AM, pistacchio pistacc...@gmail.com wrote: I'm implementing a litte game thing in Clojure. So far I'm passing around a world status object among functions. It is very functional and I can simulate any moment of

Re: Spread work onto multiple threads (in pure Clojure)

2011-10-11 Thread Michael Gardner
Just to throw in my two cents here: it would really be a shame for Clojure's pmap to continue to languish in the state it's currently in (i.e. nearly useless). Even though implementing an alternative using thread pools isn't too hard, it hurts the Clojure concurrency sales pitch-- I can't tell

Re: suggestion for clojure development

2011-09-28 Thread Michael Gardner
On Sep 28, 2011, at 7:20 PM, Arthur Edelstein wrote: So what's the plan for the future? Are there plans to make clojure stable at some point so that backward compatibility can be expected? Otherwise I am going to have difficulty continuing to advocate clojure to my colleagues. In other words,

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Michael Gardner
On Sep 26, 2011, at 8:12 AM, Paul Richards wrote: How can I efficiently pick a random element from a sorted-set? If your sorted set is densely packed (if most possible values do appear in the set), then you could just pick a random value, see if it's in the set, and repeat until you find a

Re: why expressions in macro are not evaluated?

2011-09-14 Thread Michael Gardner
On Sep 13, 2011, at 2:39 AM, jingguo wrote: I get a_message printed twice if I paste the code in a clojure REPL. But I save the code into a file called foo.clj and use clj foo.clj to run it. I get nothing in stdout. It seems that (printf a_message \n) is not evaluated. Can anybody explain

Re: puzzlement over lazy sequences

2011-09-13 Thread Michael Gardner
On Sep 12, 2011, at 11:28 PM, Ken Wesson wrote: But if, as you say, take, drop, etc. work for larger n, it should be easy to make nth work with larger n and non-random-access seqs, just by changing the non-random-access case to (first (drop n the-seq)). I'd be rather surprised if nth suddenly

Re: lambda function returning a constant?

2011-09-06 Thread Michael Gardner
On Sep 6, 2011, at 10:43 PM, Armando Blancas wrote: For something like = true try: user= (defmacro = [expr] `(fn [] ~expr)) #'user/= (macroexpand-1 '(= true)) (clojure.core/fn [] true) Alternatively: (constantly true) -- You received this message because you are subscribed to the Google

Re: Code structure/design problems

2011-07-29 Thread Michael Gardner
On Jul 29, 2011, at 1:50 AM, Laurent PETIT wrote: Without too much thinking about it, I would have thought monsters, players, etc. need to be changed in a same transaction, so would have by default implemented them as refs instead of atoms. Could you elaborate more on the choice of atoms

Re: Question regarding structural sharing, records, and maps

2011-07-29 Thread Michael Gardner
On Jul 28, 2011, at 10:59 PM, Trenton Strong wrote: So far, I have settled on just using a single ref wrapping the root node of the tree with all update functions acting on that ref via dosync. An atom would be more appropriate, unless you're coordinating updates to the tree with updates to

Re: Code structure/design problems

2011-07-28 Thread Michael Gardner
On Jul 28, 2011, at 1:44 AM, Oskar wrote: I have a hard time coming up reasons why this would be better. My function that I wanted that checks if two characters are close enough to each other is just a very small part of my game. And I could make just that function fuctional and my list of

Re: Alright, fess up, who's unhappy with clojurescript?

2011-07-24 Thread Michael Gardner
On Jul 24, 2011, at 1:11 PM, James Keats wrote: Restricting yourself to a functional subset of JavaScript can't fix JavaScript. The functional subset stinks, Javascript notaries be damned. If so where does this leave clojure itself and its advocacy of functional programming, then; see last

Re: Alright, fess up, who's unhappy with clojurescript?

2011-07-24 Thread Michael Gardner
On Jul 24, 2011, at 2:08 PM, James Keats wrote: On Jul 24, 7:24 pm, Michael Gardner gardne...@gmail.com wrote: The functional parts of Javascript are far different from those of Clojure (and not in a good way). How so? javasript, while not as functional as clojure, is far more functional

Re: Idiomatic Clojure for variadic functions with optional leading arguments?

2011-07-09 Thread Michael Gardner
On Jul 9, 2011, at 6:16 PM, Sean Corfield wrote: If I need a function to have something like the following signatures, what's the most idiomatic way to do it: ([fn-arg str-arg vec-arg others] ...) ([str-arg vec-arg others] ...) Background: several functions in clojure.java.jdbc are

Re: Question on eliminating recur

2011-07-09 Thread Michael Gardner
On Jul 9, 2011, at 8:47 AM, Brian Hurt wrote: If there is an obvious way to rewrite the code using doseq or fold (or reduce or map or etc), then yes- you should do it. However, if this way to rewrite the code isn't obvious in 10 seconds of thought, don't worry about it. Use loop/recur.

Re: Applying Java functions

2011-06-17 Thread Michael Gardner
On Jun 17, 2011, at 3:44 AM, Konrad Hinsen wrote: Java methods aren't even first-class objects (nor, in fact, objects at all) in the Java world. Clojure can hardly do better than Java in unifying things at the JVM level. The one thing that you can do with a method in Java is call it, and

Re: Jesus, how the heck to do anything?

2011-03-23 Thread Michael Gardner
On Mar 23, 2011, at 7:26 PM, Armando Blancas wrote: But there's no question that to use Clojure you need a good grasp of java, the language and infrastructure, no way around that. I don't know about that. I've been teaching a young'un Clojure without ever mentioning anything about Java.

Re: How to read this sample code?

2011-03-16 Thread Michael Gardner
On Mar 15, 2011, at 5:28 PM, Christian wrote: Secondly, what is happening inside the for structure? [idx elt] are being bound to vector returned by indexed, but that assignment only happens when pred == elt. Finally, we return the vector idx. Is this correct? [idx elt] is destructuring-bound

Re: The horrors of setting up a decent OpenGL clojure environment.

2011-02-21 Thread Michael Gardner
On Feb 21, 2011, at 8:24 AM, Timothy Baldridge wrote: Finally I found out that the best was was to use lein. So I installed lein, and after several hours finally got it to download and install Clojure. I added penumbra to my project.clj, and told lein to get the deps. It downloaded dozens of

Re: Get digits of a number

2011-02-17 Thread Michael Gardner
On Feb 17, 2011, at 1:36 PM, Mike Meyer wrote: My turn... (defn to-digits Create a seq of digits from a number. [i] ^{:user/comment For Euler Problems (Specifically 16)} (map {\0 0 \1 1 \2 2 \3 3 \4 4 \5 5 \6 6 \7 7 \8 8 \9 9} (str i))) No assumption about representation

Re: Anyone want to take a crack at making the fasta shootout program faster?

2011-02-12 Thread Michael Gardner
On Feb 12, 2011, at 3:12 PM, Isaac Gouy wrote: Yeah but it's not too hard to see why the Lisp programmer Juho Snellman opined on HN the [sic program] implementations seem to have totally dived off the deep end of complexity. That's why this kind of competition is not interesting to me. As it

Re: Anyone want to take a crack at making the fasta shootout program faster?

2011-02-12 Thread Michael Gardner
On Feb 12, 2011, at 3:38 PM, Isaac Gouy wrote: On Feb 12, 1:28 pm, Michael Gardner gardne...@gmail.com wrote: That's why this kind of competition is not interesting to me. As it only compares the fastest programs, there's every incentive to submit horrifically complex, optimized-to-the-hilt

Re: How does pmap partition its work?

2011-01-27 Thread Michael Gardner
On Jan 27, 2011, at 7:24 AM, Rasmus Svensson wrote: If you simply want all tasks to be performed as quickly as possible, one alternative could be to use an ExecutorService (perhaps one created with newFixedThreadPool) with its invokeAll method. invokeAll takes a collection of callables (in

Re: What is the difference between a tail-recursive function and a recursive function using recur?

2011-01-26 Thread Michael Gardner
Tail-recursive just means the recursive call occurs in tail position: the result of the recursive call gets returned as-is rather than having some additional computations done to it first. This means the compiler *could* optimize the recursive call to not consume any additional stack space, by

Re: How does pmap partition its work?

2011-01-25 Thread Michael Gardner
I have run across something else I don't understand about pmap. Why does the following: (pmap (fn [_] (clojure.java.shell/sh sleep 10)) (range 32)) result in all 32 sleep processes being run at once? I thought pmap used n+2 threads, where n is the number of processors/cores available (I have

Re: How does pmap partition its work?

2011-01-25 Thread Michael Gardner
On Jan 25, 2011, at 9:06 AM, Ken Wesson wrote: sh is asynchronous. It calls Runtime/exec, which launches the sleep as a separate process and immediately returns a Process object (which your pmap should be returning a seq of). It may produce n+2 Process objects at a time but it produces them

Re: How does pmap partition its work?

2011-01-25 Thread Michael Gardner
On Jan 25, 2011, at 9:33 AM, Ken Wesson wrote: Well, that's weird, because the documentation *I* read says it composits the arguments together into a command line and hands off to Runtime/exec. And the documentation of *that* says it returns a Process object and the process it launches runs

Re: How does pmap partition its work?

2011-01-25 Thread Michael Gardner
On Jan 25, 2011, at 12:13 PM, Andy Fingerhut wrote: In my original message describing pmap's behavior, there was a little gotcha near the end: Note: Sometimes working at odds with pmap's Don't work too far ahead approach is if the input sequence to pmap is chunked. When a chunk is

Re: How does pmap partition its work?

2011-01-24 Thread Michael Gardner
On Jan 23, 2011, at 10:56 PM, Ken Wesson wrote: I've managed to make this more efficient, by making each agent send process a larger portion of the job than one single item: (defn eager-pmap [f colls] (let [cores (.. Runtime getRuntime availableProcessors) agents (cycle (for [_

Re: [ANN] fs - file system utilities for Clojure

2011-01-24 Thread Michael Gardner
On Jan 19, 2011, at 11:32 AM, Miki wrote: I'd appreciate some comments about need functionality, bugs, code reviews and such. Thanks for this useful library. Some suggestions: -I'd rather (copy-tree src dest) worked like cp -R src dest (including when dest doesn't exist) rather than cp -R

Re: Calling .close() on resources -- with-open macro

2011-01-24 Thread Michael Gardner
On Jan 24, 2011, at 1:54 PM, Laurent PETIT wrote: That's interesting. Indeed, it seems to me that the .close() call should be wrapped by a try / catch with an empty catch. Why would client code want an exception thrown by .close() to get swallowed? Is that not unexpected behavior in most

How does pmap partition its work?

2011-01-23 Thread Michael Gardner
Suppose I have a sequence of tasks I'd like to parallelize using pmap. The amount of CPU time these tasks require varies greatly; in particular, many of them will require virtually no work. Can I rely on pmap to divide the work efficiently even if there is some pattern to the distribution of

Re: How does pmap partition its work?

2011-01-23 Thread Michael Gardner
On Jan 23, 2011, at 8:34 PM, Andy Fingerhut wrote: No, you cannot rely on pmap to do that. snip Thanks for the detailed and informative answer. I'll probably settle for shuffling the list of inputs before passing them to pmap, and just accept that there may be some inefficiency in the

Re: Help with java conversion

2011-01-21 Thread Michael Gardner
On Jan 21, 2011, at 10:35 AM, Laurent PETIT wrote: As far as possible, the equivalent of a java anArray[anIndex] expression will be of not using an index in the first place in Clojure (*). Expanding on Laurent's answer: to transform one list into another, use 'map'. In this case you can

Re: Code Review of my first stab

2011-01-18 Thread Michael Gardner
On Jan 18, 2011, at 10:59 AM, Tim Visher wrote: I'd love to have the code torn apart a little bit and get some suggestions for improvements. It's located at https://gist.github.com/784744 It took me a few tries to figure out what to-wallpaper-name was doing. Maybe you should write a

Re: Enhanced Primitive Support Syntax

2011-01-15 Thread Michael Gardner
On Jan 15, 2011, at 4:04 PM, Stuart Halloway wrote: I'll make a documentation update higher priority; hopefully that will help. This should help. I feel like the discussion is going in circles because there's no single, official source that summarizes exactly what is happening with numerics

Re: Clojure job scheduler

2011-01-07 Thread Michael Gardner
On Jan 7, 2011, at 11:13 AM, Trevor wrote: 3. I could set a job-schedule using the OS to run a clojure script. I'd rather not, I would like to do things like send emails / check status via web app (making option 1 more appealing). Could you elaborate on why a scheduled job to run a Clojure

Re: Clojure job scheduler

2011-01-07 Thread Michael Gardner
On Jan 7, 2011, at 9:19 PM, Ken Wesson wrote: On the other hand, running a job scheduler from outside Clojure results in cranking up a big, slow to start up, expensive JVM process every single time a task needs to run, each of which runs one task once, and the scheduling itself must be done

Re: Let's see how fast we can make this

2010-12-24 Thread Michael Gardner
On Dec 24, 2010, at 8:19 PM, David Nolen wrote: ((long double) end-start) / 1000.0 I don't think this math is correct. The units for the values returned by mach_absolute_time() are CPU-dependent: http://developer.apple.com/library/mac/#qa/qa2004/qa1398.html Using gettimeofday() on my 2.0 GHz

Re: Clojure 1.3 Alpha 4

2010-12-14 Thread Michael Gardner
On Dec 14, 2010, at 9:26 PM, Ken Wesson wrote: On Tue, Dec 14, 2010 at 10:02 PM, Brian Goslinga quickbasicg...@gmail.com wrote: This topic has been discussed to death before on this group. If so, it was before I joined. That's what archives are for:

Re: Clojure 1.3 Alpha 4

2010-12-14 Thread Michael Gardner
On Dec 14, 2010, at 11:22 PM, Ken Wesson wrote: On Tue, Dec 14, 2010 at 10:37 PM, Michael Gardner gardne...@gmail.com wrote: That's what archives are for Are you honestly suggesting I search the archives for every word of every thought that it ever occurs to me to post here? I don't have

Re: String-friendly first/rest?

2010-12-08 Thread Michael Gardner
On Dec 8, 2010, at 4:05 PM, Surgo wrote: That's a fair criticism. I suppose that I'm not necessarily looking for specifically String manipulation abstractions (I can just do a (.substr abc 1) to get bc as a String after all), but rather looking for an abstraction that takes something that's

Re: parameters destructuring sets?

2010-12-06 Thread Michael Gardner
On Dec 6, 2010, at 4:07 PM, Ken Wesson wrote: Perhaps. But under those circumstances seq itself has the same problem you're using to excuse not supporting nth, yet seq is supported. And so is (nth (seq x)) on these things; if the implementation changed its innards while you were walking the

Re: parameters destructuring sets?

2010-12-06 Thread Michael Gardner
On Dec 6, 2010, at 5:35 PM, Ken Wesson wrote: Who was relying on the order? If you merely relied on seeing 5 or 6, or on not seeing 3 or 4 twice, you were screwed. Ah, I misunderstood what you wrote. Obviously (seq) should hand you each item in the collection exactly once, but that's at a

Re: parameters destructuring sets?

2010-12-06 Thread Michael Gardner
On Dec 6, 2010, at 9:02 PM, Ken Wesson wrote: I'll try this one more time. You suggested the innards, and with them the seq order of the elements, might get rearranged. I suggested no such thing; perhaps you are confusing me with Mike Meyer? I referred more generally to the possibility of two

Re: range with decimal values

2010-12-04 Thread Michael Gardner
On Dec 4, 2010, at 8:42 AM, Glen Rubin wrote: If I use the range fn with a decimal number for step I get back something like this: (range 0.05 0.16 0.01) user (0.05 0.060005 0.07 0.08 0.09 0.0 0.10999 0.11998 0.12998

Re: discussing Clojure with non-CS types

2010-11-25 Thread Michael Gardner
On Nov 24, 2010, at 7:47 PM, CuppoJava wrote: The other reason is that Clojure emphasizes functional programming and discourages mutation. This is fine, as I believe well-written code is usually functional anyway. The problem is that bad code is usually easier to write in an imperative way

Re: Performance of seq on empty collections

2010-11-14 Thread Michael Gardner
On Nov 14, 2010, at 4:04 PM, Ken Wesson wrote: Interestingly, (= (count v) 0) is relatively fast (900 msec); (seq v) is slower (2s); (empty? v) is even slower (3s); and (= v []) is slowest (16s). Strange. Here are the timings I get for 1e8 iterations: (zero? (count v)): ~3600 msecs (seq v):

Re: Collapse some functions? (was Re: clojure.core function decision tree)

2010-11-10 Thread Michael Gardner
On Nov 10, 2010, at 11:36 AM, Carson wrote: rseq O(1), reverse O(n). peek O(1), last O(n). pop O(1), butlast O(n). get O(1), nth O(n). I don't see that in the documentation... If these functions aren't collapsed, then it's better if at least (doc reverse) says something about O(n) and

Re: Collapse some functions? (was Re: clojure.core function decision tree)

2010-11-10 Thread Michael Gardner
On Nov 10, 2010, at 12:40 PM, Michael Gardner wrote: The docstring for reverse does say not lazy, which implies at least O(n). In the general case, that is. As Meikel mentioned, reverse works on any seq, so this is the best guarantee it can provide in general. -- You received this message

Re: Collapse some functions? (was Re: clojure.core function decision tree)

2010-11-10 Thread Michael Gardner
On Nov 10, 2010, at 5:48 PM, Alan wrote: I guess you stay backwards-compatible by putting it in the docstring, but isn't it more general, clean, and programmatic to put these useful bits of information into new entries in (meta f)? That's pretty much what I was trying to get at with

Re: Why isn't there a fold-right?

2010-11-07 Thread Michael Gardner
On Nov 5, 2010, at 9:03 PM, Yang Dong wrote: Maybe because Clojure has a vector, and conj conjoins new elements to the end of the vector, so there's mere little use of fold-right. But, fold-right is an abstraction tool, missing it in the core is kind of pity. What's wrong with just using

Re: Constructing Nested Trees and Memory Consumption

2010-11-03 Thread Michael Gardner
On Nov 3, 2010, at 8:31 PM, Andy Fingerhut wrote: I'd recommend changing your code to use Java chars instead of single-char Java strings. That plus the change Paul suggests below should reduce memory consumption significantly. Another option is to .intern() the strings. You'll still create

Re: Clojure on Javascript

2010-10-29 Thread Michael Gardner
On Oct 29, 2010, at 11:09 PM, David Nolen wrote: JS brought me to Lisp, I would love to see the Clojure community bring Lisp back to JS. However I fail to see what advantage JS gives on the server side. From what I've seen the V8 GC and Node.js have a considerable number of years to go

Re: to macro or not?

2010-10-28 Thread Michael Gardner
On Oct 28, 2010, at 2:55 PM, Raoul Duke wrote: not looking to stir up a pot, looking to learn from people's experience. i've heard that in CL land, one is told to avoid macros as long as possible. i've heard other folks in the Clojure world say that if you aren't using macros, then sorta why

Re: First function

2010-10-21 Thread Michael Gardner
On Oct 21, 2010, at 3:28 AM, Brody Berg wrote: (if (empty? m_list) false (binary-search m_list 0 (- (count m_list) 1) target)) Assuming that returning nil is OK in case of the target not being present, you can replace this with (when (seq m_list) (binary-search

Re: First function

2010-10-21 Thread Michael Gardner
On Oct 21, 2010, at 3:28 AM, Brody Berg wrote: (if (== (nth m_list m_left) target) Forgot to mention: you should use = instead of == unless you're sure you will only ever get numeric arguments *and* profiling tells you that = is a performance bottleneck. -- You received this

Re: Is This Function Idiomatic Clojure?

2010-10-07 Thread Michael Gardner
On Oct 7, 2010, at 1:29 AM, Stefan Rohlfing wrote: Following an Enlive tutorial I wanted to implement a function 'd-map' that takes an arbitrary number of [:key (list of values)] parameters like this: (d-map [:headline [this is me] ] [:points [1 2 3] ] [:comments [10

Re: Idiomatic Way to Build String or Simply Use StringBuilder

2010-10-01 Thread Michael Gardner
On Sep 30, 2010, at 10:37 PM, HiHeelHottie wrote: (ns test-test.parse (:use [clojure.contrib.string :only (split)])) (defn parse-char [m c] (condp = (:state m) :degree (cond (Character/isDigit c) (assoc m :degree (+ (* (:degree m) 10) (Character/digit c 10)))

Re: Idiomatic Way to Build String or Simply Use StringBuilder

2010-09-29 Thread Michael Gardner
On Sep 29, 2010, at 10:32 PM, Stuart Campbell wrote: I would just use (str) - it uses a StringBuilder when given more than one argument: There's also (format), which I find helpful for building more complex strings. -- You received this message because you are subscribed to the Google

Re: Idiomatic Way to Build String or Simply Use StringBuilder

2010-09-29 Thread Michael Gardner
On Sep 29, 2010, at 11:01 PM, HiHeelHottie wrote: What if you are appending over different lines of code? Could you give an example of what you're trying to do? Mutable strings are almost never necessary, in my experience. -- You received this message because you are subscribed to the Google

Re: An Emacs command to close the various balanced expressions in Clojure

2010-09-28 Thread Michael Gardner
On Sep 26, 2010, at 6:51 PM, blais wrote: Writing Clojure code tends to require a larger mix of (), [] and {} characters than other LISPs I use. This sometimes makes it a bit tiring to write those balanced expressions. For outer expressions I tend to use the verbose forms (hash-map ...) and

Re: finding value nearest x

2010-09-27 Thread Michael Gardner
On Sep 27, 2010, at 9:28 AM, Glen Rubin wrote: It occurs to me that another way of doing this is to map a new list and then use the min fn. something like: (apply min (map #(Math/abs (- % 136)) xs)) maybe this is better and involves less calculations? That gives you the minimum distance

Re: return index of a value

2010-09-27 Thread Michael Gardner
On Sep 27, 2010, at 9:45 AM, Glen Rubin wrote: I have a vector of numbers [0 99 3334 53 2 5 99 2 55 63] I'd like to find the first index of a particular value. For example if the value was 99 then I want to return 1, b/c the index of 99 is 1. I can do this with a loop/recur structure

Re: finding value nearest x

2010-09-27 Thread Michael Gardner
On Sep 27, 2010, at 9:59 AM, Glen Rubin wrote: yes correct. but i can write a fn to determine the index of the minimum distance in my new list? that index applied to my original list will give me the value back. and this still would involve fewer calculations i think. Do you have a

Re: simplest graphics?

2010-09-16 Thread Michael Gardner
On Sep 15, 2010, at 10:15 PM, Lee Spector wrote: Also, this would have a smaller impact but I'm curious about it: is there a way to treat method names as data and then make calls to them, as one can with clojure functions? Then I could pass things like fillRect, or map rect to fillRect,

Re: What is the reason Lisp code is not written with closing parenthesis on new lines?

2010-08-18 Thread Michael Gardner
On Aug 18, 2010, at 1:38 PM, Greg wrote: http://gregslepak.posterous.com/on-lisps-readability That article is dishonest. The author changes indentation widths between examples, while focusing entirely on the trailing-parens. He claims in a comment that the post is not solely about trailing

Re: What is the reason Lisp code is not written with closing parenthesis on new lines?

2010-08-18 Thread Michael Gardner
On Aug 18, 2010, at 2:49 PM, Greg wrote: On Aug 18, 2010, at 12:07 PM, Michael Gardner wrote: On Aug 18, 2010, at 1:38 PM, Greg wrote: http://gregslepak.posterous.com/on-lisps-readability That article is dishonest. Speaking as the author, I'm a bit offended. Too bad. If you wanted

Re: Installing Clojure on OS X

2010-08-17 Thread Michael Gardner
On Aug 17, 2010, at 10:17 AM, Saul Hazledine wrote: On Aug 17, 3:59 pm, HB hubaghd...@gmail.com wrote: Hey, How to install Clojure on Mac OS X? I googled the web, some use MacPorts, others write some shell scripts. Is there a -standard- way to install Clojure on OS X (if possible, please

Re: two announcements: a new Clojure article, and a new site for beginners

2010-08-14 Thread Michael Gardner
On Aug 14, 2010, at 12:58 AM, Gregg Williams wrote: ** Second announcement: GettingClojure.com, a collaborative site for Clojure beginners gettingclojure.com currently redirects to www.wikidot.com. www.gettingclojure.com is fine, though. -- You received this message because you are

Re: Please help! Really simple function not working.

2010-08-09 Thread Michael Gardner
On Aug 9, 2010, at 7:24 PM, Carlos Torres wrote: I'm trying to create a function that takes a simple list and returns the number of zeros in the list. user= (count (filter zero? [0 1 2 3 0 4 5 6 0 7 8 9])) 3 -- You received this message because you are subscribed to the Google Groups

Re: looking for a simpler implementation of a function I'm using

2010-08-07 Thread Michael Gardner
(partition-by #(when (even? %) (gensym)) -- 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

Re: looking for a simpler implementation of a function I'm using

2010-08-07 Thread Michael Gardner
On Aug 7, 2010, at 8:35 PM, Michael Gardner wrote: (partition-by #(when (even? %) (gensym)) Whoops, hit 'send' too soon. And it doesn't actually work, since it splits before and after the even values. On Aug 7, 2010, at 8:39 PM, gary ng wrote: nice, why do I need the gensym ? The gensym

Re: looking for a simpler implementation of a function I'm using

2010-08-07 Thread Michael Gardner
On Aug 7, 2010, at 8:48 PM, Michael Gardner wrote: On Aug 7, 2010, at 8:39 PM, gary ng wrote: nice, why do I need the gensym ? The gensym was just a cheesy way of generating a unique value. To elaborate a bit more on my failure, I was reading the docs for partition-by thinking that new

Re: randomizing a vector

2010-07-21 Thread Michael Gardner
On Jul 21, 2010, at 12:44 PM, Michał Marczyk wrote: The biggest problem with the code is that it reconstructs the entire `ordered-ips` vector minus the last entry picked at each iteration. It would be simpler and *much* more performant to do (shuffle ordered-ips) Also note that Clojure

Re: Response

2010-07-18 Thread Michael Gardner
On Jul 17, 2010, at 9:46 PM, Isaac Hodes wrote: I did check out your response: it's rather fast on my machine. it's not really functional, though, as you use the `let` macro as a way of procedurally executing a lot of functions. This isn't bad at all, but you're not composing functions.

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread Michael Gardner
I'm assuming the StackOverflow link you refer to is http://stackoverflow.com/questions/3259825/trouble-with-lazy-convolution-fn-in-clojure. I would think about the problem this way: to compute the value at index i in the output list, you multiply together each pair of values in the input lists

Re: Response

2010-07-17 Thread Michael Gardner
On Jul 17, 2010, at 3:43 PM, Isaac Hodes wrote: It's just a shame, it seems to me, that there is such a nice way to represent the procedure in Python or even C, yet Clojure (or any Lisp really) struggles to idiomatically answer this question of convolution. No, it's pretty easy to do

Re: DSL with a grammar

2010-07-08 Thread Michael Gardner
On Jul 8, 2010, at 1:52 PM, Nicolas Oury wrote: I am trying to write a small Domain Specific Language using macro, and I want the syntax of the args of the macro to be somehow parsed and transformed. So, I have two questions: - Does anybody else does that? (except the infix calculus) Is

Re: DSL with a grammar

2010-07-08 Thread Michael Gardner
On Jul 8, 2010, at 2:34 PM, Nicolas Oury wrote: Sorry, that's why I had quote around my parse. I meant, use clojure reader to take a sequence in a macro and then parse it for my own DSL. So I shouldn't need any help from the reader (even if having some metas with line and character

Re: Idiomatic Clojure namespace names

2010-07-07 Thread Michael Gardner
On Jul 7, 2010, at 8:53 PM, j-g-faustus wrote: The disadvantage is of course that you end up with names like org.apache.http.client.params.ClientPNames/ CONNECTION_MANAGER_FACTORY_CLASS_NAME which gets old really quick if you have to type it a lot :) Why would you ever type that more than

Re: -- macro proposal

2010-07-06 Thread Michael Gardner
On Jul 6, 2010, at 3:16 PM, Greg wrote: Have you checked for those? No, sorry, I think that's a rather unreasonable request. I'm not going to spend hours sifting through the core and contrib just to jerk out examples for you. I'd rather use logic and reason to make my case. It's not

Re: Clojure / Common Lisp Question

2010-06-26 Thread Michael Gardner
On Jun 26, 2010, at 12:37 AM, rob levy wrote: Rich Hickey's insightful videos have caused me to stop writing loops whenever possible. For me this is the same level of thinking-change that happened when I moved to using Structured Programming rather than GOTO (in Fortran). Rich needs to write

Re: cond formatting

2010-06-22 Thread Michael Gardner
On Jun 22, 2010, at 3:27 PM, cageface wrote: In this case it takes some visual parsing to see what the predicates and results are and if you break them up onto individual lines you have to count evens to figure out what the results are. The extra level of indentation in the CL case makes it a

Re: cond formatting

2010-06-22 Thread Michael Gardner
On Jun 22, 2010, at 3:55 PM, cageface wrote: This looks nice but requires more hand-indenting, right? I really like being able to select a block in emacs and hit indent-region and get predictably tidy code. (The failure of emacs to do this 100% with scala code is a pet peeve). Can't help you

Re: Hash-map destructuring

2010-06-16 Thread Michael Gardner
On Jun 16, 2010, at 7:07 PM, ataggart wrote: There's a disconnect between the function definition and the datastructures used by the caller. Either fix the data structure: (def args [:bar 2 :baz [:quux]]) then use apply Or change the function definition to take a map: (defn foo [x

Re: review the clojure.string code

2010-06-03 Thread Michael Gardner
On Jun 3, 2010, at 2:31 AM, Laurent PETIT wrote: * why ltrim / rtrim , but upper-case / lower-case ? Why not ltrim / rtrim + ucase / lcase , or left-trim right-trim + upper-case / lower-case ? Will left-trim/right-trim be so often used that they must be shortened to ltrim/rtrim

Re: (apply interleave [[1 2]])

2010-05-29 Thread Michael Gardner
On May 29, 2010, at 5:07 AM, Paul Hobbs wrote: What code would this make simpler? Are you constantly having to check this special case? If not, I don't see a reason to include it. I haven't run across this particular issue, but I have many times written code that may end up calling a

Re: Newbie question about vector performance

2010-05-28 Thread Michael Gardner
On May 28, 2010, at 8:47 AM, Rubén Béjar wrote: I would thank a lot any hint, suggestion, comment, or whatever... :-) As a style issue I'd suggest using inc, dec, neg?, pos?, and zero? instead of the various (+ x 1), ( x 0), etc. in your code. This actually seems to improve performance a bit

Re: Elegant way to replace a few words in string

2010-05-28 Thread Michael Gardner
On May 28, 2010, at 12:42 PM, Laurent PETIT wrote: The rule should really always be: no warning at all (with *warn-on-reflection* set to true, of course). I strongly disagree. Why should you care about those sorts of warnings unless you've already identified a bottleneck that needs

Re: promoting contrib.string to clojure, feedback requested

2010-05-27 Thread Michael Gardner
On May 27, 2010, at 2:45 AM, Stefan Kamphausen wrote: Hi, On May 26, 11:00 pm, Stuart Halloway stuart.hallo...@gmail.com wrote: The people have spoken! The trims have it! sorry, I'm a little late. However, to me it is not clear what the trim functions shall do. If they become a

Re: Elegant way of expressing this in Clojure?

2010-05-27 Thread Michael Gardner
On May 27, 2010, at 1:11 PM, CuppoJava wrote: Hi, I have a little snippet of Java code that I want to express in Clojure. But all my attempts thus far have been much more unreadable than the equivalent Java. Some help would be greatly appreciated. It might help if we knew the purpose of your

Re: Announcing Clojure/core

2010-05-25 Thread Michael Gardner
On May 25, 2010, at 7:30 AM, Rich Hickey wrote: Note: clojure.com will now resolve to the Clojure/core site. Come check it out! Does this mean Clojure itself is to be directly associated with Relevance, Inc.? -- You received this message because you are subscribed to the Google Groups

Dividing list by predicate

2010-05-23 Thread Michael Gardner
I need to use a predicate to divide one list into two, one containing all values for which the predicate is true, and the other with all remaining values. I can do this easily by filtering twice, once with the predicate and once with its complement, but is there some core or contrib function

Re: Dividing list by predicate

2010-05-23 Thread Michael Gardner
Thanks for the tips, guys. I'll go with seq-utils/separate, as I don't really need the extra performance; it was more of an aesthetic thing. Still, it seems like separate should be written to evaluate its predicate only once for each item in the list. -- You received this message because you

<    1   2   3   >