Boost logo

Boost Users :

Subject: Re: [Boost-users] [proto] : Recursive functions in a lambda like language
From: Manjunath Kudlur (keveman_at_[hidden])
Date: 2010-07-03 00:01:24


> xpressive's tracking_ptr class. There is even documentation about how
> this collection works: http://tinyurl.com/35t2kgy.

Thanks, for the pointer. I will take a look.

> Alternatively, you can introduce into your lambda language a special
> keyword named 'self' to refer to the currently-being-defined function,
> and define fib as:
>
>  function fib = if_(_1<2) [ _1 ].else_[self(_1-1) + (_1-2)];
>
> This can also be made to work.

I too considered this approach, even had the same name "self" in mind
:), or _0(), akin to argv[0] holding the current program name.

> If you have the luxury of using C++0x features, you can change your
> lambda language to look like this:
>
>  auto fib = if_(_1<2) [ _1 ].else_[self(_1-1) + (_1-2)];

Or BOOST_AUTO is also good enough for pre c++0x compilers. But the
problem with this is, how can I write mutually recursive functions? I
want to be able to say

function F1;
function F2;

F1 = ..refers F2..
F2 = ..refers F1..

This is the main reason I wanted a named type. I am not necessarily
married to this syntax. Any other syntax, maybe just using proto
mechanism, that allows (mutually) recursive function definitions would
be cool..

> If you *have* to assign it to a named type, you could either (a) give up
> on polymorphic lambdas and use something like:
>
>  function<int(int)> fib = ...;
>
> or (b) give up on static type checking and use boost::any in the
> internal interfaces.

Can you please elucidate (b)? Making the language only have
monomorphic lambdas makes it that much less interesting.

> It's an interesting problem!

I bet it is. I hope some good ideas come out of discussing this problem.

Manjunath


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net