Boost logo

Boost Users :

Subject: [Boost-users] [proto] : Recursive functions in a lambda like language
From: Manjunath Kudlur (keveman_at_[hidden])
Date: 2010-07-02 21:00:45


I was playing with the idea of having the user declare functions
(polymorphic, possibly recursive) in a lambda like language, and the
capability to later call that function with different types of
arguments. Here is an example of what I am thinking about.

function fib = if_(_1<2) [ _1 ].else_[fib(_1-1) + (_1-2)];
int x = fib.eval(10);

How should I define the "function" class? My first attempt at a
solution was to use "boost::any" like class for function, I overloaded
operator() in that class so that it returns a proto expression. I am
attaching some source code that has a function class and a phoenix
like language. Now, I am not able to come up with a solution for
defining a polymorphic eval() for the function class. Since "function"
has to be able to store any type inside it, it has to do type erasure.
All methods in "function" has to be delegated to value_base class but
that cannot delegate a polymorphic eval() function down to value_type.
I can templatize "function" class and get monomorphic functions
defined in this language. But that is less interesting. I would
greatly appreciate any advice and suggestions on other solutions to
this problem. I realize that this is not entirely proto specific and
maybe it is a general C++ language question, but I am hoping proto
users might have faced similar problems and provide guidance.

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