idiomatic use of iterate + cycle ?

2012-09-16 Thread Jim - FooBar();

Hi all,

I'm trying to come up with a way to create a 'tournament' fn that 
basically alternates between players (in turns) and calls soem 'move' fn 
on each. Now, obviously this can be done with loop/recur no problem, 
however perhaps a combination of cycle & iterate is more 
appropriate...so I'm, thinking something along these lines :


(defn tournament [board] ;;no need for players - directions are standard
(vec ;;return a vector of the entire history of this tournament
  (iterate #(chess-best-move (cycle [-1 1]) ) board))) 
;;chess-best-move returns new board



This is obviously not good enough...cycle is in the wrong place! I 
usually use cycle in combination with map rather than iterate and now 
I'm at a loss...I can't exactly use map in this case cos i need the 
calls to 'move' to be chained (passing the new board to the next 
one)...The truth is I can use reduce like this:


(defn tournament [b]
(reduce
  (fn [history dir]
(conj history (chess-best-move dir (peek history
  [b] (take 100 (cycle '(-1 1)  ;;100 moves maximum

I just thought iterate is a better fit...can anyone think how this can 
be done in a one-liner using iterate+cycle or am I at a good path with 
reduce?


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: idiomatic use of iterate + cycle ?

2012-09-16 Thread Jim - FooBar();

Hi again,

It turns out that reduce is exactly what I need...I didn't know this but 
there is a handy 'reduced' fn that makes it easy to terminate from 
within a reduce at any given time. At least this is what i understand 
from the docs...so the final thing looks like this:


(defn tournament
"Starts a tournament between the 2 players (-1 1). If there is no 
winner, returns the entire history (vector) of
 the tournament after 100 moves. If there is a winner, a map will be 
returned containing the :winner and the :history."

[sb depth]
(reduce
  (fn [history dir]
  (let [cb (peek history)
win-dir (jit-referee cb)] ;;just-in-time referee looks for 
missing kings
(if win-dir (reduced {:winner win-dir :history history}) 
;;terminate with this map

(conj history (-> (chess-best-move dir cb depth)
  (:move)
  (try-move))
 [sb] (take 100 (cycle '(-1 1) ;;50 moves each should be enough

Ok, it's certainly not a one-liner but it's pretty clear and readable so 
I'm happy :-)


Jim



On 16/09/12 11:59, Jim - FooBar(); wrote:

Hi all,

I'm trying to come up with a way to create a 'tournament' fn that 
basically alternates between players (in turns) and calls soem 'move' 
fn on each. Now, obviously this can be done with loop/recur no 
problem, however perhaps a combination of cycle & iterate is more 
appropriate...so I'm, thinking something along these lines :


(defn tournament [board] ;;no need for players - directions are standard
(vec ;;return a vector of the entire history of this tournament
  (iterate #(chess-best-move (cycle [-1 1]) ) board))) 
;;chess-best-move returns new board



This is obviously not good enough...cycle is in the wrong place! I 
usually use cycle in combination with map rather than iterate and now 
I'm at a loss...I can't exactly use map in this case cos i need the 
calls to 'move' to be chained (passing the new board to the next 
one)...The truth is I can use reduce like this:


(defn tournament [b]
(reduce
  (fn [history dir]
(conj history (chess-best-move dir (peek history
  [b] (take 100 (cycle '(-1 1)  ;;100 moves maximum

I just thought iterate is a better fit...can anyone think how this can 
be done in a one-liner using iterate+cycle or am I at a good path with 
reduce?


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: [ANN] clj-ns-browser 1.3.0 - the "cool button-row widget" release

2012-09-16 Thread Denis Labaye
On Fri, Sep 14, 2012 at 7:53 PM, Frank Siebenlist <
frank.siebenl...@gmail.com> wrote:

> We're happy to announce the new clj-ns-browser 1.3.0 - the "cool
> button-row widget" - release.
>
> The Clojure Namespace Browser is a GUI-based, Smalltalk-like development
> tool that makes it easy to see, inspect, search, and browse the different
> namespaces, classes/types, and vars of your live Clojure environment. It
> allows you to see the online docs, the source code, the associated
> clojuredocs comments/examples/see-alsos, as well as the var's meta-data and
> values.
>
> Installation is achieved by adding a single line to your project.clj:
>
> ;; Leiningen version 1
> :dev-dependencies [[clj-ns-browser "1.3.0"]]
>
> ;; Leiningen version 2
> :profiles {:dev {:dependencies [[clj-ns-browser "1.3.0"]]}}
>
> After (use 'clj-ns-browser.sdoc), the browser can be invoked at the REPL
> with for example: (sdoc map)
> where "sdoc" is a macro equivalent to and compatible with the venerable
> "clojure.repl/doc" one, but give you just a "little" more info. After the
> browser's GUI is invoked, you can point&click to your heart's content.
>
> A few of the highlights of the new release are:
>
> • upgraded dependencies to latest&greatest (clojure 1.4, seesaw 1.4.2,
> etc.)
>
> • Andy concocted a cool, new, button-row widget that allows for a more
> flexible display of var/class/namespace information.
>
> • syntax highlighting of source code thru use of rsyntaxtextarea
>
> • improved invocation of external web-browser
>
> • many invisible improvements...
>
> There are too many other great features to mention here - please take a
> look at:
> "https://github.com/franks42/clj-ns-browser";
>
> Enjoy,
> Frank Siebenlist
> Andy Fingerhut
>

Congrats !

That's really great, especially for newcomers, the combo: REPL (to modify
the environment) + ns-browser (to view/explore the environment) makes
working with Clojure really comfortable.



>
> --
> 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: idiomatic use of iterate + cycle ?

2012-09-16 Thread Sean Corfield
On Sun, Sep 16, 2012 at 5:15 AM, Jim - FooBar(); wrote:

> It turns out that reduce is exactly what I need...I didn't know this but
> there is a handy 'reduced' fn that makes it easy to terminate from within a
> reduce at any given time. At least this is what i understand from the
> docs...so the final thing looks like this:
>

Wow, that is a super nice addition to 1.5 - I don't remember reading about
that anywhere but it went in back at the end of April:

https://github.com/clojure/clojure/commit/96e8596cfdd29a2bb245d958683ee5fc1353b87a
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: idiomatic use of iterate + cycle ?

2012-09-16 Thread Jim - FooBar();
exactly!!! this is great stuff indeed! I spent all morning trying to 
find more info than the actual docstring but I can't find anything! It 
seems to work as advertised though...very handy but it only works with 
1.5 :-)


(reduce #(if (= 3 %2) (reduced %) (conj % %2)) [] (range 5))

=>[0 1 2]


Jim


On 16/09/12 18:15, Sean Corfield wrote:
On Sun, Sep 16, 2012 at 5:15 AM, Jim - FooBar(); > wrote:


It turns out that reduce is exactly what I need...I didn't know
this but there is a handy 'reduced' fn that makes it easy to
terminate from within a reduce at any given time. At least this is
what i understand from the docs...so the final thing looks like this:


Wow, that is a super nice addition to 1.5 - I don't remember reading 
about that anywhere but it went in back at the end of April:


https://github.com/clojure/clojure/commit/96e8596cfdd29a2bb245d958683ee5fc1353b87a
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
--
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 Drip: A fast JVM launcher

2012-09-16 Thread Denis Labaye
After the bug fix on ubuntu:

denis@zeus:~/.m2$ time drip -cp
./repository/org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main -e
"(reduce + (range 100))"
4950

real0m0.123s
user0m0.032s
sys 0m0.016s
denis@zeus:~/.m2$ time java -cp
./repository/org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main -e
"(reduce + (range 100))"
4950

real0m0.632s
user0m0.828s
sys 0m0.080s


That's very very cool !

On Fri, Sep 14, 2012 at 6:59 AM, Jack Moffitt  wrote:

> >> I did just that, but I don't get any speedup with leiningen.  All I can
> >> see is that after every leiningen command, "drip ps" shows one process
> >> more.  For example:
> >
> > This is also happening for me. Is there some way to configure drip to
> > ignore certain arguments?
>
> I added a way to specify options to ignore, which fixes the problem of
> it launching multiple JVMs. Unfortunately, lein never works after the
> first invocation; I'm guessing it's not happy about the trampoline
> file disappearing and not coming back after the first invocation.
>
> Here's the non-working patch if anyone wants to try:
> https://gist.github.com/3719891
>
> Any ideas?
>
> jack.
>
> --
> 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 Drip: A fast JVM launcher

2012-09-16 Thread Michael Klishin
Denis Labaye:

After the bug fix on ubuntu: 
>
> denis@zeus:~/.m2$ time drip -cp 
> ./repository/org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main -e 
> "(reduce + (range 100))"
> 4950
>
> real0m0.123s
> user0m0.032s
> sys 0m0.016s
> denis@zeus:~/.m2$ time java -cp 
> ./repository/org/clojure/clojure/1.4.0/clojure-1.4.0.jar clojure.main -e 
> "(reduce + (range 100))"
> 4950
>
> real0m0.632s
> user0m0.828s
> sys 0m0.080s
>
>
> That's very very cool !
>
>
I am still seeing a new JVM being started every drip run. I am testing Drip 
0.1.7 with Lein 2 by running lein test 5 times in a row with 
LEIN_JAVA_CMD=drip in ~/.lein/leinrc, OS X, JDK 7.

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

Nested functions on #() reader

2012-09-16 Thread vhsmaia
Hello. I'm new here, so, not sure if those were already posted. But why is 
this not used? An example would be:
#(%a %%b %%%c) would be the same as (fn [a] (fn [b] (fn [c] (a b c)))

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

Multi Method Namespace Structure

2012-09-16 Thread rod naph
Hi, I'm trying to use multi-methods, with the implementations broken over a 
few namespaces, but am a little confused as to the best way to structure 
this.  At the moment i have this in two namespaces/files...

(ns jiff.vcs)
(defmulti jiff-seq :vcs)

(ns jiff.svn (:use jiff.vcs))
;; svn impl...

But to use this the caller needs to know to import jiff.vcs, and then any 
implementation they'd like to use.  I'd prefer it if the impls were not 
visible though, and the user only need import the jiff.vcs namespace and 
then they get access to everything that's currently been implemented.

Is there a better way to structure my namespaces to allow this?

Project is here: https://github.com/rodnaph/jiff

Any advice appreciated, thanks!

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

slime-ritz help needed on clean emacs 24.2.1 new setup

2012-09-16 Thread sal
Hi Everyone,
  Trying to setup emacs 24.2 on mac osx clean setup, nothing else.

  clojure-mode 20120808 installed  Major mode for Clojure code 
[source: github]
  nrepl 20120912.248 installed  Client for Clojure nREPL [source: 
github]
  nrepl-ritz 20120913 installed  nrepl extensions for ritz [source: 
github]
  slime-ritz 20120914 installed  slime extensions for ritz [source: 
github]

I have following things installed

and my .emacs looks like
(require 'package)
(add-to-list 'package-archives
  '("marmalade" . "http://marmalade-repo.org/packages/";) t)
(add-to-list 'package-archives
  '("melpa" . "http://melpa.milkbox.net/packages/";) t)
(package-initialize)


i am able to run clojure-jack-in and start swank server, but never see the 
command slime-mode, slime-connect in emacs.

Can someone point me to some other setup or how to fix this.

Thanks
 Sal

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

println inside a inside a for print some "nil values"

2012-09-16 Thread Giuliani Sanches
Hi guys.

In this code

http://pastebin.com/tJNhabJw

When the second case is executed the output is:

The output is (Juice
Sandwich
nil Banana
nil nil)

Where these "nil" come from ?

Thanks

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

Re: Clojurescript/facebook JS-SDK

2012-09-16 Thread Kris Jenkins
Hi Mimmo,

I don't really have an answer to this, but I share your interest in the 
question.

The only thing I can suggest is taking a look at 
Jayq. 
It's a ClojureScript wrapper around jQuery. It wrapping a large & complex 
existing JavaScript API, successfully, so it might be a good place to look 
for guidance/inspiration...

Kris

On Wednesday, 12 September 2012 19:24:52 UTC+1, Mimmo Cosenza wrote:
>
> Hi everyone, I'm pretty new with cljs and perhaps I'm asking something 
> very stupid. I'd like to know if integrating facebook js-sdk with cljs 
> could be a feaseable approach to be able to write fb app using clojure on 
> both fe and be side. I don't know if fb js-sdk is google-closure compatible 
> with :advance closure compilation option (I even don't hope that), but by 
> what I understood about external js library it should be possible anyway. 
> I'm completely out of my mind?
>
> thanx for you attention
>
> Mimmo
>
>
>

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

Using println inside a for print out some "nil"

2012-09-16 Thread Giuliani Sanches
Hi guys,

Maybe the subject does not give a got clue about  my question, so here's a 
snippet of code:

http://pastebin.com/tJNhabJw 

Could you please help me to understand why in the second case the output 
is (Juice Sandwich nil Banana nil nil) ? Where these "nil" came from ?

Thank you! 

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

Re: Immutant 0.3.0 released

2012-09-16 Thread Ali M
Greetings Jim

Can you please elaborate more on this line ... maybe give examples 

On Wednesday, September 12, 2012 3:45:56 AM UTC+2, Jim Crossley wrote:
>
> ...
> For certain applications, I would recommend using libraries to access 
> external processes like Memcached, RabbitMQ, or cron, for example. And for 
> others, I would recommend an app server.
> ...
>
> Thanks,
> 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: Question: Looking at Noir code - hey, are those singletons?

2012-09-16 Thread Sung Pae
On Thu, Sep 13, 2012 at 12:56:47PM -0400, Chas Emerick wrote:

> One of the great advantages of Ring (and other purely functional bits
> that stack on top, like Compojure, Bishop, etc) is that its handlers
> are readily composable. Among other things, this means that way you
> compose handlers from two different namespaces in the same app is
> fundamentally no different than the way you compose handlers from
> N different applications (which can come from different projects,
> maintained by different teams, etc). Combined with something like
> Compojure's nested routes[1], this is a simple and powerful way to
> build modular web apps and services by default.

Coming from the Ruby world, I was initially drawn to Noir by it's
Sinatra-esque API, but like the OP, I was a little dismayed by the magic
of defpage and the like. I am, after all, coming to Clojure so that I
can be explicit about my data and my state.

Thankfully, Noir is a fairly thin layer over Ring, Compojure, and
Hiccup, so creating routes and composing them in just the way Chas
mentions was easy and quite satisfying.

Of course, Noir is not thereby superfluous; the end result for my app
is still a namespaced var holding an atom of the app's handlers. It is
explicit and more flexible, but it took more time and typing than a
beginner may want to invest.

guns

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


Re: Is anyone relying on the js* special form?

2012-09-16 Thread Alexander Hudek
I've used it in conjunction with goog/base due to a problem with 
simple/advanced compilation. I'm not sure if things have changed since I 
encountered this problem, or if there is something else I'm doing wrong. 
See the code and comment below. The deactivated "this-as" code only worked 
with whitespace compilation.

(goog-extend
NoEnterHandler goog.editor.Plugin
([]
  ; simple and advanced compilation require a literal 'this' in goog.base
  ; js* is supposed to be a compiler detail.
#_(this-as this (goog/base this))
(goog/base (js* "this")))

(getTrogClassId [] "NoEnterHandler")

(isSupportedCommand [c] false)

(handleKeyDown
[e]
(if (= (.-keyCode e) key-codes/ENTER) (.preventDefault e

The goog.extend macro is copied from

https://github.com/netguy204/MOVE/blob/master/src/move/macros.clj

On Wednesday, September 12, 2012 7:12:21 PM UTC-4, Brandon Bloom wrote:
>
> I'm exploring some changes to the ClojureScript compiler backend and am 
> curious if anyone is using one particular implementation detail: The js* 
> special form.
>
> Note that I'm not asking about the js/ pseudo-namespace, only the js* 
> special form.
>
> Are you using it in your ClojureScript projects? If so, what for?
>

-- 
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 Drip: A fast JVM launcher

2012-09-16 Thread Denis Labaye
On Sun, Sep 16, 2012 at 8:59 PM, Michael Klishin <
michael.s.klis...@gmail.com> wrote:

> Denis Labaye:
>
> After the bug fix on ubuntu:
>>
>> denis@zeus:~/.m2$ time drip -cp ./repository/org/clojure/**
>> clojure/1.4.0/clojure-1.4.0.**jar clojure.main -e "(reduce + (range
>> 100))"
>> 4950
>>
>> real0m0.123s
>> user0m0.032s
>> sys 0m0.016s
>> denis@zeus:~/.m2$ time java -cp ./repository/org/clojure/**
>> clojure/1.4.0/clojure-1.4.0.**jar clojure.main -e "(reduce + (range
>> 100))"
>> 4950
>>
>> real0m0.632s
>> user0m0.828s
>> sys 0m0.080s
>>
>>
>> That's very very cool !
>>
>>
> I am still seeing a new JVM being started every drip run. I am testing
> Drip 0.1.7 with Lein 2 by running lein test 5 times in a row with
> LEIN_JAVA_CMD=drip in ~/.lein/leinrc, OS X, JDK 7.
>

No multiple JVM started for me (at least in my trivial tests)

drip 0.1.7




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

-- 
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: Using println inside a for print out some "nil"

2012-09-16 Thread Andy Fingerhut
println is a function that has the side effect of printing a string to the 
output, but it also has a return value of nil.

When working at the REPL, these can sometimes be mingled together due to the 
order of evaluation.

If you want to do something like 'for' but only for the purposes of side 
effects, and the return value is unimportant, try 'doseq' instead.

Andy

On Sep 13, 2012, at 6:54 PM, Giuliani Sanches wrote:

> Hi guys,
> 
> Maybe the subject does not give a got clue about  my question, so here's a 
> snippet of code:
> 
> http://pastebin.com/tJNhabJw 
> 
> Could you please help me to understand why in the second case the output is 
> (Juice Sandwich nil Banana nil nil) ? Where these "nil" came from ?
> 
> Thank you! 

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


Re: Can't start Rhino repl for ClojureScript

2012-09-16 Thread Stuart Sierra
Leiningen works under Windows (as lein.bat). I'm not sure if it works under 
Cygwin.

I've encountered problems in the past with Cygwin because the Java 
executable is the Windows version, using Windows path-separator characters, 
but scripts expect Unix-style path separators.

Try downloading Leiningen for Windows and running from the Windows shell.

-S

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

Why do Clojure collections have (seq) rather than supporting the ISeq interface directly?

2012-09-16 Thread Alex Dowad
...Just trying to understand the rationale between Clojure's design here. 
As I gradually get deeper into Clojure, I've been highly impressed by how 
well thought-out everything is, so I'm sure there is a very good reason for 
this one too. The question is:

Why are Clojure's built-in collections *seqable* rather than being *seqs*?

Or equivalently:

Why do Clojure's built-in collections support (seq) rather than (first) and 
(rest)?

A few possible reasons I can think of:

1. From reading the implementation of classes like PersistentHashMap, I can 
see that running over a map using a seq (basically a persistent cursor into 
the map) should be significantly faster, and create less garbage, then 
generating a succession of smaller and smaller maps (right down to an empty 
one) would be.
2. (seq) returns nil on an empty collection, which can naturally be used in 
a conditional.
3. (seq) works on things like Java arrays and Strings which can't be 
modified to implement ISeq.

Have I missed any? More importantly, can someone close to the core team 
identify *which* of these was the deciding factor in this design decision?

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

Modelling for DAG with identity map - or not?

2012-09-16 Thread Patrik Sundberg
Hi,

I'm a newbie at clojure and functional programming and I'm toying with the 
idea of switching a project of mine to clojure. Sorry for a long first 
post, and it may also be a bit abstract - but you never know before trying 
:)

In my previous OO prototype the domain is modelled via 2 basic principles:
1. an implicit DAG (directed acyclic graph) is created at runtime as some 
calculations are performed. i.e. calc 1 depends on values X and Y, so build 
that graph. then X depends on A and B, etc.
2. the nodes in the graph are unique, e.g. handled via an identity map. 
i.e. if calculation 1 depends on the leaf 1 and then calculation 2 also 
depends on leaf 1 they point to the same leaf 1. unique in this case means 
either via some unique ID.

The graph fulfils 2 main functions and 1 minor:
1. allows me to start from a given node X and find any nodes below that are 
of type Y (or has name Z or any other node based predicate)
2. do something to value of node X and see how that propagates through the 
graph
3. (minor) only the nodes needing refreshing gets recalculated (as a result 
of 2). i.e. graph works as an implicit and automatic cache. a nice to have 
but performance not my main goal.

My existing prototype is done in jruby via a lot of meta programming and 
voodoo. It still doesn't quite flow perfectly naturally since I can't bend 
the syntax far enough (i.e. the user has to be aware of the existence of 
nodes and distinguish between a node and it's value when I'd like to keep 
all the graph/node stuff under wraps as far as the user is concerned). I 
can see how doing it in clojure I could get all the way to the kind of user 
API I'm looking for (plus performance and java interop would probably be 
better).

The actual problem domain is modelling financial instruments if that makes 
it any more concrete. I.e. the price of security 1 depends on the price of 
security 2 to 1000, out of which half  depends (in different ways) on the 
price of security 1001, which depends on paramter X the input Y of type A. 
Find any dependencies of type A starting at price of security 1, move 
paramter X of any such dependency by epsilon and check the effect of price 
of security 1, only recalculating the parts needed (i.e. security 1001, 
half of the 2-1000 secs, and security 1).

My initial instinct is a design involving 1 graph per thread to start with 
(i.e. using a Var for graph and identity cache), the graph consisting of 
nodes and edges that can be represented as either records or maps, and 
functions attached to nodes for refreshing their values when a child has 
changed (using the values of child nodes). The graph get's created 
implicitly on first evaluation (and extended as one evaluates more nodes, 
and parts could end up rebuilding themselves if one changes some parameters 
etc). I can kind of see how I'd do it. 

A few things bothers me or are unclear:
1. There's quite a lot of state, which feels a bit unclojurey.
2. Implementing the "same" function for different types is not quite clear 
what best way to go is. Looks like multimethods perhaps. i.e. i'd like to 
just call (price secA) and (price secB) and the right thing happens even 
though completely different functions/parts of the graph get evaluated 
depending on the "type" of secA and secB. I don't think I need/want a 
record per type of security so protocols not looking like the way to go.

I'm asking myself though if there's a more functional design for 
accomplishing the same goals? My main goals are to do things consistently 
so that changing a value X propagates properly, and being able to find 
dependencies of a given value. A DAG+identity map is my first take, but 
there may be something more natural for FP I'm completely missing.

Thanks,
Patrik

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

Re: Is anyone relying on the js* special form?

2012-09-16 Thread Brandon Bloom
Would it be correct to interpret this as another vote for JVM Clojure's 
proxy macro?

On Wednesday, September 12, 2012 7:16:37 PM UTC-7, Alexander Hudek wrote:
>
> I've used it in conjunction with goog/base due to a problem with 
> simple/advanced compilation. I'm not sure if things have changed since I 
> encountered this problem, or if there is something else I'm doing wrong. 
> See the code and comment below. The deactivated "this-as" code only worked 
> with whitespace compilation.
>
> (goog-extend
> NoEnterHandler goog.editor.Plugin
> ([]
>   ; simple and advanced compilation require a literal 'this' in goog.base
>   ; js* is supposed to be a compiler detail.
> #_(this-as this (goog/base this))
> (goog/base (js* "this")))
>
> (getTrogClassId [] "NoEnterHandler")
>
> (isSupportedCommand [c] false)
>
> (handleKeyDown
> [e]
> (if (= (.-keyCode e) key-codes/ENTER) (.preventDefault e
>
> The goog.extend macro is copied from
>
> https://github.com/netguy204/MOVE/blob/master/src/move/macros.clj
>
> On Wednesday, September 12, 2012 7:12:21 PM UTC-4, Brandon Bloom wrote:
>>
>> I'm exploring some changes to the ClojureScript compiler backend and am 
>> curious if anyone is using one particular implementation detail: The js* 
>> special form.
>>
>> Note that I'm not asking about the js/ pseudo-namespace, only the js* 
>> special form.
>>
>> Are you using it in your ClojureScript projects? If so, what for?
>>
>

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

Calling Clojurescript code from Clojure

2012-09-16 Thread Brent Millare
Background: I'm developing a web based development environment.

Problem: Is there a way to evaluate clojurescript code from clojure? I need 
to call clojurescript code like (load-file "foo.cljs") from clojure. Note 
this is different then starting a clojurescript repl and typing in 
(load-file "foo.cljs"). I'm already doing this. It needs to be more like 
(eval-cljs cljs-foo-form). How does one do this?

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

Re: Is anyone relying on the js* special form?

2012-09-16 Thread Alexander Hudek
>From your description of how proxy would work, yes.

On Sunday, September 16, 2012 6:48:44 PM UTC-4, Brandon Bloom wrote:
>
> Would it be correct to interpret this as another vote for JVM Clojure's 
> proxy macro?
>
> On Wednesday, September 12, 2012 7:16:37 PM UTC-7, Alexander Hudek wrote:
>>
>> I've used it in conjunction with goog/base due to a problem with 
>> simple/advanced compilation. I'm not sure if things have changed since I 
>> encountered this problem, or if there is something else I'm doing wrong. 
>> See the code and comment below. The deactivated "this-as" code only worked 
>> with whitespace compilation.
>>
>> (goog-extend
>> NoEnterHandler goog.editor.Plugin
>> ([]
>>   ; simple and advanced compilation require a literal 'this' in goog.base
>>   ; js* is supposed to be a compiler detail.
>> #_(this-as this (goog/base this))
>> (goog/base (js* "this")))
>>
>> (getTrogClassId [] "NoEnterHandler")
>>
>> (isSupportedCommand [c] false)
>>
>> (handleKeyDown
>> [e]
>> (if (= (.-keyCode e) key-codes/ENTER) (.preventDefault e
>>
>> The goog.extend macro is copied from
>>
>> https://github.com/netguy204/MOVE/blob/master/src/move/macros.clj
>>
>> On Wednesday, September 12, 2012 7:12:21 PM UTC-4, Brandon Bloom wrote:
>>>
>>> I'm exploring some changes to the ClojureScript compiler backend and am 
>>> curious if anyone is using one particular implementation detail: The js* 
>>> special form.
>>>
>>> Note that I'm not asking about the js/ pseudo-namespace, only the js* 
>>> special form.
>>>
>>> Are you using it in your ClojureScript projects? If so, what for?
>>>
>>

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

Some feedback on clojurescript

2012-09-16 Thread Irakli Gozalishvili
Hi Folks, 

I'm still new to clojurescript, but I thought I would share with you some of 
the annoyances that person
person coming from JS (like myself) will likely run into:

http://jeditoolkit.com/2012/09/16/coljurescript-feedback.html 


Regards
--
Irakli Gozalishvili
Web: http://www.jeditoolkit.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: Why do Clojure collections have (seq) rather than supporting the ISeq interface directly?

2012-09-16 Thread Stuart Sierra
Mostly efficiency. A Seq generally gives you access to `first` and `rest` 
in constant time. Vectors, to take one example, cannot give you `rest` 
efficiently, but a Seq backed by the vector can.

Clojure lists are implemented as singly-linked lists, which do have 
first/rest pointers, so they implement ISeq directly.
-S

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

core.logic - DCG

2012-09-16 Thread Alexsandro Soares
Hi,

  I'm trying to write a small parser using DCG, but when I use the code
below

-- parser.clj ---
(ns compiler.parser
  (:refer-clojure :exclude [==])
  (:use [clojure.core.logic]
[clojure.core.logic.dcg] )
)

(def-->e token [tg x]
  ([_ ?tk] [?tk]
 (!dcg
   (project [?tk]
  (== (= (?tk :tag) tg) true)

(declare expr1 term term term1 factor)

(def-->e expr [e]
   ([?e1] (fresh [t] (term t) (expr1 t ?e1

(def-->e expr1 [t e]
   ([t1 ?e1] (fresh [tk t2]
  (token '+ tk) (term t2) (expr1 {:binop '+ t1 t2} ?e1)))
   ([_ t] []))

(def-->e term [t]
  ([?t1] (fresh [f] (factor f) (term1 f ?t1

(def-->e term1 [f t]
   ([f1 ?t1] (fresh [tk f2]
  (token '* tk) (factor f2) (term1 {:binop '* f1 f2} ?t1)))
   ([_ f] []))

(def-->e factor [tree]
   ([?tk] (token 'id ?tk))
   ([?tk] (token 'int ?tk))
   ([?tk] (token 'real ?tk)))

(def tokens1 [{:tag 'int, :value 1, :start {:line 1, :col 1}}
 {:tag '+, :start {:line 1, :col 2}}
 {:tag 'int, :value 2, :start {:line 1, :col 3}} ])

(def tokens2 [{:tag 'int, :value 1, :start {:line 1, :col 1}}
 {:tag '*, :start {:line 1, :col 2}}
 {:tag 'int, :value 2, :start {:line 1, :col 3}} ])

(defn tests [num]
   (let [tokens (case num
  1 tokens1
  2 tokens2)]
 (run 1 [tree] (expr tree tokens []

--

I get these answers in Clojure:

compiler.parser=> (tests 1)
({:binop +,  {:start {:col 3, :line 1}, :value 2, :tag int}})

compiler.parser=> (tests 2)
({:binop *,  {:start {:col 3, :line 1}, :value 2, :tag int}})

The first argument is a  logical variable not instanced and what I'm
expecting is:

compiler.parser=> (tests 1)
({:binop +  {:tag 'int, :value 1, :start {:line 1, :col 1}}
 {:start {:col 3, :line 1}, :value 2, :tag int}})

compiler.parser=> (tests 2)
({:binop *  {:tag 'int, :value 1, :start {:line 1, :col 1}}
{:start {:col 3, :line 1}, :value 2, :tag int}})


What am I doing wrong?

Thanks in advance for any answer.

Regards,
Alex

-- 
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 Drip: A fast JVM launcher

2012-09-16 Thread Tassilo Horn
Denis Labaye  writes:

>> I am still seeing a new JVM being started every drip run. I am
>> testing Drip 0.1.7 with Lein 2 by running lein test 5 times in a row
>> with LEIN_JAVA_CMD=drip in ~/.lein/leinrc, OS X, JDK 7.
>
> No multiple JVM started for me (at least in my trivial tests)
>
> drip 0.1.7

Same versions here, but after running just "lein" thrice in a project, I
still have 3 JVMs in "drip ps".  It's the same when I run another lein
command, e.g., "lein jar" or "lein test".

Bye,
Tassilo

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