janestreet / ppx_sexp_conv

Generation of S-expression conversion functions from type definitions
MIT License
88 stars 17 forks source link

README: How to print as sexps in utop? #23

Closed mars0i closed 3 years ago

mars0i commented 6 years ago

The README is very thorough. Thanks. Something that it doesn't explain is how to get sexps to print as sexps in utop, i.e. as lisp-style embedded lists rather than OCaml lists with special sexplib type variants.

# #require "ppx_sexp_conv";;
# open Sexplib.Std;;
# open Sexplib.Conv;;
# type t = A | B of int * float * t [@@deriving sexp];;
type t = A | B of int * float * t
val t_of_sexp : Sexplib0.Sexp.t -> t = <fun>
val sexp_of_t : t -> Sexplib0.Sexp.t = <fun>
# sexp_of_t (B (2, 17.0, B (3, 42.2, A))) ;;
- : Sexplib0.Sexp.t =
Ppx_sexp_conv_lib.Sexp.List
 [Ppx_sexp_conv_lib.Sexp.Atom "B"; Ppx_sexp_conv_lib.Sexp.Atom "2";
  Ppx_sexp_conv_lib.Sexp.Atom "17";
  Ppx_sexp_conv_lib.Sexp.List
   [Ppx_sexp_conv_lib.Sexp.Atom "B"; Ppx_sexp_conv_lib.Sexp.Atom "3";
    Ppx_sexp_conv_lib.Sexp.Atom "42.2"; Ppx_sexp_conv_lib.Sexp.Atom "A"]]

My guess is that there's some foo.top pretty-printer that needs to be installed to get outputs to display as they're shown in the README.

ghost commented 6 years ago

I don't remember exactly what printer needs to be installed, but if you just do #require "core.top", then Sexp.t values should be printed as s-expressions.

mars0i commented 6 years ago

Yes, that's it. Thanks.

Tried to add to README.org for a PR, but I can't get the =...= syntax to work right. I don't know what that system is. Here's my attempt, which I had inserted at the end of the paragraph that begins "If you're using ...".

In =utop=, you may need to =#require "core.top"= for s-expressions to display properly.

The #require "core.top" doesn't display correctly.

(Note the existing text in that paragraph isn't formating Core and Core.top correctly within HTML links.)

ghost commented 6 years ago

It's org-mode (it comes from the emacs world). I'll try to get that to work.

mars0i commented 6 years ago

OK, thanks much.

aalekseyev commented 4 years ago

I think this probably belongs to the documentation of sexplib rather than ppx_sexp_conv because ppx_sexp_conv makes it relatively clear that it's merely generating values for the type provided by sexplib.

It looks like that further relies on Base.Pretty_printer module, which in turn relies on "core.top", which I have trouble even getting to work. I'll ask around to try to understand the whole story better before I add anything to the doc.

aalekseyev commented 3 years ago

We added breadcrumbs in various places (sexplib, base). See dc124f2d2e646b28c2749e6c427160a5599fadb0 in sexplib and the accompanying commits in base.