letrec

Synopsis

template <class Name, class Exp, class Body>
struct letrec
{
  // unspecified
};

Description

Recursive version of let. It does the binding in Body and in Exp as well, thus Exp can refer to itself recursively by Name.

#include <mpllibs/metamonad/letrec.hpp>

Expression semantics

For any n, x and f classes, where none of them are the same and t template:

letrec<n, x, f>

is equivalent to

let<n, syntax<eval_letrec<n, x, f>>, f>

Example

using boost::mpl::times;
using boost::mpl::plus;
using boost::mpl::minus;
using boost::mpl::int_;
using boost::mpl::equal_to;

struct fact_;
typedef var<fact_> fact;

typedef
  eval_syntax<
    letrec<
      fact,
      syntax<
        lambda_c<
          n,
          if_<
            equal_to<n, int_<0>>,
            int_<1>,
            lazy<times<apply<fact, minus<n, int_<1>>>, n>>
          >
        >
      >,
      syntax<lazy<apply<fact, int_<3>>>>
    >
  >::type
  fact_3;

[up]