Boost logo

Boost :

Subject: Re: [boost] Template metaprogramming libraries
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-09-11 03:30:47


On Sun, Sep 11, 2011 at 12:01 AM, Ábel Sinkovics <abel_at_[hidden]> wrote:

> Hi Larry,
>
> > Are you saying that using the existing mpl, one cannot embed
> > lambda expressions inside other lambda expressions? Is that
> > mpl problem an example of name capture:
> >
> > http://dictionary.reference.com/browse/name+capture
> >
> > ?
>
> You can embed MPL lambda expressions inside other ones. I couldn't find
> a way of accessing the arguments of the outer lambda expression from the
> inner one, because the names _1, _2, etc were referring to the arguments
> of the inner expression, not the outer one (they were shadowing the
> outer ones).
>
> I'd express it with "\x.\x.x" in lambda calculus. Inside the inner
> lambda abstraction "x" refers to the argument of the inner, not the
> outer one.
>

A while ago someone suggested (on the developers' list) adding de Bruijn
indices [1] to Boost.Bind and/or Boost.MPL (and may have provided at least a
sample implementation for one or the other, I'm not sure), which ( I think)
would allow you to do what you want to do.

There might be some protect and bind combination of contortions to do what
you want, but I'd certainly agree that, even if it could be done, it
probably wouldn't be pretty.

[1] http://en.wikipedia.org/wiki/De_Bruijn_indices

- Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk