Blame camlp4/examples/expression_closure.ml

Packit 1f8b6b
(****************************************************************************)
Packit 1f8b6b
(*                                                                          *)
Packit 1f8b6b
(*                                   OCaml                                  *)
Packit 1f8b6b
(*                                                                          *)
Packit 1f8b6b
(*                            INRIA Rocquencourt                            *)
Packit 1f8b6b
(*                                                                          *)
Packit 1f8b6b
(*  Copyright  2006  Institut  National  de  Recherche en Informatique et   *)
Packit 1f8b6b
(*  en Automatique.  All rights reserved.  This file is distributed under   *)
Packit 1f8b6b
(*  the terms of the GNU Library General Public License, with the special   *)
Packit 1f8b6b
(*  exception on linking described in LICENSE at the top of the Camlp4      *)
Packit 1f8b6b
(*  source tree.                                                            *)
Packit 1f8b6b
(*                                                                          *)
Packit 1f8b6b
(****************************************************************************)
Packit 1f8b6b
Packit 1f8b6b
#default_quotation "expr";
Packit 1f8b6b
Packit 1f8b6b
open Camlp4.PreCast;
Packit 1f8b6b
open Format;
Packit 1f8b6b
Packit 1f8b6b
module FV = Camlp4.Struct.FreeVars.Make Ast;
Packit 1f8b6b
module PP = Camlp4.Printers.OCaml.Make Syntax;
Packit 1f8b6b
module S = FV.S;
Packit 1f8b6b
Packit 1f8b6b
value _loc = Loc.ghost;
Packit 1f8b6b
Packit 1f8b6b
value pervasives =
Packit 1f8b6b
  let list =
Packit 1f8b6b
    [ "+"; "-"; "/"; "*" (* ... *) ]
Packit 1f8b6b
  in List.fold_right S.add list S.empty;
Packit 1f8b6b
Packit 1f8b6b
value f e =
Packit 1f8b6b
  let fv = FV.free_vars pervasives e in
Packit 1f8b6b
  S.fold (fun x acc -> << fun ~ $x$ -> $acc$ >>) fv e;
Packit 1f8b6b
Packit 1f8b6b
value print_expr = (new PP.printer ())#expr;
Packit 1f8b6b
Packit 1f8b6b
printf "%a@." print_expr (f <<let z = x + 2 in x + 2 * y * x * z>>);