lang 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 invoke

See invoke.

@

@str str bind

See bind.

@

@ bind

See bind.

>

>str str save-symbol

See save-symbol.

<

<str str load-symbol

See load-symbol.

->

-> 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.

^

^str str lambda

See lambda.

^

^ lambda

See lambda.

apply

quot (a*)

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

args

quot

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

bind

a 'sym

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

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.

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 symbol 'sym.

delete-sigil

'sym

Deletes the specified user-defined sigil '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.

eval

str a*

Parses and interprets str.

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-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.

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-json

str a

Converts a JSON string into min data.

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.

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.

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.

invoke

'sym a*

Assuming that 'sym is a formatted like dictionary/symbol, calls symbol defined in dictionary (note that this also works for nested dictionaries.

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.

lambdabind

lambdabind lambda-bind

See lambda-bind.

lambda-bind

quot 'sym

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

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).

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.

parent-scope

dict1 dict2

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

parse

str quot

Parses str and returns a quoted program quot.

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]$$ " (.) => %)

Unlike other predefined symbols, this symbol is unsealed, which means it can be modified.

publish

'sym dict

Publishes symbol 'sym to the scope of dict.

puts

a a

Prints a and a new line to STDOUT.

quit

Exits the program or shell with 0 as return code.

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.

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.

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.

ROOT

dict

Returns a module holding a reference to the ROOT scope.

Tip

This symbol is very useful in conjunction with the with operator.

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.

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 ROOT 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.

symbols

(str*)

Returns a list of all symbols defined in the ROOT 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.

to-json

a str

Converts a into a JSON string.

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.

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).

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.