Users familiar with Python will feel at home with Mpl. Mpl supports syntax and basic types as in Python. Further, some unique language extensions and capabilities make Mpl more potent for the target use cases. We will learn those in subsequent sections. Below is a peek into what a typical interactive user session in Mpl repl looks like.
Mpl is available on Linux, MacOs and Windoes.
mpl can be launched on any modern terminal.
mpl -h prints supported command line options.
For a typical trouble shooting session, one can issue Mpl "commands" on repl and assign the output to a variable. That variable (typically a Json document) is available as input to next command. More details in subsequent section. For commands (in mpl they start with
!) convenient command completion options is available as user types.
Mpl interpreter in batch mode is invoked with mpl file in shell.
Mpl suppoprts types such as Number, String, Boolean, Json, Time, and Duration. Note that, unlike other languages, Mpl has Json, Time, and Duration as first-class built-in types. Refer to the 'types' section for details on each type.
Simple variable: A simple variable in Mpl can be defined similar to python Python. e.g.,
The value of
Indexed variable: Mpl support intuitive indexed variable to access values in JSON documents. Users can create JSON documents via the keyword
jsonfollowed by a valid JSON text. To access any field in the document, one can use syntax like
x.y["a"]or in more convenient dotted notation,
In addition to simple assignment of 'rhs' variable to 'lhs', 'rhs' can be an expression. Expression can be composed of basic opertors like
/ and builtin operators like 'len' and methods. For full documentation of methods supported for each type, refer to 'types' section.
Example 1: Simple arithmetic
Example 2: Simple string transformation
Mpl supports Python like
if-else branching syntax. The comparison expression can be on any Mpl supported data types. The supported compare operators are
in. In addition
if not statement supported. e.g.,
The conditional expression can be chained by
||operators. Unix like wildcard match, specified in backtick, is also supported. e.g.,
Here vlaue of
x will be
in operator find existance of value in arrays or a key in object. e.g.,
Here vlaue of
res will be
for loop syntax with simple loops over integer or iterables (like Json doc). Note that Python's indentation rule for the loop block applies. For example in following simple loop:
iis not needed, in Mpl,
for x:is a valid statement to loop for
continueare supported, shown below.
For iterables like Json array, value will be assigned as Json value of iterable. Refer to Json type section for more details on Json.
i, is assigned to
keyof map (sub document). e.g.,
Mpl supports Python like function definition. Functions have read only access to all variables from calling scope. At this time, unlike Python, Mpl functions can return only one variable. e.g.,