Re: dynamically create cmdspec for clojure.contrib.command-line

2011-06-27 Thread Marc Limotte
Thanks for your tips, Ken and Meikel.

Both of them were helpful, and helped me resolve my problem.  First I tried:

user=> (defmacro my-with-cl [spec] `(with-command-line args "desc" ~spec
(prn foo)))

This almost works:

user=> (macroexpand-1 '(my-with-cl [[foo "something about foo" nil]
remaining]))
(clojure.contrib.command-line/with-command-line
  user/args
  "desc"
  [[foo "something about foo" nil] remaining]
  (clojure.core/prn user/foo))

But breaks:

user=> (my-with-cl [[foo "something about foo" nil]
remaining])
java.lang.Exception: No such var: user/foo (NO_SOURCE_FILE:88)

This makes sense, as the backtick quote in my defmacro qualified foo under
ns user.  But I really need foo to be unqualified, so it refers to the foo
defined by with-command-line.  This variation worked:

(defmacro my-with-cl [spec] `(with-command-line args "desc" ~spec (prn
~'foo)))

Open to suggestions if there's a better way to do this.

Thanks,
Marc

On Mon, Jun 27, 2011 at 4:05 AM, Meikel Brandmeyer  wrote:

> Hi,
>
> Am Sonntag, 26. Juni 2011 17:22:14 UTC+2 schrieb mlimotte:
>
>
> user> (my-with-cl '[[foo "something about foo" nil]])
>> ; Evaluation aborted.
>> Exception: Unsupported binding form: something about foo
>>
>
> Leave out the ' in front of the vector. with-command-line quotes it for
> you. Adding the quote makes it see (quote [[...]]) instead of [[...]].
>
> Sincerely
> Meikel
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

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

Aw: dynamically create cmdspec for clojure.contrib.command-line

2011-06-27 Thread Meikel Brandmeyer
Hi,

Am Sonntag, 26. Juni 2011 17:22:14 UTC+2 schrieb mlimotte:

user> (my-with-cl '[[foo "something about foo" nil]])
> ; Evaluation aborted.
> Exception: Unsupported binding form: something about foo
>

Leave out the ' in front of the vector. with-command-line quotes it for you. 
Adding the quote makes it see (quote [[...]]) instead of [[...]].

Sincerely
Meikel
 

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

Re: dynamically create cmdspec for clojure.contrib.command-line

2011-06-26 Thread Ken Wesson
On Sun, Jun 26, 2011 at 11:22 AM, Marc Limotte  wrote:
> And (macroexpand (my-with-cl ...)) throws the same exception.

Macroexpand's a normal function, not a macro, so you need to quote its argument.

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


dynamically create cmdspec for clojure.contrib.command-line

2011-06-26 Thread Marc Limotte
Hi.

I'm trying to understand why the following macro doesn't work.  This is a
trivial example, but ultimately I want to create a macro that will let me
dynamically create the cmdspec for
clojure.contrib.command-line/with-command-line.  I haven't written many
macros, so my general understanding may be off.

user> (use 'clojure.contrib.command-line)
user> (def args ["--foo" "2"])
user> (defmacro my-with-cl [spec] `(with-command-line args "desc" ~spec (prn
foo)))
user> (my-with-cl '[[foo "something about foo" nil]])
; Evaluation aborted.
Exception: Unsupported binding form: something about foo

I would expect this to be expanded to
  (with-command-line args "desc" [[foo "a" "b"]] (prn foo))

Which runs ok, directly in the repl:
user> (with-command-line args "desc" [[foo "a" "b"]] (prn foo))
"2"
nil

And (macroexpand (my-with-cl ...)) throws the same exception.

How can I accomplish this, and why does my solution not work?

Thanks for any help.
Marc

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