I noticed that the structure of crates/compiler/builtins/
has considerably changed since #2386 and similar PRs. It looks like std.rs
has been split up into roc/*.roc
files. Wondering if the README should be updated with these changes so that new contributors can find their way around a little more easily :)
https://github.com/roc-lang/roc/pull/2386
https://github.com/roc-lang/roc/blob/main/crates/compiler/builtins/README.md
Yeah, if you see any out-of-date info in there, please submit a PR! :)
https://github.com/roc-lang/roc/issues/664 mentions withCapacity
under String builtins. A withCapacity()
function is already available in str.zig
which allocates an empty string of the specified capacity. Is this the same feature? Or are we looking for something different?
https://github.com/roc-lang/roc/pull/4227
Could someone please take a look at this
Prajwal S N said:
https://github.com/roc-lang/roc/issues/664 mentions
withCapacity
under String builtins. AwithCapacity()
function is already available instr.zig
which allocates an empty string of the specified capacity. Is this the same feature? Or are we looking for something different?
Yeah, that's the feature. However it needs to be exposed to userspace; Str.roc
does not currently expose a Str.withCapacity
function.
About bultins, is a Dict.update
planed?
Something like this:
update : Dict k v, k, (Result v [KeyNotFound] -> v) -> Dict k v
update = \dict, key, transform ->
Dict.insert dict key (transform (Dict.get dict key))
Do I need to rebuild the LLVM bitcode manually after adding a builtin? When I try to invoke the function on the REPL I get an unrecognised builtin function
error
Fixed it, forgot to export the function :skull:
About bultins, is a
Dict.update
planed?
No specific plan, but it definitely can be added. Might be called replace though
to match List.replace
. Also, could be more performant with the two steps merged, otherwise there are two searches of the dictionary.
@Ghislain I assume by Dict.update
you mean something like Elm's?
so something like:
Dict.update :
Dict k v,
k,
([Present v, Missing] -> [Present v, Missing])
-> Dict k v
I didn't think about this implementation with tags (I've no experience with Elm). Looks cool!
I just thought about something like it because I wanted this use for #roctoberfest day-5.
yeah I think it's worth adding! Want to open an issue for it and link to this thread?
Couldn't it simply be added to the list of builtins in https://github.com/roc-lang/roc/issues/664? Or is it only to keep track of what has to be done, but an issue has to be created for each?
ideally we have a separate issue for each; the main reason for originally creating 664 was just to get a list down somewhere as a starting point :big_smile:
https://github.com/roc-lang/roc/issues/4239 Feel free to rename / modify anything
excellent, thank you @Ghislain! :pray:
@Ghislain, I've continued the conversation about Dict.update
in this other topic.
Last updated: Jul 05 2025 at 12:14 UTC