anonymous fns won't work in seesaw...

2012-08-17 Thread Jim - FooBar();

Hi everyone,

I was surprised to discover that anonymous functions will not work in 
seesaw...For example the following throws an exception (wrong number of 
args):


(button :text "Undo"  :listen [:action #(alert "Not implemented!")])

but if i replace the anonymous fn with (fn [e] (alert "Not 
implemented!")) it works just fine!!!the same is true for when defining 
an action like so:


(action :handler (fn [e] (alert "Not implemented!"))
:name "Save"
:tip "Save a game to disk."
:key "menu S")

If it was an anonymous fn it would throw an exception...This is very 
weird for me cos I know that anonymous fns take variable number of args 
so i don't see what the problem is...any explanations/suggestions?


Most of the ssesaw docs show examples using (fn [e] (... ...)) but I'm 
sure I've seen snippets that use #(... ...). What is going on?


Jim

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


ANN Elastisch 1.0.0-RC1

2012-08-17 Thread Michael Klishin
Elastisch is a minimalistic well documented Clojure client for
ElasticSearch.

Minimalistic here means "not introducing any additional abstractions":
Elastisch API closely follows ES API.

Elastisch is not a new project and has been in active use since its first
weeks.
1.0.0-RC1 is reasonably feature complete (with the exception of percolation
and multi-search, they will be added in later RCs), has
most of documentation guides written (http://clojureelasticsearch.info) and
most of the API set in stone.

Elastisch has its own mailing list at
http://groups.google.com/group/clojure-elasticsearch/, targets Clojure
1.3+, licensed under the Eclipse Public License,
tested against 3 Clojure versions and 3 JDKs on travis-ci.org [1]. Updates
and releases are announced on Twitter @clojurewerkz.

Give it a try!

1. http://travis-ci.org/clojurewerkz/elastisch
-- 
MK

-- 
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: anonymous fns won't work in seesaw...

2012-08-17 Thread Bronsa
this is because the #() checks for arguments used inside its body to infer
its arity. in #(alert "..") you don't use any arg so it creates a function
with no argument, such as doing (fn [] ..)
 Il giorno 17/ago/2012 11.50, "Jim - FooBar();"  ha
scritto:

> Hi everyone,
>
> I was surprised to discover that anonymous functions will not work in
> seesaw...For example the following throws an exception (wrong number of
> args):
>
> (button :text "Undo"  :listen [:action #(alert "Not implemented!")])
>
> but if i replace the anonymous fn with (fn [e] (alert "Not implemented!"))
> it works just fine!!!the same is true for when defining an action like so:
>
> (action :handler (fn [e] (alert "Not implemented!"))
> :name "Save"
> :tip "Save a game to disk."
> :key "menu S")
>
> If it was an anonymous fn it would throw an exception...This is very weird
> for me cos I know that anonymous fns take variable number of args so i
> don't see what the problem is...any explanations/suggestions?
>
> Most of the ssesaw docs show examples using (fn [e] (... ...)) but I'm
> sure I've seen snippets that use #(... ...). What is going on?
>
> Jim
>
> --
> 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+unsubscribe@**googlegroups.com
> For more options, visit this group at
> http://groups.google.com/**group/clojure?hl=en
>

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

Re: clojure keyword and mongodb

2012-08-17 Thread Michael Klishin

Vincent escribió:
>
> Dear all ,
>
> Can one store clojure keyword in MongoDB and get it back as keyword. ? 
> How to store Date type using  clojure in MongoDB ? 
> using monger library.
>
>
Monger will convert keyword keys to strings because other languages and 
clients may or may not have the same concept and BSON really does not have 
it anyway.

In Monger session stores, this is a serious limitation because libraries 
like Friend may rely on keywords and namespaced keywords. For that reason,
there are two session stores, one for Clojure-only projects that uses 
Clojure reader serialization and another one for projects that
may need interoperability at the data format level.

See 
https://github.com/michaelklishin/monger/blob/master/src/clojure/monger/ring/session_store.clj

So, the answer is: BSON does not have a type for keywords, store the entire 
map serialized with the reader in a single field.

MK 

-- 
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: anonymous fns won't work in seesaw...

2012-08-17 Thread Jim - FooBar();
aaa ok thanks a lot! I was under the impression that #() created a (fn 
[& args] ...) !


Jim


On 17/08/12 11:46, Bronsa wrote:


this is because the #() checks for arguments used inside its body to 
infer its arity. in #(alert "..") you don't use any arg so it creates 
a function with no argument, such as doing (fn [] ..)


Il giorno 17/ago/2012 11.50, "Jim - FooBar();" > ha scritto:


Hi everyone,

I was surprised to discover that anonymous functions will not work
in seesaw...For example the following throws an exception (wrong
number of args):

(button :text "Undo"  :listen [:action #(alert "Not implemented!")])

but if i replace the anonymous fn with (fn [e] (alert "Not
implemented!")) it works just fine!!!the same is true for when
defining an action like so:

(action :handler (fn [e] (alert "Not implemented!"))
:name "Save"
:tip "Save a game to disk."
:key "menu S")

If it was an anonymous fn it would throw an exception...This is
very weird for me cos I know that anonymous fns take variable
number of args so i don't see what the problem is...any
explanations/suggestions?

Most of the ssesaw docs show examples using (fn [e] (... ...)) but
I'm sure I've seen snippets that use #(... ...). What is going on?

Jim

-- 
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: [ANN] Leiningen 2.0.0-preview8 released

2012-08-17 Thread Bruce Durling
Phil,

On Thu, Aug 16, 2012 at 7:27 PM, Phil Hagelberg  wrote:

> * Fix memory leak in repl task.

Great news. I'm really happy about the OOM fix in REPLy making it in. Thanks!

cheers,
Bruce
-- 
@otfrom | CTO & co-founder @MastodonC | mastodonc.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


I will be doing Intro to Clojure at StrangeLoop

2012-08-17 Thread Stuart Halloway
Late-breaking add to the StrageLoop preconference workshops:

https://thestrangeloop.com/sessions/intro-to-clojure

Cheers,
Stu


Stuart Halloway
Clojure/core
http://clojure.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

Rich added set-agent-send(-off)-executor! and send-via functions

2012-08-17 Thread mnicky
I have some great news: 
https://github.com/clojure/clojure/commit/f5f4faf95051f794c9bfa0315e4457b600c84cef
 
:)

-- 
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: Rich added set-agent-send(-off)-executor! and send-via functions

2012-08-17 Thread Hugo Duncan



mnicky  writes:

> I have some great news: 
> https://github.com/clojure/clojure/commit/f5f4faf95051f794c9bfa0315e4457b600c84cef
>  
> :)

Good news indeed.

Sounds like a good time to plug a little library I wrote to create
executors: https://github.com/pallet/pallet-thread

Hugo

-- 
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: Lazily extract lines from large file

2012-08-17 Thread Ben Smith-Mannschott
On Thu, Aug 16, 2012 at 11:47 PM, David Jacobs  wrote:
> I'm trying to grab 5 lines by their line numbers from a large (> 1GB) file
> with Clojure.
>
> So far I've got:
>
> (defn multi-nth [values indices]
>   (map (partial nth values) indices))
>
> (defn read-lines [file indices]
>   (with-open [rdr (clojure.java.io/reader file)]
> (let [lines (line-seq rdr)]
>   (multi-nth lines indices
>
> Now, (read-lines "my-file" [0]) works without a problem. However, passing in
> [0 1] gives me the following error: "java.lang.RuntimeException:
> java.io.IOException: Stream closed"
>
> It seems that the stream is being closed before I can read the second line
> from the file. Interestingly, if I manually pull out a line from the file
> with something like `(nth lines 200)`, the `multi-nth` call works for all
> values <= 200.
>
> Any idea what's going on?
>
> PS This question is on SO if someone wants points:
> http://stackoverflow.com/questions/11995807/lazily-extract-lines-from-large-file

The lazyness of map is biting you. The result of read-lines will not
have been fully realized before the file is closed.  Also, calling nth
repeatedly is not going to do wonders for efficiency. Try this on for
size:


(ns nthlines.core
  (:require [clojure.java.io :as io]))

(defn multi-nth [values indices]
  (let [matches-index? (set indices)]
(keep-indexed #(when (matches-index? %1) %2) values)))

(defn read-lines [file indices]
  (with-open [r (io/reader file)]
(doall (multi-nth (line-seq r) indices

(comment

  (def words "/Users/bsmith/w/nthlines/words.txt")
  (def nlines 84918960) ;; 856MB with one word per line

  (time (read-lines words [0 1 2 (- nlines 2) (- nlines 1)]))

  ;;=> "Elapsed time: 18778.904 msecs"
  ;;   ("A" "a" "aa" "Zyzomys" "Zyzzogeton")

)

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


Light Table reaches 0.1.0

2012-08-17 Thread mnicky
Another good news today: 
http://www.chris-granger.com/2012/08/17/light-table-reaches-010 :)

-- 
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: Lazily extract lines from large file

2012-08-17 Thread David Jacobs
Okay that's great. Thanks, you guys. Was read-lines only holding onto
the head of the line seq because I bound it in the let statement?

On Fri, Aug 17, 2012 at 11:09 AM, Ben Smith-Mannschott
 wrote:
> On Thu, Aug 16, 2012 at 11:47 PM, David Jacobs  wrote:
>> I'm trying to grab 5 lines by their line numbers from a large (> 1GB) file
>> with Clojure.
>>
>> So far I've got:
>>
>> (defn multi-nth [values indices]
>>   (map (partial nth values) indices))
>>
>> (defn read-lines [file indices]
>>   (with-open [rdr (clojure.java.io/reader file)]
>> (let [lines (line-seq rdr)]
>>   (multi-nth lines indices
>>
>> Now, (read-lines "my-file" [0]) works without a problem. However, passing in
>> [0 1] gives me the following error: "java.lang.RuntimeException:
>> java.io.IOException: Stream closed"
>>
>> It seems that the stream is being closed before I can read the second line
>> from the file. Interestingly, if I manually pull out a line from the file
>> with something like `(nth lines 200)`, the `multi-nth` call works for all
>> values <= 200.
>>
>> Any idea what's going on?
>>
>> PS This question is on SO if someone wants points:
>> http://stackoverflow.com/questions/11995807/lazily-extract-lines-from-large-file
>
> The lazyness of map is biting you. The result of read-lines will not
> have been fully realized before the file is closed.  Also, calling nth
> repeatedly is not going to do wonders for efficiency. Try this on for
> size:
>
>
> (ns nthlines.core
>   (:require [clojure.java.io :as io]))
>
> (defn multi-nth [values indices]
>   (let [matches-index? (set indices)]
> (keep-indexed #(when (matches-index? %1) %2) values)))
>
> (defn read-lines [file indices]
>   (with-open [r (io/reader file)]
> (doall (multi-nth (line-seq r) indices
>
> (comment
>
>   (def words "/Users/bsmith/w/nthlines/words.txt")
>   (def nlines 84918960) ;; 856MB with one word per line
>
>   (time (read-lines words [0 1 2 (- nlines 2) (- nlines 1)]))
>
>   ;;=> "Elapsed time: 18778.904 msecs"
>   ;;   ("A" "a" "aa" "Zyzomys" "Zyzzogeton")
>
> )
>
> // 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

-- 
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: Rich added set-agent-send(-off)-executor! and send-via functions

2012-08-17 Thread Sam Aaron

On 17 Aug 2012, at 18:35, mnicky  wrote:

> I have some great news: 
> https://github.com/clojure/clojure/commit/f5f4faf95051f794c9bfa0315e4457b600c84cef
>  :)

I can totally understand send-via, but set-agent-send-executor! and 
set-agent-send-off-executor! feel dangerous to me like Ruby used to in that if 
they're used by libraries that you include, then there's potential for 
non-deterministic behaviour - i.e. last-one-wins.

Can anyone explain to me why these two fns aren't dangerous and are actually 
useful?

Sam

---
http://sam.aaron.name

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


Follow-up questions on Stuart's InfoQ interview

2012-08-17 Thread Rich Morin
I took a break from reading "Programming Clojure, 2e" to watch Stuart's 
InfoQ interview:

  Stuart Halloway on Datomic, Clojure, 
Reducers
  http://www.infoq.com/interviews/halloway-datomic

I have a couple of questions which I hope folks can answer...

Q: Is there an extended treatment of Clojure "data literals"?

Stuart discussed these, saying that they hit a sweet spot between XML and 
JSON. I'd like to see an extended discussion of this topic, but Google is 
letting me down. Any suggestions?

Q: Are reducers a bit like trampolines?

Stuart talked about the fact that reducers return functions rather than 
values. As I understand it, trampolines also do this until the last bounce. 
I'm wondering whether there are any useful similarities to consider.

-r

-- 
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: Follow-up questions on Stuart's InfoQ interview

2012-08-17 Thread Ben Mabey

On 8/17/12 3:03 PM, Rich Morin wrote:

I took a break from reading "Programming Clojure, 2e" to watch Stuart's
InfoQ interview:

   Stuart Halloway on Datomic, Clojure, 
Reducers
   http://www.infoq.com/interviews/halloway-datomic

I have a couple of questions which I hope folks can answer...

Q: Is there an extended treatment of Clojure "data literals"?

Stuart discussed these, saying that they hit a sweet spot between XML and
JSON. I'd like to see an extended discussion of this topic, but Google is
letting me down. Any suggestions?




I haven't listened to the interview, but he was most likely referring to 
the new "Reader Literals" (a.k.a. tagged literals) support in 1.4.  The 
best place to read about this new feature is in the changes.md of clojure:


https://github.com/clojure/clojure/blob/master/changes.md

I've been using the tagged literal support in my current app and it has 
been very useful.  I've been exporting streams of events as clojure data 
structures that I have been replaying in the system at later times 
(event sourcing).  Being able to represent any arbitrarily object as my 
own custom literal and have it be read in automatically in a language 
supported way makes my life a lot easier. :)


-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: Rich added set-agent-send(-off)-executor! and send-via functions

2012-08-17 Thread Herwig Hochleitner
> I can totally understand send-via, but set-agent-send-executor! and
> set-agent-send-off-executor! feel dangerous to me like Ruby used to in that
> if they're used by libraries that you include, then there's potential for
> non-deterministic behaviour - i.e. last-one-wins.
>
> Can anyone explain to me why these two fns aren't dangerous and are
> actually useful?
>
>
I share your concern, because:

- send and send-off have always had fixed semantics
- with send-via you can now easily roll your own
- if you really want to globally change send / send-off, there is always
alter-var-root
- as far as I'm aware, this would be the first precedent of a setter for a
runtime - global property in clojure core

---

The deeper issue seems to me, that given the lack of first class
environments (for performance reasons) we have no good way to make runtime
configuration composable. *data-readers* raised the same issue and was
piggy-backed onto class loading, which doesn't help with composability, but
is deterministic, at least.

Maybe project jigsaw will be able to help, but they seem to still need
hammock time themselves.

---

Everything said and done, it's still great we can now configure agent
executors. Just don't do it in library code ;)

kind regards

-- 
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 on namespaces and reference resources

2012-08-17 Thread Stephen Compall
On Sun, 2012-08-12 at 19:55 -0700, Hugo Estrada wrote:
> 1. What is the best practice with namespaces? Should I follow
> java-style namespacing names, or does clojure has its own favored
> style?

Most packages simply have a prefix matching the name of the package,
without domain.  This isn't universal, though.

> 2. Is there a reference somewhere out there where I could consult these 
> kinds of questions? 

The best reference is existing project practice; there's a wealth of
free software source code out there.

-- 
Stephen Compall
^aCollection allSatisfy: [:each|aCondition]: less is better

-- 
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 on namespaces and reference resources

2012-08-17 Thread Hugo Estrada
Thanks for answering both questions. I believe I saw some musical package,
so maybe I will look at that code. Thanks so much :)

On Fri, Aug 17, 2012 at 7:20 PM, Stephen Compall
wrote:

> On Sun, 2012-08-12 at 19:55 -0700, Hugo Estrada wrote:
> > 1. What is the best practice with namespaces? Should I follow
> > java-style namespacing names, or does clojure has its own favored
> > style?
>
> Most packages simply have a prefix matching the name of the package,
> without domain.  This isn't universal, though.
>
> > 2. Is there a reference somewhere out there where I could consult these
> > kinds of questions?
>
> The best reference is existing project practice; there's a wealth of
> free software source code out there.
>
> --
> Stephen Compall
> ^aCollection allSatisfy: [:each|aCondition]: less is better
>
>

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

deployment

2012-08-17 Thread George Oliver
hi, 

I'm a Clojure beginner working on a web project and starting to think about 
deployment. Currently I host my project in a local VM and have a small VPS 
for public testing. Looking down the road I'd like a more flexible hosting 
solution. 

It seems like the hosting landscape is changing fast so I'd like to know -- 
how do you deploy your projects 'now'?

So far I've found stuff like:

* A continuum of Clojure support from cloud providers, with some free tiers 
at AWS, Heroku, Openshift, etc.
* tools like lein-beanstalk for hosting apps on Elastic Beanstalk
* libraries like appengine-magic for hosting on GAE
* libraries like pallet for abstracting deployment to multiple cloud 
providers
* many more tools depending on how much 'more Java' you're willing to 
incorporate into your project, for example deploying a WAR in a Tomcat 
container (not even sure I have the lingo right there! :) )
* combining these tools and libraries with CI tools such as Jenkins for a 
complete automatic develop -> build -> deploy solution. 

>From what I've seen, and given that (a) I have a small project (probably 
not more than 5k users eventually) and (b) I'm not a professional 
programmer, but (c) I'd like to manage this in a professional way, it seems 
like a strategy could be:

1. use a tool like lein-beanstalk for public deployment and use simple 
scripts for building
2. in the meantime get familiar with pallet for more flexibility in the 
future
3. eventually deploy using pallet
4. at this point learn a CI tool to fully automate the process. 

What do you think?


thanks, George

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

genuine help needed to speed up minimax algorithm!

2012-08-17 Thread Jim - FooBar();

Hi all,


I really need your advice/help with something I was not expecting! let 
me explain...
after spending almost a week experimenting with different designs for my 
chess minimax algorithm, I settled down on a design that I like. I like 
it because it is rather functional (as opposed to my Java one 3 years 
ago) and at least in theory, most of the job should be done in parallel. 
To be hoenst it never occurred to me to use hash-maps for such a purpose 
until I realised that a purely 'looping via map' -approach would not 
allow me to keep track of the indices easily so even though i would have 
the numeric result easily, I would not know which move this result 
originated from. So, that is where it occurred to me to nest hash-maps 
(instead of seqs via mapping) where I can always keep the originating 
node as a key. I do think my solution is quite elegant and completely in 
line with the functional lessons/obsessions/practices etc etc and  for 
that I'm really happy...Of course you can argue the oppposite - no 
problem about that...:-)


As i was saying the design is pretty and elegant (and 
lazy!)...Unfortunately it is terribly slow! I mean unbelievably 
slow...4-5 min to reach level 4? How am I ever going to train by 
evolutionary means if searching takes so much time is beyond me! Ok 
let's see inside:


the core algorithm is here:
---
(defn game-tree
  "Generate the game tree up to a level lazily (via 'map')."
  [root? dir board successors-fn depth]
  {:node board
   :direction dir
   :children   (if (zero? depth) '()
  ((if root? pmap map) ;start futures at the top via pmap
   #(game-tree false (- dir) % successors-fn (dec depth)) 
(successors-fn board dir)))})


(defn search "The recursion of min-max algorithm."
[eval-fn tree]
(letfn [(minimize [tree]  (if (seq (:children tree))
(apply min
  (map #(maximize %) (:children tree)))
   (eval-fn (:node tree) (:dir tree

(maximize [tree] (if (seq (:children tree))
 (apply max
  (map #(minimize %) (:children tree)))
(eval-fn (:node tree) (:dir tree]
(minimize tree)))

(defn evaluator
  "Returns a fn that expects a tree to start searching using this eval-fn."
  [eval-fn]
  (fn [t]
(search eval-fn t)))

(defn best-next-state
  "Get the best next state for the given game tree."
  [tree eval-fn]
  (->> (:children tree)
   (apply max-key (evaluator eval-fn))
   (:node)))

(defn next-level
 "Generate the next level of the tree using b as the current state."
 [b dir]
(let [team (filter #(= dir (:direction %)) b) ;all the team-mates (with 
same direction)

  team-moves (concat (for [piece team
   coords (core/getMoves piece)]
   (core/dest->Move @curr-game piece coords)))]
 (vec (map core/try-move team-moves
--

As you can see all the usual suspects are there...letfn, pmap, max-key, 
closures etc etc. I thought it was rather clever using pmap when 
branching out from the root node but it turns out it only makes a tiny 
positive difference overall (20-30 sec)...also looking at mu cpus, not 
all of them are working even though there is so much work to be done on 
each branch (where futures were created). Is pmap just too good to be 
true? It is the first time i am using it seriously...


Or am I looking at it completely the wrong way here? I mean, I have done 
this before in Java but it was only for checkers - not chess...we all 
know that chess has a staggering branching factor especially as soon as 
the game opens up a bit. Is it perhaps plain naive hoping to reach at 
least level 6 in reasonable time (< 2min) functionally?


I really want to hear your thoughts especially if someone has done 
anything similar...I honestly wish i had started coding checkers first 
so I could compare with the Java one! at least i would knew whether to 
pursuit it further or not...


thanks a lot for your patience and looking forward to comments :-)

Jim






--
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: genuine help needed to speed up minimax algorithm!

2012-08-17 Thread Lars Nilsson
On Fri, Aug 17, 2012 at 8:47 PM, Jim - FooBar();  wrote:
> As i was saying the design is pretty and elegant (and lazy!)...Unfortunately
> it is terribly slow! I mean unbelievably slow...4-5 min to reach level 4?
> How am I ever going to train by evolutionary means if searching takes so
> much time is beyond me! Ok let's see inside:
[...]
>
> As you can see all the usual suspects are there...letfn, pmap, max-key,
> closures etc etc. I thought it was rather clever using pmap when branching
> out from the root node but it turns out it only makes a tiny positive
> difference overall (20-30 sec)...also looking at mu cpus, not all of them
> are working even though there is so much work to be done on each branch
> (where futures were created). Is pmap just too good to be true? It is the
> first time i am using it seriously...
>
> Or am I looking at it completely the wrong way here? I mean, I have done
> this before in Java but it was only for checkers - not chess...we all know
> that chess has a staggering branching factor especially as soon as the game
> opens up a bit. Is it perhaps plain naive hoping to reach at least level 6
> in reasonable time (< 2min) functionally?

I have no particular insight regarding your code, and how to make
better. However, in general, I'd hazard a guess that high performance
game programs try to avoid memory allocations as much possible.
Preallocated arrays of sufficient sizes, etc, where values are filled
in and iterated over, stuff like that, rather than using functions
that yield temporary data structures that require memory allocation.

Perhaps check out http://www.tckerrigan.com/Chess/TSCP for a
non-optimized and written for clarity C Chess program that does not do
any memory allocation but uses fixed size arrays for the
search/principal variation, etc.

Lars Nilsson

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


library naming convention

2012-08-17 Thread John Gabriele
I've noticed a 3rd-party Clojure library naming convention (well, a
sometimes-recurring pattern at least) that seems pretty sensible:

 1. If a Clojure library wraps or otherwise provides access to a Java
lib, the Clojure lib name might likely be prefixed with "clj-". For
example, clj-time (where, clj-time wraps Joda Time).

 2. If a Clojure library provides its own implementation of a library
(or commonly-reimplemented spec), the Clojure lib name might likely
have a "-clj" suffix (for example, markdown-clj).

 3. (possibly more commonly used for projects which don't wrap an
existing lib, and don't implement a well-known standard) come up with
a new/original/creative/quirky name.

I think the first 2 are handy, because they immediately indicate what
sort of animal you're dealing with. The third, of course, is just
plain fun. :)

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


Re: Lazily extract lines from large file

2012-08-17 Thread Ben Smith-Mannschott
On Fri, Aug 17, 2012 at 10:53 PM, David Jacobs  wrote:
> Okay that's great. Thanks, you guys. Was read-lines only holding onto
> the head of the line seq because I bound it in the let statement?

Yea... I think so... I don't know if that's a case that the compiler's
"locals clearing" handles. In any event, that's why I chose to pass
the lazy sequence directly to the called function without binding it
in a let first.

// Ben

> On Fri, Aug 17, 2012 at 11:09 AM, Ben Smith-Mannschott
>  wrote:
>> On Thu, Aug 16, 2012 at 11:47 PM, David Jacobs  wrote:
>>> I'm trying to grab 5 lines by their line numbers from a large (> 1GB) file
>>> with Clojure.
>>>
>>> So far I've got:
>>>
>>> (defn multi-nth [values indices]
>>>   (map (partial nth values) indices))
>>>
>>> (defn read-lines [file indices]
>>>   (with-open [rdr (clojure.java.io/reader file)]
>>> (let [lines (line-seq rdr)]
>>>   (multi-nth lines indices
>>>
>>> Now, (read-lines "my-file" [0]) works without a problem. However, passing in
>>> [0 1] gives me the following error: "java.lang.RuntimeException:
>>> java.io.IOException: Stream closed"
>>>
>>> It seems that the stream is being closed before I can read the second line
>>> from the file. Interestingly, if I manually pull out a line from the file
>>> with something like `(nth lines 200)`, the `multi-nth` call works for all
>>> values <= 200.
>>>
>>> Any idea what's going on?
>>>
>>> PS This question is on SO if someone wants points:
>>> http://stackoverflow.com/questions/11995807/lazily-extract-lines-from-large-file
>>
>> The lazyness of map is biting you. The result of read-lines will not
>> have been fully realized before the file is closed.  Also, calling nth
>> repeatedly is not going to do wonders for efficiency. Try this on for
>> size:
>>
>>
>> (ns nthlines.core
>>   (:require [clojure.java.io :as io]))
>>
>> (defn multi-nth [values indices]
>>   (let [matches-index? (set indices)]
>> (keep-indexed #(when (matches-index? %1) %2) values)))
>>
>> (defn read-lines [file indices]
>>   (with-open [r (io/reader file)]
>> (doall (multi-nth (line-seq r) indices
>>
>> (comment
>>
>>   (def words "/Users/bsmith/w/nthlines/words.txt")
>>   (def nlines 84918960) ;; 856MB with one word per line
>>
>>   (time (read-lines words [0 1 2 (- nlines 2) (- nlines 1)]))
>>
>>   ;;=> "Elapsed time: 18778.904 msecs"
>>   ;;   ("A" "a" "aa" "Zyzomys" "Zyzzogeton")
>>
>> )
>>
>> // 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
>
> --
> 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