Boost logo

Boost :

Subject: Re: [boost] De Bruijn Bind (alternate bind syntax) Interest?
From: David Sankel (camior_at_[hidden])
Date: 2010-09-04 14:35:31


On Sat, Sep 4, 2010 at 7:39 AM, Larry Evans <cppljevans_at_[hidden]>wrote:

> On 09/04/10 06:09, Larry Evans wrote:
> > On 09/03/10 10:33, David Sankel wrote:
> >> On Fri, Sep 3, 2010 at 8:04 AM, Stewart, Robert <Robert.Stewart_at_[hidden]
> >wrote:
> >>
> >>> Larry Evans wrote:
> >>>> On 09/03/10 06:33, Stefan Strasser wrote:
> >>>>
> >>>> In:
> >>>>
> >>>> lam<I>
> >>>>
> >>>> I is arity, not nesting, of the lambda expression:
> >>>>
> >>>> http://bitbucket.org/camior/de-bruijn-bind/src#cl-45
> >>>>
> >>>> IOW:
> >>>>
> >>>> \(x1,x2,x3).x1+x2+x3
> >>>> =>
> >>>> lam<3>(arg<0,1>+arg<0,2>+arg<0,3>)
> >>>
> >>> lam<3>(_0_1 + _0_2 + _0_3) (using zero-based indices)
> >>>
> >>> So much more readable, don't you think? ;-)
> >>>
> >>
> >> Yes. I've added the following syntactic enhancements to the code (and
> >> updated README) at http://bitbucket.org/camior/de-bruijn-bind
> >>
> >> - abs -> lam
> >> - var -> arg
> >> - some _x_y shorthands for arg<x,y>()
> >>
> >
> > Since most of the time the user will be referring to the
> > arg<0,I>, why not switch args to arg to allow defaulting
> > the 2nd arg for the common case? IOW, something like:
> >
> > template
> > < unsigned ArgIndex
> > , unsigned NestingLevel=0
> > >
> > struct arg
> > ;
> >
> > instead of:
> >
> > template
> > < unsigned NestingLevel
> > , unsigned ArgIndex
> > >
> > struct arg
> > ;
> >
> > This would allow:
> >
> > typedef arg<1> _1;
> > typedef arg<2> _2;
> > ...
>
> Also, if:
>
> template
> < unsigned Arity=1
> >
> struct lam
> ;
>
> then:
>
>
> \(x1,x2,x3).x1+x2+x3
>
> =curry=>
>
> \x1\x2\x3.x1+x2+x3
>
> =deBruijn=>
>
> lam(lam(lam(arg<1,2>+arg<1,1>+arg<1,0>)))
>
> which illustrates that only a single argument arg template
> is needed.
>
> I also illustrates that the nesting level is the
> reverse of the argument order. I wonder why
> DeBruijn preferred that way?
>

DeBruijn likely never worked with multiple arguments. One nice thing is that
a lambda that doesn't include any reference to arguments of a lambda it is
nested in, that is one that is self contained, can be copied and pasted
anywhere and still have the same meaning.

OTOH, how would you express a nullary function?
> IOW, is the following possible with current code?
>
> lam<0>(9)
>

Yes this is possible with the current code.

See [1] for a similar case

[1]
http://bitbucket.org/camior/de-bruijn-bind/src/cb8e2edc75fb/src/main.cpp#cl-66

-- 
David Sankel
Sankel Software
www.sankelsoftware.com
585 617 4748 (Office)

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