Re: Trying to understand variable capture

2012-01-10 Thread TOMITA Hiroshi
(macroexpand) will help you.

(macroexpand '(assert-true (< 4 3)))
=> (let* [lhsv__1__auto__ 4 rhsv__2__auto__ 3 ret__3__auto__ (< 4 3)]
(clojure.core/if-not ret__3__auto__ (throw
(java.lang.RuntimeException. (clojure.core/str (quote 4) " is not "
(quote <) " " rhsv__2__auto__))) true))

This is what you have after compilation.



On Tue, Jan 10, 2012 at 4:20 PM, Brian Mosley  wrote:
> Macro expansion time is just before compile time.
>
> --
> 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: Trying to understand variable capture

2012-01-09 Thread Brian Mosley
Macro expansion time is just before compile time.

-- 
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: Trying to understand variable capture

2012-01-09 Thread Neal Groothuis
Macro expansion time is not run time, is it?  Thanks.  :-)

On Jan 8, 2:59 pm, Michael Fogus  wrote:
> The names in the first let only exist at compile time and do not exist when
> the expanded form eventually runs.

-- 
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: Trying to understand variable capture

2012-01-08 Thread Michael Fogus
The names in the first let only exist at compile time and do not exist when
the expanded form eventually runs.

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

Trying to understand variable capture

2012-01-08 Thread Neal Groothuis
Hello,

I'm reading /Clojure in Action/, and I'm confused by one of the
examples.  I'm hoping someone can clarify it for me. :-)

The author gives an example of an assertion macro:

(defmacro assert-true [test-expr]
  (let [[operator lhs rhs] test-expr]
`(let [lhsv# ~lhs rhsv# ~rhs ret# ~test-expr]
  (if-not ret#
(throw (RuntimeException.
   (str '~lhs " is not " '~operator " " rhsv#)))
true

This can be used in this manner: (assert-true (< 4 3)), which will
raise an exception, since 4 is not less than 3.

What I do not understand is why he does not need to use gensyms in the
first let form (i.e., (let [[operator# lhs# rhs#] test-expr] ... ) .

By my understanding, I would expect

(let [rhs
3]
   (assert-true (= rhs 4)))

To incorrectly fail to assert due to "rhs" being captured.  However,
it works the way the author intends (i.e., it raises an exception.)

Why does "rhs" not get captured?

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