9

I have just installed BER MetaOCaml with the following :

 $ opam update
 $ opam switch 4.02.1+BER
 $ eval `opam config env`

and I am not able to run MetaOCaml code in tuareg toplevel or simply ocaml toplevel. Following code :

let a = .<1+2>.;;

results in

Error: Reference to undefined global `Trx'

I have tried #load "trx.cma" but it cannot find the file.

Answer edit :

metaocaml is the right executable.

After adding this :

`(defun tuareg-run-metaocaml ()
    "Run an OCaml toplevel process.  I/O via buffer `*ocaml-toplevel*'."
    (interactive)
    (tuareg-run-process-if-needed
     "/usr/bin/opam config exec -- metaocaml")
    (display-buffer tuareg-interactive-buffer-name))

  (add-hook 'tuareg-mode-hook
        ' (lambda ()
              (define-key tuareg-mode-map (kbd "C-c M-s")
            'tuareg-run-metaocaml)))`

To my .emacs, I am now able to run MetaOCaml with C-c M-s.

Erick G. Hagstrom
  • 4,873
  • 1
  • 24
  • 38
  • 2
    I think you have to run `metaocaml` rather than `ocaml`. – Steve Vinoski Jan 08 '16 at 14:07
  • I thought the extension was implemented in the native OCaml... Is there a variable in emacs so tuareg toplevel runs metaocaml directly ? – Nicolas Scotto Di Perto Jan 08 '16 at 14:10
  • And why after executing the code above and try to interpret it with `!.` or `.!` (I have seen both on two differents websites) I get an `Error: Unbound value !.` or `Error: Unbound value .!` ? – Nicolas Scotto Di Perto Jan 08 '16 at 14:19
  • 1
    Looks like you could set `tuareg-interactive-program` to a value to run whatever toplevel you want. For example, mine is set to `"/usr/local/bin/opam config exec -- ocaml"`. You could also try `M-: (tuareg-run-process-if-needed)` (where `M-:` is bound to `eval-expression`) to call that elisp function directly, and unless you're already running a toplevel it will prompt you for what to run. – Steve Vinoski Jan 08 '16 at 14:20
  • I've added edited the answer to put the code added to my .emacs to make it works. Thanks ! And do you know why neither `!.` or `.!` runs MetaOcaml code for me ? – Nicolas Scotto Di Perto Jan 08 '16 at 14:57
  • No, sorry, I don't know why those don't work. – Steve Vinoski Jan 08 '16 at 14:58
  • 2
    `open Runcode` to get `!.` in scope, or use `Runcode.run` ordinary function. PS please move answer edit to the answer section and mark it accepted. – ygrek Feb 11 '16 at 20:38

0 Answers0