Stream: contributing

Topic: builtins


view this post on Zulip Prajwal S N (Oct 06 2022 at 14:58):

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 :)

view this post on Zulip jan kili (Oct 06 2022 at 15:01):

https://github.com/roc-lang/roc/pull/2386

view this post on Zulip jan kili (Oct 06 2022 at 15:01):

https://github.com/roc-lang/roc/blob/main/crates/compiler/builtins/README.md

view this post on Zulip jan kili (Oct 06 2022 at 15:02):

Yeah, if you see any out-of-date info in there, please submit a PR! :)

view this post on Zulip Prajwal S N (Oct 06 2022 at 18:13):

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?

view this post on Zulip Prajwal S N (Oct 06 2022 at 18:40):

https://github.com/roc-lang/roc/pull/4227
Could someone please take a look at this

view this post on Zulip Ayaz Hafiz (Oct 06 2022 at 18:53):

Prajwal S N said:

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?

Yeah, that's the feature. However it needs to be exposed to userspace; Str.roc does not currently expose a Str.withCapacity function.

view this post on Zulip Ghislain (Oct 06 2022 at 21:14):

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))

view this post on Zulip Prajwal S N (Oct 07 2022 at 12:51):

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

view this post on Zulip Prajwal S N (Oct 07 2022 at 13:00):

Fixed it, forgot to export the function :skull:

view this post on Zulip Brendan Hansknecht (Oct 07 2022 at 13:44):

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.

view this post on Zulip Richard Feldman (Oct 07 2022 at 14:51):

@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

view this post on Zulip Ghislain (Oct 07 2022 at 14:59):

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.

view this post on Zulip Richard Feldman (Oct 07 2022 at 15:02):

yeah I think it's worth adding! Want to open an issue for it and link to this thread?

view this post on Zulip Ghislain (Oct 07 2022 at 15:19):

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?

view this post on Zulip Richard Feldman (Oct 07 2022 at 15:29):

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:

view this post on Zulip Ghislain (Oct 07 2022 at 15:57):

https://github.com/roc-lang/roc/issues/4239 Feel free to rename / modify anything

view this post on Zulip Richard Feldman (Oct 07 2022 at 16:54):

excellent, thank you @Ghislain! :pray:

view this post on Zulip Chris Duncan (Oct 09 2022 at 19:55):

@Ghislain, I've continued the conversation about Dict.update in this other topic.


Last updated: Jul 05 2025 at 12:14 UTC