Hi,

On 12 Okt., 07:05, Aravindh Johendran <ajohend...@gmail.com> wrote:

> (def *cont* identity)
> (defmacro =values [& retvals]
>   `(*cont* ~...@retvals))
>
> why would the following two expressions throw errors???
> (binding [*cont* (fn [m n] (=values (list m n)))] (*cont* 'a 'b))

So what happens here: The macro =values in the anonymous fn expands
into
a call to *cont*. So it is equivalent to: (binding [*cont* (fn [m n]
(*cont* (list m n)))] (*cont* :a :b)). So when you call *cont* in the
binding you actually call the anonymous function which calls again
*cont*, ie. itself. But this time you only pass one argument (the
list)
while the function expects two. Hence the error.

> However, these two expression work without a problem!
> ((binding [*cont* (fn [m n] (=values (list m n)))] *cont*) 'a 'b)

Here your basically return the anonymous function and call it
passing :a
and :b. Since the we already left the binding body the original root
value (identity) of *cont* is restored. So calling it with one
argument
does not cause the error.

> (binding [*cont* (fn [m n] (list m n))] (*cont* 'a 'b))

I think it should be clear by now, why this one works: you have no
recursive call to *cont*. Hence problem here.

Hope that helps.

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

Reply via email to