CAMLMIX(1)
π CAMLMIX(1) π
okay bestie, welcome to the camlmix manual page β yeah it's camlmix in section 1 of the User Manuals, and it's literally a whole preprocessor that takes text with OCaml stuffed inside and spits text back out. iconic behavior honestly π¦
β¨ NAME β¨
camlmix β a preprocessor which converts text with embedded OCaml
πΈ SYNOPSIS πΈ
camlmix [Options...] files...
π DESCRIPTION π
So camlmix processes text templates that have OCaml code embedded in them, and generates text again. Like, it eats templates and produces more text, no cap.
From one or several input files it generates an OCaml text generation program, and then it executes that program to get the result. β¨
And if you use the -fun option, you can also convert the text template into an OCaml text generation function instead. cute, right? π
π OPTIONS π
-o outputβ write the generated text into the file output-cβ only generate the text generation program, don't execute it. By default, the program is calledlastfile.mlwhen lastfile is the last file argument.-co fileβ specify the name of the text generation program-funβ generate OCaml code for a text generation function from the input (see ADVANCED USAGE below)-e ocamlcβ set the name of the OCaml executable-cleanβ remove the text generation program after execution-insert ocaml_codeβ insert ocaml_code at the beginning of the text generation program-remixβ try a conversion to the camlremix syntax-versionβ print version and exit-help|--helpβ print help and exit (and yes, this man page was written from the output of-help, so you're literally reading the help's help π)
π BASIC USAGE π
Text that's wrapped in ## markers is treated as a block of OCaml code. It can be any kind of toplevel expressions β definitions, applications of printing functions, whatever you want, bestie:
This is ocaml version ## print Sys.ocaml_version ##
If the OCaml code starts with =, then it's interpreted as an expression of type string, and that string gets printed like the rest of the text:
This is ocaml version ##= Sys.ocaml_version ##
The text blocks get printed together with the evaluated OCaml pieces, using the print function. And if you want to literally print ##, just include ###. π«Ά
White space can be controlled with ##. and .##:
##.β don't print white space occurring on the left.##β don't print white space up to and including the first newline, following to the right.
π₯ ADVANCED USAGE π₯
π§ Directives
Blocks of code that start with the @ character (possibly preceded by spaces) are directives for Camlmix. There are two directives. include inserts a camlmix file, and skip skips the next block. For instance:
Hello ## @include "world.mlx"; skip .## ## let x = 123 ##!
π Conversion into a text generation function for dynamic rendering
The -fun option, used in combination with -c and often -co, produces an OCaml source file which provides a function render with the following signature:
val render : ?print:(string -> unit) -> 'a -> unit
The polymorphic argument is called param in the generated code and can be used to pass runtime arguments into the render function. The print function is used to set the initial value of Camlmix.printer (see below). Its default value is:
fun s -> print_string s; flush stdout
β Runtime hooks
The text generation program, which camlmix generates, contains a module Camlmix at the beginning, which can be used in code blocks. This module has the following signature.
module Camlmix : sig
val source : string ref
val line : int ref
val char : int ref
Location of the first character of the current block in
its source file. Line and character numbers count from 1.
These references are updated by camlmix at the beginning
of each block.
val printer : (string -> unit) ref
function for printing text blocks
val print_with : (string -> unit) -> unit
print_with f causes the next text block to be printed
with f instead of the current printer. Its behavior is
undefined if it is called several times in the same code
block.
val print_if : bool -> unit
print_if cond prints the next text block only if
condition cond is true. It uses print_with internally.
end
π¨ bestie heads up: print_with's behavior is undefined if you call it several times in the same code block. don't do it, fr fr.
π¦ SEE ALSO π¦
The camlmix web page, http://mjambon.com/camlmix/
π AUTHOR π
This manual page was written by Sylvain Le Gall <gildor@debian.org> and Hendrik Tews <hendrik@askra.de>, specifically for the Debian project (and may be used by others).
and that's the whole vibe π this was CAMLMIX, from the camlmix package, dated May 2013 β the CAMLMIX(1) manual page, section 1, User Manuals. slay, go preprocess something, bestie πβ¨
π¦ where this page comes from
- debian bookworm: camlmix 1.3.1-4+b2 Β· BSD-3-Clause
- debian trixie: camlmix 1.3.1-6+b3 Β· BSD-3-Clause
- ubuntu jammy: camlmix 1.3.1-4build1 Β· BSD-3-Clause
- ubuntu noble: camlmix 1.3.1-5 Β· BSD-3-Clause
- ubuntu questing: camlmix 1.3.1-6
- ubuntu resolute: camlmix 1.3.1-6build1 Β· BSD-3-Clause
- ubuntu stonking: camlmix 1.3.1-6build2 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms