Re: 1.2 contrib shuffles

2010-08-28 Thread B Smith-Mannschott
On Sat, Aug 28, 2010 at 07:00, Stuart Sierra wrote:

> On Aug 27, 3:42 pm, B Smith-Mannschott  wrote:
> > This thread got me thinking that when a namespace is partially promoted
> to
> > Clojure proper, it might be good to provide a reduced version of the old
> > namespace, providing just the functionality that was not promoted as an
> > alternative to complete removal.
>
> Speaking as their author, c.c.io and c.c.str* should be removed
> completely.  If a function or macro didn't get promoted to Clojure
> proper, it is because it was poorly written or redundant.
>
> -S
>
>
understood
// Ben

-- 
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: creating map throws ArrayIndexOutOfBounds (inconsistently)

2010-08-28 Thread santervo
It happens like this:

In my keyboard, I get "}" with AltGr-0

Now, if I type { :a { :b "C" } }, and hold space down while typing
AltGr-0, I get ArrayIndexOutOfBounds. In the screen there is no
difference when holding the space down.


Also, if i hold AltGr down after typing "{" (AltGr-7) when pressing
space button, i get this:

user=> { :a "b" }
java.lang.Exception: Unable to resolve symbol:  :a in this context
(NO_SOURCE_FILE:0)

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


loop/recur stack overflow

2010-08-28 Thread neveu
I implemented the "Flavius Josephus" algorithm from Programming Praxis
in Clojure using loop/recur. My first version looked like this:

(defn rotate-left
  ([ln n m]
 (take n (drop (dec m) (cycle ln
  ([ln m] (rotate-left ln (count ln) m)))

(defn josephus3 [N M] ;; execute every mth soldier
  (loop [soldiers (range N)
 m M
 deceased '()]
(let [n (count soldiers)]
  (cond
 (zero? n) deceased
 true (let [r (rotate-left soldiers n m)
dead (cons (first r) deceased)
survivors (rest r)]
(recur survivors m dead))

This works fine, but I don't really need to count the soldiers every
pass, it always decreases by 1. So I wrote this version in which n is
one of the loop parameters:

(defn josephus4 [N M] ;; execute every mth soldier
  (loop [soldiers (range N)
 n N
 m M
 deceased '()]
(cond
 (zero? n) deceased
 true (let [r (rotate-left soldiers n m)
dead (cons (first r) deceased)
survivors (rest r)]
(recur survivors (dec n)  m dead)

Both work for small N (e.g. 41) but the second one fails for large
(41000) N with a stack overflow.
What am I missing here?

Thanks,
Charles

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


newbie question: where are my log messages going to?

2010-08-28 Thread Wei Hsu
Hello,

I'm using the clojure.contrib.logging library (logging/spy seems very
useful!) but I don't know which file it's writing to. Can you please
advise?

Thanks,
Wei

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


Re: where did I read that?

2010-08-28 Thread Robert McIntyre
I took a stab at it and came up with this:

(defn make-reader [s]
  (java.io.PushbackReader. (java.io.CharArrayReader.
(into-array Character/TYPE (seq s)

(defn read-with-number
  "like read but takes in a string and returns a function
   of no arguments which will read the string and provide char number
   as in Common Lisp"
  [string]
  (let [*current-char-number* (atom 0)
numbering-pushback-reader
(proxy  [java.io.PushbackReader]
[(make-reader string)]
  (read [] (swap! *current-char-number* inc) (proxy-super read
))
  (unread [stuff] (swap! *current-char-number* dec)
(proxy-super unread stuff))
  )]

(fn [] [(read numbering-pushback-reader) (deref *current-char-number*)])))


Now you can do:

mobius.physics> (def read-oh-yeah! (read-with-number "(vector 1 2 3)
(list 5 6)"))
#'mobius.physics/read-oh-yeah!
mobius.physics> (read-oh-yeah!)
[(vector 1 2 3) 14]
mobius.physics> (read-oh-yeah!)
[(list 5 6) 25]


is that what you're going for?  please tell me how I can improve this!

--Robert McIntyre

On Sat, Aug 28, 2010 at 1:26 AM, evins.mi...@gmail.com
 wrote:
> I'm working on a project in which it would be very useful to be able
> to easily determine how many characters were consumed in the course of
> a read operation, in a similar fashion to the way that Common Lisp's
> read-from-string returns as a second value the index of the next
> character of the input past the end of the object that was read. I
> want to, for example, read Clojure values from a buffer and keep track
> of where in the buffer they were read from.
>
> Anyone have any good ideas of how to accomplish this without some
> level of reimplementation of read?
>
> --
> 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: Docstrings in Clojure?

2010-08-28 Thread Paddy3118
Thanks guys. I have mentioned Clojure in the Wikipedia entry for
Docstrings at: http://en.wikipedia.org/wiki/Docstring

On 19 Aug, 21:22, Paddy3118  wrote:
> Hi, Does clojure have docstrings:http://en.wikipedia.org/wiki/Docstring
> and, if so, do you have a link to the feature in the Clojure
> documentation? Thanks.

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


Type hints in protocols and records

2010-08-28 Thread Francesco Bellomi
Hello,

I'm trying to use type hints in protocols and records, but I found
some strange behavior.

As an example, if I use:

(defprotocol test
  (test-fn [a ^String b]))

the type hint in test-fn is parsed correctly (or at least without
raising an error), but then...

(defrecord test-record [x y z]
  test
  (test-fn [a  b] b))

user=> (def q (test-record. 1 2 3))
#'user/q
user=> (test-fn q 1)
1

...it is not used or even enforced when I implement the protocol
within a record.
If I use a compatible type hint in the record definition, I have an
error

(defrecord test-record [x y z]
  test
  (test-fn [a ^String b] b))

java.lang.IllegalArgumentException: Can't find matching method:
test_fn, leave off hints for auto match.

It is not clear to me if type hints are supported in protocols, and if
so, how I can use them.

thanks in advance, Francesco

-- 
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: Some clarifications about let form

2010-08-28 Thread HB
So, any time I want to declare a local variable (inside a function for
example), I use let form.

On Aug 26, 8:26 pm, nickikt  wrote:
> Its for defining look variables (constants) that you use more then
> once in your form and not have to write it more then once (or
> calculated it more then once)
> (let  [r1 (random-int)
>         r2 (random-int)]
>         (when (the-same? r1 r2)
>                  (str r1 " and " r2 " are the same"))
>
> Write this without let
>
> (when (the-same? (random-int) (random-int))
>     (str (random-int)  " and " (random-int) " are the same"))
>
> does this work? Of course not and thats one reason for let.
>
> Also it can make your code cleaner.
>
> (filter even? (take 10 (drop 10 (map inc (iterate inc 1) ;stuff
> like this can get long
>
> (let [N-plus-one (map inc (iterate inc 1))
>        my-range (take 10 (drop 10 N-plus-one))]
>  (filter even? my-range))
>
> You can do destructoring in the binding block.http://clojure.org/special_forms
> (search destructoring)
>
> Thats just some stuff, but as soon you have done some stuff yourself
> it will become clear.
>
> On 26 Aug., 17:02, HB  wrote:
>
>
>
> > Hey,
> > Basically, I understand what let form does but I'm not sure when to
> > use it.
> > Would you please enlighten me about it? (if possible some typical Java
> > code and then covert it to Clojure let form).
> > I really appreciate your time and help.
> > Thanks.

-- 
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: Leiningen 1.3.0 - compile task problem

2010-08-28 Thread lprefontaine
Fine,

I'll post entire project in a tar file this week end and will come back with
the URL before Sunday night. Need to complete urgent work in the garden today :)

Luc P.

Phil Hagelberg  wrote ..
> On Fri, Aug 27, 2010 at 8:06 PM,   wrote:
> > I got it working with the our-classe-only plug-in.
> > I tested it on my brain damaged project and it kept only the class files
> > for which a name space exists in the source folder. The target is now
> > cleaned up of any external class dependencies.
> >
> > Now, if others need this what do you suggest ? I am not really ready
> > yet to load this in a public repo, publish it in clojars, ...
> > Time wise I am squeezed for a week or so.
> >
> > The life time of this plug in hopefully will not be very long
> > if a compiler fix makes it in clojure 1.3.
> 
> Well, it may be useful to others who can't immediately upgrade to 1.3
> for whatever reason. If you just post the implementation of the
> has-corresponding-src? function then I can publish it as a plugin once
> I get Leiningen 1.3.1 out. Or some other Leiningen contributor could
> do it.
> 
> -Phil
> 
> -- 
> 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


I don't understand this method

2010-08-28 Thread HB
Hey,
I came across this method:

(use '[clojure.contrib.lazy-seqs :only (primes)])
(def ordinals-and-primes (map vector (iterate inc 1) primes))

map macro has this format:
(map function collection)
primes is the collection and (iterate inc 1) is the function to apply
on each element of the collection but how vector is applied here?

But I don't understand the previous method, would you please explain
it to me.
Thanks.

-- 
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: creating map throws ArrayIndexOutOfBounds (inconsistently)

2010-08-28 Thread Steve Purcell
On 27 Aug 2010, at 19:40, santervo wrote:

> Also, if i hold AltGr down after typing "{" (AltGr-7) when pressing
> space button, i get this:
> 
> user=> { :a "b" }
> java.lang.Exception: Unable to resolve symbol:  :a in this context
> (NO_SOURCE_FILE:0)


Note from the spaces in the error message that Clojure complaining it can't 
resolve the symbol " :a" -- your AltGr + Space magic is inserting a space-like 
character that Clojure is considering part of a valid symbol name. And since 
the symbol " :a" is not bound to a value in the current context, you get the 
above error message. Most extended characters are valid in symbol names.

-Steve

-- 
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: I don't understand this method

2010-08-28 Thread Stephen C. Gilardi
> (use '[clojure.contrib.lazy-seqs :only (primes)])
> (def ordinals-and-primes (map vector (iterate inc 1) primes))
> 
> map macro has this format:
> (map function collection)

The map function takes a function and any number of collections:

http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/map

> primes is the collection and (iterate inc 1) is the function to apply
> on each element of the collection but how vector is applied here?

In the code you cited, the function is "vector" and the collections are the 
remaining arguments.


http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/vector

> But I don't understand the previous method, would you please explain it to me.

The function produces a lazy sequence of vectors of two items, the first an 
ordinal and the second a prime.

--Steve

-- 
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: I don't understand this method

2010-08-28 Thread nickikt
(iterate inc 1) is not the function vector is

what you do is call vector with the first of primes and (iterate inc
1)

so the first things map does is
(vector 1 2) => [1 2]
(vector 2 3) => [2 3]
(vector 2 5) => [3 5]

meaning the first is the index number the second is the corresponding
prime number

(take 5 ordinals-and-primes) would therefore look like this
([1 2] [2 3]  [3 5] [4 7] [5 11])



On 28 Aug., 16:57, HB  wrote:
> Hey,
> I came across this method:
>
> (use '[clojure.contrib.lazy-seqs :only (primes)])
> (def ordinals-and-primes (map vector (iterate inc 1) primes))
>
> map macro has this format:
> (map function collection)
> primes is the collection and (iterate inc 1) is the function to apply
> on each element of the collection but how vector is applied here?
>
> But I don't understand the previous method, would you please explain
> it to me.
> Thanks.

-- 
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: I don't understand this method

2010-08-28 Thread nickikt
P.S. something I should of have said: map can take 1 function and more
then one collection. Calling the function with the number of arguments
of collections provided

-- 
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: Type hints in protocols and records

2010-08-28 Thread David Nolen
On Sat, Aug 28, 2010 at 9:46 AM, Francesco Bellomi <
francesco.bell...@gmail.com> wrote:

> It is not clear to me if type hints are supported in protocols, and if
> so, how I can use them.
>
> thanks in advance, Francesco
>

Hints are not supported in protocols as far as I can tell. They are
supported in definterface.

David

-- 
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: Some clarifications about let form

2010-08-28 Thread nickikt
yes, but you can not change it if you start a new (let ...).

On 28 Aug., 16:22, HB  wrote:
> So, any time I want to declare a local variable (inside a function for
> example), I use let form.
>
> On Aug 26, 8:26 pm, nickikt  wrote:
>
> > Its for defining look variables (constants) that you use more then
> > once in your form and not have to write it more then once (or
> > calculated it more then once)
> > (let  [r1 (random-int)
> >         r2 (random-int)]
> >         (when (the-same? r1 r2)
> >                  (str r1 " and " r2 " are the same"))
>
> > Write this without let
>
> > (when (the-same? (random-int) (random-int))
> >     (str (random-int)  " and " (random-int) " are the same"))
>
> > does this work? Of course not and thats one reason for let.
>
> > Also it can make your code cleaner.
>
> > (filter even? (take 10 (drop 10 (map inc (iterate inc 1) ;stuff
> > like this can get long
>
> > (let [N-plus-one (map inc (iterate inc 1))
> >        my-range (take 10 (drop 10 N-plus-one))]
> >  (filter even? my-range))
>
> > You can do destructoring in the binding 
> > block.http://clojure.org/special_forms
> > (search destructoring)
>
> > Thats just some stuff, but as soon you have done some stuff yourself
> > it will become clear.
>
> > On 26 Aug., 17:02, HB  wrote:
>
> > > Hey,
> > > Basically, I understand what let form does but I'm not sure when to
> > > use it.
> > > Would you please enlighten me about it? (if possible some typical Java
> > > code and then covert it to Clojure let form).
> > > I really appreciate your time and help.
> > > Thanks.

-- 
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: I don't understand this method

2010-08-28 Thread HB
Ok, I understand what it does but I don't understand -yet- how it is
works.
Why vector and its parameters aren't in ( ) ?
What are the parameters to the vector and what are the parameters to
the map in the example?

On Aug 28, 6:12 pm, nickikt  wrote:
> (iterate inc 1) is not the function vector is
>
> what you do is call vector with the first of primes and (iterate inc
> 1)
>
> so the first things map does is
> (vector 1 2) => [1 2]
> (vector 2 3) => [2 3]
> (vector 2 5) => [3 5]
>
> meaning the first is the index number the second is the corresponding
> prime number
>
> (take 5 ordinals-and-primes) would therefore look like this
> ([1 2] [2 3]  [3 5] [4 7] [5 11])
>
> On 28 Aug., 16:57, HB  wrote:
>
>
>
> > Hey,
> > I came across this method:
>
> > (use '[clojure.contrib.lazy-seqs :only (primes)])
> > (def ordinals-and-primes (map vector (iterate inc 1) primes))
>
> > map macro has this format:
> > (map function collection)
> > primes is the collection and (iterate inc 1) is the function to apply
> > on each element of the collection but how vector is applied here?
>
> > But I don't understand the previous method, would you please explain
> > it to me.
> > Thanks.

-- 
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: Type hints in protocols and records

2010-08-28 Thread Francesco Bellomi
thanks David,

Is the support for type hints in protocols planned for future
releases?

Francesco

On Aug 28, 5:10 pm, David Nolen  wrote:
> On Sat, Aug 28, 2010 at 9:46 AM, Francesco Bellomi <
>
> francesco.bell...@gmail.com> wrote:
> > It is not clear to me if type hints are supported in protocols, and if
> > so, how I can use them.
>
> > thanks in advance, Francesco
>
> Hints are not supported in protocols as far as I can tell. They are
> supported in definterface.
>
> David

-- 
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: misunderstanding collection

2010-08-28 Thread John Newman
Don't forget destructuring:

(for [[a b c] signal]
  (map (partial reduce +) [a b c]))

and,

((fn [[[a b c][d e f]]]
  (map (partial reduce +) [a b c d e f]))
 signal)

While messing around with that, I was wondering if there were some
function that allowed you to destructure on-demand.

Like,
=> (destruct [[[a b c][d e f]]] signal)
(1 2 3 4) (2 3 4 5) (3 4 5 6) (3 4 5 6) (4 5 6 7) (5 6 7 8)

Anything like that exist?

-- 
John

On Wed, Aug 25, 2010 at 10:36 AM, James Reeves  wrote:
> I think you're getting confused.
>
> (map reduce + %) won't work, because the signature of the map function
> is (map func & colls). In other words, the second argument is expected
> to be a collection, but you've put in +, which is a function.
>
> When dealing with nested collections, you may want to work from the
> inside out. So take one of your inner lists:
>
>  s1: (1 2 3 4)
>
>  (reduce + s1)  =>  10
>  (apply + s1)  =>  10
>
> You can use reduce or apply to sum the lists. On the next level, we have:
>
>  s2: ((1 2 3 4) (2 3 4 5) (3 4 5 6))
>
>  (map (partial reduce +) s2)  =>  (10 14 18)
>
> So we're using map to sum each list. (partial reduce +) is just
> another way of writing #(reduce + %).
>
> Next is the final layer:
>
>  signal: (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6 7 8)))
>
>  (map (partial map (partial reduce +)) signal)
>  => ((10 14 18) (18 22 26))
>
> Again, we add a map, and use partial. We could perhaps make this a
> little clearer by using for:
>
>  (for [s signal]
>    (for [c s] (reduce + c)))
>
> - James
>
>
> On 25 August 2010 15:06, Glen Rubin  wrote:
>> After toying around at the REPL I realize that I have been working
>> with a heretofore invalid understanding of collections.  For example,
>> working with the following collection(s):
>>
>> signal:
>> (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6 7 8)))
>>
>> I wanted to sum each individual list: e.g. (1 2 3 4) = (10)
>>
>> I thought I could do this as follows:
>>
>> (map #(map reduce + %) signal)
>>
>> This resulted in an error, so trying to comprehend why I ran the
>> following:
>>
>> (map #(map identity (take 1 %)) signal)
>>
>> which results in,
>> (((1 2 3 4)) ((3 4 5 6)))
>>
>> So, clojure sees 'signal' as 2 collections, whereas I thought it was a
>> single collection.  This makes me concerned that I have been doing
>> everything wrong thus far and getting computational errors. :(  So,
>> how should I sum each individual list in the above collections?
>>
>> --
>> 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: I don't understand this method

2010-08-28 Thread gary ng
On Sat, Aug 28, 2010 at 8:37 AM, HB  wrote:
> Ok, I understand what it does but I don't understand -yet- how it is
> works.
> Why vector and its parameters aren't in ( ) ?
> What are the parameters to the vector and what are the parameters to
> the map in the example?
>
vector is used as a 'function object' for map.  signature of map

map function list1 list2 -> ( (function list1_e1 list2_e1) (function
list1_e2 list2_e2) )

in this invokation, function = vector

-- 
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: misunderstanding collection

2010-08-28 Thread John Newman
A reader macro for destructuring might be nifty, like #[...].

So you could do things like:

(#(map (partial reduce +) #a b c][d e f]]] %]) signal)

Not sure if that'd be the right syntax, but you get the point.

On Sat, Aug 28, 2010 at 12:08 PM, John Newman  wrote:
> Don't forget destructuring:
>
> (for [[a b c] signal]
>  (map (partial reduce +) [a b c]))
>
> and,
>
> ((fn [[[a b c][d e f]]]
>  (map (partial reduce +) [a b c d e f]))
>  signal)
>
> While messing around with that, I was wondering if there were some
> function that allowed you to destructure on-demand.
>
> Like,
> => (destruct [[[a b c][d e f]]] signal)
> (1 2 3 4) (2 3 4 5) (3 4 5 6) (3 4 5 6) (4 5 6 7) (5 6 7 8)
>
> Anything like that exist?
>
> --
> John
>
> On Wed, Aug 25, 2010 at 10:36 AM, James Reeves  
> wrote:
>> I think you're getting confused.
>>
>> (map reduce + %) won't work, because the signature of the map function
>> is (map func & colls). In other words, the second argument is expected
>> to be a collection, but you've put in +, which is a function.
>>
>> When dealing with nested collections, you may want to work from the
>> inside out. So take one of your inner lists:
>>
>>  s1: (1 2 3 4)
>>
>>  (reduce + s1)  =>  10
>>  (apply + s1)  =>  10
>>
>> You can use reduce or apply to sum the lists. On the next level, we have:
>>
>>  s2: ((1 2 3 4) (2 3 4 5) (3 4 5 6))
>>
>>  (map (partial reduce +) s2)  =>  (10 14 18)
>>
>> So we're using map to sum each list. (partial reduce +) is just
>> another way of writing #(reduce + %).
>>
>> Next is the final layer:
>>
>>  signal: (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6 7 8)))
>>
>>  (map (partial map (partial reduce +)) signal)
>>  => ((10 14 18) (18 22 26))
>>
>> Again, we add a map, and use partial. We could perhaps make this a
>> little clearer by using for:
>>
>>  (for [s signal]
>>    (for [c s] (reduce + c)))
>>
>> - James
>>
>>
>> On 25 August 2010 15:06, Glen Rubin  wrote:
>>> After toying around at the REPL I realize that I have been working
>>> with a heretofore invalid understanding of collections.  For example,
>>> working with the following collection(s):
>>>
>>> signal:
>>> (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6 7 8)))
>>>
>>> I wanted to sum each individual list: e.g. (1 2 3 4) = (10)
>>>
>>> I thought I could do this as follows:
>>>
>>> (map #(map reduce + %) signal)
>>>
>>> This resulted in an error, so trying to comprehend why I ran the
>>> following:
>>>
>>> (map #(map identity (take 1 %)) signal)
>>>
>>> which results in,
>>> (((1 2 3 4)) ((3 4 5 6)))
>>>
>>> So, clojure sees 'signal' as 2 collections, whereas I thought it was a
>>> single collection.  This makes me concerned that I have been doing
>>> everything wrong thus far and getting computational errors. :(  So,
>>> how should I sum each individual list in the above collections?
>>>
>>> --
>>> 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
>



-- 
John

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


Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Luke VanderHart
For the past week or two, I've been investigating what it would take
to write something that would allow *.clj  and *.java files to
seamlessly compile together, such that they could be freely intermixed
in a project. I knew it was a difficult problem, but I think the
adoption benefits would be substantial, and the benefits huge for
those stuck in Java-land at work.

My conclusion (and *please* tell me if I'm missing something) is,
unfortunately, that the problem requires full compiler support from
both ends. Either a new compiler needs to be written that can compile
both Clojure and Java, or the existing Java/Clojure compilers need
some fairly extensive patching to make this possible, to share a
dependency graph and symbol tables.

The exception would be if it were possible to simply "pass through"
class references when compiling *.clj files to *.class files, and not
resolve them until run-time (or perhaps a seperate "resolution" phase
of the compile process, for more compile-time safety). I realize this
can't be done for dependencies between Clojure source files, since
macro definitions are required at compile time. But is there any
reason you couldn't do this for Java references from Clojure files?

Then, it'd be very easy - just compile all the Clojure, put the
classes in the classpath, and compile the Java.

Any thoughts?



-- 
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: Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Luke VanderHart
My apologies, the title got cut off. It should be:

"Is it possible in theory to write/modify a Clojure compiler that
doesn't resolve Java references?"

On Aug 28, 12:50 pm, Luke VanderHart 
wrote:
> For the past week or two, I've been investigating what it would take
> to write something that would allow *.clj  and *.java files to
> seamlessly compile together, such that they could be freely intermixed
> in a project. I knew it was a difficult problem, but I think the
> adoption benefits would be substantial, and the benefits huge for
> those stuck in Java-land at work.
>
> My conclusion (and *please* tell me if I'm missing something) is,
> unfortunately, that the problem requires full compiler support from
> both ends. Either a new compiler needs to be written that can compile
> both Clojure and Java, or the existing Java/Clojure compilers need
> some fairly extensive patching to make this possible, to share a
> dependency graph and symbol tables.
>
> The exception would be if it were possible to simply "pass through"
> class references when compiling *.clj files to *.class files, and not
> resolve them until run-time (or perhaps a seperate "resolution" phase
> of the compile process, for more compile-time safety). I realize this
> can't be done for dependencies between Clojure source files, since
> macro definitions are required at compile time. But is there any
> reason you couldn't do this for Java references from Clojure files?
>
> Then, it'd be very easy - just compile all the Clojure, put the
> classes in the classpath, and compile the Java.
>
> Any thoughts?

-- 
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: Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Michał Marczyk
Providing we're happy with disallowing circular dependencies (which is
what javac and clojure.lang.Compiler do anyway), I wonder if it might
be possible to have a build tool invoke the appropriate compilers on a
file-by-file basis, so that if foo.java depends on a class generated
by bar.clj, which in turn depends on the class defined in quux.java,
the compilation order is quux.java => bar.clj (at this stage
target/classes/quux.class already exists) => foo.java (at this stage
all the .class files generated by the compilation of bar.clj are there
in target/classes)...?

Alternatively, I suppose a "two-pass" compilation of Clojure sources
might be possible: (1) compile all Clojure code in a way heavily
reliant on reflection for all method calls on classes outside the base
library, disregarding all type hints and such; (2) compile the Java
code; (3) compile the Clojure code again, hopefully producing more
performant, less reflection-heavy bytecode.

I'm sure I'm missing lots of things, but I'd love to know which, so --
please let me know. :-)

Sincerely,
Michał

-- 
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: Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Peter Schuller
What is the primary goal you're trying to achieve?

Specifically, something that is not addressed by e.g. a maven project
with both clojure and java source (which works seamlessly out of the
box)?

I realize it's not the same thing; perhaps you're after making a
single compiler invocation for performance reasons?

-- 
/ Peter Schuller

-- 
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: Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Luke VanderHart
I'm not just talking about class hierarchy dependencies, but also
reference dependencies.

For example:

Foo.java
class Foo {
   public Bar getBar() {...}
}

Bar.java
class Bar{
public Foo getFoo() {...}
}

This is pretty common in the Java world.

What I'd like to do is have Foo be written in Java, and Bar in Clojure
(for example). Right now, I'm not aware of any way to make this work.

The two-pass compilation does sound like the right track...
interesting idea.



On Aug 28, 1:09 pm, Michał Marczyk  wrote:
> Providing we're happy with disallowing circular dependencies (which is
> what javac and clojure.lang.Compiler do anyway), I wonder if it might
> be possible to have a build tool invoke the appropriate compilers on a
> file-by-file basis, so that if foo.java depends on a class generated
> by bar.clj, which in turn depends on the class defined in quux.java,
> the compilation order is quux.java => bar.clj (at this stage
> target/classes/quux.class already exists) => foo.java (at this stage
> all the .class files generated by the compilation of bar.clj are there
> in target/classes)...?
>
> Alternatively, I suppose a "two-pass" compilation of Clojure sources
> might be possible: (1) compile all Clojure code in a way heavily
> reliant on reflection for all method calls on classes outside the base
> library, disregarding all type hints and such; (2) compile the Java
> code; (3) compile the Clojure code again, hopefully producing more
> performant, less reflection-heavy bytecode.
>
> I'm sure I'm missing lots of things, but I'd love to know which, so --
> please let me know. :-)
>
> Sincerely,
> Michał

-- 
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: Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Michał Marczyk
Oh, I also think that mixing and matching Clojure & Java "modules" --
groups of namespaces / classes which would be share a single build
artifact -- is already fairly simple, whereas I'm not sure if mixing
and matching at the level of individual source files -- with
dependency chains like "foo.java -> bar.clj -> quux.java -> wibble.clj
-> wobble.java -> ..." -- is even desirable. :-) Still, my initial
reaction is that this should be doable at the build tool level, with
the "purely reflective compilation" thing probably being just a crazy
idea.

Sincerely,
Michał

-- 
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: Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Michał Marczyk
On 28 August 2010 19:19, Luke VanderHart  wrote:
> I'm not just talking about class hierarchy dependencies, but also
> reference dependencies.

Ah, I see. In that case, maybe generate placeholders for all the
classes to be implemented in Clojure (with all methods doing something
like "throw new RuntimeException()"), compile those stubs with javac
together with all the Java classes, then discard the placeholder
.class files and compile the Clojure classes?

Sincerely,
Michał

-- 
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: loop/recur stack overflow

2010-08-28 Thread Michael Wood
Hi

On 28 August 2010 02:25, neveu  wrote:
> I implemented the "Flavius Josephus" algorithm from Programming Praxis
> in Clojure using loop/recur. My first version looked like this:
>
> (defn rotate-left
>  ([ln n m]
>     (take n (drop (dec m) (cycle ln
>  ([ln m] (rotate-left ln (count ln) m)))
>
> (defn josephus3 [N M] ;; execute every mth soldier
>  (loop [soldiers (range N)
>         m M
>         deceased '()]
>    (let [n (count soldiers)]
>      (cond
>     (zero? n) deceased
>     true (let [r (rotate-left soldiers n m)
>                dead (cons (first r) deceased)
>                survivors (rest r)]
>            (recur survivors m dead))
>
> This works fine, but I don't really need to count the soldiers every
> pass, it always decreases by 1. So I wrote this version in which n is
> one of the loop parameters:
>
> (defn josephus4 [N M] ;; execute every mth soldier
>  (loop [soldiers (range N)
>         n N
>         m M
>         deceased '()]
>    (cond
>     (zero? n) deceased
>     true (let [r (rotate-left soldiers n m)
>                dead (cons (first r) deceased)
>                survivors (rest r)]
>            (recur survivors (dec n)  m dead)
>
> Both work for small N (e.g. 41) but the second one fails for large
> (41000) N with a stack overflow.
> What am I missing here?

It seems to be the lazyness of rotate-left that causes it.  Not sure
why it doesn't affect josephus3, but breaks josephus4, though.

I tried starting java with a 60k thread stack size to make it easier
to see the problem:

java -Xss60k ...

Then this fails with an n as low as 100:

(defn josephus5 [N M] ;; execute every mth soldier
  (loop [soldiers (range N)
 n N
 m M
 deceased []]
(cond
  (zero? n) deceased
  :else (let [r (rotate-left soldiers n m)
  dead (conj deceased (first r))
  survivors (rest r)]
  (recur survivors (dec n) m dead)

but this works (obviously with the wrong results):

(defn josephus6 [N M] ;; execute every mth soldier
  (loop [soldiers (range N)
 n N
 m M
 deceased []]
(cond
  (zero? n) deceased
  :else (let [r soldiers
  dead (conj deceased (first r))
  survivors (rest r)]
  (recur survivors (dec n) m dead)

I then changed rotate-left and updated josephus as follows:

(defn rotate-left2
  ([ln n m]
   (doall (take n (drop (dec m) (cycle ln)
  ([ln m] (rotate-left ln (count ln) m)))

(defn josephus7 [N M] ;; execute every mth soldier
  (loop [soldiers (range N)
 n N
 m M
 deceased []]
(cond
  (zero? n) deceased
  :else (let [r (rotate-left2 soldiers n m)
  dead (conj deceased (first r))
  survivors (rest r)]
  (recur survivors (dec n) m dead)

and that seems to work.

-- 
Michael Wood 

-- 
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: misunderstanding collection

2010-08-28 Thread Mike Meyer
On Sat, 28 Aug 2010 12:23:04 -0400
John Newman  wrote:

> A reader macro for destructuring might be nifty, like #[...].

I don't think so.

But first, we already have an "on-demand" destructuring facility: let.

> So you could do things like:
> 
> (#(map (partial reduce +) #a b c][d e f]]] %]) signal)

which would be

(#(map (partial reduce +) (let a b c][d e f]]] %] [a b c d e f])) signal)

But using let allows you to put the destructuring first, which I
think is a bit easier to read:

(#(let a b c][d e f]]] %] (map (partial reduce +) [a b c d e f])) signal)

> Not sure if that'd be the right syntax, but you get the point.

I think so. It's sort of like fn and #(, only "backwards". #( lets you
elide the argument list by creating implicit names for them, so it's
as flexible as fn and a bit shorter. #[, on the other hand, elides the
body part of the let, just giving you back the list. This isn't nearly
as flexible as let, since all you get is a list, with no chance to
plug the values into an expression where they'll do the most good.

Another issue: What does this mean:

   #a b c]]] (first signal) [[[d e f]]] (second signal)]

And finally, the names (a, b, etc.) are pointless. Why not just call
them %1, %2, %3 so that you could do:

 #%3 %2 %1][%4 %5 %6]]] signal] -> [c b a d e f]

Except then you have to worry about #[[%1 %1 %2] value], so maybe just
make them all %?

http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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: Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Michael Wood
On 28 August 2010 19:27, Michał Marczyk  wrote:
> On 28 August 2010 19:19, Luke VanderHart  wrote:
>> I'm not just talking about class hierarchy dependencies, but also
>> reference dependencies.
>
> Ah, I see. In that case, maybe generate placeholders for all the
> classes to be implemented in Clojure (with all methods doing something
> like "throw new RuntimeException()"), compile those stubs with javac
> together with all the Java classes, then discard the placeholder
> .class files and compile the Clojure classes?

I believe this discussion has been had before with similar conclusion.

-- 
Michael Wood 

-- 
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: newbie question: where are my log messages going to?

2010-08-28 Thread ataggart
c.c.logging just delegates to the underlying logging implementation.
If you haven't included a separate logging library on your classpath
(e.g., log4j) then it will default to using java.util.logging.  Note
that by default the j.u.logging will output to stdout, and has a
default threshold of INFO. Since the spy macro outputs at debug, you
won't see it unless you change your configuration.

I'd recommend using log4j in preference to the default
java.util.logging. The following is a very basic configuration for
log4j; place it in a file called \"log4j.properties\" and place that
file (and the log4j JAR) on the classpath:

  log4j.rootLogger=WARN, A1
  log4j.logger.user=DEBUG
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  log4j.appender.A1.layout.ConversionPattern=%d %-5p %c: %m%n

The above will print messages to the console for :debug or higher if
one is in the 'user namespace, and :warn or higher in all other
namespaces.



On Aug 27, 7:58 pm, Wei Hsu  wrote:
> Hello,
>
> I'm using the clojure.contrib.logging library (logging/spy seems very
> useful!) but I don't know which file it's writing to. Can you please
> advise?
>
> Thanks,
> Wei

-- 
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: JavaFX and Clojure

2010-08-28 Thread Mark Engelberg
On Fri, Aug 27, 2010 at 11:00 AM, Emeka  wrote:
> Mark,
> Can JavaFX do that?
> Regards,
> Emeka

I don't know that much about JavaFX, but my understanding is that it
was born out of Sun's desire to compete with Adobe's Flash/Flex/AIR.
Similarly, Silverlight is Microsoft's effort to compete in that same
domain.

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


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

2010-08-28 Thread Laurent PETIT
Hi,

2010/8/18 Sean Corfield 

> On Wed, Aug 18, 2010 at 1:36 PM, Greg  wrote:
> > Attached is a screenshot of some code from the wonderful Incanter
> library. I think it's a great illustration of how confusing stacking
> parenthesis can be (there are many functions in there that are like this).
>
> But the indentation is broken in that code already. If the indentation
> were fixed (and the long functions refactored) it would be a lot more
> readable. In order to reformat it with trailing parens, you'd have to
> fix the basic indentation first anyway...
>
> In the blog post's example, I found the println 'parent' straight away
> and the extra vertical whitespace didn't help (sorry but lone closing
> parens just create vertical whitespace for me).
>
> I did find the 4 char indents easier to read than the 2 char indents.
> I wish CCW respected the "displayed tab width" setting as its
> indentation in strict structural mode as I'd rather have 4 spaces than
> 2 but it seems 2 is pretty much the standard around here?
>

You can file an issue, I'll see how easy it is to do it.


>
> > The readability issue occurs when there's a drop in several indentation
> levels after many lines.  This is a problem regardless of what the
> indentation width is, but is certainly made worse by a small indentation
> width.
>
> The readability of the attached screenshot is due to broken
> indentation and the function being too long, IMO.
>
> (and, for background, I'm far more used to programming in C-style
> languages even tho' my Lisp usages dates back to the early 80's - but
> I do find I naturally settle into a different style in Lisp to what I
> use elsewhere)
> --
> Sean A Corfield -- (904) 302-SEAN
> Railo Technologies, Inc. -- http://getrailo.com/
> An Architect's View -- http://corfield.org/
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood
>
> --
> 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: where did I read that?

2010-08-28 Thread evins.mi...@gmail.com


On Aug 28, 1:41 am, Robert McIntyre  wrote:
> I took a stab at it and came up with this:

> is that what you're going for?

I was actually asking how to avoid doing what you did :-). If it's
necessary to do it, that's fine, but I thought I'd ask first, in case
there was a way around it that I hadn't noticed.

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


Re: where did I read that?

2010-08-28 Thread Michał Marczyk
On 28 August 2010 22:14, evins.mi...@gmail.com  wrote:
> I was actually asking how to avoid doing what you did :-). If it's
> necessary to do it, that's fine, but I thought I'd ask first, in case
> there was a way around it that I hadn't noticed.

Well, some level of reimplementation will probably be necessary (if
there is an implementation of an "indexing reader" in the base class
libraries, I'd love to learn about it, but I don't think there is!).

Having said that, you could take Robert's approach and have the proxy
implement a new interface (which you can define through definterface)
to check current offset:

;;; untested...

(definterface IReaderOffset
  (^int readerOffset []))

;;; and the proxy form:
(proxy [java.io.PushbackReader IReaderOffset] [...]
  (read ...)
  (unread ...)
  (readerOffset [] @*current-char-number*))

;;; also, drop the final (fn ...) form from read-with-number --
;;; return the proxy itself instead; maybe also rename
;;; to e.g. indexing-reader?

Then you could use the regular read function and say (.readerOffset
reader-instance) to find out what the current index is. This does at
least have the nice property that you can ignore the extra information
when it's not needed (as you could with multiple return values in CL).

Sincerely,
Michał

-- 
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: misunderstanding collection

2010-08-28 Thread John Newman
> #%3 %2 %1][%4 %5 %6]]] signal] -> [c b a d e f]

Right, the names are superfluous.  So are the extra set of brackets I
guess.  Perhaps even better would be:

(#[[_ _ _][_ _ _]] signal)

Or if you wanted just the third item of the second collection:

(#[[][2]] signal)

Also, I took the signal out of the #[...] form and passed it in as an
argument instead.

No, it is not as flexible as let, but it eliminates having to
duplicate a b c d e h, etc.

I am going to see if I can write a function that does:

=> (destructure [[][2]] signal)
(5 6 7 8)

Or would it have to be a macro?

John



On Sat, Aug 28, 2010 at 2:55 PM, Mike Meyer  wrote:
> On Sat, 28 Aug 2010 12:23:04 -0400
> John Newman  wrote:
>
>> A reader macro for destructuring might be nifty, like #[...].
>
> I don't think so.
>
> But first, we already have an "on-demand" destructuring facility: let.
>
>> So you could do things like:
>>
>> (#(map (partial reduce +) #a b c][d e f]]] %]) signal)
>
> which would be
>
> (#(map (partial reduce +) (let a b c][d e f]]] %] [a b c d e f])) signal)
>
> But using let allows you to put the destructuring first, which I
> think is a bit easier to read:
>
> (#(let a b c][d e f]]] %] (map (partial reduce +) [a b c d e f])) signal)
>
>> Not sure if that'd be the right syntax, but you get the point.
>
> I think so. It's sort of like fn and #(, only "backwards". #( lets you
> elide the argument list by creating implicit names for them, so it's
> as flexible as fn and a bit shorter. #[, on the other hand, elides the
> body part of the let, just giving you back the list. This isn't nearly
> as flexible as let, since all you get is a list, with no chance to
> plug the values into an expression where they'll do the most good.
>
> Another issue: What does this mean:
>
>   #a b c]]] (first signal) [[[d e f]]] (second signal)]
>
> And finally, the names (a, b, etc.) are pointless. Why not just call
> them %1, %2, %3 so that you could do:
>
>     #%3 %2 %1][%4 %5 %6]]] signal] -> [c b a d e f]
>
> Except then you have to worry about #[[%1 %1 %2] value], so maybe just
> make them all %?
>
>        --
> Mike Meyer               http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
>

-- 
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: Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Seth
This sounds very similar to groovyc: 
http://groovyland.wordpress.com/2009/03/03/groovyscalajava/

On Aug 28, 12:50 pm, Luke VanderHart 
wrote:
> For the past week or two, I've been investigating what it would take
> to write something that would allow *.clj  and *.java files to
> seamlessly compile together, such that they could be freely intermixed
> in a project. I knew it was a difficult problem, but I think the
> adoption benefits would be substantial, and the benefits huge for
> those stuck in Java-land at work.
>
> My conclusion (and *please* tell me if I'm missing something) is,
> unfortunately, that the problem requires full compiler support from
> both ends. Either a new compiler needs to be written that can compile
> both Clojure and Java, or the existing Java/Clojure compilers need
> some fairly extensive patching to make this possible, to share a
> dependency graph and symbol tables.
>
> The exception would be if it were possible to simply "pass through"
> class references when compiling *.clj files to *.class files, and not
> resolve them until run-time (or perhaps a seperate "resolution" phase
> of the compile process, for more compile-time safety). I realize this
> can't be done for dependencies between Clojure source files, since
> macro definitions are required at compile time. But is there any
> reason you couldn't do this for Java references from Clojure files?
>
> Then, it'd be very easy - just compile all the Clojure, put the
> classes in the classpath, and compile the Java.
>
> Any thoughts?

-- 
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: misunderstanding collection

2010-08-28 Thread Mike Meyer
On Sat, 28 Aug 2010 18:11:41 -0400
John Newman  wrote:

> > #%3 %2 %1][%4 %5 %6]]] signal] -> [c b a d e f]
> 
> Right, the names are superfluous.  So are the extra set of brackets I
> guess.  Perhaps even better would be:
> 
> (#[[_ _ _][_ _ _]] signal)
> 
> Or if you wanted just the third item of the second collection:
> 
> (#[[][2]] signal)
> Also, I took the signal out of the #[...] form and passed it in as an
> argument instead.

This looks like a generally useful destructuring tweak, but it's
really only useful in the context of #[...], as it elides the
names - which you have to have to use it in current destructurings.

In this case, #[ would be reader macro that swallows the vector it
opens, and returns a function that destructures it's one argument and
returns a vector of the places indicated by the integers in the vector
expression.

I dunno why, but this feels more useful. In more detail:

#[...]: Should evaluate a vector holding either vectors or integers,
and those vectors hold either vectors or integers, etc. and
return a function with a binding that destructures it's
argument (only one allowed). Vectors would work as they do
now; integers would work to select elements in the sequence
that destructuring matches to the enclosing vector. Note that
the :as an & constructs aren't supported here - they don't
make much sense.

The integers denote which positions you wanted to take in the
subvector, so #[[0 2] 1] would turn into something like:

   (fn [[a _ b] c] [a b c])

Of course, we want to let the integer values be calculated at run
time, so that #[[0 2] 1] is equivalent to (let [a 0 b 2 c 1] #[[a b] c])

Duplicates numbers don't cause a problem - they just generate
duplicates in the output. So (#[[0 2] 0] [[a b c d]]) should give
[a c [a b c d]].  That can be done as (fn [[a _ b :as c]] [a b c]).

> No, it is not as flexible as let, but it eliminates having to
> duplicate a b c d e h, etc.

Yup. Or in the new form, and more like #(, even having to worry about
the names.

> I am going to see if I can write a function that does:
> 
> => (destructure [[][2]] signal)
> (5 6 7 8)
> Or would it have to be a macro?

I dunno. Feels like it ought to be a function to me (both arguments
are evaluated on invocation), but you're going to build an fn
invocation and evaluate it, which sort of says macro. Sounds like
fun either way.

http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
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: Is it possible in theory to write/modify a Clojure compiler that doesn't

2010-08-28 Thread Luke VanderHart
Hm, thanks for the reference to that groovy thread... an interesting
read.

I might take a stab at writing a *generate-stubs* patch to Clojure's
compiler, just to see how hard it would be to do.

Out of curiosity, if Rich or anyone on the dev team reads this, is
this the sort of thing that might possibly be a candidate for
inclusion into the main Clojure compiler?

On Aug 28, 7:02 pm, Seth  wrote:
> This sounds very similar to 
> groovyc:http://groovyland.wordpress.com/2009/03/03/groovyscalajava/
>
> On Aug 28, 12:50 pm, Luke VanderHart 
> wrote:
>
>
>
> > For the past week or two, I've been investigating what it would take
> > to write something that would allow *.clj  and *.java files to
> > seamlessly compile together, such that they could be freely intermixed
> > in a project. I knew it was a difficult problem, but I think the
> > adoption benefits would be substantial, and the benefits huge for
> > those stuck in Java-land at work.
>
> > My conclusion (and *please* tell me if I'm missing something) is,
> > unfortunately, that the problem requires full compiler support from
> > both ends. Either a new compiler needs to be written that can compile
> > both Clojure and Java, or the existing Java/Clojure compilers need
> > some fairly extensive patching to make this possible, to share a
> > dependency graph and symbol tables.
>
> > The exception would be if it were possible to simply "pass through"
> > class references when compiling *.clj files to *.class files, and not
> > resolve them until run-time (or perhaps a seperate "resolution" phase
> > of the compile process, for more compile-time safety). I realize this
> > can't be done for dependencies between Clojure source files, since
> > macro definitions are required at compile time. But is there any
> > reason you couldn't do this for Java references from Clojure files?
>
> > Then, it'd be very easy - just compile all the Clojure, put the
> > classes in the classpath, and compile the Java.
>
> > Any thoughts?

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


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

2010-08-28 Thread Sean Corfield
On Sat, Aug 28, 2010 at 1:10 PM, Laurent PETIT  wrote:
>> I did find the 4 char indents easier to read than the 2 char indents.
>> I wish CCW respected the "displayed tab width" setting as its
>> indentation in strict structural mode as I'd rather have 4 spaces than
>> 2 but it seems 2 is pretty much the standard around here?
>
> You can file an issue, I'll see how easy it is to do it.

Thanx Laurent. I guess I was more curious to understand what
"displayed tab width" actually does since if you create the code in
CCW, it has no tabs anyway...?

Here's the issue: http://code.google.com/p/counterclockwise/issues/detail?id=137
-- 
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

-- 
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: misunderstanding collection

2010-08-28 Thread Michał Marczyk
On 29 August 2010 00:11, John Newman  wrote:
> I am going to see if I can write a function that does:
>
> => (destructure [[][2]] signal)
> (5 6 7 8)

Note that the name is already taken by clojure.core/destructure, which
is the engine behind all destructuring done by Clojure macros:

user> (let [[_ [_ _ x]] signal] x)
(5 6 7 8)
user> (destructure `[[~'_ [~'_ ~'_ ~'x]] ~signal])
[vec__2102 (((1 2 3 4) (2 3 4 5) (3 4 5 6)) ((3 4 5 6) (4 5 6 7) (5 6
7 8))) _ (clojure.core/nth vec__2102 0 nil) vec__2103
(clojure.core/nth vec__2102 1 nil) _ (clojure.core/nth vec__2103 0
nil) _ (clojure.core/nth vec__2103 1 nil) x (clojure.core/nth
vec__2103 2 nil)]

Also note that if signal was built out of vectors (and not lists), you
could extract (5 6 7 8) with associative destructuring:

user> (let [{{x 2} 1} signal]
x)
[5 6 7 8]

Sincerely,
Michał

-- 
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: Leiningen 1.3.0 - compile task problem

2010-08-28 Thread lprefontaine
Hi Phil,

there's a tar file at this url with the entire project skeleton:

http://cid-0bd9c1ec7356c53b.office.live.com/browse.aspx/lein-our-classes-only-0.0.1-SNAPSHOT?Bsrc=GetSharingLink&Bpub=SDX.Docs

I added a README file. There is a small twist when building the target.

For those having the same issue and in need of an immediate work around,
I loaded the hook on clojars.

Add this in your dev-dependencies in project.clj:

 [lein-our-classes-only "0.0.1-SNAPSHOT"]

And to insure leiningen is picking up the hook:

:hooks [leiningen.hooks.our-classes-only]

The hook has been built against leiningen 1.3.0 with clojure and contrib 1.2

I re-tested here after removing the artifact from archiva to make sure it's
picked up from clojars.

This hook may work with earlier versions of leiningen and clojure but has
not been tested...

Luc P.


lprefonta...@softaddicts.ca wrote ..
> Fine,
> 
> I'll post entire project in a tar file this week end and will come back with
> the URL before Sunday night. Need to complete urgent work in the garden today 
> :)
> 
> Luc P.
> 
> Phil Hagelberg  wrote ..
> > On Fri, Aug 27, 2010 at 8:06 PM,   wrote:
> > > I got it working with the our-classe-only plug-in.
> > > I tested it on my brain damaged project and it kept only the class files
> > > for which a name space exists in the source folder. The target is now
> > > cleaned up of any external class dependencies.
> > >
> > > Now, if others need this what do you suggest ? I am not really ready
> > > yet to load this in a public repo, publish it in clojars, ...
> > > Time wise I am squeezed for a week or so.
> > >
> > > The life time of this plug in hopefully will not be very long
> > > if a compiler fix makes it in clojure 1.3.
> > 
> > Well, it may be useful to others who can't immediately upgrade to 1.3
> > for whatever reason. If you just post the implementation of the
> > has-corresponding-src? function then I can publish it as a plugin once
> > I get Leiningen 1.3.1 out. Or some other Leiningen contributor could
> > do it.
> > 
> > -Phil
> > 
> > -- 
> > 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: What is the reason Lisp code is not written with closing parenthesis on new lines?

2010-08-28 Thread kyle smith
On Aug 19, 12:08 pm, Brian Goslinga  wrote:
> Here is another trick that works for me in Emacs:  delete most of the
> stack of closing parens, and then spam the ) key until the Emacs
> matches it to the desired opening paren.

this.

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


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

2010-08-28 Thread Michał Marczyk
See also

http://edward.oconnor.cx/elisp/hl-sexp.el

(Highlights the "innermost list structure".)

Sincerely,
Michał

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