From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id AD75D81792 for ; Mon, 1 Jul 2013 23:30:50 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of michipili@gmail.com) identity=pra; client-ip=209.85.128.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="michipili@gmail.com"; x-sender="michipili@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of michipili@gmail.com designates 209.85.128.178 as permitted sender) identity=mailfrom; client-ip=209.85.128.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="michipili@gmail.com"; x-sender="michipili@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ve0-f178.google.com) identity=helo; client-ip=209.85.128.178; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="michipili@gmail.com"; x-sender="postmaster@mail-ve0-f178.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhkBAMTx0VHRVYCym2dsb2JhbABagztJwDAIFg4BAQEBAQYLCwkUKIJRGQEbEQ0DEhBdAREBBQGIMQEDD5tVgn6MTYJ/hCUKGScNWId0AQUMj2+DUQOXSIEpjjcWKYQ5Og X-IPAS-Result: AhkBAMTx0VHRVYCym2dsb2JhbABagztJwDAIFg4BAQEBAQYLCwkUKIJRGQEbEQ0DEhBdAREBBQGIMQEDD5tVgn6MTYJ/hCUKGScNWId0AQUMj2+DUQOXSIEpjjcWKYQ5Og X-IronPort-AV: E=Sophos;i="4.87,976,1363129200"; d="scan'208";a="24154776" Received: from mail-ve0-f178.google.com ([209.85.128.178]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 01 Jul 2013 23:30:50 +0200 Received: by mail-ve0-f178.google.com with SMTP id pb11so4241915veb.37 for ; Mon, 01 Jul 2013 14:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=pAyXmMy3zfzAij5GtGV6qN/6r+8+O0PqS8PeAQ6fTLM=; b=Oz6YqTNuxmKI5ay77zKtyqOPBzqnGZdTw6GJVklwyPoIjJNY+cRNKwn6kU2J8qBTcc OAoi+l/1zTVrodYxpBj24oC9/PBVt0piVKos9Bn1/JZNi6aoLFKjvvr/LbbTi3+mov4v t7WyIQSA5DY4+A2gzoVB8zNQxP3oa4znRbT2PnAjPJYJUym4y4ZnYQlG28Vb4CTcYlIV BYLZnL5L1KKAJFJHoL7YcTEXh7oWFZMsRpwQw5FlZl57cuXvNmC67oP6dxk37SbPUTWY Kbn5H4CI6ZKqH3Ym6AmcdRXpt1rclizxQfEm1O05GHYsSGN3vN4wEFgNgtZG+r0DRnSj pX0w== MIME-Version: 1.0 X-Received: by 10.52.90.194 with SMTP id by2mr5322697vdb.62.1372714249215; Mon, 01 Jul 2013 14:30:49 -0700 (PDT) Received: by 10.52.115.231 with HTTP; Mon, 1 Jul 2013 14:30:49 -0700 (PDT) Date: Mon, 1 Jul 2013 23:30:49 +0200 Message-ID: From: =?ISO-8859-1?Q?Michael_Le_Barbier_Gr=FCnewald?= To: caml-list@inria.fr Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: [Caml-list] Opening a module from toploop startup Dear Camlers, I am learning to produce customised toplevel loops and, while I was able to automatically add custom printers, could not open modules. Obviously, there is something I should know, and don't=85 could someone help me? My code (working example, see below) is a bit long, so let me outline it: The _startup_ procedure issues a few toploop directives, adding search directories, installing printers for the given modules (currently one) and opening them. _open_module_ and _install_printer_ produce and interpret toplevel phrases corresponding to the directives with the same name. Tank you for your help, Michael ----8<---- Compile: |ocamlfind ocamlc -c -package "compiler-libs" -o demonstrate.cmo demonstrate.ml||| |||ocamlfind ocamlmktop -package "compiler-libs" -custom -linkall -dllpath-all -linkpkg -package "compiler-libs" demonstrate.cmo -o mytoplevel||| || Demonstrate that the Demonstrate.Tag module is not opened: |> ./mytoplevel||| ||| OCaml version 4.00.1||| |||| |||# test_open_module;;||| |||Error: Unbound value test_open_module||| |||# ^D||| || Demonstrate that the custom printer is installed: |> ./mytoplevel||| ||| OCaml version 4.00.1||| |||| |||# open Demonstrate;;||| |||# (5 : Tag.t);;||| |||- : Demonstrate.Tag.t =3D Tag#5||| |||# ^D| The whole code: ~~~~ |open Format|| || ||module Tag =3D|| ||struct|| || type t =3D int|| || let format fft tag =3D|| || fprintf fft "Tag#%d" tag|| || let test_open_module () =3D|| || true|| ||end|| || ||let libdir =3D [|| || "/usr/local/lib/ocaml/compiler-libs";|| ||]|| || ||let execute_phrase ident phrase =3D|| || if Toploop.execute_phrase false Format.std_formatter phrase|| || then|| || ()|| || else|| || failwith ident|| || ||let rec make_path_rev p =3D|| || match p with|| || | [] -> invalid_arg "make_path_rev"|| || | h :: [] -> Longident.Lident h|| || | h :: t -> Longident.Ldot (make_path_rev t, h)|| || ||let make_path p =3D|| || make_path_rev (List.rev p)|| || || ||let install_printer path =3D|| || let longident =3D make_path_rev ("format" :: List.rev path) in|| || let phrase =3D Parsetree.Ptop_dir(|| || "install_printer", Parsetree.Pdir_ident longident|| || )|| || in|| || execute_phrase "install_printer" phrase|| || || ||let open_module p =3D|| || let open Parsetree in|| || let open Location in|| || let open Asttypes in|| || let loc =3D {|| || loc_start =3D Lexing.dummy_pos;|| || loc_end =3D Lexing.dummy_pos;|| || loc_ghost =3D false|| || }|| || in|| || let phrase =3D Ptop_def [|| || {|| || pstr_desc =3D|| || Pstr_open {|| || txt =3D make_path p;|| || loc;|| || };|| || pstr_loc =3D loc|| || };|| || ]|| || in|| || execute_phrase "open_module" phrase|| || ||let startup () =3D|| || begin|| || List.iter Topdirs.dir_directory libdir;|| || List.iter install_printer [["Demonstrate"; "Tag"]];|| || List.iter open_module [["Demonstrate"]; ["Demonstrate"; "Tag" ]];|| || end|| || ||let _ =3D|| || Toploop.toplevel_startup_hook :=3D startup| ---->8----