Rill v0.13 Reference

Chapter 12

Built-in functions

println(x) / print(x) print any value type, with or without a newline; standard output is buffered like C's — a line at a time on a terminal, 64 KB otherwise — and written out before the program ends, before exit, before a read of standard input and before a strand waits
show(x) -> Str render any value as a string
int_to_str float_to_str bool_to_str str_to_int conversions
to_float(n) to_int(x) between Int and Float; to_int truncates toward zero
#s (or str_len(s)) s[i] (or str_get(s, i)) s[i:j] (or str_sub(s, start, len)) str_find(s, needle) str_find_from(s, needle, from) str_cmp chr(byte) strings, byte-indexed; a string reads by index but never writes — it is a value, not storage. str_find_from starts partway along, so a long line can be walked field by field without slicing off the part already read; a start outside the string is clamped
channel() send(ch, v) recv(ch) close(ch) closed(ch) channels; close wakes everything parked on one, and the prelude's recv_opt is written from chan_wait and chan_taken — see §7
map_new() m[k] = v (or map_set) map_len map_del map_clear hash tables; #m is map_len, and the prelude's map_get, map_or, map_has, map_keys, map_values and map_items are written on top of these
map_find(m, k) map_next(m, i) map_key_at(m, i) map_val_at(m, i) the slot a key is in, the next slot with anything in it, and what is in one — what the prelude's map functions are made of, and what to write a walk of your own with. A slot number means nothing after the next insertion
arg_count() arg(i) raw command-line access (args() is friendlier)
yield() this strand's turn given up, if another is waiting on the worker — for a long for loop with no call to be checked at (§7)
assert(c) assert_eq(got, want) end the program where the condition is false, saying the line — and, for assert_eq, both values; what rill test is written with (§13)
read_file_raw(path) write_file(path, text) read_line() scan_int() io_ok() file and stdin IO; standard input is read in blocks, and scan_int scans a number out of it without allocating
file_open file_read file_pread file_pread_into file_write file_pwrite file_seek file_pos file_size file_truncate file_sync file_lock file_unlock file_close file_remove file_rename file_exists dir_make dir_list dir_sync a file as a descriptor, for one too big to hold or still being appended to; see §10
strbuf() b += s (or strbuf_add) b += byte (or strbuf_byte) strbuf_str(b) strbuf_clear(b) #b building a string a piece at a time; strbuf_clear empties one and keeps its room
to_cstr from_cstr str_from_ptr free_ptr null_ptr is_null the C string and pointer bridge
alloc_bytes(n) ptr_offset(p, bytes) poke_* peek_* raw buffers for C
now_nanos() sleep_ms(ms) a monotonic clock, and a wait that parks the strand
wait_signal() parks until the program is told something, and says which; see §7
workers() how many workers this run has — 1 unless RILL_THREADS said otherwise — for deciding how many strands a big piece of work is worth
unique(x) whether this frame holds the only reference to a counted value; see §6
float2(a, b) splat2(x) lane0(v) lane1(v) f2_load(buf, i) f2_store(buf, i, v) fma2(a, b, c) fmin2(a, b) fmax2(a, b) two lanes at once; see §3
buf_float_uninit(n) a buffer of floats whose elements are whatever the memory held, for a caller about to write every one — no clearing pass
exit(code) terminate