Aloha all, I'm unable to push directly to Worg.
Inline, please find a patch. Let me know if you have questions. All the best, Tom
>From 5d81e1f38d4006a627717df21bbe7095e4949851 Mon Sep 17 00:00:00 2001 From: "Thomas S. Dye" <tsd@tsdye.online> Date: Fri, 15 Aug 2025 10:22:22 -1000 Subject: [PATCH] Add ob-doc-ocaml.org. --- org-contrib/babel/languages/ob-doc-ocaml.org | 113 +++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 org-contrib/babel/languages/ob-doc-ocaml.org diff --git a/org-contrib/babel/languages/ob-doc-ocaml.org b/org-contrib/babel/languages/ob-doc-ocaml.org new file mode 100644 index 00000000..6aa40b8d --- /dev/null +++ b/org-contrib/babel/languages/ob-doc-ocaml.org @@ -0,0 +1,113 @@ +#+OPTIONS: H:3 num:nil toc:2 \n:nil ::t |:t ^:{} -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc broken-links:nil +#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate hideblocks +#+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@) +#+TAGS: Write(w) Update(u) Fix(f) Check(c) noexport(n) +#+TITLE: OCaml Code Blocks in Babel +#+AUTHOR: Thomas S. Dye +#+EMAIL: tsd[at]tsdye[dot]online +#+LANGUAGE: en +#+HTML_LINK_UP: index.html +#+HTML_LINK_HOME: https://orgmode.org/worg/ +#+EXCLUDE_TAGS: noexport + +#+name: banner +#+begin_export html + <div id="subtitle" style="float: center; text-align: center;"> + <p> + Babel support for <a href="https://ocaml.org/">OCaml</a> + </p> + <p> + <a href="https://ocaml.org/"> + <img src="https://ocaml.org/_/MDBjN2M4YjIxY2Y1YWExZWE3Njk4M2FiZTg1NWZjNTM/logo-with-name.svg"/> + </a> + </p> + </div> +#+end_export + +* Template Checklist [12/12] :noexport: + - [X] Revise #+TITLE: + - [X] Indicate #+AUTHOR: + - [X] Add #+EMAIL: + - [X] Revise banner source block [3/3] + - [X] Add link to a useful language web site + - [X] Replace "Language" with language name + - [X] Find a suitable graphic and use it to link to the language + web site + - [X] Write an [[Introduction]] + - [X] Describe [[Requirements and Setup][Requirements and Setup]] + - [X] Replace "Language" with language name in [[Org Mode Features for Language Source Code Blocks][Babel Features for Language Source Code Blocks]] + - [X] Describe [[Header Arguments][Header Arguments]] + - [X] Describe support for [[Sessions]] + - [X] Describe [[Result Types][Result Types]] + - [X] Describe [[Other]] differences from supported languages + - [X] Provide brief [[Examples of Use][Examples of Use]] +* Introduction + +=OCaml= is a statically-typed, functional programming language, similar to =F#=, =Haskell=, =Scala=, =Rust=, and =Standard ML=. + +* Requirements and Setup + +Babel support for =OCaml= requires a working installation of the =OCaml= +platform, which combines the =OCaml= compiler with a coherent set of +tools, documentation, libraries, and testing resources. + +Babel currently evaluates =OCaml= code with the =OCaml= interpreter +and not the compiler. + +It requires [[https://elpa.nongnu.org/nongnu/tuareg.html][tuareg-mode]], which uses a constant string to name the +default interpreter session =*OCaml*=. + +To configure =OCaml= code blocks in Org mode, add the appropriate +dotted pair to =org-babel-load-languages=: + +#+begin_src emacs-lisp :exports code + (org-babel-do-load-languages + 'org-babel-load-languages + '((ocaml . t))) ; this line activates OCaml +#+end_src + +* Babel Features for OCaml Code Blocks + +Babel supports =OCaml= sessions, which run in a buffer named =*OCaml*= by default. +The header argument =:session= can only be one of ="none"=, ="default"=, or +="*OCaml*"=, other values raise an error. + +There are no =OCaml=-specific header arguments. + +* Examples of Use +Here is the obligatory "Hello World!" example. + +#+begin_example +,#+begin_src ocaml +"Hello World!" +,#+end_src + +,#+RESULTS: +: Hello World! +#+end_example + + +To return only the value, use the default header argument =:results value=. +Note the double colon separating lines of code. + +#+begin_example +,#+begin_src ocaml :var y=10 + let square x = x * x;; + square y +,#+end_src + +,#+RESULTS: +: 100 +#+end_example + +To return the value and its type, which is conventional in =OCaml=, set the header argument =:results +verbatim=. Note that the =square= function persists in the interpreter session. + +#+begin_example +,#+begin_src ocaml :var y=10 :results verbatim + square y +,#+end_src + +,#+RESULTS: +: - : int = 100 +#+end_example -- 2.34.1
-- Thomas S. Dye https://tsdye.online/tsdye