Inherited from v1.0.0

Global functions

These functions are registered in the global scope at startup. You can call them from any file without an import. Where an English name has a Bangla synonym, both bind to the same callable.

I/O and display

print(...args) / লিখুন(...args)

Write each argument's display string to standard output, separated by single spaces, terminated by a newline. Variadic — takes any number of arguments.

print("hello", 42, true);    // hello 42 true
লিখুন("নম্বর:", 7);          // নম্বর: 7

When an argument is a list or map, print formats it with the same layout as pretty: inline when short, multi-line with 4-space indent otherwise. Strings inside collections are quoted so they're visibly distinct from identifiers.

print([1, 2, 3]);
// [1, 2, 3]

print({a: 1, b: "hello", c: [10, 20, 30]});
// {a: 1, b: "hello", c: [10, 20, 30]}

print([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
// [
//     1,
//     2,
//     ...
//     20
// ]

When stdout is an interactive terminal, collection contents are colored by type (numbers cyan, strings green, booleans yellow, null gray, map keys bright cyan). Override with:

  • BNL_PRINT_COLOR=1 — force color on (useful in CI logs that support ANSI)
  • BNL_PRINT_COLOR=0 or NO_COLOR=1 — force color off

Piping or redirecting (bnl app.bnl > out.txt) auto-disables color so files stay byte-clean.

Returns null.

input(prompt?) / ইনপুট(prompt?)

Read one line from standard input. If prompt is given, write it to stdout (no trailing newline) before reading.

The returned string does not include the trailing newline. Returns null on EOF (Ctrl-Z + Enter on Windows, Ctrl-D on POSIX), so you can detect end-of-input with if (line == null) { ... }.

var name = input("Name? ");
if (name == null) { return; }
print("Hello,", name);

Type conversion

str(value)

Convert any value to its display string — the same form print would emit.

print(str(42));         // "42"
print(str([1, 2, 3]));  // "[1, 2, 3]"
print(str(null));       // "null"

to_number(s)

Parse a string to a number. Returns null on failure rather than throwing — pair with an == null check. Whitespace around the number is tolerated. Numbers pass through unchanged.

print(to_number("3.14"));    // 3.14
print(to_number("  42 "));   // 42
print(to_number("abc"));     // null
print(to_number(7));         // 7

chr(n)

Build a single-byte string from a byte value. n must be a number in 0..255. Throws otherwise.

print(chr(65));     // "A"
print(chr(10));     // "\n"

Reflection

type(value) / ধরণ(value)

Return the value's type name as a string. Possible results: "null", "bool", "number", "string", "list", "map", "function", "class", "instance", "module", "future".

print(type(null));        // null
print(type(true));        // bool
print(type(42));          // number
print(type("hi"));        // string
print(type([1, 2]));      // list
print(type({a: 1}));      // map
print(type(print));       // function

Error recovery

try_call(thunk, on_err)

Call thunk() with no arguments. If it returns normally, return its value. If it throws, call on_err(<message-or-thrown-value>) and return what that returns.

try_call is useful in places where try / catch syntax is awkward — for example, expression-level recovery inside another call, or inside a library that needs to turn handler exceptions into responses without crashing the loop.

var result = try_call(
    function () { return risky_op(); },
    function (err) { print("recovered:", err); return null; }
);

Debugging

pretty(value)

Pretty-print a value into a multi-line string with nested indentation. Strings are shown in quotes (so "x" is visibly distinct from a bare identifier). Output is truncated at BNL_PRINT_LIMIT codepoints (default 100; set BNL_PRINT_LIMIT=0 to disable, or any positive integer to override) with a trailing "..." when cut.

print(pretty({ user: "alice", roles: ["admin", "editor"], age: 30 }));

Intended for use as print(pretty(x)); when you want a quick legible view of nested data.

dump(value)

Same formatter as pretty, but with no truncation. Use when you need to see the entire value during debugging.

print(dump(big_response));

Asynchronous values

Future

Built-in type representing a value that will eventually settle (fulfill or reject). Pair with the wait keyword to compose asynchronous code as straight-line scripts.

Future is both callable (invoke as a constructor) and exposes static methods:

// Construct a Future from an executor.
var f = Future(function (resolve, reject) {
    timers.set(0, function () { resolve("done"); });
});

// Static factories.
Future.of(7);                    // already fulfilled with 7
Future.err("nope");              // already rejected with "nope"
Future.all([f1, f2, f3]);        // fulfills with [v1, v2, v3]; rejects on first error
Future.race([f1, f2]);           // settles with the first one to settle
Future.all_settled([f1, f2]);    // fulfills with a list of {ok, value?, error?} maps; never rejects

Instance methods chain on any Future:

MethodDescription
f.next(on_ok) / f.next(on_ok, on_err)Run on_ok on fulfillment. Returns a new Future of its result.
f.fail(on_err)Run on_err on rejection.
f.always(fn)Run fn regardless of outcome. Doesn't alter the carried value.
f.state"pending", "fulfilled", or "rejected".

Inside any function, wait f suspends the call until f settles and yields its value (or throws its rejection). See the Future module page for the full reference.

function fetch_user(id) {
    var resp = wait request.get("/users/" + str(id));
    return resp.data;
}

futurify(fn)

Wrap a callback-style function (one whose last argument is an (err, result) callback) so it returns a Future instead. Useful for bridging legacy APIs or your own callback-driven code into the wait/Future world.

function legacy_read(path, cb) {
    timers.set(0, function () { cb(null, "data from " + path); });
}

var read_async = futurify(legacy_read);
read_async("file.txt").next(function (data) { print(data); });
// or
var data = wait read_async("file.txt");

futurify returns a function whose arity is "all the original args minus the trailing callback." Multiple-arg callbacks (cb(err, a, b)) are not supported — only the standard cb(err, result) shape.

Notes

  • Every global on this page has a Bangla synonym pointing at the same callable: print/লিখুন, input/ইনপুট, str/স্ট্রিং, to_number/সংখ্যা, chr/অক্ষর, type/ধরণ, try_call/নিরাপদ_কল, pretty/সুন্দর, dump/বিস্তারিত, Future/ভবিষ্যৎ, futurify/ভবিষ্যৎকর. See Bilingual aliases for the full table.
  • These are real function values — you can pass them around: var p = print; p("hi");.
  • They live in the global scope, so any user-defined variable with the same name in the same scope will shadow them.