global Module

'

'str str quotesym

See quotesym.

'

' quotesym

See quotesym.

:

:str str define

See define.

:

: define

See define.

::

:: operator

See operator.

?

?str str help

See help.

?

? help

See help.

~

~str str lambda-bind

See lambda-bind.

~

~ lambda-bind

See lambda-bind.

$

$str str get-env

See get-env.

$

$ get-env

See get-env.

@

@str str bind

See bind.

@

@ bind

See bind.

->

-> dequote

See dequote.

>>

>> prefix-dequote

See prefix-dequote.

><

>< infix-dequote

See infix-dequote.

=>

=> apply

See apply.

==>

Symbol used to separate input and output values in operator signatures.

=-=

=-= expect-empty-stack

See expect-empty-stack.

%

% interpolate

See interpolate.

=%

=% apply-interpolate

See apply-interpolate.

^

^str str lambda

See lambda.

^

^ lambda

See lambda.

+

num1 num2 num3

Sums num1 and num2.

-

num1 num2 num3

Subtracts num2 from num1.

-inf

num

Returns negative infinity.

*

num1 num2 num3

Multiplies num1 by num2.

/

num1 num2 num3

Divides num1 by num2.

>

a1 a2 bool

Returns true if a1 is greater than a2, false otherwise.

Note

Only comparisons among two numbers or two strings are supported.

>=

a1 a2 bool

Returns true if a1 is greater than or equal to a2, false otherwise.

Note

Only comparisons among two numbers or two strings are supported.

<

a1 a2 bool

Returns true if a1 is smaller than a2, false otherwise.

Note

Only comparisons among two numbers or two strings are supported.

<=

a1 a2 bool

Returns true if a1 is smaller than or equal to a2, false otherwise.

Note

Only comparisons among two numbers or two strings are supported.

==

a1 a2 bool

Returns true if a1 is equal to a2, false otherwise.

!=

a1 a2 bool

Returns true if a1 is not equal to a2, false otherwise.

||

|| expect-any

See expect-any.

&&

&& expect-all

See expect-all.

and

bool1 bool2 bool3

Returns true if bool1 is equal to bool2, false otherwise.

apply

quot (a*)

Returns a new quotation obtained by evaluating each element of quot in a separate stack.

apply-interpolate

str quot str

The same as pushing apply and then interpolate on the stack.

args

quot

Returns a list of all arguments passed to the current program.

avg

quot num

Returns the average of the items of quot.

base

"dec"|"hex"|"oct"|"bin"

Sets the numeric base used to represent integers.

base?

"dec"|"hex"|"oct"|"bin"

Returns the numeric base currently used to represent integers (default: "dec").

bind

a 'sym

Binds the specified value (auto-quoted) to an existing symbol 'sym.

bitand

int1 int2 int3

Computes the bitwise and of integer int1 and int2.

bitclear

int1 quot int2

Sets the bytes specified via their position in int1 through quot to 0.

bitflip

int1 quot int2

Flips the bytes specified via their position in int1 through quot.

bitnot

int1 int2

Computes the bitwise complement of int1.

bitor

int1 int2 int3

Computes the bitwise or of integers int1 and int2.

bitparity

int1 int2

Calculate the bit parity in int1. If the number of 1-bits is odd, the parity is 1, otherwise 0.

bitset

int1 quot int2

Sets the bytes specified via their position in int1 through quot to 0.

bitxor

int1 int2 int3

Computes the bitwise xor of integers int1 and int2.

bool

a bool

Converts a to a boolean value based on the following rules:

  • If a is a boolean value, no conversion is performed.
  • If a is null, it is converted to false.
  • If a is a numeric value, zero is converted to false, otherwise it is converted to true.
  • If a is a quotation or a dictionary, the empty quotation or dictionary is converted to false, otherwise it is converted to true.
  • If a is a string, the empty string, and "false" are converted to false, otherwise it is converted to true.

boolean?

a bool

Returns true if a is a boolean, false otherwise.

capitalize

'sym str

Returns a copy of 'sym with the first character capitalized.

chr

int str

Returns the single character str obtained by interpreting int as an ASCII code.

case

((quot1 quot2)*) a*

This operator takes a quotation containing n different conditional branches.

Each branch must be a quotation containing two quotations, and it is processed as follows:

  • if quot1 evaluates to true, then the quot2 is executed.
  • if quot1 evaluates to false, then the following branch is processed (if any).

compiled?

bool

Returns true if the current program has been compiled.

define

a 'sym

Defines a new symbol 'sym, containing the specified value.

define-sigil

a 'sym

Defines a new sigil 'sym, containing the specified value (auto-quoted if not already a quotation).

defined-symbol?

'sym bool

Returns true if the symbol 'sym is defined, false otherwise.

defined-sigil?

'sym bool

Returns true if the symbol 'sym is defined, false otherwise.

delete-sigil

'sym

Deletes the specified user-defined sigil 'sym.

delete-symbol

'sym

Deletes the specified symbol 'sym.

dequote

quot a*

Pushes the contents of quotation quot on the stack.

Each element is pushed on the stack one by one. If any error occurs, quot is restored on the stack.

dev

Toggles development mode.

dev?

bool

Returns true if the current program is being executed in development mode.

dictionary?

a bool

Returns true if a is a dictionary, false otherwise.

div

int1 int2 int3

Divides int1 by int2 (integer division).

escape

'sym str

Returns a copy of 'sym with quotes and backslashes escaped with a backslash.

eval

str a*

Parses and interprets str.

even?

int bool

Returns true if int is even, false otherwise.

exit

int

Exits the program or shell with int as return code.

expect

quot1 quot2

If the -d (--dev) flag is specified when running the program, validates the first n elements of the stack against the type descriptions specified in quot1 (n is quot1’s length) and if all the elements are valid returns them wrapped in quot2 (in reverse order). If the -d (--dev) flag is not specified when running the program, no validation is performed and all elements are just returned in a quotation in reverse order.

Tips

  • You can specify a typed dictionary by prepending the type name with dict:. Example: dict:socket
  • You can specify two or more matching types by separating combined together in a logical type expression, e.g.: string|quot

expect-all

quot bool

Assuming that quot is a quotation of quotations each evaluating to a boolean value, it pushes true on the stack if they all evaluate to true, false otherwise.

expect-any

quot bool

Assuming that quot is a quotation of quotations each evaluating to a boolean value, it pushes true on the stack if any evaluates to true, false otherwise.

expect-empty-stack

Raises an error if the stack is not empty.

float

a flt

Converts a to a float value based on the following rules:

  • If a is true, it is converted to 1.0.
  • If a is false, it is converted to 0.0.
  • If a is null, it is converted to 0.0.
  • If a is a integer, it is converted to float value.
  • If a is a float, no conversion is performed.
  • If a is a string, it is parsed as a float value.

float?

a bool

Returns true if a is a float, false otherwise.

foreach

quot1 quot2 a*

Applies the quotation quot2 to each element of quot1.

format-error

dict:error str

Formats the error dict:error as a string.

from-bin

'sym int

Parses 'sym as a binary number.

from-dec

'sym int

Parses 'sym as a decimal number.

from-hex

'sym int

Parses 'sym as a hexadecimal number.

from-json

str a

Converts a JSON string into min data.

from-oct

'sym int

Parses 'sym as a octal number.

from-semver

str dict

Given a basic SemVer-compliant string (with no additional labels) str, it pushes a dictionary dict on the stack containing a major, minor, and patch key/value pairs.

from-yaml

str a

Converts a YAML string into min data.

Note

At present, only YAML objects containing string values are supported.

gets

str

Reads a line from STDIN and places it on top of the stack as a string.

get-env

'sym str

Returns environment variable 'sym.

help

'sym

Prints the help text for 'sym, if available.

if

quot1 quot2 quot3 a*

If quot1 evaluates to true then evaluates quot2, otherwise evaluates quot3.

import

'sym

Imports the a previously-loaded module 'sym, defining all its symbols in the current scope.

indent

'sym int str

Returns str containing 'sym indented with int spaces.

indexof

str1 str2 int

If str2 is contained in str1, returns the index of the first match or -1 if no match is found.

inf

num

Returns infinity.

infix-dequote

quot a

Dequotes quot using infix notation.

Note that no special operator preference is defined, symbols precedence is always left-to-right. However, you can use parentheses (quotes) to evaluate expressions before others.

integer

a int

Converts a to an integer value based on the following rules:

  • If a is true, it is converted to 1.
  • If a is false, it is converted to 0.
  • If a is null, it is converted to 0.
  • If a is an integer, no conversion is performed.
  • If a is a float, it is converted to an integer value by truncating its decimal part.
  • If a is a string, it is parsed as an integer value.

integer?

a bool

Returns true if a is an integer, false otherwise.

interpolate

str quot str

Substitutes the placeholders included in str with the values in quot.

Notes

  • If quot contains symbols or quotations, they are not interpreted. To do so, call apply before interpolating or use apply-interpolate instead.
  • You can use the $# placeholder to indicate the next placeholder that has not been already referenced in the string.
  • You can use named placeholders like $pwd, but in this case quot must contain a quotation containing both the placeholder names (odd items) and the values (even items).

join

quot 'sym str

Joins the elements of quot using separator 'sym, producing str.

lambda

quot 'sym

Defines a new symbol 'sym, containing the specified quotation quot. Unlike with define, in this case quot will not be quoted, so its values will be pushed on the stack when the symbol 'sym is pushed on the stack.

Essentially, this symbol allows you to define an operator without any validation of constraints and bind it to a symbol.

lambda-bind

quot 'sym

Binds the specified quotation to an existing symbol 'sym which was previously-set via lambda.

length

'sym int

Returns the length of 'sym.

line-info

dict

Returns a dictionary dict containing a filename, line, and column properties identifying the filename, line and column of the current symbol.

linrec

quot1 quot2 quot3 quot4 a*

Implements linear recursions as follows:

  1. Evaluates quot1.
    • If quot1 evaluates to true, then it evaluates quot2.
    • Otherwises it executes quot3 and recurses using the same four quotations.
  2. Finally, it executes quot4.

load

'sym a*

Parses and interprets the specified min file 'sym, adding .min if not specified.

load-symbol

'sym a*

Loads the contents of symbol 'sym from the .min_symbols file.

loglevel

'sym

Sets the current logging level to 'sym. 'sym must be one of the following strings or quoted symbols:

  • debug
  • info
  • notice
  • warn
  • error
  • fatal

Note

The default logging level is notice.

loglevel?

str

Returns the current log level (debug, info, notice, warn, error or fatal).

lowercase

'sym str

Returns a copy of 'sym converted to lowercase.

match?

str1 str2 bool

Returns true if str2 matches str1, false otherwise.

med

quot num

Returns the median of the items of quot.

mod

int1 int2 int3

Returns the integer module of int1 divided by int2.

nan

nan

Returns NaN (not a number).

not

bool1 bool2

Negates bool1.

null?

a bool

Returns true if a is null, false otherwise.

number?

a bool

Returns true if a is a number, false otherwise.

odd?

int bool

Returns true if int is odd, false otherwise.

operator

quot a*

Provides a way to define a new operator (symbol, sigil, or typeclass) on the current scope performing additional checks (compared to define and define-sigil), and automatically mapping inputs and outputs.

quot is a quotation containing:

  • A symbol identifying the type of operator to define (symbol, sigil, or typeclass).
  • A symbol identifying the name of the operator.
  • A quotation defining the signature of the operator, containing input and output values identified by their type and a capturing symbol, separated by the ==> symbol.
  • A quotation identifying the body of the operator.

The main additional features offered by this way of defining operators are the following:

  • If in development mode (-d or --dev flag specified at run time), both input and output values are checked against a type (like when using the expect operator and automatically captured in a symbol that can be referenced in the operator body quotation.
  • The full signature of the operator is declared, making the resulting code easier to understand at quick glance.
  • An exception is automatically raised if the operator body pollutes the stack by adding or removing elements from the stack (besides adding the declared output values).
  • It is possible to use the return symbol within the body quotation to immediately stop the evaluation of the body quotation and automatically push the output values on the stack.

opts

dict

Returns a dictionary of all options passed to the current program, with their respective values.

ord

str int

Returns the ASCII code int corresponding to the single character str.

parent-scope

dict1 dict2

Returns a dictionary dict2 holding a reference to the parent scope of dict1 or null if dict1 is global.

parse

str quot

Parses str and returns a quoted program quot.

parse-url

str dict:url

Parses the url str into its components and stores them into dict:url.

prefix

'sym1 'sym2 str

Prepends 'sym2 to 'sym1.

prefix-dequote

quot a

Dequotes quot using prefix notation (essentially it reverses quot and dequotes it).

prompt

str

This symbol is used to configure the prompt of the min shell. By default, it is set to the following quotation:

("[$1]$$ " (sys.pwd) => %)

{#op

{#op||or||bool1 bool2||bool3|| Returns true if bool1 or bool2 is true, false otherwise.#}

pred

int1 int2

Returns the predecessor of int1.

product

quot int

Returns the product of all items of quot. quot is a quotation of integers.

puts

a a

Prints a and a new line to STDOUT.

put-env

'sym1 'sym2 str

Sets environment variable 'sym2 to 'sym1.

quit

Exits the program or shell with 0 as return code.

quotation?

a bool

Returns true if a is a quotation, false otherwise.

quoted-symbol?

a bool

Returns true if a is a quoted symbol, false otherwise.

quote

a (a)

Wraps a in a quotation.

quotecmd

str (sym)

Creates a command with the value of str and wraps it in a quotation.

quotesym

str (sym)

Creates a symbol with the value of str and wraps it in a quotation.

random

int1 int2

Returns a random number int2 between 0 and int1-1.

Note

You must call randomize to initialize the random number generator, otherwise the same sequence of numbers will be returned.

randomize

{{null}

Initializes the random number generator using a seed based on the current timestamp.

range

quot2 quot2

Takes a quotation quot1 of two or three integers in the form of start, end and an optional step (1 if not specified) and generates the sequence and returns the resulting quotation of integers quot2.

raise

dict:error

Raises the error specified via the dictionary dict:error.

raw-args

quot

Returns a list of all arguments and (non-parsed) options passed to the current program.

remove-symbol

'sym

Removes the symbol 'sym from the .min_symbols file.

repeat

'sym int str

Returns str containing 'sym repeated int times.

replace

str1 str2 str3 str4

Returns a copy of str1 containing all occurrences of str2 replaced by str3

replace-apply

str1 str2 quot str3

Returns a copy of str1 containing all occurrences of str2 replaced by applying quot to each quotation corresponding to each match.

require

'sym dict

Parses and interprets (in a separated interpreter) the specified min module, and returns a module dictionary dict containing all the symbols defined in 'sym.

This symbol will attempt to locate the specified module in this way. Given the following min program:

'my-module require :my-module
  1. Check for a file named my-module in the same folder as the current file (with our without a .min extension).
  2. Check for a file named index.min in the mmm/my-module/*/index.min folder relative to the current file (locally-installed managed-module).
  3. Check for a file named index.min in the $HOME/mmm/my-module/*/index.min folder (globally-installed managed-module). If multiple versions of the same module are present, the first one will be loaded.

return

If used within the body quotation of an operator definition, causes the interpreter to stop pushing further body elements on the stack and start pushing tbe operator output values on the stack.

If used outside of the body quotation of an operator definition, it raises an exception.

save-symbol

'sym

Saves the contents of symbol 'sym to the .min_symbols file.

scope

dict

Returns a dictionary dict holding a reference to the current scope.

This can be useful to save a reference to a given execution scope to access later on.

saved-symbols

(str*)

Returns a quotation containing all symbols saved in the .min_symbols file.

scope-sigils

dict (str*)

Returns a list of all sigils defined in dictionary dict.

scope-symbols

dict (str*)

Returns a list of all symbols defined in dictionary dict.

seal-symbol

'sym

Seals symbol 'sym, so that it cannot be re-assigned.

seal-sigil

'sym

Seals the user-defined sigil 'sym, so that it cannot be re-defined.

sealed-symbol?

'sym bool

Returns true if the symbol 'sym is sealed, false otherwise.

sealed-sigil?

'sym bool

Returns true if the sigil 'sym is sealed, false otherwise.

search

str1 str2 quot

Returns a quotation containing the first occurrence of str2 within str1. Note that:

  • The first element of quot is the matching substring.
  • Other elements (if any) contain captured substrings.
  • If no matches are found, the quotation contains empty strings.

search-all

str1 str2 quot

Returns a quotation of quotations (like the one returned by the search operator) containing all occurrences of str2 within str1.

semver-inc-major

str1 str2

Increments the major digit of the SemVer-compliant string (with no additional labels) str1.

semver-inc-minor

str1 str2

Increments the minor digit of the SemVer-compliant string (with no additional labels) str1.

semver-inc-patch

str1 str2

Increments the patch digit of the SemVer-compliant string (with no additional labels) str1.

semver?

str bool

Checks whether str is a SemVer-compliant version or not.

split

'sym1 'sym2 quot

Splits 'sym1 using separator 'sym2 (a Perl Compatible Regular Expression) and returns the resulting strings within the quotation quot.

shl

int1 int2 int3

Computes the shift left operation of int1 and int2.

shr

int1 int2 int3

Computes the shift right operation of int1 and int2.

sigil-help

'sym dict:help|null

Returns the help dictionary for the sigil 'sym, if available, null otherwise.

sigils

(str*)

Returns a list of all sigils defined in the global scope.

source

'sym quot

Display the source code of symbol 'sym (if it has been implemented a min quotation).

string

a str

Converts a to its string representation.

stringlike?

a bool

Returns true if a is a string or a quoted symbol, false otherwise.

string?

a bool

Returns true if a is a string, false otherwise.

strip

'sym str

Returns str, which is set to 'sym with leading and trailing spaces removed.

substr

str1 int1 int2 str2

Returns a substring str2 obtained by retrieving int2 characters starting from index int1 within str1.

succ

int1 int2

Returns the successor of int1.

suffix

'sym1 'sym2 str

Appends 'sym2 to 'sym1.

sum

quot int

Returns the sum of all items of quot. quot is a quotation of integers.

symbols

(str*)

Returns a list of all symbols defined in the global scope.

symbol-help

'sym dict:help|null

Returns the help dictionary for the symbol 'sym, if available, null otherwise.

tap

a quot a

Performs the following operations:

  1. Removes a from the stack.
  2. For each quotation defined in quot (which is a quotation of quotations each requiring one argument and returning one argument):
    1. Pushes a back to the stack.
    2. Dequotes the quotation and saves the result as a.
  3. Push the resulting a back on the stack.

times

quot int a*

Applies the quotation quot int times.

titleize

'sym str

Returns a copy of 'sym in which the first character of each word is capitalized.

tokenize

str quot

Parses the min program str and returns a quotation quot containing dictionaries with a type symbol and a value symbol for each token.

to-bin

int str

Converts int to its binary representation.

to-dec

int str

Converts int to its decimal representation.

to-hex

int str

Converts int to its hexadecimal representation.

to-json

a str

Converts a into a JSON string.

to-oct

int str

Converts int to its octal representation.

to-semver

dict str

Given a a dictionary dict containing a major, minor, and patch key/value pairs , it pushes a basic SemVer-compliant string (with no additional labels) str on the stack.

to-yaml

a str

Converts a into a YAML string.

Note

At present, only min dictionaries containing string values are supported.

try

(quot1 quot2? quot3?) a*

Evaluates a quotation as a try/catch/finally block.

The must contain the following elements:

  1. A quotation quot1 containing the code to be evaluated (try block).
  2. (optional) A quotation quot2 containing the code to execute in case of error (catch block).
  3. (optional) A quotation quot3 containing the code to execute after the code has been evaluated, whether an error occurred or not (finally block).

type

a str

Returns the type of a.

typealias

'sym1 'sym2

Creates a type alias 'sym1 for type expression 'sym2.

type?

a 'sym bool

Returns true if the data type of a satisfies the specified type expression 'sym, false otherwise.

unless

quot1 quot2 a*

If 1 evaluates to false then evaluates 2.

unseal-symbol

'sym

Unseals the user-defined symbol 'sym, so that it can be re-assigned.

unseal-sigil

'sym

Unseals sigil 'sym, so that it can be re-defined (system sigils cannot be unsealed).

uppercase

'sym1 'sym2

Returns a copy of 'sym converted to uppercase.

version

str

Returns the current min version number.

when

quot1 quot2 a*

If quot1 evaluates to true then evaluates quot2.

while

quot1 quot2 a*

Executes quot2 while quot1 evaluates to true.

with

quot1 quot2 a*

Pushes each item of quot1 on the stack using the scope of quot2 as scope.

xor

bool1 bool2 bool3

Returns true if bool1 and bool2 are different, false otherwise.