Re: Most Elegant Clojure Solution For Wilson's Maze Algorithm

2011-01-27 Thread Christophe Grand
updated with a "rectangular hexgrid" example https://gist.github.com/792959

On Mon, Jan 24, 2011 at 9:07 AM, Christophe Grand wrote:

> Hi Conrad,
>
> Here is my take: https://gist.github.com/792959
>
> Since I despise indices I wrote the core algorithm without them. That gave
> me a maze generation code which can create a maze in any kind of graph. This
> would be fun to run it on the utah teapot for example :-)
>
> Christophe
>
>
> On Thu, Jan 20, 2011 at 8:07 PM, Conrad  wrote:
>
>> Oh yeah, here is the blog post:
>>
>> http://weblog.jamisbuck.org/2011/1/20/maze-generation-wilson-s-algorithm/comments/8627#comment-8627
>>
>> --
>> 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
>>
>
>
>
> --
> Professional: http://cgrand.net/ (fr)
> On Clojure: http://clj-me.cgrand.net/ (en)
>



-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (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 difference between a tail-recursive function and a recursive function using recur?

2011-01-27 Thread Nick Zbinden
Maybe this is intressting for you:
http://stackoverflow.com/questions/4304468/clojure-jvm-7-8-improvements/4306950#4306950

It should answer your question and give some more information.

On Jan 26, 4:04 pm, Harrison Maseko  wrote:
> Hi all,
> I need some help in understanding some basic concept. The book
> Programming Clojure on pages 134 - 136 deals with tail recursion and
> self-recursion using recur. The tail recursive example blows the stack
> while the self-recursive function using recur presented on page 135
> does not. On page 136 the book says that "the critical difference
> between tail-fibo (tail recursion) and recur-fibo (self-recursion
> using recur) is on line 7, where recur replaces the call to fib." Why
> does recur make such a difference in the way the function consumes
> resources? What really is the difference between a tail-recursive
> function and a recursive function using recur?
> Thanks for your help.
> -h.

-- 
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: How does pmap partition its work?

2011-01-27 Thread Rasmus Svensson
2011/1/24 Michael Gardner :
> Suppose I have a sequence of tasks I'd like to parallelize using pmap. The 
> amount of CPU time these tasks require varies greatly; in particular, many of 
> them will require virtually no work. Can I rely on pmap to divide the work 
> efficiently even if there is some pattern to the distribution of easy tasks 
> (e.g. clumped at the beginning, or every nth)? Assume it's not possible to 
> identify the easy tasks beforehand.

If you simply want all tasks to be performed as quickly as possible,
one alternative could be to use an ExecutorService (perhaps one
created with newFixedThreadPool) with its invokeAll method. invokeAll
takes a collection of callables (in clojure terms: you can pass it a
seq of zero-arg functions) and returns a collection of futures. An
ExecutorService could perhaps give you fine-grained control.

I recently wrote a blog post on this; you might find it interesting:
http://blog.raek.se/2011/01/24/executors-in-clojure/

// raek

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


Struct vs. Record: Now and Future

2011-01-27 Thread OGINO Masanori
Hello.

I have two questions:

1. Is there any reason why we should use struct rather than record in
new code without support for old Clojure?

2. If there is nothing, will struct be marked as duplicated someday?

Thank you.

-- 
Name:  OGINO Masanori (荻野 雅紀)
E-mail: masanori.og...@gmail.com

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread Nick Zbinden
Structs are nicer to work with. We should get all the nice stuff you
can do with structs to records then we can mark structs as dublicated.


On Jan 27, 2:43 pm, OGINO Masanori  wrote:
> Hello.
>
> I have two questions:
>
> 1. Is there any reason why we should use struct rather than record in
> new code without support for old Clojure?
>
> 2. If there is nothing, will struct be marked as duplicated someday?
>
> Thank you.
>
> --
> Name:  OGINO Masanori (荻野 雅紀)
> E-mail: masanori.og...@gmail.com

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


Minimalistic ETL

2011-01-27 Thread mk
Hi,

I recently had do do some ETL work (select from database one,
transform, insert into database two). I searched for an existing tool,
but found none that was reasonably simple but Scriptella, which
implements a DSL for this job. Hm. I thought, "Hey, this must be easy
to do with a Lisp". And it was. I wrote a post about my experience
here:

http://michakurt.blogspot.com/2011/01/minimalistic-etl-with-clojure.html

To sum up, with about a screen-page of clojure-code one can implement
a very handy DSL that allows you to write something like this:

(with-query-results source "select * from emp"
  (sql target "insert into employees_names (name) values (?)" [(v?
ename)]))

Very simple, but gets the job done.

I just wanted to share this.

Have fun,

Michael

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread Meikel Brandmeyer
Hi,

On 27 Jan., 14:47, Nick Zbinden  wrote:

> Structs are nicer to work with. We should get all the nice stuff you
> can do with structs to records then we can mark structs as dublicated.

What in particular do you find lacking with records?

Sincerely
Meikel

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread Lee Spector

There was a recent thread on this. Some of the issues that were raised (and for 
which workarounds were presented) were slot defaults, keyword args to 
struct-map, and the fact that defstructs implement IFn. I had also found it 
more elegant to write a macro or two to expand into struct-related code than 
into record-related code. I do think that decent workarounds were presented for 
all of the issues that were raised, but they were workarounds and the built-in 
features of records don't yet include the struct features that were raised. 

 -Lee


On Jan 27, 2011, at 9:18 AM, Meikel Brandmeyer wrote:

> Hi,
> 
> On 27 Jan., 14:47, Nick Zbinden  wrote:
> 
>> Structs are nicer to work with. We should get all the nice stuff you
>> can do with structs to records then we can mark structs as dublicated.
> 
> What in particular do you find lacking with records?
> 
> Sincerely
> Meikel
> 
> -- 
> 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

--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspec...@hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438

-- 
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: Textmash - another IDE for Clojure

2011-01-27 Thread Laurent PETIT
OK, I've released paredit.clj in clojars.
I've also documented the github project, please start from there:

https://github.com/laurentpetit/paredit.clj

Please one word: paredit.clj internals may change in future versions.
Consider this currently as a "black box" tool.

(I've not had time to work on textmash recently, but the README on the
project gives, IMHO, enough instructions to be able to use
paredit.clj)

Cheers,

-- 
Laurent

2011/1/20 Jeff Rose :
> I'd also be interested in clojure paredit as a library.  We've been
> talking about having a stripped down editor for defining synthesizers
> and musical processes inside of Overtone, so some tools to get a
> useful little Clojure editing window would be great.
>
> -Jeff
>
> On Jan 19, 10:44 am, Laurent PETIT  wrote:
>> Hello,
>>
>> 2011/1/18 Olek 
>>
>> > Hi,
>>
>> > Here is a link:http://code.google.com/p/textmash/
>>
>> > Some time ago I have written it in order to help accomplish a task of
>> > creating some paraller processing  system written entirely in Clojure
>> > (it was the map reduce framework from Google).
>>
>> > It was also used with success in other tasks, like editing PHP pages,
>> > Clojure learning, writing small programs in Clojure and some simple
>> > text processing.
>>
>> > Feel free to contribute in bug fixing and improving or maybe even
>> > rewriting it in Clojure (there are not too much lines of code).
>>
>> There's a "task" I have in my todo list since a long time, which is to
>> extract more of ccw "structural editing" and "clojure source code grammar
>> parser" into external projects.
>>
>> Currently, "structural editing" in ccw is already totally decoupled from
>> Eclipse, or even any graphical toolkit (Swing / SWT). The only dependencies
>> of the "clojure grammar definition+parsley parser+structural edition
>> a-la-paredit commands" are clojure and clojure-contrib.
>>
>> If you're interested, I could reprioritize this task and put it near the top
>> of my todo list.
>>
>> As an example, calling a "paredit.clj" command looks like this: call a
>> multimethod named paredit.core/paredit:
>>
>>   * call the parser to get a parsetree. Note that the parsetree follows
>> clojure.xml format.
>>   * give the parsetree to the paredit command, along with the command name
>> and the state of the editor (plain textual content, cursor position,
>> selection length). As a result you'll get a set of text changes to apply to
>> the source code in the form of a list of maps representing deltas: {:keys
>> [offset length text]} (in the original source code, replace the range
>> [offset (+ offset length)[ with text to effectively apply the paredit
>> command you invoked)
>>
>> in code (pseudo-code, not my dev environment at hand), this would look like
>> with the current shape of the code/namespaces:
>>
>> ;; how would we invoke "raise over sexp" to get "(spy foo)" transformed into
>> "foo" with the cursor before "f" char and no current selection
>> (require '[paredit.parser :as p] '[paredit.core :as s])
>> (let [original-code "(spy foo)"
>>       parsetree (p/parse original-code)
>>       raise-over-delta (s/paredit :paredit-raise-sexp parsetree {:text
>> original-code :offset 5 :length 0})]
>>   raise-over-delta)
>> => {:text "(spy foo)" :offset 5 :length 0 :modifs [ {:text "foo" :offset 0
>> :length 9} ]}
>>
>> HTH,
>>
>> --
>> Laurent
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> > The main idea is to take what is best in Eclipse, NetBeans and
>> > ergonomy of Mac OS and put into light tool.
>> > I hope you will enjoy it.
>>
>> > Bye!
>>
>> > --
>> > 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: Struct vs. Record: Now and Future

2011-01-27 Thread Ken Wesson
On Thu, Jan 27, 2011 at 9:34 AM, Lee Spector  wrote:
>
> There was a recent thread on this. Some of the issues that were raised (and 
> for which workarounds were presented) were slot defaults, keyword args to 
> struct-map, and the fact that defstructs implement IFn. I had also found it 
> more elegant to write a macro or two to expand into struct-related code than 
> into record-related code. I do think that decent workarounds were presented 
> for all of the issues that were raised, but they were workarounds and the 
> built-in features of records don't yet include the struct features that were 
> raised.

Fairly easy:

(def record-data (atom {}))

(defmacro defrecord-x [name fields & more]
  (let [fieldnames (vec (take-nth 2 fields))
defaults (vec (take-nth 2 (rest fields)))]
`(let [r# (defrecord ~name ~fieldnames
~'clojure.lang.IFn
(invoke [this# k#] (get this# k#))
(invoke [this# k# n#] (get this# k# n#))
~@more)]
   (swap! record-data update-in [r#] assoc :defaults ~defaults)
   r#)))

(defn record [rec & args]
  (let [d (:defaults (@record-data rec))
n (count args)
a (concat args (drop n d))]
(eval (apply list (quote new) rec a

user=> com.example.sbox=> (defrecord-x Foo [a 1 b 2])
user.Foo
user=> (record Foo 3 4)
{:a 3, :b 4}
user=> (record Foo 3)
{:a 3, :b 2}
user=> (record Foo)
{:a 1, :b 2}
user=> ((record Foo 3) :b)
2
user=> ((record Foo 3) :c)
nil
user=> ((record Foo 3) :c 42)
42

The record function is a bit icky under the hood; the only apparent
way to "apply" variable arguments to a record constructor is to use
eval. But with that, record behaves basically the way struct does. It
can be used with a normal defrecord, with the correct number of
arguments (unlike struct it won't default the remaining fields to nil
with too few arguments, but instead will throw), and it can be used
with a defrecord-x record as shown above.

The defrecord-x macro acts like defrecord, except it also stores
defaults where record will look for them, and the record implements
IFn. The field name vector in defrecord becomes a bindings-like vector
in defrecord-x (no destructuring, sorry). Calling the record with the
wrong number of arguments throws AbstractMethodError rather than
IllegalArgumentException; changing that is a simple but tedious matter
of adding a lot of (invoke [this# _# _# _# ...] (throw ...)) lines to
defrecord-x.

Because of the way that defrecord works, you can still create records
with a custom IFn implementation with defrecord-x. If the same
interface is given two implementations in defrecord, the second one
simply supersedes the first. Since the ~@more is at the end of the
defrecord form in the macro, a user-supplied IFn implementation will
supersede the implementation defrecord-x provides.

Adding a keyfn option to the record function is left as an exercise
for the reader. :)

-- 
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 difference between a tail-recursive function and a recursive function using recur?

2011-01-27 Thread Harrison Maseko
This discussion is enlightening. Thank you all for your instructive
comments.
-h.

On Jan 27, 1:39 pm, Nick Zbinden  wrote:
> Maybe this is intressting for 
> you:http://stackoverflow.com/questions/4304468/clojure-jvm-7-8-improvemen...
>
> It should answer your question and give some more information.
>
> On Jan 26, 4:04 pm, Harrison Maseko  wrote:
>
>
>
> > Hi all,
> > I need some help in understanding some basic concept. The book
> > Programming Clojure on pages 134 - 136 deals with tail recursion and
> > self-recursion using recur. The tail recursive example blows the stack
> > while the self-recursive function using recur presented on page 135
> > does not. On page 136 the book says that "the critical difference
> > between tail-fibo (tail recursion) and recur-fibo (self-recursion
> > using recur) is on line 7, where recur replaces the call to fib." Why
> > does recur make such a difference in the way the function consumes
> > resources? What really is the difference between a tail-recursive
> > function and a recursive function using recur?
> > Thanks for your help.
> > -h.- Hide quoted text -
>
> - Show quoted text -

-- 
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: How does pmap partition its work?

2011-01-27 Thread Michael Gardner
On Jan 27, 2011, at 7:24 AM, Rasmus Svensson wrote:

> If you simply want all tasks to be performed as quickly as possible,
> one alternative could be to use an ExecutorService (perhaps one
> created with newFixedThreadPool) with its invokeAll method. invokeAll
> takes a collection of callables (in clojure terms: you can pass it a
> seq of zero-arg functions) and returns a collection of futures. An
> ExecutorService could perhaps give you fine-grained control.
> 
> I recently wrote a blog post on this; you might find it interesting:
> http://blog.raek.se/2011/01/24/executors-in-clojure/

Thanks for the tip. By coincidence, I just stumbled across ExecutorService 
yesterday via the example at http://clojure.org/concurrent_programming. I'm 
never thrilled about having to use Java APIs directly, but in this case an 
ExecutorService does what I want much better than pmap, and isn't too difficult 
to use.

-- 
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: How does pmap partition its work?

2011-01-27 Thread Ken Wesson
On Thu, Jan 27, 2011 at 2:09 PM, Michael Gardner  wrote:
> On Jan 27, 2011, at 7:24 AM, Rasmus Svensson wrote:
>
>> If you simply want all tasks to be performed as quickly as possible,
>> one alternative could be to use an ExecutorService (perhaps one
>> created with newFixedThreadPool) with its invokeAll method. invokeAll
>> takes a collection of callables (in clojure terms: you can pass it a
>> seq of zero-arg functions) and returns a collection of futures. An
>> ExecutorService could perhaps give you fine-grained control.
>>
>> I recently wrote a blog post on this; you might find it interesting:
>> http://blog.raek.se/2011/01/24/executors-in-clojure/
>
> Thanks for the tip. By coincidence, I just stumbled across ExecutorService 
> yesterday via the example at http://clojure.org/concurrent_programming. I'm 
> never thrilled about having to use Java APIs directly, but in this case an 
> ExecutorService does what I want much better than pmap, and isn't too 
> difficult to use.

Perhaps pmap should be rewritten to use ExecutorService, if that is so.

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread OGINO Masanori
2011/1/27, Lee Spector :
>
> There was a recent thread on this. Some of the issues that were raised (and
> for which workarounds were presented) were slot defaults, keyword args to
> struct-map, and the fact that defstructs implement IFn. I had also found it
> more elegant to write a macro or two to expand into struct-related code than
> into record-related code. I do think that decent workarounds were presented
> for all of the issues that were raised, but they were workarounds and the
> built-in features of records don't yet include the struct features that were
> raised.
>
>  -Lee
>
>
> On Jan 27, 2011, at 9:18 AM, Meikel Brandmeyer wrote:
>
>> Hi,
>>
>> On 27 Jan., 14:47, Nick Zbinden  wrote:
>>
>>> Structs are nicer to work with. We should get all the nice stuff you
>>> can do with structs to records then we can mark structs as dublicated.
>>
>> What in particular do you find lacking with records?
>>
>> Sincerely
>> Meikel
>>
>> --
>> 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
>
> --
> Lee Spector, Professor of Computer Science
> Cognitive Science, Hampshire College
> 893 West Street, Amherst, MA 01002-3359
> lspec...@hampshire.edu, http://hampshire.edu/lspector/
> Phone: 413-559-5352, Fax: 413-559-5438
>
> --
> 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


-- 
Name:  OGINO Masanori (荻野 雅紀)
E-mail: masanori.og...@gmail.com

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread OGINO Masanori
Hello.

Well, record lacks some features in struct for now, I see.
And "defstructs implement IFn" means that we can use struct in the
places need callbacks but record can't, right?

Thank you.

-- 
Name:  OGINO Masanori (荻野 雅紀)
E-mail: masanori.og...@gmail.com

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread David Nolen
2011/1/27 OGINO Masanori 

> Hello.
>
> Well, record lacks some features in struct for now, I see.
> And "defstructs implement IFn" means that we can use struct in the
> places need callbacks but record can't, right?
>
> Thank you.
>
> --
> Name:  OGINO Masanori (荻野 雅紀)
> E-mail: masanori.og...@gmail.com


Extending your record to IFn is easy, just add the invoke method.

(defrecord Foo []
   clojure.lang.IFn
   (invoke [this k] (get this k))

(def x (Foo.))

((assoc x :test 1) :test) ;; 1

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: How does pmap partition its work?

2011-01-27 Thread Rasmus Svensson
2011/1/27 Ken Wesson :
> On Thu, Jan 27, 2011 at 2:09 PM, Michael Gardner  wrote:
>> On Jan 27, 2011, at 7:24 AM, Rasmus Svensson wrote:
>>
>>> If you simply want all tasks to be performed as quickly as possible,
>>> one alternative could be to use an ExecutorService (perhaps one
>>> created with newFixedThreadPool) with its invokeAll method. invokeAll
>>> takes a collection of callables (in clojure terms: you can pass it a
>>> seq of zero-arg functions) and returns a collection of futures. An
>>> ExecutorService could perhaps give you fine-grained control.
>>>
>>> I recently wrote a blog post on this; you might find it interesting:
>>> http://blog.raek.se/2011/01/24/executors-in-clojure/
>>
>> Thanks for the tip. By coincidence, I just stumbled across ExecutorService 
>> yesterday via the example at http://clojure.org/concurrent_programming. I'm 
>> never thrilled about having to use Java APIs directly, but in this case an 
>> ExecutorService does what I want much better than pmap, and isn't too 
>> difficult to use.
>
> Perhaps pmap should be rewritten to use ExecutorService, if that is so.

Actually, 'pmap' is built on top of 'future' which is built on top of
an ExecutorService.

// raek

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread OGINO Masanori
Hello.

Sorry for miss-operation resulting in meaningless post.

> Extending your record to IFn is easy, just add the invoke method.

Oh, it's really easy.
It seems ugly for someone using them like function frequently, but
cool for someone using them like function rarely.

I also read Ken's code, and I feel it powerful. (and complex, a little)
Then, I realize that "code as data" is great :-)

Thank you.

-- 
Name:  OGINO Masanori (荻野 雅紀)
E-mail: masanori.og...@gmail.com

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread Meikel Brandmeyer
Hi,

Am 27.01.2011 um 23:08 schrieb OGINO Masanori:

> It seems ugly for someone using them like function frequently, but
> cool for someone using them like function rarely.

Consider this:

(defn to-factory
  [record]
  (-> record
name
(.replaceAll "([a-z0-9])([A-Z])" "$1-$2")
.toLowerCase
(->> (str "make-"))
symbol))

(defmacro defrecordx
  [name fields & more]
  (let [defaults (into {} (map #(if (vector? %) % [% nil]) fields))
fields   (vec (map #(if (vector? %) (nth % 0) %) fields))]
`(do
   (defrecord ~name ~fields
 clojure.lang.IFn
 (invoke [this# key#] (get this# key#))
 (invoke [this# key# default#] (get this# key# default#))
 ~@more)
   (defn ~(to-factory name)
 [& {:keys ~fields :or ~defaults}]
 (new ~name ~@fields)

Usage example:

(defrecordx Ant [direction [food false]])
(make-ant :direction 0)

vs.

(defstruct ant :direction :food)
(struct-map ant :direction 0 :food false)

I kind of miss the difference in ugliness. If you want default values for your 
structs you also need a factory function. So unless you write the factory 
function for each struct, you'll also need a defstructx.

records will be the way to go. Even today. And I'm yet to see a reasonable 
example, where structs have any advantage over records. records might not be 
perfect at the moment, but neither are structs…

Sincerely
Meikel

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread Mark Engelberg
Records don't have serialization yet, do they?

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread Lee Spector

On Jan 27, 2011, at 6:02 PM, Meikel Brandmeyer wrote:
> 
> I kind of miss the difference in ugliness. If you want default values for 
> your structs you also need a factory function. So unless you write the 
> factory function for each struct, you'll also need a defstructx.

> records will be the way to go. Even today. And I'm yet to see a reasonable 
> example, where structs have any advantage over records. records might not be 
> perfect at the moment, but neither are structs…

In some cases (maybe rare, but they happen to include the one that motivated me 
to raise the issue) nil defaults are sufficient, and structs provide those 
while unadorned records don't.  Several others have also provided nice code to 
recover other struct features like keyword args and IFn implementation (or to 
provide something better) with records, and that's great, but that code isn't 
yet built in.

While your bottom-line usage examples for structs and records are roughly 
equivalent in ugliness your record examples require inclusion of the to-factory 
and defrecordx definitions. I prefer to keep my own code as concise and simple 
as possible, so I'll probably keep using defstruct until roughly equivalent 
functionality is provided for records out of the box.  

 -Lee


-- 
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: How does pmap partition its work?

2011-01-27 Thread Ken Wesson
On Thu, Jan 27, 2011 at 5:05 PM, Rasmus Svensson  wrote:
> 2011/1/27 Ken Wesson :
>> On Thu, Jan 27, 2011 at 2:09 PM, Michael Gardner  wrote:
>>> On Jan 27, 2011, at 7:24 AM, Rasmus Svensson wrote:
>>>
 If you simply want all tasks to be performed as quickly as possible,
 one alternative could be to use an ExecutorService (perhaps one
 created with newFixedThreadPool) with its invokeAll method. invokeAll
 takes a collection of callables (in clojure terms: you can pass it a
 seq of zero-arg functions) and returns a collection of futures. An
 ExecutorService could perhaps give you fine-grained control.

 I recently wrote a blog post on this; you might find it interesting:
 http://blog.raek.se/2011/01/24/executors-in-clojure/
>>>
>>> Thanks for the tip. By coincidence, I just stumbled across ExecutorService 
>>> yesterday via the example at http://clojure.org/concurrent_programming. I'm 
>>> never thrilled about having to use Java APIs directly, but in this case an 
>>> ExecutorService does what I want much better than pmap, and isn't too 
>>> difficult to use.
>>
>> Perhaps pmap should be rewritten to use ExecutorService, if that is so.
>
> Actually, 'pmap' is built on top of 'future' which is built on top of
> an ExecutorService.

Then how come they have different performance characteristics?

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread Ken Wesson
On Thu, Jan 27, 2011 at 6:24 PM, Mark Engelberg
 wrote:
> Records don't have serialization yet, do they?

user=> (defrecord Foo [n])
user.Foo
user=> ((supers Foo) java.io.Serializable)
java.io.Serializable

Looks like they do. And if they didn't,

(defrecord Foo [n]
  java.io.Serializable)

would probably have rectified that.

Unless you need a custom readResolve or writeObject method, of course.

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread Mark Engelberg
So what's the recommended way to serialize, then?  It used to be that
binding *print-dup* to true was the recommended way, but last I checked,
that technique didn't work for things like records.

Remember, it's not just about serializing an individual record, it's about
serializing an arbitrary piece of Clojure data, which might be an aggregate
of a record inside a map inside a vector with metadata, for example.

I got the impression that things regarding serialization were in flux, with
new constructs like records not supporting the old way of doing things, but
not everything converted into the "new way" whatever that is.

If I'm wrong, and this is all now resolved, I'd love to hear about it.

On Thu, Jan 27, 2011 at 6:24 PM, Ken Wesson  wrote:

> On Thu, Jan 27, 2011 at 6:24 PM, Mark Engelberg
>  wrote:
> > Records don't have serialization yet, do they?
>
> user=> (defrecord Foo [n])
> user.Foo
> user=> ((supers Foo) java.io.Serializable)
> java.io.Serializable
>
> Looks like they do. And if they didn't,
>
> (defrecord Foo [n]
>  java.io.Serializable)
>
> would probably have rectified that.
>
> Unless you need a custom readResolve or writeObject method, of course.
>
>

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

Problem Installing VimClojure + lein-vimclojure

2011-01-27 Thread Stefan Rohlfing
Hi all, 

I have been trying to install the Vim pluing VimClojure togheter with the 
lein plugin lein-vimclojure but always get an error message telling me ng 
(the Nailgun client) cannot be found.

This is how my installation went so far:

1) Downloaded  Vimclojure from 
Github and copied it into /.vim/bundle (I am using the Pathogen plugin)

Opened a Clojure file in Vim to verify that features that don’t require the 
Nailgun server, such as syntax highlighting, work as expected.


2) Downloaded  lein-vimclojure 
from Github and added the following dev dependency to Leiningen’s 
project.clj:

:dev-dependencies [[swank-clojure "1.2.1"]
  *[org.clojars.autre/lein-vimclojure "1.0.0"]*]) 


3) Added the following line to .vimrc:

let vimclojure#WantNailgun = 1


4) Started the nailgun server:

*Command*:
$ *lein vimclojure &*
*Output*:
[1] 10509
$ NGServer started on 127.0.0.1, port 2113.

4) Opened a Clojure file from the above Leiningen project in Vim  but 
 received the following error message:

*Error message:
Could not determine the Namespace of the file.
This might have different reasons. Please check, that the ng server
is running with the correct classpath and that the file does not contain
syntax errors. The interactive features will not be enabled, ie. the
keybindings will not be mapped.
Reason:
Error executing Nail! (127)
/bin/bash: ng: command not found*

Apparently, the Nailgun client could not be found.
Does lein-vimclojure also install the Nailgun client or does this plugin 
only set the correct classpath to the Leiningen project?

I already 
downloadedthe
 Nailgun client from kotka.de but have to admit 
that I am not sure how to do a manual install and what to put into .vimrc 
when using VimClojure + lein-vimclojure.
Therefore I hope that someone with a successfull install using 
lein-vimclojure could give me some hints. Any suggestions are highly 
welcome!

Best regards,

Stefan

-- 
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: Struct vs. Record: Now and Future

2011-01-27 Thread Ben Mabey

On 1/27/11 7:24 PM, Ken Wesson wrote:

On Thu, Jan 27, 2011 at 6:24 PM, Mark Engelberg
  wrote:

Records don't have serialization yet, do they?

user=>  (defrecord Foo [n])
user.Foo
user=>  ((supers Foo) java.io.Serializable)
java.io.Serializable

Looks like they do.


I've been serializing/serializing records in my current project quite a 
bit.  The one caveat is that for java to serialize the record a class 
file needs to be compiled for the record.  In my case that just meant I 
had to introduce AOT via leiningen (which does complicate things TBH).


While this serialization has been fine for most of my needs I have quite 
often wanted to be able to use *print-dup* since binary serialization 
seemed overkill in those cases.  Hopefully something like defrecord2 
gets added to clojure at some point to make dealing with records more 
pleasant.


-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: Struct vs. Record: Now and Future

2011-01-27 Thread Ben Mabey

On 1/27/11 8:41 PM, Ben Mabey wrote:

On 1/27/11 7:24 PM, Ken Wesson wrote:

On Thu, Jan 27, 2011 at 6:24 PM, Mark Engelberg
  wrote:

Records don't have serialization yet, do they?

user=>  (defrecord Foo [n])
user.Foo
user=>  ((supers Foo) java.io.Serializable)
java.io.Serializable

Looks like they do.


The one caveat is that for java to serialize the record a class file 
needs to be compiled for the record.
Sorry, I meant to say deserialize... You can serialize it without the 
class file on disk just fine.


--
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: Problem Installing VimClojure + lein-vimclojure

2011-01-27 Thread Stefan Rohlfing
As it seems the Nailgun client has to be installed manually. 

This is what I did so far:

1) 
Downloaded
 the 
Nailgun Client and extracted it.
2) Added the following commands to my ~/.vimrc file:

let vimclojure#WantNailgun = 1
let vimclojure#NailgunClient = 
"/home/sovonex/Clojure/Add-ins/vimclojure-nailgun-client/ng.exe"
let clj_want_gorilla = 1

Opened a Clojure file from my Leiningen project in Vim but received the 
following error message:

*Could not determine the Namespace of the file.*
*[...]*
*Reason:*
*Error executing Nail! (126)*
*/bin/bash: /home/sovonex/Clojure/Add-ins/vimclojure-nailgun-client/ng.exe: 
Permission 
denied*

Pointing to ng.exe in my ~/.vimrc file is definitely not correct as I am not 
using Windows but Kubuntu 10.10.
The missing piece to a successful installation therefore is probably the 
building of the Nailgun client. Does anybody know how to build the Nailgun 
client on Linux when using VimClojure + lein-vimclojure?

Best regards,

Stefan



-- 
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: Problem Installing VimClojure + lein-vimclojure

2011-01-27 Thread Miki


> Does anybody know how to build the Nailgun client on Linux when using 
> VimClojure + lein-vimclojure?
>
> Clone the project from https://bitbucket.org/kotarak/vimclojure. Then "(cd 
client && make)", there should be a client/ng.

HTH,
--
Miki 

-- 
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 Conj 2011?

2011-01-27 Thread Alex Miller
Strange Loop 2011 will be Sept. 18-20th in St. Louis.

More info:
http://thestrangeloop.com/blog/10/11/05/strange-loop-video-schedule

(send-off conj-agent (not (schedule ([[9 18 2011] [9 20 2011]]


On Dec 28 2010, 6:20 pm, Alex Miller  wrote:
> I have not yet set a date forStrangeLoop(although I am talking to
> venues now).  I'm currently looking at Sept 29-30 as the target date.
> JavaOne is the following week.
>
> Alex
>
> On Dec 28, 1:50 pm, scott  wrote:
>
>
>
>
>
>
>
> > fwiw - there was a number of lucky folks who I met atStrangeLoopin
> > St. Louis the week before Conj 2010 who were able to go to both. It
> > seemed like there was quite a bit of overlap in interest of those two
> > events. I could have probably gone to both if there was at least a few
> > weeks time between the two.
>
> > Scott Hickey (no relation)
>
> > On Dec 27, 8:07 pm, Alan Dipert  wrote:
>
> > > Hi,
>
> > > On Mon, Dec 27, 2010 at 7:41 PM, Sean Corfield  
> > > wrote:
> > > > Now that videos are being posted for the 2010 conj, I figured it might
> > > > be worth asking if there has been any discussion about when/where the
> > > > 2011 conj might happen?
>
> > > Conj 2011 will most likely be in either Raleigh or Durham, North
> > > Carolina, and probably will happen around the same time of year as the
> > > last Conj.  We've reviewed all the feedback we've gotten, and are
> > > looking for a venue.  Our hope is to announce the time and place as
> > > soon as possible.
>
> > > Sorry you couldn't make it to the last one, but looking forward to
> > > seeing you at the next one!
> > > Alan
>
> > > > I had a schedule conflict last year (actually a double conflict) so
> > > > I'd like to get this year's event on my calendar as early as possible
> > > > so I don't miss it again :)
> > > > --
> > > > 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-Hidequoted text -
>
> > > - Show quoted text -

-- 
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] fs - file system utilities for Clojure

2011-01-27 Thread Miki


> -I'd rather (copy-tree src dest) worked like "cp -R src dest" (including 
> when dest doesn't exist) rather than "cp -R src/* dest/".
>
Done in 0.6.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

Re: Problem Installing VimClojure + lein-vimclojure

2011-01-27 Thread Stefan Rohlfing
Hi Miki,

Thanks for your help. Now the Nailgun client is running.

Best regards,

Stefan

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

simplistic M/R framework

2011-01-27 Thread Ulises
Hi,

I've just implemented a simplistic map-reduce framework which mimics
the steps involved in the workflow of a Hadoop job. It basically
amounted to implementing a helper function to emit results and the
shuffle-combine step which happens in between a map and a reduce task.
Please consider that I am also still new to Hadoop so the code below
amounts to my interpretation of how a Hadoop job is structured:

(defn emit
  "Helper function to produce intermediate and final results."
  [k v]
  {:k k :v v})

(defn shuffle
  "Shuffle step where all v's from maps get grouped for the reduce steps"
  [ coll ]
  (when (seq coll)
(sort-by :k (reduce
 (fn [acc i]
   (assoc acc (:k i)
  (cons i ((:k i) acc
 {} (flatten coll)

(defn job
  "Equivalent to a hadoop job"
  [map-fn reduce-fn coll]
  (when (seq coll)
(map reduce-fn
 (shuffle (map map-fn coll)

And the necessary wordcount example:

(defn tf-mapper
  [ s ]
  (when (seq s)
(map (fn [i] (emit i 1)) s)))

(defn tf-reducer
  [[k vs]]
  (emit k (reduce (fn [acc {v :v}] (+ acc v)) 0 vs)))

(defn tfidf
  "Calculates the term frequency of each token in the collection"
  [ coll ]
  (when (seq coll)
(job tf-mapper tf-reducer coll)))

The wordcount example does not tokenise the documents/strings, it
assumes that each document is actually a seq, so the collection is
just a seq of seqs.

Am I right to think that replacing calls to map with pmap would make
the framework work in parallel within a single box?

Any feedback always welcome.

Cheers,

U

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


simple map-reduce framework

2011-01-27 Thread Ulises
Hi,

I've just implemented a simple map-reduce framework which mimics the
steps involved in the workflow of a Hadoop job. It basically amounted
to implementing a helper function to emit results and the
shuffle-combine step which happens in between a map and a reduce task.
Please consider that I am also still new to Hadoop so the code below
amounts to my interpretation of how a Hadoop job is structured:

(defn emit
  "Helper function to produce intermediate and final results."
  [k v]
  {:k k :v v})

(defn shuffle
  "Shuffle step where all v's from maps get grouped for the reduce steps"
  [ coll ]
  (when (seq coll)
(sort-by :k (reduce
 (fn [acc i]
   (assoc acc (:k i)
  (cons i ((:k i) acc
 {} (flatten coll)

(defn job
  "Equivalent to a hadoop job"
  [map-fn reduce-fn coll]
  (when (seq coll)
(map reduce-fn
 (shuffle (map map-fn coll)

And the necessary wordcount example:

(defn tf-mapper
  [ s ]
  (when (seq s)
(map (fn [i] (emit i 1)) s)))

(defn tf-reducer
  [[k vs]]
  (emit k (reduce (fn [acc {v :v}] (+ acc v)) 0 vs)))

(defn tf
  "Calculates the term frequency of each token in the collection"
  [ coll ]
  (when (seq coll)
(job tf-mapper tf-reducer coll)))

user> (tf [[:a :b] [:a :b :c] [:c]])
({:k :c, :v 2} {:k :b, :v 2} {:k :a, :v 2})

The wordcount example does not tokenise the documents/strings, it
assumes that each document is actually a seq, so the collection is
just a seq of seqs.

Am I right to think that replacing calls to map with pmap would make
the framework work in parallel within a single box?

Any feedback always welcome.

Cheers,

U

-- 
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: Problem Installing VimClojure + lein-vimclojure

2011-01-27 Thread Meikel Brandmeyer
Hi,

On 28 Jan., 05:15, Stefan Rohlfing  wrote:

> Pointing to ng.exe in my ~/.vimrc file is definitely not correct as I am not
> using Windows but Kubuntu 10.10.
> The missing piece to a successful installation therefore is probably the
> building of the Nailgun client. Does anybody know how to build the Nailgun
> client on Linux when using VimClojure + lein-vimclojure?

These are the instructions from the README contained in the vim plugin
zip:

"Building the Nailgun interface

You have to download and install the client program once. Unless there
is a note in the release notes it will be compatible with future
releases. The client can be downloaded from:
http://kotka.de/projects/vimclojure/vimclojure-nailgun-client-.zip.

After unzipping the archive, simply type make in the subdirectory from
the zip archive. This will compile the nailgun client. For Windows the
client is already pre-compiled as ng.exe.

Configure the location of the nailgun client in your .vimrc:

let vimclojure#NailgunClient = "/path/to/your/ng"

It will default to just ng which should work if the client is on your
PATH.

Note: You might need to check the Makefile for special lib
requirements to compile the nailgun client, eg. on OpenSolaris."

Please let me know if they are unclear in some way or lacking in
information.

Note: there is also a vimclojure google group if you have vimclojure
specific needs.

Sincerely
Meikel

-- 
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: A simple scheme interpreter in clojure

2011-01-27 Thread Andrzej
On Tue, Jan 25, 2011 at 12:52 AM, Andrzej  wrote:
> On Mon, Jan 24, 2011 at 5:50 PM, dennis  wrote:
>> Hi,
>> Yes,i have seen the rscheme.
>>
>> cscheme is just an exercise,it is not practical at all.
>
> So was rscheme. :-) In many respects your implementation is more
> complete than mine.

Pushed it to github:
https://github.com/andrzej-r/rscheme

Andrzej

-- 
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: Problem Installing VimClojure + lein-vimclojure

2011-01-27 Thread Stefan Rohlfing
Hi Meikel,

Thanks for pointing me to the installation instructions. I somehow must have 
missed that part.

I have already joined the VimClojure Group and will probably have some more 
questions while learning how to use this plugin.

Best regards,

Stefan

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