Language reference · Section 14
Running programs
plum run program.plum [args...] # run a program
plum run --check-leaks program.plum # ...and report objects left in cycles (11.3)
plum run --mem-stats program.plum # ...and print the memory it used (11.5)
plum program.plum [args...] # the same
plum check program.plum # check for errors without running
plum test # run tests (Stage 5)
plum fmt files-or-directories... # format source files in place (14.1)
plum fmt --check paths... # ...change nothing; list files that would change
plum fmt - # format standard input to standard output
plum # interactive prompt, on a terminal (14.2)
plum repl # the interactive prompt, also with piped input
plum lsp # the language server, for editors (docs/lsp.md)Exit codes: 0 success, 1 the program failed (compile or runtime error, or
exit(1)), 2 the command was used wrongly, 3 a source file could not be
read.
14.1 Formatting
plum fmt gives source code one canonical layout. It formats the files it
is given, and every .plum file under the directories it is given;
--check changes nothing, lists the files that would change and exits 1 if
there are any; --stdout writes the result to standard output instead of
the file. A file with syntax errors is reported and left as it is (exit 1).
The layout:
- four spaces per level;
{ends its line and}starts its own; - one space around binary operators and after commas, none around
..; - at most one blank line between statements, none at the start or end of a
block, and one before and after a top-level
branch,tree,traitorkindthat takes more than one line; - a list, map, call, parameter list or kind that the source spreads over
several lines gets one item per line, with a trailing comma (kind cases
go without); one on a single line stays on one line. An
ifexpression over several lines puts each branch on lines of its own; - literals keep their spelling (
0xFF,1_000, escapes,"""strings,true), and parentheses the source wrote are kept; - a comment on a line of its own stays on a line of its own, before what follows it; one after code stays after that code, and trailing comments on neighbouring lines are lined up.
Formatting never changes what a program means, and formatting a formatted file changes nothing.
14.2 The interactive prompt
plum with no arguments, when standard input is a terminal, starts a REPL;
with piped input it prints the help instead (plum repl reads piped input
as entries, without prompts). Each entry, a line, or several lines while a
bracket is open, a line ends with an operator, , or =>, or a """
string is open, is checked and run at once, as if it were the next part of
one program:
- What an entry declares (variables, functions, trees, traits, kinds and
seedimports) is there for the entries after it. An entry may declare a name again; the new declaration hides the old one from then on, while code written before keeps the old one. - An entry that is one expression prints its value as
dropwould (an object through itsto_str) and its type:= 42 : int. Anonevalue prints nothing. Such an expression is not an unused value (5.7). - An entry with a compile error or a runtime error reports it and leaves nothing it declared behind; what earlier entries made is kept. Imported files are loaded and run once, by the first entry that imports them.
- Tasks run while an entry runs, and the entry ends when its own code does; tasks still running carry on while later entries run (12).
exit(n)ends the session with exit coden; otherwise it ends with 0 at the end of the input,:quitor Ctrl-D.
Commands start with :: :help, :type expr (the expression's type,
without running it), :load file.plum (run a file's code as an entry),
:reset (forget every declaration) and :quit (or :q).