Boost logo

Boost :

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


On Fri, Sep 3, 2010 at 11:13 PM, Joel de Guzman
<joel_at_[hidden]>wrote:

> On 9/4/2010 10:40 AM, David Sankel wrote:
>
>> Your lambda uses brackets and I'm assuming this is for sequencing zero
>> argument procedures.
>>
>
> Yeah. It's use and syntax is historical. The intent is to be as close
> as possible to C++ and to somehow emulate C++ statements. It is
> used that way, e.g.:
>
> if_(c)
> [
> dothis()
> ]
> .else_
> [
> dothat()
> ]
>
> It's not only for the sake of being clever. More importantly, C++ users
> connect to this easily compared to other concocted means. It is instantly
> recognizable.
>

I think there's virtue in using syntactic sugar to expose a lambda calculus
engine in a way that resembles C++ code.

My focus for DBB is to create a powerful, yet simple, engine that, among
other things, others can build syntax sugar on top of -- whether that be a
C++ resembling lambda syntax or functional reactive programming syntax.

As an aside, I taught a fork of DBB a new trick today, fix[1]. This enables
one to declare recursive functions like factorial and fib. With some syntax
sugar this could be quite nifty:

//llam → lazy lambda is only evaluated when needed
//_a_b → the b argument of the a nested lambda
//_a → the a nested lambda

auto fact = iff( _1_1 == 1
               , 1
               , llam( _2_1 * _2( _2_1 - 1 ) )
               )

⇒ syntax sugar traslated to fix

fix( lam( lam( iff( _1_1 == 1
                  , 1
                  , llam( _2_1 * _3_1( _2_1 - 1 ) )
                  )
             )
        )
   );

I'm also pretty confidant I can make the evaluator do tail call optimization

[1] http://en.wikipedia.org/wiki/Fixed_point_combinator
[2] http://en.wikipedia.org/wiki/Tail_call#Tail_call_optimization

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