[camlp4] Add another application of the FreeVars module

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@7527 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Nicolas Pouillard 2006-07-20 08:11:32 +00:00
parent 881e477ca6
commit 0b1510bcf8
1 changed files with 24 additions and 0 deletions

24
camlp4/test/fixtures/free_vars_test2.ml vendored Normal file
View File

@ -0,0 +1,24 @@
#default_quotation "expr";
open Camlp4.PreCast;
open Format;
module FV = Camlp4.Struct.FreeVars.Make Ast;
module PP = Camlp4.Printers.OCaml.Make Syntax;
module S = FV.S;
value _loc = Loc.ghost;
value pervasives =
let list =
[ "+"; "-"; "/"; "*" (* ... *) ]
in List.fold_right S.add list S.empty;
value f e =
let fv = FV.free_vars pervasives e in
S.fold (fun x acc -> << fun ~ $x$ -> $acc$ >>) fv e;
value print_expr = (new PP.printer ())#expr;
printf "%a@." print_expr (f <<let z = x + 2 in x + 2 * y * x * z>>);