Tools
The REPL and eval
burn repl (or burni without arguments) reads Burn code line by line, runs it, and prints the value of each
expression:
$ burn repl
Burn 26.1.0-experimental-6 REPL. Type :help for help, :quit to exit.
>>> var names = ["ada", "lin"]
>>> names.push("grace")
>>> len(names)
3
>>> fun shout(s: string): string {
... return upper(s) + "!"
... }
>>> shout(names[2])
GRACE!
>>> :quit- Everything is kept between inputs: variables, functions, types and imports. A later input can use and change what an earlier one defined.
- Expressions print their value; statements and declarations print nothing.
- Unfinished input continues. While braces, brackets or parentheses are open, the prompt changes to
...and the next line is added to the same input. - Errors do not end the session. A compile error is reported and the input is dropped; a runtime error stops only that input, and the values from before it are kept.
- The standard library's functions are there without
import:sqrt,readFile,parseJSONand the others. Import a module for its types and constants, such asimport "std/math"forPI.
| Command | Effect |
|---|---|
:help, :h |
list the commands |
:source |
print the code entered so far, as one program |
:reset |
forget everything and start over |
:quit, :q, :exit, exit, quit, Ctrl-D |
leave |
:source is handy to turn an experiment into a file: :source, copy, paste into app.bn.
eval
burn eval runs a snippet from the command line, with the standard library's functions available like in the REPL:
burn eval 'print(6 * 7)'
burni -e 'for i in 0..3 { print(i * i) }'
burn eval 'print(toJSON({"root": sqrt(2.0)}))'The exit code is the snippet's: exit(3) exits with 3, and a runtime error with 1.
How it works
Each input is checked together with everything entered before it, compiled to a bvm module and run on the same bvm
as burn run, with the session's globals kept in between. So code behaves exactly as it would in a file.