why not change > < type compare functions do a compare on strings as well?

2010-11-28 Thread Tim Robinson
why not change > < type compare functions do a compare on strings as
well?

(defn >
([x] true)
  ([x y](if (string? x)
(. clojure.lang.Numbers (isPos (.compareTo x y)))
(. clojure.lang.Numbers (gt x y
  ([x y & more]
  (if (> x y)
(if (next more)
(recur y (first more) (next more))
(> y (first more)))
false)))

(defn <
([x] true)
  ([x y](if (string? x)
(. clojure.lang.Numbers (isNeg (.compareTo x y)))
(. clojure.lang.Numbers (gt x y
  ([x y & more]
  (if (< x y)
(if (next more)
(recur y (first more) (next more))
(< y (first more)))
false)))


It's just cleaner so we can do things like:

user=> (< "2010-06-11" "2010-11-01")
true

user=> (< "Banana" "Apple")
false

make sense?

Notes:
* I ran a bunch of benchmarks, showing no real impact on performance.
* probably would need to include >= and <= too.

-- 
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: Autodoc dependencies broken?

2010-11-28 Thread Brendan Ribera
I'm seeing related weirdness on a project that has no dependencies except
Clojure itself. It'll accept any Clojure from 1.0.0 up, but will default to
downloading the newest version:

> :dependencies [[org.clojure/clojure "[1.0.0,)"]]

The error I get is the same (missing org.clojure:clojure:jar:1.3.0-alpha3).
I did notice one interesting bit of information, however. Maven is
attempting to pull clojure-1.3.0-alpha3.jar from clojure-snapshots, but that
repo only has 1.3.0-alpha3*-SNAPSHOT*. It first grabs the pom from clojure,
and then tries to grab the jar from clojure-snapshots:

> Downloading: org/clojure/clojure/1.3.0-alpha3/clojure-1.3.0-alpha3.pom
from clojure
> Transferring 1K from clojure
> Downloading: org/clojure/clojure/1.3.0-alpha3/clojure-1.3.0-alpha3.jar
from clojure-snapshots
> An error has occurred while processing the Maven artifact tasks.

This seems crazy to me, but I don't know enough about Maven to diagnose
further.

-Brendan

On Sat, Nov 27, 2010 at 3:56 PM, Rayne  wrote:

> If it's helpful, I have a snapshot of autodoc 0.8.0 on clojars that
> I'm using in cake-autodoc: http://clojars.org/org.clojars.rayne/autodoc
>
> On Nov 26, 9:21 pm, James Reeves  wrote:
> > I've investigated this a little further, and it looks like I was
> > misinterpreting the dependency error messages.
> >
> > 0.8.0-SNAPSHOT doesn't work because it hasn't been uploaded to Clojars.
> >
> > 0.7.1 doesn't work because it references clojure-contrib
> > 1.1.0-master-SNAPSHOT, and clojure 1.3.0-alpha3, the latter via
> > Enlive, which seems to always reference the latest version, stable or
> > not.
> >
> > But I'm not sure with 1.3.0-alpha3 would fail, because as far as I can
> > tell it's in the Clojure repository. I'll investigate further
> > tomorrow.
> >
> > - James
> >
> > On 27 November 2010 02:17, Tom Faulhaber  wrote:
> >
> >
> >
> > > James,
> >
> > > I don't know why this would be true, but something may have broken in
> > > the underlying dependency chains. Autodoc hasn't been updated in
> > > clojars for a very long time and does not directly depend on super-
> > > pom.jar.
> >
> > > Are you using autodoc standalone or as a lein plugin?
> >
> > > Tom
> >
> > > On Nov 26, 1:09 pm, James Reeves  wrote:
> > >> I've just tried installing autodoc 1.7.1 and 0.8.0-SNAPSHOT via
> > >> Leiningen and Clojars, and it seems to be missing some dependencies
> > >> (specifically org.apache.maven:super-pom:jar:2.0).
> >
> > >> Has anyone else had this problem recently?
> >
> > >> - James
> >
> > > --
> > > 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
>
> --
> 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
>

-- 
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: Ring startup processing?

2010-11-28 Thread Stuart Campbell
Ah, OK. We just use Tomcat 6 for everything here :)

On 29 November 2010 12:16,  wrote:

> Yep but some app servers have bugs with this interface (GlassFish 2,
> jetty 6.1, tomcat 5.5, ...) and the interface is not called appropriately.
> There are less problems reported with the load-on-startup flag.
>
> Of course if you know your app server's behavior regarding this feature,
> it might not be a problem.
>
> I got caught once so I prefer a safer mechanism, we are not always using
> the same app server here. Might work in dev and not in prod... oups...
>
> Luc P.
>
> Stuart Campbell  wrote ..
> > On 28 November 2010 16:51,  wrote:
> >
> > > We use a dedicated servlet for every web app to make sure all
> prerequisites
> > > are met. Since it's loaded first, we can find problems by looking at a
> > > single
> > > piece of the log files just after the container messages announcing
> that
> > > it's loading the app.
> > >
> >
> > There's also ServletContextListener (
> >
>
> http://download.oracle.com/javaee/5/api/javax/servlet/ServletContextListener.html
> ),
> > which is configured in web.xml too.
> >
> > Regards,
> > 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
> > 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
> Luc P.
>
> 
> The rabid Muppet
>
> --
> 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
>

-- 
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

Funding 2011?

2010-11-28 Thread Jeremy Dunck
In Dec 2009, Rich asked the community to step up and support core
development -- and the community came through.

I'm interested in clojure, but not using it professionally yet.  I was
wondering if funding for 2011 has already been worked out, or if it is
an open question?

I'd be happy to contribute again, but I'd like some feedback on the
state of play.

To more success in 2011,
  Jeremy

-- 
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: Partition At True Values Of Predicate

2010-11-28 Thread Benny Tsai
Hi Asim,

Thank you for the code and the explanation of the context.

I noticed that partition-after could be implemented by taking my
previous code and incrementing all the 'true' indices by one.  My
first stab:

(defn partition-after [pred coll]
  (if (empty? coll)
'()
(let [indices (add-zero (map inc (index-filter pred coll)))
  index-groups (partition-all 2 1 indices)]
  (map #(apply subsequence coll %) index-groups

But this returns an extra list at the end if the last element is true,
so I decided to call (remove empty?) on the end result.  This allowed
me to make several other simplifications.  For your consideration, an
index-based implementation of partition-before and partition-after:

(use '[clojure.contrib.seq :only (indexed)])

(defn index-filter [pred coll]
  (when pred
(for [[idx elt] (indexed coll) :when (pred elt)] idx)))

(defn subsequence
  ([coll start]
 (drop start coll))
  ([coll start end]
 (take (- end start) (drop start coll

(defn subsequences [coll indices]
  (let [index-groups (partition-all 2 1 indices)
subseqs (map #(apply subsequence coll %) index-groups)]
(remove empty? subseqs)))

(defn partition-before [pred coll]
  (let [indices (cons 0 (index-filter pred coll))]
(subsequences coll indices)))

(defn partition-after [pred coll]
  (let [indices (cons 0 (map inc (index-filter pred coll)))]
(subsequences coll indices)))

On Nov 28, 12:17 pm, Asim Jalis  wrote:
> Here is partition-before and partition-after -- partition-after is simpler.
>
> (defn partition-before-internal [pred coll]
>   (let [first-item (first coll)]
>    (if (nil? first-item) ()
>      (letfn [(get-partial-partition-with-item []
>                (let [partial-partition (partition-before-internal pred
> (rest coll))]
>                  (cons
>                    (cons
>                      first-item
>                      (first partial-partition))
>                    (rest partial-partition]
>        (if (pred first-item)
>          (cons () (lazy-seq (get-partial-partition-with-item)))
>          (get-partial-partition-with-item))
>
> (defn partition-before [pred coll]
>   (lazy-seq
>     (let [partition-result (partition-before-internal pred coll)]
>       (if (empty? (first partition-result))
>         (rest partition-result)
>         partition-result
>
> (deftest partitioning-before
>   (are [input output] (= ',output (partition-before true? ',input))
>     ()        ()
>     (true)    ((true))
>     (false)   ((false))
>     (false false false true false true true true)
>       ((false false false) (true false) (true) (true) (true))
>     (true false false false true false true true true)
>       ((true false false false) (true false) (true) (true) (true
>
> (defn partition-after [pred coll]
>   (lazy-seq
>     (let [first-item (first coll)]
>      (if (nil? first-item) ()
>        (let [partial-partition (lazy-seq (partition-after pred (rest coll)))]
>          (if (pred first-item)
>            (cons (list first-item) partial-partition)
>            (cons
>              (cons
>                first-item
>                (first partial-partition))
>              (rest partial-partition
>
> (deftest partitioning-after
>   (are [input output] (= ',output (partition-after true? ',input))
>     ()        ()
>     (true)    ((true))
>     (false)   ((false))
>     (false false false true false true true true)
>       ((false false false true) (false true) (true) (true))
>     (true false false false true false true true true)
>       ((true) (false false false true) (false true) (true) (true

-- 
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: Ring startup processing?

2010-11-28 Thread lprefontaine
Yep but some app servers have bugs with this interface (GlassFish 2, 
jetty 6.1, tomcat 5.5, ...) and the interface is not called appropriately.
There are less problems reported with the load-on-startup flag.

Of course if you know your app server's behavior regarding this feature,
it might not be a problem.

I got caught once so I prefer a safer mechanism, we are not always using
the same app server here. Might work in dev and not in prod... oups...

Luc P.

Stuart Campbell  wrote ..
> On 28 November 2010 16:51,  wrote:
> 
> > We use a dedicated servlet for every web app to make sure all prerequisites
> > are met. Since it's loaded first, we can find problems by looking at a
> > single
> > piece of the log files just after the container messages announcing that
> > it's loading the app.
> >
> 
> There's also ServletContextListener (
>
http://download.oracle.com/javaee/5/api/javax/servlet/ServletContextListener.html),
> which is configured in web.xml too.
> 
> Regards,
> 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
> 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
Luc P.


The rabid Muppet

-- 
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: Ring startup processing?

2010-11-28 Thread Stuart Campbell
On 28 November 2010 16:51,  wrote:

> We use a dedicated servlet for every web app to make sure all prerequisites
> are met. Since it's loaded first, we can find problems by looking at a
> single
> piece of the log files just after the container messages announcing that
> it's loading the app.
>

There's also ServletContextListener (
http://download.oracle.com/javaee/5/api/javax/servlet/ServletContextListener.html),
which is configured in web.xml too.

Regards,
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
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: Partition At True Values Of Predicate

2010-11-28 Thread Ken Wesson
On Sun, Nov 28, 2010 at 5:23 PM, Asim Jalis  wrote:
> On Sun, Nov 28, 2010 at 1:17 PM, Ken Wesson  wrote:
>> The implementation I posted earlier appears to fit the contract of
>> your partition-before (and, additionally, works properly if the input
>> starts with (nil ...) :)).
>
> Good catch :) I should have used (empty? coll) instead of (nil?
> first-item) to check for emptiness.
>
> The implementation you posted earlier (split-when) is quite elegant.
> However, one thing I noticed about it was that it calls pred multiple
> times for each item in coll -- it would be nice if this redundancy
> could be removed somehow.

I don't think it does -- it calls clojure.core/split-with, which
presumably runs over the items until it hits one for which pred was
false (so, ipred is true) and splits the collection there. Only the
second half gets another split-with called on it, and with the first
item (which was already tested) omitted.

If split-with is actually implemented as simply [(take-while pred
coll) (drop-while pred coll)] then the redundancy exists but your
issue is with the authors of split-with. :)

My partition-dropping does call pred twice on some items, specifically
the first item in each partition gets an extra pred check to see if it
should be dropped.

In both cases I'd probably actually use a direct implementation in
terms of lazy-seq in production code, which would get rid of any such
redundancies, get rid of the overhead of wrapping pred in ipred, and
get rid of the risk of a stack overflow from piling on nested lazy
calls (which may or may not actually be there, mind you).

-- 
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


dosync style

2010-11-28 Thread Takahiro Hozumi
Hi,
This is trivial question.
Which style do you like?

(def *counts* (ref {}))

(defn dec-or-dissoc! [key]
  (dosync
   (let [n (@*counts* key)]
 (if (< 1 n)
   (alter *counts* assoc key (dec n))
   (alter *counts* dissoc key)

(defn dec-or-dissoc! [key]
  (dosync
   (alter *counts*
  (fn [m]
(let [n (m key)]
  (if (< 1 n)
(assoc m key (dec n))
(dissoc m key)))

I think former style is normal, but latter is easy to replace ref with
atom.
Thanks.

--
Takahiro Hozumi

-- 
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: Partition At True Values Of Predicate

2010-11-28 Thread Asim Jalis
On Sun, Nov 28, 2010 at 1:17 PM, Ken Wesson  wrote:
> The implementation I posted earlier appears to fit the contract of
> your partition-before (and, additionally, works properly if the input
> starts with (nil ...) :)).

Good catch :) I should have used (empty? coll) instead of (nil?
first-item) to check for emptiness.

The implementation you posted earlier (split-when) is quite elegant.
However, one thing I noticed about it was that it calls pred multiple
times for each item in coll -- it would be nice if this redundancy
could be removed somehow.

-- 
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: Partition At True Values Of Predicate

2010-11-28 Thread Ken Wesson
The implementation I posted earlier appears to fit the contract of
your partition-before (and, additionally, works properly if the input
starts with (nil ...) :)).

There is another possible variation: partition-dropping. Here the
elements for which pred returns true don't get included in the output
at all; e.g. (partition-dropping #(= 0 (rem % 3)) (range 16)) would
emit ((1 2) (4 5) (7 8) (10 11) (13 14) (16)). The use case for this
is when the pred is testing for a separator sentinel value, an object
in the sequence that you're not actually interested in for any purpose
other than its use as a separator. For instance if you had a text file
of blank-line-delimited paragraphs and wanted a paragraph-seq out of
it, you might use (partition-dropping #(= "" %) (line-seq ...)). Or a
more sophisticated predicate that recognizes all lines with no
nonwhitespace characters as blank:

(defn blank? [s]
  (every? #(Character/isWhitespace %) s))

(partition-dropping blank? (line-seq ...))

And here's an implementation:

(defn partition-dropping [pred coll]
  (let [ipred (complement pred)
bits (iterate
   (fn [[out coll]]
 (let [[a b] (split-with ipred (rest coll))
  x (first coll)]
   (if (and (seq coll) (pred x))
 [a b]
 [(cons x a) b])))
   [nil coll])]
(map #(first (first %))
  (take-while #(seq (second (second %))) (map vector (rest bits) bits)

user=> (partition-dropping #(= 0 (rem % 4)) (range 15))
((1 2 3)
 (5 6 7)
 (9 10 11)
 (13 14))
user=> (take 5 (partition-dropping #(= 0 (rem % 4)) (iterate inc 1)))
((1 2 3)
 (5 6 7)
 (9 10 11)
 (13 14 15)
 (17 18 19))

It handles nils properly:

user=> (partition-dropping identity [nil nil nil true 'x false 1 2
true nil 17 false 4 8 15 16 23 42])
((nil nil nil)
 ()
 (false)
 ()
 ()
 (nil)
 (false)
 ()
 ()
 ()
 ()
 ()
 ())
user=> (partition-dropping (complement identity) [nil nil nil true 'x
false 1 2 true nil 17 false 4 8 15 16 23 42])
(()
 ()
 (true x)
 (1 2 true)
 (17)
 (4 8 15 16 23 42))

though you'll note that empty lists appear whenever pred is true for
two adjacent items. If you want to get rid of those:

user=> (remove empty? (partition-dropping (complement identity) [nil
nil nil true 'x false 1 2 true nil 17 false 4 8 15 16 23 42]))
((true x)
 (1 2 true)
 (17)
 (4 8 15 16 23 42))

-- 
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: Why isn't there a fold-right?

2010-11-28 Thread Asim Jalis
This looks like map rather than foldr.

On Sun, Nov 28, 2010 at 7:40 AM, tpeng  wrote:
> i have a one:
> (defn lazy-foldr [f coll]
>    (lazy-seq
>        (if-let [[x & xs] coll]
>            (cons x (lazy-foldr f xs)
>
> it seems works so far ;-p
>
> On Nov 28, 4:01 pm, Laurent PETIT  wrote:
>> Hello,
>>
>> clojure is not lazy on evaluation of arguments by default, so I think this
>> is not possible to do this "transparently".
>>
>> Using delay/force could help, but this would not be "transparent" at all for
>> the writer of the fn ;-)
>>
>> 2010/11/27 tpeng 
>>
>> > thanks Alex for this nice foldr. ;-)
>>
>> > however this lazy-foldr can only be used when the fn can stop by
>> > itself (in this case, it's 'and' which is short-circuited)  otherwise
>> > lazy-foldr will never get stop.
>> > i think for a good foldr, the evaluation of #(lazy-foldr f val xs)
>> > should be only forced when necessary?
>>
>> > On Nov 27, 6:44 pm, Alex Osborne  wrote:
>> > > "nicolas.o...@gmail.com"  writes:
>> > > > I doubt there is a foldr that handles the infinite list.
>> > > > To do anything, it would have to read at least one element: the last.
>>
>> > > > Alex nice answer is a foldl.
>>
>> > > Actually I think you have them backwards.  Wikipedia has a pair of
>> > > diagrams which I find very useful for visualising which is which:
>>
>> > > foldr:http://en.wikipedia.org/wiki/File:Right-fold-transformation.png
>>
>> > > foldl (reduce in Clojure):
>> >http://en.wikipedia.org/wiki/File:Left-fold-transformation.png
>>
>> > > Look at the right side of the diagram.  That's the call structure.  (The
>> > > left side of the diagram is the linked list (1 2 3 4 5).  The ":" just
>> > > means cons in Haskell syntax.)
>>
>> > > With a foldr the outermost call is given the first element of the list,
>> > > so mine is definitely a foldr.
>>
>> > > Let's use (and) as the combining function and use an infinite list that
>> > > begins [true true false false ...].  So that looks like:
>>
>> > > (lazy-foldr #(and %1 (%2)) nil (cycle [true true false false]))
>>
>> > > We can draw an ASCII call structure diagram in the same form as the
>> > > Wikipedia one and see this:
>>
>> > >       and
>> > >       / \
>> > >      T  and
>> > >         / \
>> > >        T  and
>> > >           / \
>> > >          F   (not evaluated)
>>
>> > > Since (and) short-circuits when given false, only the part of the list
>> > > up to the first false is evaluated.
>>
>> > > There's probably not much practical use for lazy-foldr.  But it was fun
>> > > to write. :-)
>>
>> > --
>> > 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
>
> --
> 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

-- 
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: Partition At True Values Of Predicate

2010-11-28 Thread Asim Jalis
Here is partition-before and partition-after -- partition-after is simpler.

(defn partition-before-internal [pred coll]
  (let [first-item (first coll)]
   (if (nil? first-item) ()
 (letfn [(get-partial-partition-with-item []
   (let [partial-partition (partition-before-internal pred
(rest coll))]
 (cons
   (cons
 first-item
 (first partial-partition))
   (rest partial-partition]
   (if (pred first-item)
 (cons () (lazy-seq (get-partial-partition-with-item)))
 (get-partial-partition-with-item))

(defn partition-before [pred coll]
  (lazy-seq
(let [partition-result (partition-before-internal pred coll)]
  (if (empty? (first partition-result))
(rest partition-result)
partition-result

(deftest partitioning-before
  (are [input output] (= ',output (partition-before true? ',input))
()()
(true)((true))
(false)   ((false))
(false false false true false true true true)
  ((false false false) (true false) (true) (true) (true))
(true false false false true false true true true)
  ((true false false false) (true false) (true) (true) (true

(defn partition-after [pred coll]
  (lazy-seq
(let [first-item (first coll)]
 (if (nil? first-item) ()
   (let [partial-partition (lazy-seq (partition-after pred (rest coll)))]
 (if (pred first-item)
   (cons (list first-item) partial-partition)
   (cons
 (cons
   first-item
   (first partial-partition))
 (rest partial-partition

(deftest partitioning-after
  (are [input output] (= ',output (partition-after true? ',input))
()()
(true)((true))
(false)   ((false))
(false false false true false true true true)
  ((false false false true) (false true) (true) (true))
(true false false false true false true true true)
  ((true) (false false false true) (false true) (true) (true

-- 
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: ANN: Gloss, a byte-format DSL

2010-11-28 Thread Zach Tellman
You're right, that's an omission from the frame syntax.  I'll add the
ability for all or part of the frame to be scoped as (little-
endian ...) and (big-endian ...), with big-endian as the default.

Just as a side-note, though, Calx [1] is already handling little-
endian data by using encode-to-buffer, where it's writing to a buffer
whose endianness has been preset.   This obviously isn't a general
solution, but just thought I'd point it out.

Zach

[1] https://github.com/ztellman/calx



On Nov 28, 8:50 am, zoka  wrote:
> If Gloss is to decode incoming packet (byte array) in little-endian
> format it is straightforward:
> Wrap byte array into ByteBuffer b, invoke b.order(LITTLE_ENDIAN) and
> pass b to decode function that will return Clojure map of decoded
> values.
>
> However, when outgoing packet byte array is to be produced from map of
> values, encode function will always return ByteBuffer in default big-
> endian format, so resulting byte array extracted form ByteBuffer using
> get() method will be incorrect.
>
> If Gloss is to support little-endian frames, it seems that endianness
> needs to be part of frame definition. In that case Gloss decode fun
> would refuse to accept ByteBuffers with wrong order() and encode fun
> will always generate the correct result.
>
> Zoka
>
> On Nov 25, 3:00 am, Zach Tellman  wrote:
>
>
>
>
>
>
>
> > ByteBuffers have an order() method which allows you to toggle the
> > endianness.  I haven't tested this, but since everything is built on
> > top of Java's ByteBuffer functionality it should be fine as long as
> > the ByteBuffers are correctly set and correctly ordered with respect
> > to each other.
>
> > Zach
>
> > On Nov 23, 2:52 pm, zoka  wrote:
>
> > > JVM stores numbers in in big endian format - is there a way to process
> > > binary stream containing little endian numbers?
>
> > > Zoka
>
> > > On Nov 24, 7:24 am, Zach Tellman  wrote:
>
> > > > Good question.  The solution didn't make the cut for my initial
> > > > release, but will be added soon.  My plan is to have an (ordered-
> > > > map ...) frame which encodes and decodes the keys in the given order.
> > > > So for C interop, the frame would be
>
> > > > (ordered-map :a :int16, :b :float32)
>
> > > > An alternative would be to just turn any vector which is alternating
> > > > keys and types into an ordered-map, but that seems a bit too magical.
>
> > > > Zach
>
> > > > On Nov 23, 12:12 pm, Chris Perkins  wrote:
>
> > > > > On Nov 23, 12:03 pm, Zach Tellman  wrote:
>
> > > > > > When writing Calx [1], I discovered it was a huge pain to deal with
> > > > > > mixed C datatypes in Java.  When writing Aleph [2], I discovered the
> > > > > > problem increases by a factor of ten when dealing with streams of
> > > > > > bytes.  In an attempt to alleviate my own pain, and hopefully help a
> > > > > > few other people out, I've written Gloss, which can transform a 
> > > > > > simple
> > > > > > byte-format specification into an encoder and streaming decoder.
>
> > > > > > A full writeup can be found 
> > > > > > athttps://github.com/ztellman/gloss/wiki.
>
> > > > > > A few people have already asked me how this differs from protocol
> > > > > > buffers, so I'll preemptively answer that protocol buffers are a 
> > > > > > fixed
> > > > > > format that cannot be used to interface with external systems.  
> > > > > > Gloss
> > > > > > is less performant than protocol buffers, but is also much less 
> > > > > > picky
> > > > > > about formats.
>
> > > > > > If anyone has any questions, I'd be happy to answer them.
>
> > > > > Looks very useful, Zach. Thanks.
>
> > > > > I have a question.
>
> > > > > I have only taken a quick look, so maybe I'm misunderstanding the
> > > > > intent, but it's not clear to me how you would use this for sending
> > > > > and receiving structured data from, say, a C program.
>
> > > > > Taking your example from the wiki:
>
> > > > > (def fr (compile-frame {:a :int16, :b :float32}))
>
> > > > > Let's say I want to talk to a C program that speaks in structs, like
> > > > > this:
>
> > > > > struct Foo { short a; float b; }
>
> > > > > The problem is, the C program cares about order - the short comes
> > > > > before the float. How does the Clojure program know what order I need
> > > > > the fields in, since I have specified the format with a map; an
> > > > > unordered data structure? Is there another way to specify a structure
> > > > > where order of the fields matters? If so, why have two ways of doing
> > > > > it? Or am I just missing something?
>
> > > > > Thanks,
>
> > > > > - Chris

-- 
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=

Re: Partition At True Values Of Predicate

2010-11-28 Thread Asim Jalis
On Sat, Nov 27, 2010 at 5:53 PM, Benny Tsai  wrote:
> If you don't mind, I would love to see your version with lazy-seq and
> recursion.  Seems like that's the idiomatic way of solving problems
> like this, judging by the source for the partition functions.

Hi Benny,

Certainly. My solution is appended at the bottom.

Here is some background on this. I frequently run into this problem
where I have lines and I have to group them based on some marker. A
simple example is a file containing mail messages in which lines that
begin with "^From " mark the start of each new message. To parse this
requires a way to start with a sequence of undifferentiated lines and
turn that into a sequence of collections of lines each representing a
message.

And there are really two versions of this partition: partition-before
and partition-after: partition-before would put the true with the
falses following it, and partition-after will group it with the falses
preceding it.

Here is the solution I have for partition-before. The function
partition-before-internal is almost like partition-before except that
it always puts a list of items preceding the first true as its first
element. If the first element of coll is true then it sticks an empty
list here.

(defn partition-before-internal [pred coll]
  (let [first-item (first coll)
second-item (second coll)
rest-items (rest coll)]
   (if (nil? first-item) ()
 (if (nil? second-item) (list () (list first-item))
   (letfn [(get-partial-partition-with-item []
 (let [partial-partition (partition-before-internal
pred rest-items)]
   (cons
 (cons
   first-item
   (first partial-partition))
 (rest partial-partition]
 (if (pred first-item)
   (cons () (lazy-seq (get-partial-partition-with-item)))
   (get-partial-partition-with-item)))

(defn partition-before [pred coll]
  (lazy-seq
(let [partition-result (partition-before-internal pred coll)]
  (if (empty? (first partition-result))
(rest partition-result)
partition-result

(deftest partitioning-using-predicate
  (are [input output] (= ',output (partition-before true? ',input))
()()
(true)((true))
(false)   ((false))
(false false false true false true true true)
  ((false false false) (true false) (true) (true) (true))
(true false false false true false true true true)
  ((true false false false) (true false) (true) (true) (true

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: clojure 1.3 alpha3 and swank

2010-11-28 Thread Michael Ossareh
On Sun, Nov 28, 2010 at 00:15, Sunil S Nandihalli <
sunil.nandiha...@gmail.com> wrote:

> what repository did you get it from?
> I don't seem to fine 1.3.0 anywhere..
>
>
http://clojars.org/swank-clojure

I forgot the -SNAPSHOT in my previous message.

-- 
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: ANN: Gloss, a byte-format DSL

2010-11-28 Thread zoka
If Gloss is to decode incoming packet (byte array) in little-endian
format it is straightforward:
Wrap byte array into ByteBuffer b, invoke b.order(LITTLE_ENDIAN) and
pass b to decode function that will return Clojure map of decoded
values.

However, when outgoing packet byte array is to be produced from map of
values, encode function will always return ByteBuffer in default big-
endian format, so resulting byte array extracted form ByteBuffer using
get() method will be incorrect.

If Gloss is to support little-endian frames, it seems that endianness
needs to be part of frame definition. In that case Gloss decode fun
would refuse to accept ByteBuffers with wrong order() and encode fun
will always generate the correct result.

Zoka


On Nov 25, 3:00 am, Zach Tellman  wrote:
> ByteBuffers have an order() method which allows you to toggle the
> endianness.  I haven't tested this, but since everything is built on
> top of Java's ByteBuffer functionality it should be fine as long as
> the ByteBuffers are correctly set and correctly ordered with respect
> to each other.
>
> Zach
>
> On Nov 23, 2:52 pm, zoka  wrote:
>
> > JVM stores numbers in in big endian format - is there a way to process
> > binary stream containing little endian numbers?
>
> > Zoka
>
> > On Nov 24, 7:24 am, Zach Tellman  wrote:
>
> > > Good question.  The solution didn't make the cut for my initial
> > > release, but will be added soon.  My plan is to have an (ordered-
> > > map ...) frame which encodes and decodes the keys in the given order.
> > > So for C interop, the frame would be
>
> > > (ordered-map :a :int16, :b :float32)
>
> > > An alternative would be to just turn any vector which is alternating
> > > keys and types into an ordered-map, but that seems a bit too magical.
>
> > > Zach
>
> > > On Nov 23, 12:12 pm, Chris Perkins  wrote:
>
> > > > On Nov 23, 12:03 pm, Zach Tellman  wrote:
>
> > > > > When writing Calx [1], I discovered it was a huge pain to deal with
> > > > > mixed C datatypes in Java.  When writing Aleph [2], I discovered the
> > > > > problem increases by a factor of ten when dealing with streams of
> > > > > bytes.  In an attempt to alleviate my own pain, and hopefully help a
> > > > > few other people out, I've written Gloss, which can transform a simple
> > > > > byte-format specification into an encoder and streaming decoder.
>
> > > > > A full writeup can be found athttps://github.com/ztellman/gloss/wiki.
>
> > > > > A few people have already asked me how this differs from protocol
> > > > > buffers, so I'll preemptively answer that protocol buffers are a fixed
> > > > > format that cannot be used to interface with external systems.  Gloss
> > > > > is less performant than protocol buffers, but is also much less picky
> > > > > about formats.
>
> > > > > If anyone has any questions, I'd be happy to answer them.
>
> > > > Looks very useful, Zach. Thanks.
>
> > > > I have a question.
>
> > > > I have only taken a quick look, so maybe I'm misunderstanding the
> > > > intent, but it's not clear to me how you would use this for sending
> > > > and receiving structured data from, say, a C program.
>
> > > > Taking your example from the wiki:
>
> > > > (def fr (compile-frame {:a :int16, :b :float32}))
>
> > > > Let's say I want to talk to a C program that speaks in structs, like
> > > > this:
>
> > > > struct Foo { short a; float b; }
>
> > > > The problem is, the C program cares about order - the short comes
> > > > before the float. How does the Clojure program know what order I need
> > > > the fields in, since I have specified the format with a map; an
> > > > unordered data structure? Is there another way to specify a structure
> > > > where order of the fields matters? If so, why have two ways of doing
> > > > it? Or am I just missing something?
>
> > > > Thanks,
>
> > > > - Chris
>
>

-- 
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: Why isn't there a fold-right?

2010-11-28 Thread tpeng
i have a one:
(defn lazy-foldr [f coll]
(lazy-seq
(if-let [[x & xs] coll]
(cons x (lazy-foldr f xs)

it seems works so far ;-p

On Nov 28, 4:01 pm, Laurent PETIT  wrote:
> Hello,
>
> clojure is not lazy on evaluation of arguments by default, so I think this
> is not possible to do this "transparently".
>
> Using delay/force could help, but this would not be "transparent" at all for
> the writer of the fn ;-)
>
> 2010/11/27 tpeng 
>
> > thanks Alex for this nice foldr. ;-)
>
> > however this lazy-foldr can only be used when the fn can stop by
> > itself (in this case, it's 'and' which is short-circuited)  otherwise
> > lazy-foldr will never get stop.
> > i think for a good foldr, the evaluation of #(lazy-foldr f val xs)
> > should be only forced when necessary?
>
> > On Nov 27, 6:44 pm, Alex Osborne  wrote:
> > > "nicolas.o...@gmail.com"  writes:
> > > > I doubt there is a foldr that handles the infinite list.
> > > > To do anything, it would have to read at least one element: the last.
>
> > > > Alex nice answer is a foldl.
>
> > > Actually I think you have them backwards.  Wikipedia has a pair of
> > > diagrams which I find very useful for visualising which is which:
>
> > > foldr:http://en.wikipedia.org/wiki/File:Right-fold-transformation.png
>
> > > foldl (reduce in Clojure):
> >http://en.wikipedia.org/wiki/File:Left-fold-transformation.png
>
> > > Look at the right side of the diagram.  That's the call structure.  (The
> > > left side of the diagram is the linked list (1 2 3 4 5).  The ":" just
> > > means cons in Haskell syntax.)
>
> > > With a foldr the outermost call is given the first element of the list,
> > > so mine is definitely a foldr.
>
> > > Let's use (and) as the combining function and use an infinite list that
> > > begins [true true false false ...].  So that looks like:
>
> > > (lazy-foldr #(and %1 (%2)) nil (cycle [true true false false]))
>
> > > We can draw an ASCII call structure diagram in the same form as the
> > > Wikipedia one and see this:
>
> > >       and
> > >       / \
> > >      T  and
> > >         / \
> > >        T  and
> > >           / \
> > >          F   (not evaluated)
>
> > > Since (and) short-circuits when given false, only the part of the list
> > > up to the first false is evaluated.
>
> > > There's probably not much practical use for lazy-foldr.  But it was fun
> > > to write. :-)
>
> > --
> > 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

-- 
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: Exporting FatJar from Eclipse CCW does not work

2010-11-28 Thread Gijs S.
Hi Alex,

Glad to be of help. I had never heard of FatJar before and it turned
out to work great for a clojure project I needed to distribute.

Also, as a fellow Dutch clojurian I can recommend the Amsterdam
Clojurians group at http://ams-clj.github.com.

Cheers,
Gijs

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure benchmark memory use and future improvements (Re: Clojure vs F# performance)

2010-11-28 Thread Alex Osborne
John Fingerhut  writes:

> Does anyone know a way from within a Java/Clojure program to determine
> which GC algorithm is currently in use? I'm curious what the default
> is when one is not specified on the command line, and accessing the
> one being used from inside  of a program would be one good way to find
> out for sure. There doesn't seem to be anything returned by
> Runtime.getRuntime().getProperties() to indicate that. 

You can get at least something via JMX:

   (require '[clojure.contrib.jmx :as jmx])

   (map #(subs (str %) 37) 
(jmx/mbean-names "java.lang:type=GarbageCollector,*"))

Default on my PC:("PS MarkSweep" "PS Scavenge")
With -XX:-UseParallelGC: ("Copy" "MarkSweepCompact")
With -XX:+UseG1GC:   ("G1 Old Generation" "G1 Young Generation")

You can also see this same data by running JConsole (shipped in the
JDK's bin directory) and attaching to a running Java process. 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Clojure benchmark memory use and future improvements (Re: Clojure vs F# performance)

2010-11-28 Thread John Fingerhut
Thanks, Ken.  I've changed that in my program now.

I've also found that one reason why the Clojure benchmarks on the shootout
web site were using so much more memory than the corresponding Java programs
(e.g. up to about 350 Mbytes for the fannkuch-redux benchmark program) is a
combination of several factors:

(1) the Clojure programs were generating garbage, i.e. allocating memory
that later became unused.  Even though the total amount of live objects at
any one time was well under 4 MBytes for the fannkuch-redux benchmark
program, for example, it was not being collected soon enough to keep the
amount of resident memory low.

(2) That combined with the default heap size and GC method used, when no
special command line arguments were being used on the java command line, led
to large measured memory usage.

By selecting an appropriate maximum heap size using the -Xmx command line
option, the maximum resident memory used by several of the Clojure (and also
JRuby) programs have been reduced significantly.  Several of the programs
formerly had their memory use 30x the corresponding Java program.  Now the
worst case ratio of (Clojure memory use / Java memory use) is about 3x, and
there are still several programs for which I haven't yet run the experiments
to find an appropriate max heap size to use.  After that happens, the
average memory use of Clojure programs (and JRuby programs) will go down
further.  Here is a link where you can see the results for the one-core
32-bit benchmark machine, for example:

http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=clojure

Does anyone know a way from within a Java/Clojure program to determine which
GC algorithm is currently in use?  I'm curious what the default is when one
is not specified on the command line, and accessing the one being used from
inside of a program would be one good way to find out for sure.  There
doesn't seem to be anything returned by Runtime.getRuntime().getProperties()
to indicate that.

Andy


On Mon, Nov 22, 2010 at 9:51 AM, Ken Wesson  wrote:

> On Mon, Nov 22, 2010 at 11:47 AM, John Fingerhut
>  wrote:
> > max live=63.1 MB - The maximum heap size before any GC invocation
> > was 63.1 MB.  The name "max live" is probably not the best name
> > for that value, since objects in heap before a GC begins are often
> > not all live.
>
> You'll get a much better approximation to the concept of "max live"
> from the maximum heap size right AFTER any GC invocation.
>
> --
> 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

-- 
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

a few helper macros for debugging written for learning macro writing

2010-11-28 Thread Sunil S Nandihalli
Hello everybody,
https://gist.github.com/718725

has a few helper macros for debugging which were written to learn macro
writing.. so would love to get some feed back


Thanks,
Sunil.

-- 
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: a macro to debug the let form

2010-11-28 Thread Sunil S Nandihalli
Hi Robert,
 What I had posted before was half-baked buggy code .. the following gist
has a few more helper debug macros
https://gist.github.com/718725

This code was written when I was trying to
learn writing macros .. so any criticism is very welcome.
Thanks
Sunil.

On Sat, Nov 27, 2010 at 11:06 PM, Robert McIntyre  wrote:

> cool!  Although I think with-seperator should be spelled "with-separator"
>
> --Robert McIntyre
>
> On Thu, Nov 25, 2010 at 9:13 AM, Sunil S Nandihalli
>  wrote:
> > I just tried to re-write with-seperator without using the symbol-macros
> from
> > macro-utils and it seems to work fine ..
> >
> > On Thu, Nov 25, 2010 at 1:27 PM, Sunil S Nandihalli
> >  wrote:
> >>
> >> Hello everybody,
> >>  I was trying to learn to write clojure macros and the code is posted
> here
> >> in the following link
> >> https://gist.github.com/715047
> >> There are basically three macros
> >> 1. with-seperator - a zero argument macro and is supposed to just draw a
> >> line to indicate beginning and ending of the execution of the body.
> >> 2. display-local-bindings - a function to print the local bindings in
> the
> >> lexical scope where the macro is called
> >> 3. letd - a helper macro to print the values of all the bindings
>  followed
> >> by printing of the local bindings using display-local-bindings
> >> The letd macro as posted works as expected but without the seperation
> line
> >> .  It is supposed to print the seperation line when I uncomment line 14
> and
> >> comment line 15 but some how this is causing the &env variable
> automatically
> >> passed with every macro to be nil display-local-binding .. but the I
> feel it
> >> is not the case .. can somebody help me understand this. This was an
> >> exercise to learn macro writing than to writing a letd debugging helper
> >> function..
> >> Thanks,
> >> Sunil.
> >
> > --
> > 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
>
> --
> 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

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: clojure 1.3 alpha3 and swank

2010-11-28 Thread Sunil S Nandihalli
what repository did you get it from?
I don't seem to fine 1.3.0 anywhere..
Sunil

On Sun, Nov 28, 2010 at 10:24 AM, Michael Ossareh  wrote:

> I had no issues with swank-clojure 1.3.0:
>
> in project.clj [swank-clojure "1.3.0"]
>
> I had plenty of issues using other libraries as there are some breaking
> changes in 1.3. YMMV.
>
> On Thu, Nov 25, 2010 at 05:52, Sunil S Nandihalli <
> sunil.nandiha...@gmail.com> wrote:
>
>> Hello Everybody,
>>  I would like to have a go at 1.3 alpha3 .. but having a lot of trouble
>> with the swank.. can somebody suggest me a version of swank-clojure that has
>> worked for them along with 1.3 alpha3
>>
>> Thanks,
>> Sunil.
>>
>> --
>> 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
>
>
>  --
> 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

-- 
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: Why isn't there a fold-right?

2010-11-28 Thread Laurent PETIT
Hello,

clojure is not lazy on evaluation of arguments by default, so I think this
is not possible to do this "transparently".

Using delay/force could help, but this would not be "transparent" at all for
the writer of the fn ;-)

2010/11/27 tpeng 

> thanks Alex for this nice foldr. ;-)
>
> however this lazy-foldr can only be used when the fn can stop by
> itself (in this case, it's 'and' which is short-circuited)  otherwise
> lazy-foldr will never get stop.
> i think for a good foldr, the evaluation of #(lazy-foldr f val xs)
> should be only forced when necessary?
>
> On Nov 27, 6:44 pm, Alex Osborne  wrote:
> > "nicolas.o...@gmail.com"  writes:
> > > I doubt there is a foldr that handles the infinite list.
> > > To do anything, it would have to read at least one element: the last.
> >
> > > Alex nice answer is a foldl.
> >
> > Actually I think you have them backwards.  Wikipedia has a pair of
> > diagrams which I find very useful for visualising which is which:
> >
> > foldr:http://en.wikipedia.org/wiki/File:Right-fold-transformation.png
> >
> > foldl (reduce in Clojure):
> http://en.wikipedia.org/wiki/File:Left-fold-transformation.png
> >
> > Look at the right side of the diagram.  That's the call structure.  (The
> > left side of the diagram is the linked list (1 2 3 4 5).  The ":" just
> > means cons in Haskell syntax.)
> >
> > With a foldr the outermost call is given the first element of the list,
> > so mine is definitely a foldr.
> >
> > Let's use (and) as the combining function and use an infinite list that
> > begins [true true false false ...].  So that looks like:
> >
> > (lazy-foldr #(and %1 (%2)) nil (cycle [true true false false]))
> >
> > We can draw an ASCII call structure diagram in the same form as the
> > Wikipedia one and see this:
> >
> >   and
> >   / \
> >  T  and
> > / \
> >T  and
> >   / \
> >  F   (not evaluated)
> >
> > Since (and) short-circuits when given false, only the part of the list
> > up to the first false is evaluated.
> >
> > There's probably not much practical use for lazy-foldr.  But it was fun
> > to write. :-)
>
> --
> 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
>

-- 
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