English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Format
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-05-06 (17:42)
From: Vasilij Karpow <malc@b...>
Subject: [Caml-list] Format
I wonder if anyone can teach me properly outputing values of
following type:

type sexp =
  | Slist of (string * lsexp)
  | Satts of lsexp
  | Sbody of lsexp
  | Sattr of (string * string)
  | Sdata of string
and lsexp = sexp list.

Even default(and hence dumb) interactive ocaml toplevel printer does
it better than my own attempts of abusing Format.

let rec print_sexp pff = function
  | Slist (n, l) -> fprintf pff "@ @,@[<1>(%s %a)@]" n print_lsexp l
  | Sbody b -> print_lsexp pff b
  | Satts a -> fprintf pff "@[(%a)@]" print_lsexp a
  | Sattr (n, a) -> fprintf pff "@[%s: \"%s\"@ @]" n (attr_value a)
  | Sdata s -> fprintf pff "@ \"%s\"" (String.escaped s)
and print_lsexp pff l = List.iter (print_sexp pff) l
I must confess though, i do not fully understand what im doing here.
So please anyone.

P.S. Oh btw. this is NOT an assignment ;)
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr