-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Initial set of primitives
Implement the primitives described in the list below. See Notes to coordinate with other tasks.
Note on JIT (#27)
- If common functions are kept as
defs(e.g.map/fold/length/concat/split),
a JIT could accelerate them without turning them into primitives.
Note on FFI (#28)
read_file/write_filemight be implemented via FFI with C,
instead of dedicated primitives.
Proposed primitives
Debug / observability (can inspect without consuming the term)
- Rationale: inspect terms in lazy mode without altering evaluation.
%show(x: a) -> String- Stringifies without reducing and without consuming the term.
- Use the current printing format (normalize mode / no collapse).
%trace(msgs: List<String>, x: a) -> a- Prints the concatenation of
msgsand returnsxwithout consuming it. - Use the current printing format (normalize mode / no collapse).
- Prints the concatenation of
Control / error
- Rationale: explicit failures and error messages.
%panic(msg: String) -> a- Aborts with a message; only triggers if evaluated.
IO
- Rationale: basic input/output effects with explicit errors.
%log(s: String) -> #Nil(existing)String= list of#Chr.- Kept as-is (returns
[]).
%read_file(path: String) -> #Ok{String} | #Err{String}- IO with explicit error; no silent failure.
%write_file(path: String, data: String) -> #Ok{} | #Err{String}- IO with explicit error.
%read_bytes(path: String) -> #Ok{List<#U8{NUM}>} | #Err{String}- Byte =
#U8{n}withnstored in 8 bits.
- Byte =
%write_bytes(path: String, data: List<#U8{NUM}>) -> #Ok{} | #Err{String}- Byte =
#U8{n}withnstored in 8 bits.
- Byte =
Effects / nondeterminism
- Rationale: time and RNG utilities while keeping clear semantics.
%time_ms() -> NUM- Monotonic; effectful; result depends on when it is demanded.
%rand(seed: NUM, bits: NUM) -> #Pair{seed2, value}- Pure/deterministic PRNG;
bitsdefines width. - Supported term bit sizes:
- 7 (TAG), 24 (EXT), 32 (VAL).
- Supported common sizes: 8 / 16 / 64.
bitsoutside this set:panic.
- Pure/deterministic PRNG;
Common FP utilities
- Rationale: basic library building blocks; decide whether they remain defs or become primitives.
- Lists:
map,fold,length,concat,split - Strings:
num_to_str,str_to_num
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels