Re: The Number of Clojure (Was: Alright, fess up, who's unhappy with clojurescript?)

2011-07-27 Thread OGINO Masanori
And I should have posted about the spec separately, right?
;; or all I have to do is to forbid myself to post anything...

-- 
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: [ANN] emacs-clojure-vagrant: a sane development virtual environment

2011-07-27 Thread Joseph Jones
Update: I just got back from vacation and have done a fresh git clone, et
all (including updating VB to 4.1.0). I still get the same issue: No error,
but a hang at Installed Jark (I say hang because the terminal shell is
stuck running the vagrant script where I would assume it would have returned
once the VM was successfully running).

I opened a new terminal window and ran the clojure_emacs.sh script manually.
Unlike last time, this seems to have worked but requied a logout and back in
to get jark running and emacs to connect. From there things seems ok.

However, vagrant halt didn't do anything (but hang the shell) and I was
forced to shutdown manually from inside the vm (sudo shutdown  now). I did a
vagrant up again and it is setting up a brand new VM for me. Not sure what
it did with the old VM or why it insists on creating a new one.

If this run doesn't work then I will send all the output to a file and send
that to you so you can see if anything seems amiss.

Thanx,
joe

P.S. The current git repo requires at least VB 4.1.0, but the actual image
it downloads throws a warning up about the VB Extensions not matching. The
VM still has 4.0.6 extensions installed on it.

On Sat, Jul 9, 2011 at 10:16 AM, Stan Dyck stan.d...@gmail.com wrote:

 Another thing to try is this:

 1. Bring up the vm with a vagrant up
 2. Log in with vagrant ssh
 3. Run the /vagrant/clojure_emacs.sh script directly on the vm

 That might not work either, but at least you'll get some feedback about
 what fails from the script output. I'm curious about why it's failing so let
 me know if you find out.

 StanD.


 On 07/08/2011 10:47 PM, Joseph Jones wrote:

 Still no love. Same thing, only this time there wasn't even an empty
 .emacs.d folder.

 On Fri, Jul 8, 2011 at 10:51 AM, Joseph Jones 
 darkdescend...@gmail.commailto:
 darkdescendant@gmail.**com darkdescend...@gmail.com wrote:

When I tried bringing it down and back up, it restarted the whole
 process over from scratch. Basically, vagrant halt
seems to cause the entire VM to disappear as if vagrant destroy was
 called. :-(

I'll try to re-get from git and see if it works better now.


On Fri, Jul 8, 2011 at 9:30 AM, Stan Dyck stan.d...@gmail.commailto:
 stan.d...@gmail.com wrote:

There was a minor bug in the provisioning script that prevented the
 .emacs.d directory from being populated but
a fix has been pushed for that.

That being said, I also had the hang issue. I did the same as you;
 I did a vagrant ssh from a new terminal
window and everything worked. Also, after bringing down the virtual
 server and bringing it up again, the problem
has not recurred. I haven't had the time to figure out why it hung
 in the first place though.

StanD.


On 07/08/2011 08:37 AM, Joseph Jones wrote:

I'm having a problem on Max OS X 10.6.8 where vagrant hangs
 setting up the VM right after installing jark.
It seems to
just stop doing anything. I initially thought that that meant
 it was completed  but opening a new terminal
window and
doing vagrant ssh brought me to a VM that had nothing setup. No
 Jark running (in fact no Jark on the path),
no swank,
and emacs knew nothing about slime in any way.

I checked out the .emacs.d folder and there was nothing in it
 so obviously whatever step was supposed to put
something
there never ran.

Any ideas on what the issue could be?

Thanx,
joe


On Sun, Jun 26, 2011 at 9:50 PM, Justin Lilly 
 jus...@justinlilly.com mailto:jus...@justinlilly.com**
mailto:jus...@justinlilly.com mailto:jus...@justinlilly.com*
 *__ wrote:

I've put together a simple development environment for
 those looking
for a stable place to work on clojure code. The idea was
 dual purpose:
a consistent environment for which to try out multiple code
 bases and
something that is familiar to me when working on a foreign
 operating
system.

The included vagrant file will setup an Ubuntu 11.04
 virtual machine
with clojure and clojure-contrib 1.2, emacs 24 (with
 emacs-starter-kit
2 and all relevant clojure modes), tmux (similar to GNU
 screen),
Leiningen and Jark.

Special thanks to Phil Hagelberg for his help getting
 things setup.

Please check out the github project hosted by the Seajure
 user group
at 
 https://github.com/Seajure/__**emacs-clojure-vagranthttps://github.com/Seajure/__emacs-clojure-vagrant
 https://github.com/Seajure/**emacs-clojure-vagranthttps://github.com/Seajure/emacs-clojure-vagrant
 

. Your forks and
contributions are appreciated.

Thanks,
  -justin


 --
 You 

Re: The Number of Clojure (Was: Alright, fess up, who's unhappy with clojurescript?)

2011-07-27 Thread Marek Kubica
On Tue, 26 Jul 2011 21:30:25 -0700 (PDT)
pmbauer paul.michael.ba...@gmail.com wrote:

 These unhappy threads need to die a horrible death.

Well, criticism can also be constructive. It does at least show some of
the problems and/or desires that the community has. Fortunately, noone
is forced to read them :)

regards,
Marek

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


send from agent error handler does not work

2011-07-27 Thread abhi
  I tested the following on clojure 1.2 and clojure 1.2.1 and it
does not seem to work.

(def foo (agent nil))
(def bar (agent nil :error-handler (fn [a e] (do (def called? true)
(send foo (constantly e)
(def called? false)
(send bar inc) ; try incrementing nil
(await error); wait for agent to finish
[@foo called?] ; check value
= [nil true]

The last expression should evaluate to: [true
#NullPointerException java.lang.NullPointerException]. Instead, it's
evaluating to '[nil true]', which indicates that the 'error-handler'
is indeed being called but 'send' isn't working.

It works as expected on clojure 1.3.0-beta1 though.

 Seems like this issue was reported last year and has resurfaced.
Link to previous discussion about the bug:
http://groups.google.com/group/clojure/browse_thread/thread/c1d05bdbb50d7d28/4d1a64405e8fb766?lnk=gstq=send+from+agent+error+handler#4d1a64405e8fb766

--
Abhijith

-- 
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 with take-while

2011-07-27 Thread Michael Wood
On 27 July 2011 00:03, axyzxp axy...@gmail.com wrote:
 Hi,
 experimenting with clojure API i had this:

 user= (take-while #(= (mod 20 %) 0) (apply (fn [x y] (rest (range
 (max x y [10 20]))
 (1 2)

 but i expect to have (1 2 5 10) because of (apply (fn [x y] (rest
 (range (max x y [10 20]) returns (1 2 3 4 5 6 7 8 9 10 11 12 13 14
 15 16 17 18 19) and (mod 20 5) and (mod 20 10) should give me true and
 not should be dropped...

 I'm sure i'm doing some big nasty errors but don't know where...

In addition to the other answers, you can use:

(range 1 20)

instead of:

(rest (range 20))

and zero? instead of (= x 0).

e.g.:

(filter #(zero? (mod 20 %))
  (range 1 (apply max [10 20])))

-- 
Michael Wood esiot...@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: Invitation for Open Source Project

2011-07-27 Thread Vincent
right sir

-- 
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] cljs-devmode - A development mode for ClojureScript

2011-07-27 Thread Max Weber
Hello everyone,

I like to introduce you to cljs-devmode, which is a development mode for
ClojureScript. It is really a primitive prototype for a ClojureScript
development mode, but it works for me so far. I only wrote it to get started
with ClojureScript in one of my Clojure web applications.

cljs-devmode allows you to develop Clojure web applications in combination
with ClojureScript seamlessly. You can develop your normal Clojure web
application (with Ring and Compojure for example) and whenever you change a
ClojureScript source file it is automatically recompiled and you can test
the changes in your web browser.

You can find cljs-devmode and a detailed description here:
https://github.com/maxweber/cljs-devmode

Furthermore there is an example project, which shows how to use
cljs-devmode:
https://github.com/maxweber/cljs-devmode-example

There are many things which can be improved. So fork it on GitHub if you are
not satisfied with it. I hope it will serve you well, when you develop
ClojureScript inside your Clojure web application.

Best regards

Max

-- 
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: cljs-devmode - A development mode for ClojureScript

2011-07-27 Thread Alen Ribic
Thanks Max. This is wonderful. I can throw my current hack-job out the
window.

-Alen

PS. Should I encounter any issues, I'll post them via github.


On Jul 27, 12:31 pm, Max Weber mm.we...@web.de wrote:
 Hello everyone,

 I like to introduce you to cljs-devmode, which is a development mode for
 ClojureScript. It is really a primitive prototype for a ClojureScript
 development mode, but it works for me so far. I only wrote it to get started
 with ClojureScript in one of my Clojure web applications.

 cljs-devmode allows you to develop Clojure web applications in combination
 with ClojureScript seamlessly. You can develop your normal Clojure web
 application (with Ring and Compojure for example) and whenever you change a
 ClojureScript source file it is automatically recompiled and you can test
 the changes in your web browser.

 You can find cljs-devmode and a detailed description 
 here:https://github.com/maxweber/cljs-devmode

 Furthermore there is an example project, which shows how to use
 cljs-devmode:https://github.com/maxweber/cljs-devmode-example

 There are many things which can be improved. So fork it on GitHub if you are
 not satisfied with it. I hope it will serve you well, when you develop
 ClojureScript inside your Clojure web application.

 Best regards

 Max

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


Emacs, swank, leiningen repl-init and output to *out* getting lost...

2011-07-27 Thread kjeldahl
If that subject did not scare you off already you might be the right
person to comment.

To set the scene, I'm writing an application with an embedded web
server (using ring and jetty), and my srv.core module has a log
function defined as:

  (let [repl-out *out*]
(defn log [msg  vals]
  (binding [*out* repl-out]
(let [line (apply format msg vals)]
  (println line)

The reason I'm storing *out* in repl-out is that I also want to
capture output from all threads (including jetty's) and have it
displayed in my repl (and probably elsewhere in the future). Without
this kind of construction, output seems to get lost inside the emacs
repl, possibly related to Java's behaviour of redirecting output in
threads to /dev/null or similar.

This seemed to work fine, until I decided to get fancy. Leiningen
allows you to load up a repl specific namespace through it's repl-
init setting, and I figured this may be a nice place to create a
function to manually start up the jetty web server by calling one of
my functions inside the srv.core module.

My method in srv.core is nothing fancy, just:

  (defn srvstart []
(log Server started)
(alter-var-root (var server)
(fn [v]
  (run-jetty (app) {:port 8080 :join? false}

In my repl.helper module, I first tried:

  (ns repl.helper
(:use clojure.repl
srv.core))

  (defn replsrv []
(srv.core/srvstart))

Worked fine, except my log output got lost. If I ran it in a terminal
based console lein repl style, the log output appeared, but if I ran
it inside emacs clojure-jack-in style, it did not.

I haven't figured out exactly why (yet anyway). It seems the *out*
value that got stored in repl-out when the module was pulled in by the
use srv.core statement in repl.helper stores a different value than
the final value *out* has when the repl is up and running, at least
inside the emacs repl.

I figured I would try to delay pulling in srv.core until it was
actually needed, and that seems to solve it, ending up with the
following code in repl.helper:

  (ns repl.helper
(:use clojure.repl))

  (defn replsrv []
(require 'srv.core)
(@(resolve 'srv.core/srvstart)))

I have only vague theories about *out* getting set to something
unusable if pulled in during the first reading phase. Whether that is
correct behaviour or not, or if this is just a feature of how the
repl works inside emacs, I have no clue about.

If somebody with a clue would like to comment, please do.

Thanks,

Marius K.

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


Minimalist autocompile workflow for ClojureScript

2011-07-27 Thread Alex Osborne
Just sharing the stopgap method for static HTML (no server)
ClojureScript development I'm using until someone cooks up a REPL that
evals in the browser instead of Rhino.

Nothing particularly exciting here, but really beats restarting the JVM
on every compile. :-)

This will only work on Linux as is but could be trivially adapted to any
OS that has an equivalent to inotifywait.  (JDK 7 will have an API for it.)

1. Install your distro's inotify-tools package.
2. Adjust the paths in the code below to suit your project.
3. Run ClojureScript's ./script/repl and paste in the code below.
4. Point your favourite editor and web browser at your project.

Now use a workflow something like this:

1. In the editor make a code change and save it.
2. Flip to browser and refresh to test it.
3. Repeat until done.

Here's the code:

(require '[cljs.closure :as cljsc])

(defn await-change [path]
  (- (Runtime/getRuntime)
  (.exec (into-array [inotifywait -qre modify path]))
  (.waitFor)))

(let [root /home/ato/src/myproject]
  (while true
(println Compiling...)

(time
 (cljsc/build
  (str root /src/myproject/core.cljs)
  {:optimizations nil  ; vs :simple or :advanced
   :target nil ; vs :nodejs
   :pretty-print true
   :output-dir (str root /out)
   :output-to (str root /myproject.js)}))

(await-change (str root /src

Hints:

1. Avoid optimizations :simple or :advanced when you can while
developing.  On my PC after the JVM warms up a basic compile takes 30ms
while :simple or :advanced take at least 1 second.

2. If there's a compile error you might not notice it.  Position your
terminal somewhere you can easily see from both editor and browser.

3. I highly recommend global hot-keying your browser, editor and
terminal somehow.  You could use virtual desktops.  Me, I use the same
three tools for all my work so I just have Super-w, Super-e and Super-d
focus each respectively.

4. The same method works well for any compiled language that lacks an
interactive dev environment.  When I'm working on C code I just run
this in a terminal:

while inotifywait -qre modify src; make  ./myprogram; done

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


How to write `when-lets`

2011-07-27 Thread Feng Shen
Clojure core.clj has a macro when-let,
I am wondering how to write a macro `when-lets`

(when-lets [symbol-1 test-1
   symbol-2 test-2
...
]
   body
   )

body only get evaluated when (and test-1 test-2 )
I am thinking about it, anybody has any clue?

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


cake create project / setup instructions

2011-07-27 Thread octopusgrabbus
Before getting too far along, I'd like to set up my project the way
I've seen other projects' configurations, like clj-http and clojure-
csv. I can build my project, but it is not set up in the standard way.

I am using cake, but cannot find instructions on configuring and then
creating the project from scratch.

tnx
cmn

-- 
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 made you something.

2011-07-27 Thread Steven Deobald
http://groups.google.com/group/clojure-meta

Big hugs to you all, from a tired old man.
-steven

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

Code structure/design problems

2011-07-27 Thread Oskar
Hi!

I'm making a game with Clojure. And I have a few code structure/design
problems.

I have an atom with characters (a map of maps) in my main file. But
because I don't want to make that file too big I have, for example, a
file called ai.clj with AI stuff, that I require from the main file.
For the monsters' AI to work, the AI needs to know the state of the
world, i.e. the characters. My current solution is to (declare
characters) and then have a
(defn init-ai [characters] (def characters characters))
function in ai.clj that I call from the main file at the start of the
game. It works, but it doesn't feel quite right. I don't want to have
to pass the characters as an argument all the time, that seems a
little bit too verbose to me. It seems somehow unnecessary to have to
just pass the same atom around to all the functions.

That's a general theme in my project: modules/files depend on the main
module/file. And sometimes there's nothing I can do about it. The
graphics engine I'm using, for example, insists that my application
extends an Application class from the engine. And that the main loop
is in that app. So that's in my main file. But I really want the
graphics module to be a separate thing to which I send things to be
represented graphically. But, of course, the graphics module depends
on the app instance in my main file. So I did for the graphics what
I did for the AI.

Another concern of mine is that there are so many places where I need
to update the characters' state. There's the AI stuff, that updates
the monsters with their targets and paths, etc. Other examples: when
one character attacks another, then the health needs updating; or when
the player moves. I have a doubts that I am doing this the Clojure
way.

Often, the characters' ids are arguments to functions. For example, I
have a function called physical-attack (the one I mentioned above)
that takes the id of the attacker and the id of the target. Then it
calculates how much damage the attack is supposed to do, and updates
the target's health in the 'characters' atom. Sure, it could return
the amount of damage instead, that would be one step towards purity.
But to be really pure it would have to take the actual maps as
arguments too. It may work in this case, but it's not always so easy
to make the functions pure. The function that calls physical-attack,
for example, also updates the attacker (he now has to wait before he
can attack again), and returning both of the updated characters is not
as nice as returning one. And the update still has to happen
somewhere, because attacking *has* a side effect (in the game), so
maybe it's ok. It's just that now the updates are spread out all over,
and I thought that maybe it was better to have them in a special place
in the code, for sturcture and sanity.

A concrete problem: I want a function that takes the ids of two
characters (because as I explained above that's more convenient) and
checks if they are close enough to each other to attack. But I want to
use the function in the ai file and in the main file. But I can't
define it in some sort of utility file, because it depends on the
characters atom. And it doesn't feel quite right to define it in
ai.clj since 'characters' is defined in the main file, but the main
file requires ai and not the other way around. I could also define the
function in the main file and send it to the ai file as I did with
'characters' itself, but that seems really messy. Sure, this function
could be functional, and that would solve these problems. But that
would be inconvenient, because I would just have to look up the
position of the characters in a lot more places instead, leading to
increased code size.

I just wanted to write down my problems and maybe get some comments on
it. This being my first real Clojure project, I feel that I could use
some guidance, so feel free to comment as much as you'd like. I
realize that these are problems programmers deal with all the time (at
least I think so), but I thought that maybe the Clojure community,
being so wise, might have some answers. ;)

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


ClojureScript url path confusion

2011-07-27 Thread kjeldahl
I've set up my ring/jetty based application to dynamically compile any
updated clojurescript source files, similar to the clojurescript
devenv package recently announced. I'm having some trouble getting the
paths correct though. My toplevel directory looks like this:

mysoft
  srv
src
  srv
core.clj (implements namespace srv.core)
  client
hello.cljs
  www
index.html

What I'm trying to do is gettng the server, implemented in core.clj to
dynamically compile any updates to any cljs files in the client
directory, and output compiled sources to the www directory. I've
almost gotten it working; After compiling, the www directory gets
populated with hello.js and an out directory with the proper
subfolders.

What is not correct, however, is the url's in the generated files.
When compiling, I use the following code:

(cljsc/build ../client
 {:output-dir ../www/out
  :output-to ../www/hello.js})))

As I've mentioned, the correct files and directories seem to get put
into the www directory correctly. What is not correct however is the
content of the file hello.js:

goog.addDependency(../../../srv/../www/out/cljs/core.js,
['cljs.core'], ['goog.string', 'goog.string.StringBuffer',
'goog.object', 'goog.array']);
goog.addDependency(../../../srv/../www/out/hello.js, ['hello'],
['cljs.core']);

It seems my local file paths pollutes the url paths incorrectly. In
case it wasn't clear, the www is the root of the embedded webserver
in my application.

Am I doing something wrong, or should there really be some kind of
uriBase parameter also sent to the build function to avoid the local
filepaths polluting the url tree?

Thanks,

Marius K.

-- 
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 to write `when-lets`

2011-07-27 Thread Dmitry Gutov
This would be a straightforward solution:

(defmacro when-lets [bindings  body]
  `(let ~bindings
 (when (and ~@(map first (partition 2 2 bindings)))
   ~@body)))

It works well in simple cases, but breaks e.g. in case of parameter
destructuring.
If you read `(source when-let)`, you'll see that it uses a temporary
binding. So we can add that and a loop, or just reuse `when-let` and
use something akin to recursion:

(defmacro when-lets [bindings  body]
  (if (empty? bindings)
`(do ~@body)
`(when-let [~@(take 2 bindings)]
   (when-lets [~@(drop 2 bindings)]
  ~@body

user= (when-lets [a 1 [b c] [1 2]] (+ a b c))
4
user= (when-lets [a 1 [b c] nil] (+ a b c))
nil

Questions?

On Jul 27, 4:50 pm, Feng Shen shen...@gmail.com wrote:
 Clojure core.clj has a macro when-let,
 I am wondering how to write a macro `when-lets`

 (when-lets [symbol-1 test-1
                    symbol-2 test-2
             ...
             ]
            body
            )

 body only get evaluated when (and test-1 test-2 )
 I am thinking about it, anybody has any clue?

-- 
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: Code structure/design problems

2011-07-27 Thread Benny Tsai
Hi Oskar,

I just came across this article yesterday, which I thought you may find 
useful.  It's a 4-part series where the author discusses his experience 
implementing games in a functional style:

http://prog21.dadgum.com/23.html

He was using Erlang, but I think many of the same ideas apply here as well. 
 Hope this helps.

-- 
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 to write `when-lets`

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 10:51 AM, Dmitry Gutov raa...@gmail.com wrote:
 This would be a straightforward solution:

 (defmacro when-lets [bindings  body]
  `(let ~bindings
     (when (and ~@(map first (partition 2 2 bindings)))
       ~@body)))

 It works well in simple cases, but breaks e.g. in case of parameter
 destructuring.
 If you read `(source when-let)`, you'll see that it uses a temporary
 binding. So we can add that and a loop, or just reuse `when-let` and
 use something akin to recursion:

 (defmacro when-lets [bindings  body]
  (if (empty? bindings)
    `(do ~@body)
    `(when-let [~@(take 2 bindings)]
       (when-lets [~@(drop 2 bindings)]
          ~@body

 user= (when-lets [a 1 [b c] [1 2]] (+ a b c))
 4
 user= (when-lets [a 1 [b c] nil] (+ a b c))
 nil

 Questions?

I'd go with the latter approach. The former has the problem that we'd
really like this:

(when-lets [wr (:key some-map-of-weak-references)
v (.get wr)]
  (do-something-with v))

not to blow up when :key isn't found in the map.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Code structure/design problems

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 10:04 AM, Oskar oskar.kv...@gmail.com wrote:
 I have an atom with characters (a map of maps) in my main file. But
 because I don't want to make that file too big I have, for example, a
 file called ai.clj with AI stuff, that I require from the main file.
 For the monsters' AI to work, the AI needs to know the state of the
 world, i.e. the characters. My current solution is to (declare
 characters) and then have a
 (defn init-ai [characters] (def characters characters))
 function in ai.clj that I call from the main file at the start of the
 game. It works, but it doesn't feel quite right.

(ns namespace-1 ...)

(def chs (promise))

(defn characters [] (@chs))

...

(ns namespace-2
  (:require namespace-1 :as n1)
  ...)

(defn patrol [...] ...)

(defn predatory-wildlife [...] ...)

(deliver n1/chs
  {
   ...
   {:desc Dire Wolf :level 7 :race :canine :ai predatory-wildlife ...}
   {:desc Dwarven Guard :level 18 :race :dwarf :ai patrol ...}
   ...})

You'll need to use (characters) or @chs rather than just characters in
namespace-1, though.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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 to write `when-lets`

2011-07-27 Thread Oskar
I tried to solve this, and, having very litte macro-writing
experience, just looked at when-let and tried to modify it to work
with multiple binds. This is what I ended up with:

(defmacro when-lets
  [bindings  body]
  (if-not (seq bindings)
`(do ~@body)
(let [form (bindings 0) tst (bindings 1) rst (drop 2 bindings)]
  `(let [temp# ~tst]
 (when temp#
   (let [~form temp#]
 (when-lets ~(vec rst)
   ~@body)))

Not as elegant as Dmitry's code, I know...

But before I landed on the above version, I had this:

(defmacro when-lets
  [bindings  body]
  (if-not (seq bindings)
`(do ~@body)
(let [form (bindings 0) tst (bindings 1) rst (drop 2 bindings)]
  `(let [temp# ~tst]
 (when temp#
   (when-lets ~(vec rst)
 (let [~form temp#]
   ~@body)))

Notice that the when-lets and let close to the end there has swapped
places. This is wrong, because the tests/values get evaluated in the
wrong order. But apart from that I expected this to work. But it does
not. This last code yields this:

= (when-lets [a 1 b 2] [a b])
[2 2]

Two questions:

First: Why doesn't macroexpand expand the inner when-lets?

= (macroexpand '(when-lets [a 1 b 2] [a b]))
(let* [temp__1551__auto__ 1] (clojure.core/when temp__1551__auto__
(user/when-lets [b 2] (clojure.core/let [a temp__1551__auto__] [a
b]

Second: If I extract the inner when-lets manually and expand that, and
reinsert it, I end up with this:

(let* [temp__1551__auto__ 1] (clojure.core/when temp__1551__auto__
(let* [temp__1551__auto__ 2] (clojure.core/when temp__1551__auto__
(user/when-lets [] (clojure.core/let [b temp__1551__auto__]
(clojure.core/let [a temp__1551__auto__] [a b])))

I thought that the name of the gensyms might just be the same for a
and b because I did two expands in the repl or something. But it seems
to me that them getting the same name is the only explaination for the
result above (maybe they are the same, somehow?).

Is the gensym in the two expands the same thing, or do they get the
same name? That was surprising to me. I can't think of any real
example where that is a problem. But what if I had wanted to write a
macro like the second when-lets?

On Jul 27, 4:51 pm, Dmitry Gutov raa...@gmail.com wrote:
 This would be a straightforward solution:

 (defmacro when-lets [bindings  body]
   `(let ~bindings
      (when (and ~@(map first (partition 2 2 bindings)))
        ~@body)))

 It works well in simple cases, but breaks e.g. in case of parameter
 destructuring.
 If you read `(source when-let)`, you'll see that it uses a temporary
 binding. So we can add that and a loop, or just reuse `when-let` and
 use something akin to recursion:

 (defmacro when-lets [bindings  body]
   (if (empty? bindings)
     `(do ~@body)
     `(when-let [~@(take 2 bindings)]
        (when-lets [~@(drop 2 bindings)]
           ~@body

 user= (when-lets [a 1 [b c] [1 2]] (+ a b c))
 4
 user= (when-lets [a 1 [b c] nil] (+ a b c))
 nil

 Questions?

 On Jul 27, 4:50 pm, Feng Shen shen...@gmail.com wrote:







  Clojure core.clj has a macro when-let,
  I am wondering how to write a macro `when-lets`

  (when-lets [symbol-1 test-1
                     symbol-2 test-2
              ...
              ]
             body
             )

  body only get evaluated when (and test-1 test-2 )
  I am thinking about it, anybody has any clue?

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


ClojureScript - why is javascript object array and not a map?

2011-07-27 Thread Marko Kocić
Note the following code that works:

(defn ^:export displayPlain [id]
  (let [h (.getElementById window/document id)
txt (aget h innerText)]
(window/alert (str plain  txt))
(aset h innerText here I am!)))
Here, javascript object h is treated as array, and I was able to get and 
set its value (since it is mutable).

Note that the following code doesn't work, since h is not a map, and thus we 
can't access its properties neither as keywords nor as names.

(defn ^:export displayPlain2 [id]
  (let [h (.getElementById window/document id)
;; txt (get h innerText)
txt (:innerText h)]
(window/alert (str plain  txt

This makes dealing with js objects a bit mor verbose than clojure maps. It 
would be good if Clojure maps and JS object would be interchangeable from 
ClojureScript code.

Would it make sense to open a bug/feature for this?

I know that this is doable using closure library, but it would be nice if it 
could be easily doable using plain objects.
(defn ^:export display [id]
  (let [h (dom/getElement id)
txt (dom/getTextContent h)]
(window/alert (str gdom  txt

Regards,
Marko

-- 
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 - why is javascript object array and not a map?

2011-07-27 Thread Stuart Halloway
 Note the following code that works:
 
 (defn ^:export displayPlain [id]
   (let [h (.getElementById window/document id)
 txt (aget h innerText)]
 (window/alert (str plain  txt))
 (aset h innerText here I am!)))
 Here, javascript object h is treated as array, and I was able to get and 
 set its value (since it is mutable).
 
 Note that the following code doesn't work, since h is not a map, and thus we 
 can't access its properties neither as keywords nor as names.
 
 (defn ^:export displayPlain2 [id]
   (let [h (.getElementById window/document id)
 ;; txt (get h innerText)
 txt (:innerText h)]
 (window/alert (str plain  txt
 
 This makes dealing with js objects a bit mor verbose than clojure maps. It 
 would be good if Clojure maps and JS object would be interchangeable from 
 ClojureScript code.
 
 Would it make sense to open a bug/feature for this?
 
 I know that this is doable using closure library, but it would be nice if it 
 could be easily doable using plain objects.
 (defn ^:export display [id]
   (let [h (dom/getElement id)
 txt (dom/getTextContent h)]
 (window/alert (str gdom  txt
 
 Regards,
 Marko

Design is underway on this. Stay tuned.

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

Additional delay after pcalls?

2011-07-27 Thread mc4924
Hello everyone, I am a beginner with clojure and I am playing around
with pcalls (I am using clojure 1.2.1).
I see different behavior if I run some code from inside the REPL or
launching it form the command line.

I have the following code in a file called test-pcalls.clj:

(let [waste-time (fn [label]
(dotimes [k 4]
  (let [msg (str label   k \n)]
(Thread/sleep 2000)
(print msg]
  (dorun (pcalls #(waste-time A) #(waste-time b

This just creates the function 'waste-time' which slowly (2 seconds at
a time) counts 0..3 and prints a label and the count each time. Two
copies of the function are then started in parallel with a different
label (A and b)

I start clojure and then from the REPL I do (load-file test-
pcalls.clj).
After 8 seconds (2 seconds x 4) I see the two sequences being printed
out all in one go.
First question I cannot find an aswer is: why do I see everything
printed together instead of one step a time?

Then I exit to the command line and then start clojure with the source
file:
   clojure test-pcalls.clj
Again after 8 seconds I see the sequences printed out as above. But
now clojure hangs for a minute or so before returning to the command
prompt.
Can anyone explain this additional delay?

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: cake create project / setup instructions

2011-07-27 Thread octopusgrabbus
I found the new command for cake, but I get this error, so I'm a
little confused as to what's going on. cake builds otherwise.

cnorton@steamboy:~/projects/clojure$ cake new addr_verify
unknown task: new


On Jul 27, 8:50 am, octopusgrabbus octopusgrab...@gmail.com wrote:
 Before getting too far along, I'd like to set up my project the way
 I've seen other projects' configurations, like clj-http and clojure-
 csv. I can build my project, but it is not set up in the standard way.

 I am using cake, but cannot find instructions on configuring and then
 creating the project from scratch.

 tnx
 cmn

-- 
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: Additional delay after pcalls?

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 11:44 AM, mc4924 claudio.potenza...@gmail.com wrote:
 Hello everyone, I am a beginner with clojure and I am playing around
 with pcalls (I am using clojure 1.2.1).
 I see different behavior if I run some code from inside the REPL or
 launching it form the command line.

 I have the following code in a file called test-pcalls.clj:

 (let [waste-time (fn [label]
                    (dotimes [k 4]
                      (let [msg (str label   k \n)]
                        (Thread/sleep 2000)
                        (print msg]
  (dorun (pcalls #(waste-time A) #(waste-time b

 This just creates the function 'waste-time' which slowly (2 seconds at
 a time) counts 0..3 and prints a label and the count each time. Two
 copies of the function are then started in parallel with a different
 label (A and b)

 I start clojure and then from the REPL I do (load-file test-
 pcalls.clj).
 After 8 seconds (2 seconds x 4) I see the two sequences being printed
 out all in one go.
 First question I cannot find an aswer is: why do I see everything
 printed together instead of one step a time?

Buffering of I/O. Try using println, or adding (.flush *out*) after each print.

 Then I exit to the command line and then start clojure with the source
 file:
   clojure test-pcalls.clj
 Again after 8 seconds I see the sequences printed out as above. But
 now clojure hangs for a minute or so before returning to the command
 prompt.
 Can anyone explain this additional delay?

Waiting for the pcalls thread pool to shut down, I expect.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Additional delay after pcalls?

2011-07-27 Thread Ben Mabey

On 7/27/11 11:19 AM, Ken Wesson wrote:

On Wed, Jul 27, 2011 at 11:44 AM, mc4924claudio.potenza...@gmail.com  wrote:

Hello everyone, I am a beginner with clojure and I am playing around
with pcalls (I am using clojure 1.2.1).
I see different behavior if I run some code from inside the REPL or
launching it form the command line.

I have the following code in a file called test-pcalls.clj:

(let [waste-time (fn [label]
(dotimes [k 4]
  (let [msg (str label   k \n)]
(Thread/sleep 2000)
(print msg]
  (dorun (pcalls #(waste-time A) #(waste-time b

This just creates the function 'waste-time' which slowly (2 seconds at
a time) counts 0..3 and prints a label and the count each time. Two
copies of the function are then started in parallel with a different
label (A and b)

I start clojure and then from the REPL I do (load-file test-
pcalls.clj).
After 8 seconds (2 seconds x 4) I see the two sequences being printed
out all in one go.
First question I cannot find an aswer is: why do I see everything
printed together instead of one step a time?

Buffering of I/O. Try using println, or adding (.flush *out*) after each print.


Then I exit to the command line and then start clojure with the source
file:
   clojure test-pcalls.clj
Again after 8 seconds I see the sequences printed out as above. But
now clojure hangs for a minute or so before returning to the command
prompt.
Can anyone explain this additional delay?

Waiting for the pcalls thread pool to shut down, I expect.

Yeah, you will want to call '(shutdown-agents)' to have Clojure shut 
down the thread pool it uses for agents, futures, etc..


-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: cake create project / setup instructions

2011-07-27 Thread octopusgrabbus
cake new does work. I had run cake new in the wrong place before, so I
am rebuilding the tree. Problem solved for now.

On Jul 27, 1:13 pm, octopusgrabbus octopusgrab...@gmail.com wrote:
 I found the new command for cake, but I get this error, so I'm a
 little confused as to what's going on. cake builds otherwise.

 cnorton@steamboy:~/projects/clojure$ cake new addr_verify
 unknown task: new

 On Jul 27, 8:50 am, octopusgrabbus octopusgrab...@gmail.com wrote:







  Before getting too far along, I'd like to set up my project the way
  I've seen other projects' configurations, like clj-http and clojure-
  csv. I can build my project, but it is not set up in the standard way.

  I am using cake, but cannot find instructions on configuring and then
  creating the project from scratch.

  tnx
  cmn

-- 
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 with ClojureScript and Node.js

2011-07-27 Thread Oliver Kaiser
I seem to have fixed this by editing
closure/library/closure/goog/base.js and rebuilding lib/goog.jar.
The relevant line is goog.global = this; somewhere at the top where
this should be replaced by
(function(){return this})();; the bootstrap script contains the
command to create the jarfile.

I can't tell if this is the ~correct~ way of fixing this problem, but
so far it doesn't appear to have broken
anything. Tested with v0.4 branch and 0.5.2 release, both work.

Regards,
tok

-- 
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: Alright, fess up, who's unhappy with clojurescript?

2011-07-27 Thread Daniel Werner
On 27 July 2011 01:43, Mark Derricutt m...@talios.com wrote:
 My unhappiness with it is more akin to my unhappiness with ANY language that
 tries to target multiple VM platforms, and that's mostly due to the
 -potential- to break the community.

It may be helpful to approach the issue with the premise that
ClojureScript != Clojure. They share a lot of syntax and semantics,
and a developer experienced in one can easily transfer his/her working
knowledge to the other. But in the end, I perceive them as two
different languages that just happen to have a lot in common.

 Enter ClojureScript, for the most part you will be able to reuse server code 
 on the
 front end, but some of those libraries you've become accustomed to using just
 won't work, and if you're working to a deadline and suddenly hit that - you're
 going to become frustrated beyond all hell ;-)

Personally, I wouldn't assume that anything works on ClojureScript
unless explicitly tested and labeled as such.

This seems like an interesting avenue to follow. This thread is
already past its expiry date, though, so I doubt further discussion
will get much attention here.

-- 
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 with take-while

2011-07-27 Thread axyzxp
thanks guys, now everything is clearer to me.
I really apreciate your help

-- 
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 with take-while

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 1:51 PM, axyzxp axy...@gmail.com wrote:
 thanks guys, now everything is clearer to me.
 I really apreciate your help

You're welcome.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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 to write `when-lets`

2011-07-27 Thread Alan Malloy
On Jul 27, 5:50 am, Feng Shen shen...@gmail.com wrote:
 Clojure core.clj has a macro when-let,
 I am wondering how to write a macro `when-lets`

 (when-lets [symbol-1 test-1
                    symbol-2 test-2
             ...
             ]
            body
            )

 body only get evaluated when (and test-1 test-2 )
 I am thinking about it, anybody has any clue?

(defmacro when-lets [tests  body]
  (reduce (fn [body test]
`(when-let ~(vec test)
   ~body))
  `(do ~@body)
  (partition 2 (reverse tests

This would be cleaner if we had foldr in the language already - I find
myself wanting it quite often for macros like 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: How to write `when-lets`

2011-07-27 Thread Alan Malloy
On Jul 27, 11:11 am, Alan Malloy a...@malloys.org wrote:
 On Jul 27, 5:50 am, Feng Shen shen...@gmail.com wrote:

  Clojure core.clj has a macro when-let,
  I am wondering how to write a macro `when-lets`

  (when-lets [symbol-1 test-1
                     symbol-2 test-2
              ...
              ]
             body
             )

  body only get evaluated when (and test-1 test-2 )
  I am thinking about it, anybody has any clue?

 (defmacro when-lets [tests  body]
   (reduce (fn [body test]
             `(when-let ~(vec test)
                ~body))
           `(do ~@body)
           (partition 2 (reverse tests

 This would be cleaner if we had foldr in the language already - I find
 myself wanting it quite often for macros like this.

Sorry, should of course be

(defmacro when-lets [tests  body]
  (reduce (fn [body test]
`(when-let ~(vec test)
   ~body))
  `(do ~@body)
  (reverse (partition 2 tests

Apparently the reason I want foldr is because I get it wrong when I do
it myself.

-- 
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 to write `when-lets`

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 2:13 PM, Alan Malloy a...@malloys.org wrote:
 On Jul 27, 11:11 am, Alan Malloy a...@malloys.org wrote:
 On Jul 27, 5:50 am, Feng Shen shen...@gmail.com wrote:

  Clojure core.clj has a macro when-let,
  I am wondering how to write a macro `when-lets`

  (when-lets [symbol-1 test-1
                     symbol-2 test-2
              ...
              ]
             body
             )

  body only get evaluated when (and test-1 test-2 )
  I am thinking about it, anybody has any clue?

 (defmacro when-lets [tests  body]
   (reduce (fn [body test]
             `(when-let ~(vec test)
                ~body))
           `(do ~@body)
           (partition 2 (reverse tests

 This would be cleaner if we had foldr in the language already - I find
 myself wanting it quite often for macros like this.

 Sorry, should of course be

 (defmacro when-lets [tests  body]
  (reduce (fn [body test]
            `(when-let ~(vec test)
               ~body))
          `(do ~@body)
          (reverse (partition 2 tests

 Apparently the reason I want foldr is because I get it wrong when I do
 it myself.

(defn foldr
  ([f coll]
(reduce f (reverse coll)))
  ([f init coll]
(reduce f init (reverse coll

There. :)

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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 to write `when-lets`

2011-07-27 Thread Aaron Cohen
On Wed, Jul 27, 2011 at 2:15 PM, Ken Wesson kwess...@gmail.com wrote:

 On Wed, Jul 27, 2011 at 2:13 PM, Alan Malloy a...@malloys.org wrote:
  On Jul 27, 11:11 am, Alan Malloy a...@malloys.org wrote:
  On Jul 27, 5:50 am, Feng Shen shen...@gmail.com wrote:
 

 (defn foldr
  ([f coll]
(reduce f (reverse coll)))
  ([f init coll]
(reduce f init (reverse coll

 There. :)


I may be wrong, but don't you need to swap the order of the arguments to f?

-- 
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 to write `when-lets`

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 2:35 PM, Aaron Cohen aa...@assonance.org wrote:
 I may be wrong, but don't you need to swap the order of the arguments to f?

You can do that by writing f itself appropriately. Usually either it
will be a closure or it won't matter (core +, etc.).

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

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


Cake CLASSPATH Error

2011-07-27 Thread octopusgrabbus
I originally had a project set up that built correctly, but the
project directories had not been set up with cake new.

I saved my project and main files; created a new project tree with
cake new addr_verify; and then replaced project.clj and
addr_verify.clj with the working files. Before, addr_verify.clj needed
to go into addr_verify/src, and this time it went into addr_verify/src/
addr_verify.

Here is my CLASSPATH /usr/share/java

I'm getting this error on cake compile and am not sure how to correct
the error or what to add. I would appreciate help.

java.lang.RuntimeException: java.io.FileNotFoundException: Could not
locate addr_verify__init.class or addr_verify.clj on classpath:

this is project.clj
(defproject util-str 0.0.1-SNAPSHOT
  :description This provides some string handling routines not found
directly in Clojure's libraries.
  :dependencies [[org.clojure/clojure 1.2.1]
 [org.clojure/clojure-contrib 1.2.0]
 [clojure-csv/clojure-csv 1.2.4]
 [clj-http 0.1.3]])

this is the first few lines of addr_verify.clj

(ns addr-verify
  (:gen-class)
  (:use clojure.contrib.command-line)
  (:require [clojure.string :as cstr])
  (:require [clojure.contrib.str-utils :as ustr])
  (:require [clj-http.client :as client])
  (:import java.util.Date)
  (:import java.lang.Thread)
  (:use clojure-csv.core))

(def accumail-url-keys [CA, STREET, STREET2, CITY, STATE,
ZIP, YR, BILL_NO, BILL_TYPE] )
(def accumail-url http://MailVerify/Lookup/chkAddr.asp;)

Thanks. cmn

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


format and printf can't be used with BigInt

2011-07-27 Thread Andrea Tortorella
Hi everyone,
I don't know where to post about bugs (if this is a bug).
Anyway in clojure 1.3 with the new numerics:

(format %d 2N)

throws IllegalFormatConversionException, is it a bug? are there any
workarounds?

-- 
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 to write `when-lets`

2011-07-27 Thread Dmitry Gutov
 First: Why doesn't macroexpand expand the inner when-lets?

It's not supposed to, see the doc. To do full expansion, you can use
`clojure.walk/macroexpand-all`.

 Is the gensym in the two expands the same thing, or do they get the
 same name? That was surprising to me. I can't think of any real
 example where that is a problem. But what if I had wanted to write a
 macro like the second when-lets?

Looks like a bug/limitation of the gensym reader macro, these symbols
are treated as belonging to the same quoted form, so they get the same
name.
But I don't think the second macro does what you're saying - the
evaluation order is the same, since `tst` is evaluated in the `let`
form above `when-lets` in both cases, only the order of binding the
values is reversed.
To reverse the evaluation order, you need to move that `let` inside:

(defmacro when-lets
  [bindings  body]
  (if-not (seq bindings)
`(do ~@body)
(let [form (bindings 0) tst (bindings 1) rst (drop 2 bindings)]
  `(when-lets ~(vec rst)
 (let [temp# ~tst]
   (when temp#
 (let [~form temp#]
   ~@body)))

user= (when-lets [b (inc a) a 3] (+ b a))
7

-- 
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 to write `when-lets`

2011-07-27 Thread Aaron Cohen
On Wed, Jul 27, 2011 at 2:39 PM, Ken Wesson kwess...@gmail.com wrote:

 On Wed, Jul 27, 2011 at 2:35 PM, Aaron Cohen aa...@assonance.org wrote:
  I may be wrong, but don't you need to swap the order of the arguments to
 f?

 You can do that by writing f itself appropriately. Usually either it
 will be a closure or it won't matter (core +, etc.).


If the order of evaluation doesn't matter, you should probably just be using
reduce in the first place.

-- 
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: Cake CLASSPATH Error

2011-07-27 Thread Mark Rathwell
Namespace file locations start from the src directory, in your project
directory.  So, a file that declares namespace addr-verify should be located
in src/addr_verify.clj.  A file that declares namespace
addr-verify.addr-verify would be found in src/addr_verify/addr_verify.clj.


On Wed, Jul 27, 2011 at 2:42 PM, octopusgrabbus octopusgrab...@gmail.comwrote:

 I originally had a project set up that built correctly, but the
 project directories had not been set up with cake new.

 I saved my project and main files; created a new project tree with
 cake new addr_verify; and then replaced project.clj and
 addr_verify.clj with the working files. Before, addr_verify.clj needed
 to go into addr_verify/src, and this time it went into addr_verify/src/
 addr_verify.

 Here is my CLASSPATH /usr/share/java

 I'm getting this error on cake compile and am not sure how to correct
 the error or what to add. I would appreciate help.

 java.lang.RuntimeException: java.io.FileNotFoundException: Could not
 locate addr_verify__init.class or addr_verify.clj on classpath:

 this is project.clj
 (defproject util-str 0.0.1-SNAPSHOT
  :description This provides some string handling routines not found
 directly in Clojure's libraries.
  :dependencies [[org.clojure/clojure 1.2.1]
 [org.clojure/clojure-contrib 1.2.0]
 [clojure-csv/clojure-csv 1.2.4]
 [clj-http 0.1.3]])

 this is the first few lines of addr_verify.clj

 (ns addr-verify
  (:gen-class)
  (:use clojure.contrib.command-line)
  (:require [clojure.string :as cstr])
  (:require [clojure.contrib.str-utils :as ustr])
  (:require [clj-http.client :as client])
  (:import java.util.Date)
  (:import java.lang.Thread)
  (:use clojure-csv.core))

 (def accumail-url-keys [CA, STREET, STREET2, CITY, STATE,
 ZIP, YR, BILL_NO, BILL_TYPE] )
 (def accumail-url http://MailVerify/Lookup/chkAddr.asp;)

 Thanks. cmn

 --
 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: Cake CLASSPATH Error

2011-07-27 Thread octopusgrabbus
Thanks. It appears it was set up correctly all along, but didn't have
the extra directories created by cake new.

On Jul 27, 3:09 pm, Mark Rathwell mark.rathw...@gmail.com wrote:
 Namespace file locations start from the src directory, in your project
 directory.  So, a file that declares namespace addr-verify should be located
 in src/addr_verify.clj.  A file that declares namespace
 addr-verify.addr-verify would be found in src/addr_verify/addr_verify.clj.

 On Wed, Jul 27, 2011 at 2:42 PM, octopusgrabbus 
 octopusgrab...@gmail.comwrote:







  I originally had a project set up that built correctly, but the
  project directories had not been set up with cake new.

  I saved my project and main files; created a new project tree with
  cake new addr_verify; and then replaced project.clj and
  addr_verify.clj with the working files. Before, addr_verify.clj needed
  to go into addr_verify/src, and this time it went into addr_verify/src/
  addr_verify.

  Here is my CLASSPATH /usr/share/java

  I'm getting this error on cake compile and am not sure how to correct
  the error or what to add. I would appreciate help.

  java.lang.RuntimeException: java.io.FileNotFoundException: Could not
  locate addr_verify__init.class or addr_verify.clj on classpath:

  this is project.clj
  (defproject util-str 0.0.1-SNAPSHOT
   :description This provides some string handling routines not found
  directly in Clojure's libraries.
   :dependencies [[org.clojure/clojure 1.2.1]
                  [org.clojure/clojure-contrib 1.2.0]
                  [clojure-csv/clojure-csv 1.2.4]
                  [clj-http 0.1.3]])

  this is the first few lines of addr_verify.clj

  (ns addr-verify
   (:gen-class)
   (:use clojure.contrib.command-line)
   (:require [clojure.string :as cstr])
   (:require [clojure.contrib.str-utils :as ustr])
   (:require [clj-http.client :as client])
   (:import java.util.Date)
   (:import java.lang.Thread)
   (:use clojure-csv.core))

  (def accumail-url-keys [CA, STREET, STREET2, CITY, STATE,
  ZIP, YR, BILL_NO, BILL_TYPE] )
  (def accumail-url http://MailVerify/Lookup/chkAddr.asp;)

  Thanks. cmn

  --
  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: How to write `when-lets`

2011-07-27 Thread Alan Malloy
On Jul 27, 11:57 am, Aaron Cohen aa...@assonance.org wrote:
 On Wed, Jul 27, 2011 at 2:39 PM, Ken Wesson kwess...@gmail.com wrote:
  On Wed, Jul 27, 2011 at 2:35 PM, Aaron Cohen aa...@assonance.org wrote:
   I may be wrong, but don't you need to swap the order of the arguments to
  f?

  You can do that by writing f itself appropriately. Usually either it
  will be a closure or it won't matter (core +, etc.).

 If the order of evaluation doesn't matter, you should probably just be using
 reduce in the first place.

I wrote my foldr to swap the order of arguments to f, but I think
Ken's right not to. Having acc be on the right is a good reminder that
you're folding right, and makes some of the most common patterns, like
(cons x acc) look natural.

-- 
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 to write `when-lets`

2011-07-27 Thread Alan Malloy
On Jul 27, 11:56 am, Dmitry Gutov raa...@gmail.com wrote:
  First: Why doesn't macroexpand expand the inner when-lets?

 It's not supposed to, see the doc. To do full expansion, you can use
 `clojure.walk/macroexpand-all`.

  Is the gensym in the two expands the same thing, or do they get the
  same name? That was surprising to me. I can't think of any real
  example where that is a problem. But what if I had wanted to write a
  macro like the second when-lets?

 Looks like a bug/limitation of the gensym reader macro, these symbols
 are treated as belonging to the same quoted form, so they get the same
 name.

Nothing to do with being the same quoted form: foo# symbols are
gensymmed at read time, so by the time the macro runs there's no
evidence that they were ever gensyms: just a symbol named
temp__1551__auto__, and it has no reason to suppose you intend them to
be different.

I don't think this is a problem for many (any?) macros, but if you
want more control you can gensym yourself:

(defmacro when-lets
  [bindings  body]
  (if-not (seq bindings)
`(do ~@body)
(let [temp (gensym) form (bindings 0) tst (bindings 1) rst (drop 2
bindings)]
  `(let [~temp ~tst]
 (when ~temp
   (when-lets ~(vec rst)
 (let [~form ~temp]
   ~@body)))

user (use 'clojure.walk) (macroexpand-all '(when-lets [a 1 b 2] [a
b]))
(let* [G__1815 1] (if G__1815 (do (let* [G__1816 2] (if G__1816 (do
(do (let* [b G__1816] (let* [a G__1815] [a b])

user (when-lets [a 1 b 2] [a b])
[1 2]

-- 
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: format and printf can't be used with BigInt

2011-07-27 Thread Alan Malloy
On Jul 27, 11:45 am, Andrea Tortorella elian...@gmail.com wrote:
 Hi everyone,
 I don't know where to post about bugs (if this is a bug).
 Anyway in clojure 1.3 with the new numerics:

 (format %d 2N)

 throws IllegalFormatConversionException, is it a bug? are there any
 workarounds?

Unlikely to change anytime soon: format just calls
java.util.Formatter.format; if you look at the source of that, it
tests for each built-in numeric type specially, instead of using
Number. But you can probably use the %s specifier, since converting it
to a string is unlikely to do much harm.

-- 
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 to write `when-lets`

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 2:57 PM, Aaron Cohen aa...@assonance.org wrote:
 On Wed, Jul 27, 2011 at 2:39 PM, Ken Wesson kwess...@gmail.com wrote:

 On Wed, Jul 27, 2011 at 2:35 PM, Aaron Cohen aa...@assonance.org wrote:
  I may be wrong, but don't you need to swap the order of the arguments to
  f?

 You can do that by writing f itself appropriately. Usually either it
 will be a closure or it won't matter (core +, etc.).

 If the order of evaluation doesn't matter, you should probably just be using
 reduce in the first place.

True. But the point is that for the likely core functions to use in
foldr/reduce, the argument order doesn't matter, so when it does
you're likely using a local closure rather than an elsewhere-defined
function anyway.

It does occur to me, though, that if an operation is commutative, but
not associative, then foldr and reduce might give different results
even in a case where swapping the function arguments' order doesn't do
so. It's just very rare for an operation that's not associative to be
commutative. Common math operations for instance are both (*, +),
neither (/, -), or associative but not commutative (matrix
multiplication, composition of functions), with clojure.core
furnishing examples in all three categories (* and +; / and -; comp).

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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 to write `when-lets`

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 3:23 PM, Alan Malloy a...@malloys.org wrote:
 On Jul 27, 11:56 am, Dmitry Gutov raa...@gmail.com wrote:
  First: Why doesn't macroexpand expand the inner when-lets?

 It's not supposed to, see the doc. To do full expansion, you can use
 `clojure.walk/macroexpand-all`.

  Is the gensym in the two expands the same thing, or do they get the
  same name? That was surprising to me. I can't think of any real
  example where that is a problem. But what if I had wanted to write a
  macro like the second when-lets?

 Looks like a bug/limitation of the gensym reader macro, these symbols
 are treated as belonging to the same quoted form, so they get the same
 name.

 Nothing to do with being the same quoted form: foo# symbols are
 gensymmed at read time, so by the time the macro runs there's no
 evidence that they were ever gensyms: just a symbol named
 temp__1551__auto__, and it has no reason to suppose you intend them to
 be different.

I'd say it's a bug. This sort of capture/shadowing simply should not
happen in Clojure macros without the user jumping through hoops to
specifically enable it (e.g. ~'foo; ~(symbol ...)).

If the reader is turning the foo#s in a particular syntax-quoted
expression into a fixed symbol, I say it should instead be turning
`(... foo# ... foo# ...) into an implicit (let [foo (gensym)] `(...
~foo ... ~foo ...)), which the compiler will then turn into code that
generates a separate gensym for each invocation of the containing
macro, as seems desirable and necessary to avoid the sort of problem
observed in this thread.

Of course, the implicit let binding needs to be something that won't
collide with anything else around, but using the pre-# part of the
symbol, as with foo above, ought to suffice for that. When was the
last time you saw anyone combine foo# and ~foo, meaning different
things, in the same syntax quote? Or use foo# itself as the symbol
name. As I understand it, once past the reader layer that's as valid
an identifier as any, but one the reader will barf on in any other
context. Or, for added meta fun, use (gensym 'foo) to generate it. :)

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: format and printf can't be used with BigInt

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 4:33 PM, Alan Malloy a...@malloys.org wrote:
 On Jul 27, 11:45 am, Andrea Tortorella elian...@gmail.com wrote:
 Hi everyone,
 I don't know where to post about bugs (if this is a bug).
 Anyway in clojure 1.3 with the new numerics:

 (format %d 2N)

 throws IllegalFormatConversionException, is it a bug? are there any
 workarounds?

 Unlikely to change anytime soon: format just calls
 java.util.Formatter.format; if you look at the source of that, it
 tests for each built-in numeric type specially, instead of using
 Number. But you can probably use the %s specifier, since converting it
 to a string is unlikely to do much harm.

Of course none of the nice number-specific formatting options are
available then. If you don't mind loss of precision in
less-significant digits, you might use %f and (double the-number) to
format its coercion to double.

But according to
http://download.oracle.com/javase/6/docs/api/java/util/Formatter.html
Formatter *is* supposed to work with BigInteger with %d (and other
integer-formatting options, and with BigDecimal with %f and other
float-formatting options). So I don't know what's going wrong here,
other than that it also says IllegalFormatConversionException gets
thrown if the format symbol and the parameter are mismatched.

The JavaSE 6 Formatter works properly when invoked explicitly via interop:

= (.format (java.util.Formatter.) %d (into-array Object [(bigint 2)]))
#Formatter 2

(2N isn't recognized as a BigInteger literal by Clojure 1.2, it seems.)

In my copy of Clojure 1.2, format also seems to work:

= (format %d (bigint 2))
2

So this could be a bug in 1.3 the OP is running into, or else 2N is
turning into something other than what (bigint 2) evaluates to.

= (format %d #=(bigint 2))
2

also works for me, and is more closely equivalent to what the OP is
trying to do (as the bigint is embedded directly in the code via the
reader rather than constructed on the fly at eval time).

It looks like either 2N is doing something unexpected or the format
function somehow broke in 1.3.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: format and printf can't be used with BigInt

2011-07-27 Thread Sean Corfield
On Wed, Jul 27, 2011 at 4:32 PM, Ken Wesson kwess...@gmail.com wrote:
 = (.format (java.util.Formatter.) %d (into-array Object [(bigint 2)]))
 #Formatter 2

 (2N isn't recognized as a BigInteger literal by Clojure 1.2, it seems.)

 In my copy of Clojure 1.2, format also seems to work:

 = (format %d (bigint 2))
 2

In Clojure 1.2:

(type (bigint 2)) = java.math.BigInteger

In Clojure 1.3:

(type (bigint 2)) = clojure.lang.BigInt
(type 2N) = clojure.lang.BigInt

clojure.lang.BigInt != java.math.BigInteger which is why format no longer works.

You can do this:

(format %d (.toBigInteger 2N))
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.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


ClojureQL: debugging generated SQL / Dates

2011-07-27 Thread Brian Marick
I'm trying to figure out how to send a jodatime date into Postgres, for example 
to generate this SQL:

SELECT animals.* FROM animals WHERE removed_from_service = '2001-11-11'

Along the way, I've discovered that the SQL queries ClojureQL prints out can't 
be the ones it actually sends. Consider, for example, this:

user (ql/select (ql/table :animals)
 (ql/where (in :official_name [1 2 2])))
SELECT animals.* FROM animals WHERE official_name IN (1,2 2)

If you run the query, it seems to work. But that SELECT won't work if you type 
it at Postgres. The correct syntax should be:

SELECT animals.* FROM animals WHERE official_name IN ('1','2 2')

Is the REPL command I typed not the right way to see what SQL is sent to the 
database?

How *does* one provide dates to ClojureQL for transmission to Postgres?  I want 
to do something like this:

(ql/conj! (ql/table :animals) {:official_name fred :added_to_service 
something that counts as a SQL Date})

-
Brian Marick, Artisanal Labrador
Contract programming in Ruby and Clojure
Occasional consulting on Agile
www.exampler.com, www.twitter.com/marick

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


Bizarre ClojureScript issue

2011-07-27 Thread Anthony Grimes
Sorry for the terrible subject line. I couldn't think of an easy way to 
describe the problem in a single line.

(def net (node/require net))

(defn portal
  [port host] (.createConnection net port host))

(defn -main [ args] ; Note that only one of these -main functions is in the 
file at any given time, of course.
  (.createConnection net 1337 localhost))

(defn -main [ args]
  (portal 1337 localhost))

(set! *main-cli-fn* -main)

For some reason, the first -main above works fine but the second doesn't. 
When I use the second and try to run it, I get this: TypeError: Cannot read 
property 'net' of undefined

Why would my 'portal' function not be able to see 'net', or is that even 
what this means? I'm unfamiliar with these JavaScriptish error messages. :

I have no idea what is causing this. I reviewed the node example in the 
sample directory and I don't see what I'm missing. It's odd that it works 
fine in

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Anthony Grimes
It's odd that it works fine in the first one but no the second.

You'd think with that post button being so small that it'd be difficult 
to... yeah.

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Kevin Downey
are you sure you don't have an extra space in there?
(. createConnection net …) vs. (.createConnection net …)

On Wed, Jul 27, 2011 at 5:38 PM, Anthony Grimes disciplera...@gmail.com wrote:
 Sorry for the terrible subject line. I couldn't think of an easy way to
 describe the problem in a single line.
 (def net (node/require net))
 (defn portal
   [port host] (.createConnection net port host))
 (defn -main [ args] ; Note that only one of these -main functions is in the
 file at any given time, of course.
   (.createConnection net 1337 localhost))
 (defn -main [ args]
   (portal 1337 localhost))
 (set! *main-cli-fn* -main)

 For some reason, the first -main above works fine but the second doesn't.
 When I use the second and try to run it, I get this: TypeError: Cannot read
 property 'net' of undefined
 Why would my 'portal' function not be able to see 'net', or is that even
 what this means? I'm unfamiliar with these JavaScriptish error messages. :
 I have no idea what is causing this. I reviewed the node example in the
 sample directory and I don't see what I'm missing. It's odd that it works
 fine in

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



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Anthony Grimes
Yep, just double checked. No extra spaces.

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Kevin Downey
have you looked at the generated javascript?

On Wed, Jul 27, 2011 at 5:44 PM, Anthony Grimes disciplera...@gmail.com wrote:
 Yep, just double checked. No extra spaces.

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



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

-- 
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: format and printf can't be used with BigInt

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 8:25 PM, Sean Corfield seancorfi...@gmail.com wrote:
 On Wed, Jul 27, 2011 at 4:32 PM, Ken Wesson kwess...@gmail.com wrote:
 = (.format (java.util.Formatter.) %d (into-array Object [(bigint 2)]))
 #Formatter 2

 (2N isn't recognized as a BigInteger literal by Clojure 1.2, it seems.)

 In my copy of Clojure 1.2, format also seems to work:

 = (format %d (bigint 2))
 2

 In Clojure 1.2:

 (type (bigint 2)) = java.math.BigInteger

 In Clojure 1.3:

 (type (bigint 2)) = clojure.lang.BigInt
 (type 2N) = clojure.lang.BigInt

What the devil? Why was this done? Seems like wheel reinvention to me.

And format should account for it. A simple change will do it:

(defn format
  Formats a string using java.lang.String.format, see
java.util.Formatter for format
  string syntax
  {:added 1.0
   :static true}
  ^String [fmt  args]
  (String/format fmt (to-array (map fixup args

where

(defn fixup [o]
  (cond
(instance? clojure.lang.BigInt o) (.toBigInteger o)
...
:else o))

Of course, this suggests a generalization of condp:

(defn replace [rmap coll]
  (let [s (map #(if-let [[_ v] (find rmap %)] v %) coll)]
(if (seq? coll)
  s
  (into (empty coll) s

(defmacro condx [symb expr  clauses]
  (let [default (if (odd? (count clauses)) [:else (last clauses)] [])]
`(cond
   ~@(mapcat
   (fn [[v x]]
 [(replace {symb v} expr) x])
   (partition 2 clauses))
   ~@default)))

(defn fixup [o]
  (condx class (instance? class o)
clojure.lang.BigInt (.toBigInteger o)
...
o))

Of course, full flexibility might warrant a multimethod for fixup so
that format can be extended to any type. Format tends to occur in I/O
bound code so the runtime overhead of multimethods is probably
acceptable -- indeed, the pprint contrib library already employs them
in a very similar role.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Anthony Grimes
Yeah. To the extent that I can read Javascript, the calls look exactly the 
same and it looks 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: Bizarre ClojureScript issue

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 8:38 PM, Anthony Grimes disciplera...@gmail.com wrote:
 Sorry for the terrible subject line. I couldn't think of an easy way to
 describe the problem in a single line.
 (def net (node/require net))
 (defn portal
   [port host] (.createConnection net port host))
 (defn -main [ args] ; Note that only one of these -main functions is in the
 file at any given time, of course.
   (.createConnection net 1337 localhost))
 (defn -main [ args]
   (portal 1337 localhost))
 (set! *main-cli-fn* -main)

 For some reason, the first -main above works fine but the second doesn't.
 When I use the second and try to run it, I get this: TypeError: Cannot read
 property 'net' of undefined
 Why would my 'portal' function not be able to see 'net',

Caveat: I'm by no means a ClojureScript expert.

But maybe net is a private member of a class of which -main ends up a
method, somewhat like how gen-class works in plain Clojure, and so
-main can see it whereas portal, as a free-standing function, can't?

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Anthony Grimes
That's actually what I thought at first, but the node example that ships 
with ClojureScript actually does the same thing (uses a node function 
outside of -main and then calls that function from -main) I did and it works 
fine.

Here is the generated JavaScript for the failing -main and such:

portal.core.net = cljs.nodejs.require.call(null, net);
portal.core.portal = function portal(b, c) {
  return portal.core.net.createConnection(b, c)
};
portal.core._main = function(a) {
  cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0);
  return portal.core.portal.call(null, 1337, localhost)
};

And here is the generated JS for the working -main:

portal.core._main = function(a) {
  cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0);
  return portal.core.net.createConnection(1337, localhost)
};

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 9:05 PM, Anthony Grimes disciplera...@gmail.com wrote:
 That's actually what I thought at first, but the node example that ships
 with ClojureScript actually does the same thing (uses a node function
 outside of -main and then calls that function from -main) I did and it works
 fine.
 Here is the generated JavaScript for the failing -main and such:
 portal.core.net = cljs.nodejs.require.call(null, net);
 portal.core.portal = function portal(b, c) {
   return portal.core.net.createConnection(b, c)
 };
 portal.core._main = function(a) {
   cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0);
   return portal.core.portal.call(null, 1337, localhost)
 };
 And here is the generated JS for the working -main:
 portal.core._main = function(a) {
   cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0);
   return portal.core.net.createConnection(1337, localhost)
 };

The generated portal function seems to want two arguments (b, c) but
it's called with (null, 1337, localhost). Should that be happening?
Not that that should cause portal.core.net to not resolve.

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Anthony Grimes
The first argument to Javascript's 'call' is a 'this' argument. All 
generated functions are called like 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: Bizarre ClojureScript issue

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 9:21 PM, Anthony Grimes disciplera...@gmail.com wrote:
 The first argument to Javascript's 'call' is a 'this' argument. All
 generated functions are called like this.

If portal.core.net is an instance rather than a class variable then a
null this would explain it not resolving. Is _main called with
(null, arguments) or with (some_portal.core_object, arguments)?

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Anthony Grimes
It looks like main is called the same way. Like I said, my example is not 
much different than the one that comes with cljs.

(ns nodels
  (:require [cljs.nodejs :as nodejs]))

(def fs (nodejs/require fs))
(def path (nodejs/require path))

(defn file-seq [dir]
  (tree-seq
(fn [f] (.isDirectory (.statSync fs f) ()))
(fn [d] (map #(.join path d %) (.readdirSync fs d)))
dir))

(defn -main [ paths] 
  (dorun (map println (mapcat file-seq paths

(set! *main-cli-fn* -main)

The above example is the one I'm talking about and works fine. It's weird.

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 9:30 PM, Anthony Grimes disciplera...@gmail.com wrote:
 It looks like main is called the same way. Like I said, my example is not
 much different than the one that comes with cljs.

 (ns nodels
   (:require [cljs.nodejs :as nodejs]))
 (def fs (nodejs/require fs))
 (def path (nodejs/require path))
 (defn file-seq [dir]
   (tree-seq
     (fn [f] (.isDirectory (.statSync fs f) ()))
     (fn [d] (map #(.join path d %) (.readdirSync fs d)))
     dir))
 (defn -main [ paths]
   (dorun (map println (mapcat file-seq paths
 (set! *main-cli-fn* -main)
 The above example is the one I'm talking about and works fine. It's weird.

I see some maybe-salient differences:

1. The working example has an ns form. Maybe being in the JS
equivalent of the default package is causing problems?

2. The working example has nodejs/require instead of node/require in the defs.

However, if you're using (ns something (:require [cljs.nodejs :as
node])) and just didn't post it then neither of those can be related
to the cause...


-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Asim Jalis
Is it possible that the new function called portal is overwriting the
namespace called portal? Could you try renaming the function called
portal to something else? Like portal2?

On Wed, Jul 27, 2011 at 6:05 PM, Anthony Grimes disciplera...@gmail.com wrote:
 That's actually what I thought at first, but the node example that ships
 with ClojureScript actually does the same thing (uses a node function
 outside of -main and then calls that function from -main) I did and it works
 fine.
 Here is the generated JavaScript for the failing -main and such:
 portal.core.net = cljs.nodejs.require.call(null, net);
 portal.core.portal = function portal(b, c) {
   return portal.core.net.createConnection(b, c)
 };
 portal.core._main = function(a) {
   cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0);
   return portal.core.portal.call(null, 1337, localhost)
 };
 And here is the generated JS for the working -main:
 portal.core._main = function(a) {
   cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0);
   return portal.core.net.createConnection(1337, localhost)
 };

 --
 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: Bizarre ClojureScript issue

2011-07-27 Thread Anthony Grimes
Hah! That was it! You, sir, are one clever fellow. Thank you very much.

-- 
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: format and printf can't be used with BigInt

2011-07-27 Thread Chas Emerick

On Jul 27, 2011, at 8:56 PM, Ken Wesson wrote:

 In Clojure 1.2:
 
 (type (bigint 2)) = java.math.BigInteger
 
 In Clojure 1.3:
 
 (type (bigint 2)) = clojure.lang.BigInt
 (type 2N) = clojure.lang.BigInt
 
 What the devil? Why was this done? Seems like wheel reinvention to me.

See http://dev.clojure.org/display/doc/Enhanced+Primitive+Support:

* BigInt provides hashcodes consistent with Long through the range of long
* BigInts will enable optimizations when [operations fit] in long (not yet 
implemented)

- Chas

-- 
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: Bizarre ClojureScript issue

2011-07-27 Thread Ken Wesson
On Wed, Jul 27, 2011 at 9:48 PM, Anthony Grimes disciplera...@gmail.com wrote:
 Hah! That was it! You, sir, are one clever fellow. Thank you very much.

Damn. I didn't think of that. In normal Clojure, defn'ing x.y/x
doesn't clobber the Java package named x with a function named x. But
it looks like in JS packages and functions go into the same namespace,
so the defn shadows portal later on and portal.net looks for a
member net in the portal function object instead of the portal
namespace.

Another gotcha with ClojureScript vs. Clojure, where a function named
portal.core/portal would work fine.

The error message could clearly stand some improvement: it should
clearly identify the object it was trying to find something in.
Instead of TypeError: Cannot read property 'net' of undefined it
should have said TypeError: Cannot read property 'net' of 'portal',
which is an object of type 'function' or something. Then it would
have been clear it was looking inside the function object instead of a
namespace object for net.

The fix for this may be quite simple: have the compiler generate code
to pass the function object instead of null as the first parameter
when it generates those .call calls. :P

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

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


Generated nodejs code from ClojureScript doesn't include some functions

2011-07-27 Thread Anthony Grimes
This is an odd one. It seems that, when new functions are added to 
cljs.core, the code generated when you compile targeting nodejs doesn't 
include them. I noticed this initially when I pulled this 
commit 
https://github.com/clojure/clojurescript/commit/3b3ed7783ebbd07fec6772b6a1bca4ed32924fb8
 
and then tried to use 'rand'. I checked the generated code and rand is not 
defined anywhere. It works if I don't target nodejs (that works differently 
because it doesn't generate a file with the core functions and your code in 
it together) and it works from the REPL. I've quadruple checked my classpath 
and it's the same classpath every time. It only happens when I target 
nodejs.

Any ideas?

-- 
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: Generated nodejs code from ClojureScript doesn't include some functions

2011-07-27 Thread Anthony Grimes
I guess I should have added that it's not just rand that isn't being 
included. It's all of the recently added functions. Check the commit log.

-- 
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 to write `when-lets`

2011-07-27 Thread Oskar


On Jul 27, 8:56 pm, Dmitry Gutov raa...@gmail.com wrote:
  First: Why doesn't macroexpand expand the inner when-lets?

 It's not supposed to, see the doc. To do full expansion, you can use
 `clojure.walk/macroexpand-all`.

Oh, yeah. Thanks!


  Is the gensym in the two expands the same thing, or do they get the
  same name? That was surprising to me. I can't think of any real
  example where that is a problem. But what if I had wanted to write a
  macro like the second when-lets?

 Looks like a bug/limitation of the gensym reader macro, these symbols
 are treated as belonging to the same quoted form, so they get the same
 name.
 But I don't think the second macro does what you're saying - the
 evaluation order is the same

Yes of course. I was tired yesterday. :)

 , since `tst` is evaluated in the `let`
 form above `when-lets` in both cases, only the order of binding the
 values is reversed.
 To reverse the evaluation order, you need to move that `let` inside:

 (defmacro when-lets
   [bindings  body]
   (if-not (seq bindings)
     `(do ~@body)
     (let [form (bindings 0) tst (bindings 1) rst (drop 2 bindings)]
       `(when-lets ~(vec rst)
          (let [temp# ~tst]
            (when temp#
              (let [~form temp#]
                ~@body)))

 user= (when-lets [b (inc a) a 3] (+ b a))
 7

-- 
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 to write `when-lets`

2011-07-27 Thread Oskar


On Jul 27, 9:23 pm, Alan Malloy a...@malloys.org wrote:
 On Jul 27, 11:56 am, Dmitry Gutov raa...@gmail.com wrote:

   First: Why doesn't macroexpand expand the inner when-lets?

  It's not supposed to, see the doc. To do full expansion, you can use
  `clojure.walk/macroexpand-all`.

   Is the gensym in the two expands the same thing, or do they get the
   same name? That was surprising to me. I can't think of any real
   example where that is a problem. But what if I had wanted to write a
   macro like the second when-lets?

  Looks like a bug/limitation of the gensym reader macro, these symbols
  are treated as belonging to the same quoted form, so they get the same
  name.



 Nothing to do with being the same quoted form: foo# symbols are
 gensymmed at read time, so by the time the macro runs there's no
 evidence that they were ever gensyms: just a symbol named
 temp__1551__auto__, and it has no reason to suppose you intend them to
 be different.

 I don't think this is a problem for many (any?) macros, but if you
 want more control you can gensym yourself:

Right! Thanks!


 (defmacro when-lets
   [bindings  body]
   (if-not (seq bindings)
     `(do ~@body)
     (let [temp (gensym) form (bindings 0) tst (bindings 1) rst (drop 2
 bindings)]
       `(let [~temp ~tst]
          (when ~temp
            (when-lets ~(vec rst)
              (let [~form ~temp]
                ~@body)))

 user (use 'clojure.walk) (macroexpand-all '(when-lets [a 1 b 2] [a
 b]))
 (let* [G__1815 1] (if G__1815 (do (let* [G__1816 2] (if G__1816 (do
 (do (let* [b G__1816] (let* [a G__1815] [a b])

 user (when-lets [a 1 b 2] [a b])
 [1 2]

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