I learned a lot. Thanks.
Best Regards
Shen Feng
On Wed, Jul 27, 2011 at 8:50 PM, Feng Shen 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
>...
>]
>
On Jul 27, 9:23 pm, Alan Malloy wrote:
> On Jul 27, 11:56 am, Dmitry Gutov 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 ex
On Jul 27, 8:56 pm, Dmitry Gutov 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"
On Wed, Jul 27, 2011 at 3:23 PM, Alan Malloy wrote:
> On Jul 27, 11:56 am, Dmitry Gutov 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
On Wed, Jul 27, 2011 at 2:57 PM, Aaron Cohen wrote:
> On Wed, Jul 27, 2011 at 2:39 PM, Ken Wesson wrote:
>>
>> On Wed, Jul 27, 2011 at 2:35 PM, Aaron Cohen 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 appro
On Jul 27, 11:56 am, Dmitry Gutov 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 na
On Jul 27, 11:57 am, Aaron Cohen wrote:
> On Wed, Jul 27, 2011 at 2:39 PM, Ken Wesson wrote:
> > On Wed, Jul 27, 2011 at 2:35 PM, Aaron Cohen 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. Usua
On Wed, Jul 27, 2011 at 2:39 PM, Ken Wesson wrote:
> On Wed, Jul 27, 2011 at 2:35 PM, Aaron Cohen 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 matt
> 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 re
On Wed, Jul 27, 2011 at 2:35 PM, Aaron Cohen 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 p
On Wed, Jul 27, 2011 at 2:15 PM, Ken Wesson wrote:
> On Wed, Jul 27, 2011 at 2:13 PM, Alan Malloy wrote:
> > On Jul 27, 11:11 am, Alan Malloy wrote:
> >> On Jul 27, 5:50 am, Feng Shen wrote:
> >>
>
> (defn foldr
> ([f coll]
>(reduce f (reverse coll)))
> ([f init coll]
>(reduce f init
On Wed, Jul 27, 2011 at 2:13 PM, Alan Malloy wrote:
> On Jul 27, 11:11 am, Alan Malloy wrote:
>> On Jul 27, 5:50 am, Feng Shen 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
>> > sy
On Jul 27, 11:11 am, Alan Malloy wrote:
> On Jul 27, 5:50 am, Feng Shen 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
> > ...
> > ]
> >
On Jul 27, 5:50 am, Feng Shen 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 (
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 (bindi
On Wed, Jul 27, 2011 at 10:51 AM, Dmitry Gutov 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 pa
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
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 ha
18 matches
Mail list logo