Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: pad@ryxa.irisa.fr
To: caml-list@inria.fr
Subject: [Caml-list] a generic print (ugly hack)
Date: Fri, 15 Oct 2004 18:57:52 +0200	[thread overview]
Message-ID: <200410151657.i9FGvqt18876@ryxa.irisa.fr> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1256 bytes --]


the goal is to allow the programmer to write in his program for instance:

 let _ = print_string (generic_print [[1;3];[2;9;8];[3;4]] "int list list") in
 ...
 let _ = print_string (generic_print [1;3;2;9;8;3;4] "int list") in
 let v = ... (* big computation, big data structure *)
 let _ = print_string (generic_print v "(int * float * color) assoc") in
 ...
  

and to get on stdout:
 [[1; 3]; [2; 9; 8]; [3; 4]]
 [1; 3; 2; 9; 8; 3; 4]
 [(1, 2.02, Red); (2, 4.02, Yellow)];


the type of generic_print is
 'a -> string -> string

code:
 http://www.irisa.fr/prive/padiolea/hacks/generic_print.ml

the principle is that the toplevel of O'Caml know how to print value,
so by "reusing" the toplevel, our program can too.


It is slow, ugly, not robust,  but it can be helpful.
any suggestion or critics are welcome.


-- 
Yoann  Padioleau,  INSA de Rennes, France   
Opinions expressed here are only mine. Je n'écris qu'à titre personnel.
**____   Get Free. Be Smart.  Simply use Linux and Free Software.   ____**

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


             reply	other threads:[~2004-10-15 16:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-15 16:57 pad [this message]
2004-10-15 17:20 ` Nicolas Cannasse
2004-10-15 18:52   ` pad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200410151657.i9FGvqt18876@ryxa.irisa.fr \
    --to=pad@ryxa.irisa.fr \
    --cc=caml-list@inria.fr \
    --cc=padiolea@irisa.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox