Re: rules for writing macros

2009-02-15 Thread Stuart Halloway
Does this clarify the point I was making? When writing macros, you cannot dynamically build one of the syntactic sugar forms. For example, you cannot write a macro that expands cls and member into (cls/member): (defmacro call-static [cls member] `(~cls/~member)) -

Re: Fully lazy sequences are coming - feedback wanted!

2009-02-15 Thread Stuart Halloway
I prefer first/rest/next. Because of where the book is in the production cycle, it will be difficult for me to change the prose. But if this gets decided (and clojure-contrib updated) in the next week or two I think I can get the book printed with the changes incorporated throughout.

Re: Fully lazy sequences are coming - feedback wanted!

2009-02-16 Thread Stuart Halloway
Thanks Rich! :-) , 2009, at 11:25 AM, David Nolen wrote: butlast, doall, dorun, doseq, dosync, dotimes, doto, fnseq, gensym, macroexpand, macroexpand-1, mapcat, nthrest -1 Because they are similar to other Lisps I assume. The same reason for println vs print-line. Changing these are

Re: Fully lazy sequences are coming - feedback wanted!

2009-02-16 Thread Stuart Halloway
I agree with Walt, and there is no need to pressure the Prags, we are on it! :-) That said, it would be *very* helpful to me if we could get the lazyness thing settled this week... Stuart Regarding Programming Clojure: I think that placing the burden of book vs actual incompatibility

terminology question re: binding

2009-02-16 Thread Stuart Halloway
David Sletten sent me this erratum: At the beginning of section 2.4 we have The symbol user/foo refers to a var which is bound to the value 10. Under the next subsection Bindings we have Vars are bound to names, but there are other kinds of bindings as well. The Common Lisp standard

Re: how to learn clojure ?

2009-02-19 Thread Stuart Halloway
Thanks for the kind words, David. I hope many people will like Programming Clojure and find it useful. Clojure has a *ton* of goodness in it. I think many of the chapters in Programming Clojure book could usefully be followed with an entire book. Here is a partial list of recommendations

better syntax highlighting for Clojure

2009-02-23 Thread Stuart Halloway
I have improved the clojure.js bits [1]. Various small changes, but the big issue was to discontinue using \b for end of word, which does not work well with names-like-this. Feedback or additional improvements welcome. Stuart [1]

challenge: best fibo implementation under the new laziness?

2009-02-23 Thread Stuart Halloway
I have updated the sample source from the book (http://tinyurl.com/clojure-samples ) to the new laziness. Along the way, I replaced the lazy-cons based implementation of the fibonacci numbers with this: (defn fibo ([] (concat [0 1] (fibo 0 1))) ([a b] (let [n (+ a b)]

Re: better syntax highlighting for Clojure

2009-02-23 Thread Stuart Halloway
to stick with this coloring scheme. Thanks in advance, -- Laurent 2009/2/23 Stuart Halloway stuart.hallo...@gmail.com I have improved the clojure.js bits [1]. Various small changes, but the big issue was to discontinue using \b for end of word, which does not work well with names-like

Re: challenge: best fibo implementation under the new laziness?

2009-02-23 Thread Stuart Halloway
Beautiful-thanks. Using a good old sequence of vectors: (defn fibo [] (map first (iterate (fn [[a b]] [b (+ a b)]) [0 1]))) Christophe Stuart Halloway a écrit : I have updated the sample source from the book (http://tinyurl.com/clojure-samples ) to the new laziness. Along the way, I

Re: retrieving argument :tag metadata

2009-02-24 Thread Stuart Halloway
Cool, thanks. On Tue, Feb 24, 2009 at 11:59 AM, Stuart Halloway stuart.hallo...@gmail.com wrote: Is there a way to programmatically retrieve the :tag of an argument? The var metadata will return the tag of a return value... The :arglists metadata attached to the Var by defn appear

new laziness: terminology help

2009-02-24 Thread Stuart Halloway
I am wrestling the sequences chapter of the book into conformance with the new laziness, and I am finding it tricky to infer accurate definitions of the words sequence, seq (noun), seq (function), and ISeq from the variety of extant documentation, code, email chats, and IRC logs. I would

Re: new laziness: terminology help

2009-02-25 Thread Stuart Halloway
I like this, and I am OK with seq (function) being the oddball that returns a seq or nil. Rich, this is what Beta 8 of the book currently says -- ok with you? Stuart I believe that one of Rich's stated purposes with the latest revision of the laziness branch was to get rid of some of the

Re: new laziness: terminology help

2009-02-25 Thread Stuart Halloway
All sequences are represented by (chains of) (possibly lazy) seqs, of type ISeq. So yes, sequence/seq(noun)/ISeq are technically synonyms, but [1] Great. [1] In practice, a sequence fn (like map et al) may return an empty sequence, while seq/next will instead return a (forced) thing with

Re: class of java array

2009-03-09 Thread Stuart Halloway
Hi Adrian, Here is one way: (- (into-array [one two]) (class) (.getComponentType)) - java.lang.String (- (to-array [one two]) (class) (.getComponentType)) - java.lang.Object Stu I have a java object that either contains a String or an array of Strings. (instance? java.lang.String

Re: New release 20090320

2009-03-20 Thread Stuart Halloway
I am updating some of the examples in the FP chapter to use letfn, and the book is already up-to-date on fully lazy seqs. Any other new features jump out as must discuss in book? Stu New release 20090320 - http://clojure.googlecode.com/files/clojure_20090320.zip Incorporates all the

Re: Clojure + Java compilation and IntelliJ IDEA plugin

2009-03-25 Thread Stuart Halloway
Hi Ilya, I would like to be able to demo the sample code from the book in IDEA. Here are a few things I am seeing so far: (1) When I set a breakpoint, I get a warning icon that says no executable code found at... but the breakpoint does in fact seem to work. (2) The variable window

Book erratum (was: Clojure + Java compilation and IntelliJ IDEA plugin)

2009-03-26 Thread Stuart Halloway
by compilation from command line, so I'm afraid some- thing wrong either with current clojure-contrib version or this example. Kind regards, Ilya 2009/3/25 Stuart Halloway stuart.hallo...@gmail.com Hi Ilya, I would like to be able to demo the sample code from the book in IDEA. Here

questions about clojure.contrib.error-kit

2009-03-27 Thread Stuart Halloway
(1) Is there any reasonable way to attach handlers to lazy sequences such that the handlers will still be in place outside the original handler scope, when the sequence is finally evaluated? (It is not obvious to me how to do this without making the handler system part of the language

Re: Quick slime/emacs questions

2009-03-29 Thread Stuart Halloway
describe-key (usually C-h k) followed by a key will tell you what a key is currently bound to. On my setup C-x C-b is bound to ido-switch-buffer--it is not immediately obvious how to make it pop the buffer list in the current window. You might find What You Can Learn From ido.el

Re: Java interoperability and Clojure

2009-04-02 Thread Stuart Halloway
Hi Geoff, You should have no trouble using setAccessible. There are several demos of this in the source code for the book [1] that use setAccessible to check private fields in a unit test. (See lancet/test/ step-2-complete.clj [2], for instance). Hope this helps, Stu [1]

Re: Every function is a thread in Clojure?

2009-04-03 Thread Stuart Halloway
No threads: (ancestors (class (fn[]))) - #{java.lang.Runnable java.io.Serializable clojure.lang.AFn clojure.lang.Obj java.lang.Object clojure.lang.Fn clojure.lang.AFunction clojure.lang.IObj clojure.lang.IFn java.util.concurrent.Callable clojure.lang.IMeta java.util.Comparator} What you

proposed new contrib: java-utils

2009-04-03 Thread Stuart Halloway
Hi all, I would like to pull together functions that help with Java interop and place them in a new contrib: java-utils. Some examples: (1) Pull out SteveG's properties fn, currently hidden in the internals of clojure.contrib.sql (2) reflective helpers for accessing private and protected

DISCUSS: clojure.contrib.java-utils/file

2009-04-05 Thread Stuart Halloway
Never worry about foo vs. (File. foo) again! (doc file) - clojure.contrib.java-utils/file ([arg] [parent child] [parent child more]) Returns a java.io.File from string or file args. Notes: (1) You will need to build contrib from source to see this. (2) This

DISCUSS: clojure.contrib.java-utils/the-str

2009-04-05 Thread Stuart Halloway
Never worry about the distinction between symbols, keywords, and strings when working with Java APIs that know only strings! (doc the-str) - clojure.contrib.java-utils/the-str ([x]) Returns the name or string representation of x Notes: (1) You will need to build

DISCUSS: clojure.contrib.java-utils/with-system-properties

2009-04-05 Thread Stuart Halloway
Don't work with the yucky properties API, just install a map of properties for the duration of a block! - clojure.contrib.java-utils/with-system-properties ([settings body]) Macro setting = property-name value Sets the system properties

Re: DISCUSS: clojure.contrib.java-utils/the-str

2009-04-05 Thread Stuart Halloway
I noticed the indentation changed for the ns form with your changes to sql.clj sql/internal.clj . Is the indentation you used produced by some tool? --Steve No -- the intended change was from multiple :use forms to one :use form with multiple namespaces. Any indentation changes

Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-05 Thread Stuart Halloway
Doh! Missed that. The duck-streams and java-utils versions of file have overlapping but disjoint functionality. Other-Stuart, I can take a look at combining these, or we can just leave them separate for now. --Stuart On Apr 5, 5:07 pm, Stuart Halloway stuart.hallo...@gmail.com wrote

Re: proposed new contrib: java-utils

2009-04-05 Thread Stuart Halloway
I'd also like to get your latest thinking on your suggestions from some time ago about clojure.contrib.lazy-seqs. If they can be rewritten as you suggested as functions that return a new sequence rather than as def'd sequences, that's strictly more powerful and would be an

Re: DISCUSS: clojure.contrib.java-utils/file

2009-04-05 Thread Stuart Halloway
Good summary. Let's keep them separate until we feel pain. - Stuart Halloway They work rather differently. duck-streams/file treats all arguments as strings, so (file foo bar) = File foobar I wrote it that way because I often want to construct a file name like (file base . extension

lazy seqs (was Re: proposed new contrib: java-utils)

2009-04-06 Thread Stuart Halloway
r652 is a breaking change to contrib. (powers-of-2) and (fibs) are now functions and do not hold their heads. primes is still a sequence because it needs to hold past values for efficiency. Stuart On Apr 5, 2009, at 4:27 PM, Stuart Halloway wrote: At quick glance it looks to me that all

reading properties file: does this helper already exist?

2009-04-08 Thread Stuart Halloway
Does something like this (or better) already exist in Clojure? If not I will add it to java-utils. Thanks, Stu (defn read-properties [f] (into {} (let [props (Properties.)] (.load props (FileInputStream. f)) props)))

Re: reading properties file: does this helper already exist?

2009-04-08 Thread Stuart Halloway
I don't like that if you treat properties as a seq you get Java Hashtable$Entry objects, instead of a vector as you would with a map, hence my into {}. But maybe it is a silly quibble since destructuring works fine with either. Stuart Can't you just write: (.load (Properties.)

Java 6 dependency in clojure-contrib ok?

2009-04-08 Thread Stuart Halloway
Perry's proposed props functions (http://groups.google.com/group/clojure/browse_thread/thread/c8ec751b8e66b019/d56ed1200aa95bca ) uses some Java 6 methods. Is it ok for me to add such things to contrib, or are we maintaining Java 5 compatibility? Stu

Re: DISCUSS: clojure.contrib.java-utils/the-str

2009-04-08 Thread Stuart Halloway
Changed to as-str (r654). Stu In Compojure, I called this str*, but I think I like as-str a little better. - James On Apr 5, 5:19 pm, Stuart Halloway stuart.hallo...@gmail.com wrote: Never worry about the distinction between symbols, keywords, and strings when working with Java APIs

Re: clojure dependency management and build

2009-04-08 Thread Stuart Halloway
Lancet is more at proof-of-concept stage than ready for heavy lifting -- I am using a mix of Ant and Rake on my own Clojure stuff. :-) I am happy to contribute to solving some of these issues but don't have time to lead the effort. Stuart When you are building something real with Clojure

getting code coverage into clojure-contrib builds?

2009-04-09 Thread Stuart Halloway
I spent a few minutes this morning trying to get an emma coverage report over contrib. Short answer is that it doesn't work -- emma throws an exception while instrumenting the code (see attached console.txt). I will go and bug the emma folks, but first wanted to ask here if there is any

Re: getting code coverage into clojure-contrib builds?

2009-04-09 Thread Stuart Halloway
OK, I'll try Cobertura next. There is a reason my Java knowledge sounds about 5 years old ... :-) Stu Stuart Halloway wrote: I will go and bug the emma folks, but first wanted to ask here if there is any specific reason that Clojure-generated bytecode might surprise emma? I might

OK, cobertura runs, but...

2009-04-09 Thread Stuart Halloway
I have Cobertura running and producing reports against contrib, sort-of. Problems: (1) AFAICT, cobertura *insists* in trying to parse the source code as Java to do cyclomatic complexity analysis. This blows up, of course. (2) The red/green coloring of the lines does not match what I know is

Re: DISCUSS: tests that read and write files

2009-04-09 Thread Stuart Halloway
. (defmacro with-tmp-properties-file [ body] `(binding [*tmp-properties-file* (File/createTempFile temp .properties)] (spit *tmp-properties-file* contents of the test file) ~...@body (.delete *tmp-properties-file*))) -Stuart Sierra On Apr 9, 1:54 pm, Stuart Halloway stuart.hallo

Re: set-system-properties

2009-04-09 Thread Stuart Halloway
Yes to almost all of this (r662). I am not totally comfortable with the false/false conversion. Stu Hi Stuart H! Comment on: (defn set-system-properties [settings] Set some system properties. Nil clears a property. (doseq [[name val] settings] (if val (System/setProperty

Re: The Path to 1.0

2009-04-17 Thread Stuart Halloway
I would love to see 1.0, and the sooner the better. At Relevance we are doing real work in Clojure today. As for wish list I would love to see improvements to the development process: * move from svn to git * move regression tests from contrib into clojure itself But neither of these need

Re: str-utils change proposal, round 2

2009-05-14 Thread Stuart Halloway
FYI: I am working on an open-source CSV parser in Clojure. Splitting on delimiters is rarely enough in my experience. Stu would you consider adding support of a split by passing a delimiter? since parsing csv/tsv is a pretty common task. I know it can be done by using re-split. but it

monad tutorial question

2009-05-18 Thread Stuart Halloway
When working through Part 3 of the monad tutorial [1], I am seeing the following behavior for fib-trace: (fib-trace 3) = [2 [[[1 1] [[[0 0] []] [[2 1] [[[1 1] [ According to the tutorial, it should be: (fib-trace 3) = [2 [[1 1] [0 0] [2 1] [1 1]]] Am I doing something wrong?

is there a sibling of fmap that maps keys instead of values?

2009-05-30 Thread Stuart Halloway
clojure.contrib.generic.functor.fmap will return a map with values updated by a function. What if I wany *keys* updated by a function? Does this exist yet? If not, what should I name it for inclusion in contrib? Stu --~--~-~--~~~---~--~~ You received this

Re: is there a sibling of fmap that maps keys instead of values?

2009-05-30 Thread Stuart Halloway
given the ambiguity that names like mapkeys might be misleading. Other suggestions? Stu On 30.05.2009, at 17:11, Stuart Halloway wrote: clojure.contrib.generic.functor.fmap will return a map with values updated by a function. What if I wany *keys* updated by a function? Does this exist yet

Re: Good examples of defmulti polymorphism

2009-06-02 Thread Stuart Halloway
Hi Glen, (1) Real-world example: I use polymorphism on the types of two different arguments to define implicit conversions: (defmulti coerce (fn [dest-class src-inst] [dest-class (class src-inst)])) (defmethod coerce [java.io.File String] [_ str] (java.io.File. str)) (defmethod

Re: You know you've been writing too much Clojure when...

2009-06-02 Thread Stuart Halloway
People keep looking at me funny when I point out variables as code smells during code review... Stu Same here with the commas. Since I've been neck deep in Clojure, I've been pathologically forgetting to add them with other languages. On Jun 2, 10:06 am, Shawn Hoover

feature request: docstring for defstruct

2009-06-02 Thread Stuart Halloway
I would like to see defstruct take an optional docstring. Would such a patch be welcome? Stu --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: filter on sequence

2009-06-02 Thread Stuart Halloway
Ditto what everyone else said, plus let's get rid of the duplicated call to Math/log by splitting the iterate into an iterate + a map: (take-while (fn [[_ second]] ( second 10)) (map (fn [x] [x (/ x (Math/log x))]) (iterate #(* % 2) 2))) Stu On 02.06.2009, at 17:35, Wilson

Re: unit testing private methods?

2009-06-02 Thread Stuart Halloway
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

Re: unit testing private methods?

2009-06-03 Thread Stuart Halloway
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

Re: Spring and Clojure

2009-06-04 Thread Stuart Halloway
I think Clojure addresses (at the language level, and better) all the issues that Spring addresses. So in the long run Spring is unnecessary in a Clojure world. But in the short run you have the codebase you have, and the skills that you have. So if it makes sense, do it. Stu At this

Re: [ANN] test-expect functional mocking/expectation library

2009-06-10 Thread Stuart Halloway
Hi Matt, I would like to move this to contrib, if you will sign the CA. I'll be moving my simple binding-based stubs to use this and will send along suggestions if I have any. Thanks for writing this! Stu P.S. Apologies if variants of this message show up twice. Mail client wonkiness...

Re: [ANN] test-expect functional mocking/expectation library

2009-06-10 Thread Stuart Halloway
Hi Matt, I would definitely like to see test-expect added to contrib. If you will sign the CA I will move it there. I have a bunch of existing tests that are simply using binding to do cheap stubbing, and will be converting those tests to test-expect over the next several days. Thanks for

(re)setting a function globally

2009-06-10 Thread Stuart Halloway
Matt Clark's test-expect library includes two versions of a report- problem function: a standalone version, and another that integrates with test-is. The comments suggest two ways to active the test-is version: wrapping calls to expect in a binding, and interning the specialized version of

Re: (re)setting a function globally

2009-06-11 Thread Stuart Halloway
Matt is signing the CA and I will be adding test-expect to contrib. Stu Can I help from the test-is side? Could test-expect be added to clojure-contrib? -Stuart On Jun 10, 1:36 pm, Matt Clark matt.clar...@gmail.com wrote: Thanks for these ideas, I will give them a try tonight and

Re: (re)setting a function globally

2009-06-12 Thread Stuart Halloway
global function changes. Go figure I come up with this after reading the entire clojure modules thread and starting a solution using deftemplate :) - Matt On Jun 11, 8:36 am, Stuart Halloway stuart.hallo...@gmail.com wrote: Matt is signing the CA and I will be adding test-expect to contrib

Re: will clojure evolve to be able to do systems programming?

2009-06-16 Thread Stuart Halloway
Would be interesting to combine Clojure with NailGun for utility scripting... http://sourceforge.net/projects/nailgun/ Due to the startup cost of the JVM, Clojure and Java probably aren't the best choices for tiny five to ten line utility scripts. That being said, Clojure works well for

binding at the REPL

2009-06-16 Thread Stuart Halloway
This surprised me. What part of my mental model needs to be adjusted? :-) user= (def dozen 12) #'user/dozen user= (binding [dozen 13] dozen) 12 ; hunh? user= (#(binding [dozen 13] dozen)) 13 --~--~-~--~~~---~--~~ You received this message because you are

Re: binding at the REPL

2009-06-16 Thread Stuart Halloway
[dozen 13] dozen) 13 user (#(binding [dozen 13] dozen)) 13 user -the other Stuart On Jun 16, 2:08 pm, Stuart Halloway stuart.hallo...@gmail.com wrote: This surprised me. What part of my mental model needs to be adjusted? :-) user= (def dozen 12) #'user/dozen user= (binding [dozen 13

Re: clojure.contrib.*

2009-06-19 Thread Stuart Halloway
Hi Justin, The easiest solution is to download the sample code for the book from [1] (this is referenced in the Preface under Downloading Sample Code). The sample code includes everything you need: clojure, clojure- contrib, and the book samples, plus launch scripts that get all the

ANN: libraries promoted from contrib to clojure

2009-06-25 Thread Stuart Halloway
If you are following the github head of the Clojure and contrib projects, you will see that several libraries have moved from contrib into Clojure: * clojure.contrib.test-is becomes clojure.test * clojure.contrib.stacktrace becomes clojure.stacktrace * clojure.contrib.template becomes

executing tasks on a schedule

2009-06-26 Thread Stuart Halloway
I am working on a Clojure project that is becoming more and more schedule-oriented. So far I have been using Clojure's native concurrency constructs, but I am becoming tempted to use Java's concurrency primitives to get interruptability, etc. -- or maybe even wrap a Java library like

porting Practical Common Lisp examples to Clojure

2008-09-16 Thread Stuart Halloway
Hi all, I am porting [1] the Practical Common Lisp examples [2] to Clojure, and blogging notes [3] as I go. Feedback of all kinds is most welcome, and I hope that some folks here will find this useful. Cheers, Stuart [1] http://github.com/stuarthalloway/practical-cl-clojure [2]

Re: (seq? abc)

2008-10-02 Thread Stuart Halloway
Right. So, should sort work? user= (sort bca) java.lang.IncompatibleClassChangeError: Class java.lang.String does not implement the requested interface java.util.Collection Stuart (seq? ...) tests for whether or not the argument is a sequence, i.e. an instance of ISeq. (seq ...) works

Re: (seq? abc)

2008-10-02 Thread Stuart Halloway
could sort this way: user (apply str (sort (seq bac))) abc On Oct 2, 11:58 am, Stuart Halloway [EMAIL PROTECTED] wrote: Right. So, should sort work? user= (sort bca) java.lang.IncompatibleClassChangeError: Class java.lang.String does not implement the requested interface java.util.Collection

class weirdness

2008-10-03 Thread Stuart Halloway
Does this make sense? user= (let [x Integer] (.getName x)) java.lang.Integer user= (.getName Integer) java.lang.NoSuchFieldException: getName --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post

safe navigation operator

2008-10-03 Thread Stuart Halloway
Groovy has a safe navigation operator. Yes, this probably enables Law of Demeter violations, but it is darn useful when you are dealing with existing Java APIs that required lots.of.dotted.notation. I would like to have this in Clojure. Anybody else like it? (defmacro ?. like .. but

Re: class weirdness

2008-10-03 Thread Stuart Halloway
Thanks Stephen, Chouser, and Rich. Understanding the historical reason that (. SomeClass method) doesn't work, I would be in favor of the deprecation Rich mentioned, leading to (. SomeClass method) being able to work in the future. Cheers, Stuart

Re: safe navigation operator

2008-10-06 Thread Stuart Halloway
Yes, that's better. Glad you like the idea. Does anybody not named Stuart also want to see this added to Clojure? ;-) Stuart On Oct 3, 3:13 pm, Stuart Halloway [EMAIL PROTECTED] wrote: (defmacro ?. like .. but drops out on null object ([x form] `(. ~x ~form)) ([x form

followup on struct inheritance

2008-10-07 Thread Stuart Halloway
This is a tangent from Brian's question about struct inheritance: While I am not sure that I want struct inheritance, it seems unnecessarily hard to write the macro for it. Structs are not first class citizens, in that you cannot reflect against them. I want to ask: (defstruct person

Re: help a journalist: why Clojure?

2008-10-10 Thread Stuart Halloway
programmed by real humans. I am nominally a pointy-headed boss and I am already convinced. Stuart Halloway CEO Relevance, Inc. I'm doing an article for CIO.com on 5 [or whatever] languages that ought to be on your [IT Manager's] radar, and I'd like to include Clojure. I'm looking for a short statement

ANN: Clojure book

2008-10-10 Thread Stuart Halloway
Hi all, I am working on what I hope will become the first Clojure book in print: http://www.pragprog.com/titles/shcloj/programming-clojure If you are interested in being a reviewer please let me know off-list. Regards, Stuart --~--~-~--~~~---~--~~ You received

Re: Dealing with keyword-keyed maps in Java land

2008-10-13 Thread Stuart Halloway
Hi Paul, I think that I would rather see things remain explicit, i.e. if you need to interoperate with Java you convert manually before throwing the map over. In the Rails world they tried to solve a similar problem (string vs. symbol keys) by wrappering Hash to be indifferent between

Re: recur question

2008-10-13 Thread Stuart Halloway
Hi Michael, The multiplication by n comes after the recur. Cheers, Stuart Giving the factorial function as: (def factorial (fn [n] (cond (= n 1) ( n 1) (* n (recur (dec n)) the compiler complains Can only recur from tail position. Isn't really the recur in

are pr friends correct for regexps?

2008-10-13 Thread Stuart Halloway
(prn #\\w+) - \w+ I was expecting something the reader could handle... Cheers, Stuart --~--~-~--~~~---~--~~ 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

Re: Nested Multimethods

2008-10-13 Thread Stuart Halloway
Hi Patrick, How about: (defmulti length (fn [x] (if (= :stateMachine (:class x)) (:state x) (:class x (defmethod length :yardstick [x] 36) (defmethod length :walking [x] short) (defmethod length :running [x] long) user= (length

Re: are pr friends correct for regexps?

2008-10-15 Thread Stuart Halloway
Yep, I was on an older build. Nevermind. :-) On Mon, Oct 13, 2008 at 9:06 AM, Stuart Halloway [EMAIL PROTECTED] wrote: (prn #\\w+) - \w+ Works for me, SVN 1067: user= #\\w+ #\\w+ user= (prn #\\w+) #\\w+ nil --Chouser --~--~-~--~~~---~--~~ You

Re: max

2008-10-16 Thread Stuart Halloway
function so we could do something like (apply max (compact coll))? Paul On Thu, Oct 16, 2008 at 3:22 PM, Stuart Halloway [EMAIL PROTECTED] wrote: Hi Paul, I think the current behavior is reasonable. It is consistent across all the numeric functions. And if the nil got into max by being

Re: max

2008-10-16 Thread Stuart Halloway
Just to add to the confusion: I want compact to remove nil and false. :-) Perhaps another nudge for compact is that it's not as simple as (filter identity coll), to wit: user (filter identity [1 2 nil false 4]) (1 2 4) user (filter #(not (nil? %)) [1 2 nil false 4]) (1 2 false 4)

should (test ...) resolve symbols?

2008-10-17 Thread Stuart Halloway
I was surprised to find that test does not resolve symbols into Vars: ; don't do this (test 'foo) - :no-test ; do this (test #'foo) - :ok Is there a conceptual reason that test should not resolve symbols into Vars? --~--~-~--~~~---~--~~ You received this

Re: Beginners (and idiomatic Clojure)

2008-10-20 Thread Stuart Halloway
Hi Krukow, The quality will definitely be higher than this: http://blog.thinkrelevance.com/2008/9/16/pcl-clojure Same author, more time. :-) Stuart On Oct 20, 12:30 am, Paul Barry [EMAIL PROTECTED] wrote: Krukow, I agree, it would help to have a resource for learning Clojure. For now,

destructuring/multimethods vs. pattern matching

2008-10-20 Thread Stuart Halloway
Hi all, I seem to recall Rich saying I like the destructuring part of pattern matching. In my efforts to appreciate that statement, I am playing around with porting simple Haskell examples to Clojure, trying to use destructuring (and multimethods) where the Haskell does pattern matches.

Re: destructuring/multimethods vs. pattern matching

2008-10-20 Thread Stuart Halloway
. The English connotations of the former are too imperative for me, but I don't know a better word for it. Stuart On Oct 20, 2008, at 11:16 AM, Stuart Halloway wrote: Hi all, I seem to recall Rich saying I like the destructuring part of pattern matching. In my efforts to appreciate that statement

Re: destructuring/multimethods vs. pattern matching

2008-10-20 Thread Stuart Halloway
: (defn qsort ([] []) ([x xs] (concat (apply qsort (filter #( % x) xs)) (cons x (apply qsort (filter #(= % x) xs)) user (qsort 1234 56 789 0) (0 56 789 1234) Kind regards, achim Am 20.10.2008 um 17:16 schrieb Stuart Halloway

Re: destructuring/multimethods vs. pattern matching

2008-10-20 Thread Stuart Halloway
What are your concerns re: apply? Are there performance issues? Or is it not being able to call qsort on a collection directly? I just want the code to look pretty, no deeper concerns than that. :-) --~--~-~--~~~---~--~~ You received this message because you

Re: Beginners (and idiomatic Clojure)

2008-10-21 Thread Stuart Halloway
knowledge. We also have a pretty decent system for estimation, so we should get some real metrics of relative effort. Cheers, Stuart On Oct 20, 2:02 pm, Stuart Halloway [EMAIL PROTECTED] wrote: Hi Krukow, The quality will definitely be higher than this: http://blog.thinkrelevance.com/2008/9/16

Re: unit tests

2008-10-21 Thread Stuart Halloway
Hi Tim, Example below. This is from a demo porting Java code to Clojure, the original Java code is in the Apache Commons [1]. Note that test does not resolve symbols: ; don't do this (test 'index-of-any) - :no-test ; do this (test #'index-of-any) - :ok Cheers, Stuart [1]

Re: Testing Clojure (was Re: Bug? Strange set equality (r1075))

2008-10-21 Thread Stuart Halloway
for arbitrary--is there a prettier syntax for ignoring the argument after using it for dispatch?) Cheers, Stuart ;;; clojure_check.clj: quick check framework for Clojure ;; Copyright (c) 2008 Stuart Halloway. All rights reserved. ;; Inspired by Scalacheck et al (http://code.google.com/p

Re: unit tests

2008-10-21 Thread Stuart Halloway
Hi Tim, You have run afoul of the automagical conversion between Lispy - and Javaish _: ' sad (use 'clojure.contrib.test_is) java.lang.Exception: namespace 'clojure.contrib.test_is' not found after loading '/clojure/contrib/test_is/test_is.clj' (NO_SOURCE_FILE:0 ; happy user= (use

Re: Idiomatic Clojure code?

2008-10-27 Thread Stuart Halloway
Chouser, I think I am missing something here, can you elaborate? By the way, difference is eager, so I'm not sure there's much point in using lazy-cat. :-) I am using lazy-cat *because* difference is eager. Is that mistaken? For example, the first expression below returns immediately, and

troubleshooting classloader problems

2008-10-28 Thread Stuart Halloway
Hi all, When I am troubleshooting classloader problems I find myself wanting to know the list of URLs currently on the classpath. I didn't find this exposed anywhere, so I wrote the functions below. Usage: (take 3 (classpath-url-seq)) -

Re: idiomatic Clojure for agents?

2008-10-28 Thread Stuart Halloway
spring to mind? Stuart P.S. I think that is the second time you have had to tell me to stop using count as a local name. Bad habits die slowly... :-) On Mon, Oct 27, 2008 at 10:06 PM, Stuart Halloway [EMAIL PROTECTED] wrote: The code below implements a Monte Carlo simulation to estimate

Re: idiomatic Clojure for agents?

2008-10-28 Thread Stuart Halloway
am biased toward a map based on Ruby experience. I haven't decided which is more readable. Stuart Hi Stuart, On Mon, Oct 27, 2008 at 7:06 PM, Stuart Halloway [EMAIL PROTECTED] wrote: Hi all, The code below implements a Monte Carlo simulation to estimate the value of pi. It works

Re: idiomatic Clojure for agents?

2008-10-28 Thread Stuart Halloway
interested readers to the literature. This has me wondering: should Clojure's rand and rand-int default to use a thread-bound instance of java.util.Random? Stuart On Oct 27, 7:06 pm, Stuart Halloway [EMAIL PROTECTED] wrote: ; take samples, tracking number that land ; :in circle and :total

commutes do not trigger validate-fn?

2008-10-28 Thread Stuart Halloway
Is this by design? It surprised me, as I expected all transactional updates to be protected by validate-fn. Stuart --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email

Re: Using a Java Debugger with Clojure

2008-10-29 Thread Stuart Halloway
Hi Luc, Do you have any special sauce for Spring/Clojure integration that the community might be interested in? Or is it just so easy that there is nothing to say? :-) Stuart Debugging presently with JSwat and it works fine. We have extensive logging (javalog) and use some trace macros

Re: Documentation string in metadata?

2008-10-29 Thread Stuart Halloway
Axel, The second function definition doesn't have a documentation string, it has a string form in its body. Valid behavior, but potentially confusing. Stuart the metadata for the second function definition doesn't contain the documentation string. I was wondering if this is valid

Re: Ants and agents

2008-10-29 Thread Stuart Halloway
Hi Jim, send-off is never immediate. It schedules a function for execution later. The call to send-off queues execution of the next evaporation, and the code continues on. Agents cannot do more than one thing at once, so the queued evaporation cannot possibly happen while this evaporation

  1   2   3   4   5   6   7   8   >