Re: adding line number while reading a file

2009-01-10 Thread GS
> Next, instead of filter, you probably want doseq. The filter function > filters a collection according to a predicate. The doseq function > applies a function with side effects (such as println) to each item in > a collection. > > (with-open [rdr (reader "executors.clj")] >   (doseq [[line inde

How to create and read from a stream of random characters?

2009-01-11 Thread GS
Hi, For the purposes of testing another function (not discussed here), I wrote a function to generate random strings. This is what I ended up with after some trial and error. (defn generate-data [size maxlength] ; Returns a collection of 'size random strings, each at most 'maxlength chars

Re: How to create and read from a stream of random characters?

2009-01-12 Thread GS
> (defn seq-of-rand-strings [maxlength] >   (repeatedly (fn [] >     (apply str (take (rand-int maxlength) >                      (repeatedly #(char (+ (int \a) (rand-int 26) > > user=> (take 3 (seq-of-rand-strings 10)) > ("kae" "xwuwyp" "xa") Thanks Chouser. I learned some useful and i

Re: Utilities for clojure.contrib?

2009-01-13 Thread GS
On Jan 13, 2:59 pm, Chouser wrote: > > It raises a question, though -- how much functionality should a > function provide to be worth making everyone who reads the code learn > the new vocabulary?  I've written each of these inline when I've > needed them.  Are they better as idioms or functions?

Suggested functions for core: any? none?

2009-01-13 Thread GS
Hi, I searched the archives and saw that this has been raised once before, although it wasn't really a suggestion, didn't raise any real discussion and didn't reach any conclusion. I just think it's worth proposing that a function set that includes every? and not-every? but does not include any?

Re: Utilities for clojure.contrib?

2009-01-13 Thread GS
On Jan 14, 9:13 am, Jason Wolfe wrote: > > One thing worth pointing out is that, if a utility is really useful > many people will independently recreate it with slightly different > names and functionality, and use it in their code.  It seems that this > results in code that's much more difficult

Re: Clojure now running in production

2009-01-13 Thread GS
On Jan 14, 9:07 am, Luc Prefontaine wrote: > > As this is a commercial project, I imagine you are quite limited in > > what you can tell us, but I'd love to hear about the issues you faced > > during development. > > Mostly integration problems with the work flow in the radiology system. > [..

Re: By Example - another Clojure introduction wiki page

2009-01-13 Thread GS
On Jan 14, 1:12 am, Timothy Pratley wrote: > I've written small wiki article which dives right into the look and > meaning of common Clojure constructs with examples. Personally I find > I learn best by examples and when starting out they were hard to find, > whereas formal descriptions were ther

Re: Suggested functions for core: any? none?

2009-01-13 Thread GS
On Jan 14, 2:27 pm, "Mark Engelberg" wrote: > I also find the choice of some/not-any? as opposites to be hard to > remember.  I'd rather it be some/not-some? or any/not-any? I think some and any? both have their place. (let [foo (some prime? numseq)] (do something with foo)) (if (any? com

Re: Utilities for clojure.contrib?

2009-01-13 Thread GS
> > > (defn chunk "Lazily break s into chunks of length n (or less, for the > > > final chunk)." > > >  [n s] > > >  (when (seq s) > > >    (lazy-cons (take n s) > > >               (chunk n (drop n s) > > > Should that "seq" be "seq?".  If not, why not? On Jan 13, 7:17 pm, "Nick Vogel" wrot

Re: Utilities for clojure.contrib?

2009-01-14 Thread GS
> > So, either: > > >  1. My experiment was wrong, and seq? is not a valid stand-in > >     for seq in the above code. > > Right on the first try!  :-) Well, that's something :) > user=> (seq-chunk 2 [1 2 3 4 5]) > ((1 2) (3 4) (5)) > user=> (seq?-chunk 2 [1 2 3 4 5]) > nil > > This is because a

clojure-contrib basic questions

2009-02-02 Thread GS
Hi, There are three "homes" for clojure-contrib that I've seen referred to on the web (each in more than one place): Google Code Sourceforge git://github.com/kevinoneill/clojure-contrib.git Now I think I've got a pretty good idea which one is the correct one, but how did this situation co

Re: rules for writing macros

2009-02-03 Thread GS
On Feb 4, 12:01 am, Mark Volkmann wrote: > Are the following statements true? They aren't discussed > athttp://clojure.org/macros, but I think they are true. > > Macros cannot call other macros during their evaluation, but they can > expand to code that calls macros. I don't know, but I'll br

Re: how to emulate lisp's labels functionality?

2009-02-14 Thread GS
On Feb 14, 12:21 pm, Chouser wrote: > > (defn count-instances [obj lsts] > >   (let [instances-in (fn [lst] > >                        (if (cons? lst) > >                          (+ (if (= (first lst) obj) 1 0) > >                             (instances-in (rest lst))) > >                      

Re: Fully lazy sequences are coming - feedback wanted!

2009-02-16 Thread GS
On Feb 16, 1:44 pm, Rich Hickey wrote: > > My thoughts so far: > > > 4.  The new model is definitely more complicated to understand than > > the previous model.  There was already a certain degree of mental > > overlap between collections and the seq interface.  Now, there is also > > the subtle

Re: How do I do this in clojure?

2009-02-16 Thread GS
On Feb 17, 1:18 pm, Jesse Aldridge wrote: > I'm trying to port some Python code to Clojure.  I'm new to functional > programming and I hit a function that is causing my brain to melt. > The python function looks something like this: > [..] > > If someone could please demonstrate how to

Re: If/cond thoughts..

2009-03-01 Thread GS
On Feb 25, 10:19 pm, glow wrote: > Hi everyone! > I am currently learning Lisp and Clojure. A few days ago i read how > "if" in Arc works and I wonder why it is not the same in Clojure: > (if a b       ; if a then b >     c d       ; elseif c then d >       e)      ; else e. (cond pred1 form1

Re: Static type guy trying to convert

2009-03-10 Thread GS
Timothy Pratley wrote: > Jump on in! Just like with swimming the cold soon goes away. [...] Bad analogy. In swimming, the cold returns about half an hour later :) Gavin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Grou