Stream: ideas

Topic: Str.len stub


view this post on Zulip Anton (Mar 12 2025 at 10:08):

For easy discoverability, we could make a Str.len function that returns LearnAboutStringsInRoc "<copy of text in https://www.roc-lang.org/faq.html#strings-in-roc>"

view this post on Zulip Richard Feldman (Mar 12 2025 at 14:06):

I've thought about this, but I think it's probably best to find another way. The tradeoffs are:

view this post on Zulip Anthony Bullard (Mar 12 2025 at 14:26):

You could just have a special case for when you have a non-existent symbol. Is the qualifier Str that resolves to builtins.Str, and the symbol len? Return the above error instead of the usual one

view this post on Zulip Anton (Mar 12 2025 at 14:49):

@Anthony Bullard are you talking about automplete specifically? What does "the usual one" refer to?

view this post on Zulip Anton (Mar 12 2025 at 14:51):

helps beginners very briefly

It could be a make or break moment though, people will give up on Roc if they find it too difficult to code the behavior they have in mind.

view this post on Zulip Anton (Mar 12 2025 at 14:51):

cluttering their docs

It could be an asset in the docs as well, when they're searching for len because they expect it to exist.

view this post on Zulip Anton (Mar 12 2025 at 14:53):

autocomplete results

There are currently no other Str functions that start with an l so I don't expect this to be a problem in practice.

view this post on Zulip Anton (Mar 12 2025 at 14:56):

LLMs may get confused and try to use it based on the name

This should also be fine in practice (in the near future), Roc training data will not contain .len for Strings because it's not useful in real code.

view this post on Zulip Anton (Mar 12 2025 at 15:33):

We could also evaluate having this function and get rid of it if it does not turn out well. That won't break any production code :p

view this post on Zulip Richard Feldman (Mar 12 2025 at 17:50):

true!

view this post on Zulip Richard Feldman (Mar 12 2025 at 17:50):

I'm up for trying it

view this post on Zulip Hannes (Mar 15 2025 at 09:21):

This seems like something that would be better handled with editor tooling in the future, e.g. if you write Str.len you get a red squiggle underline with a message. Actually, this could already be done if roc check showed a warning for Str.len

view this post on Zulip Anton (Mar 15 2025 at 09:39):

That would still leave the scenario where people type len in the docs website search bar, see nothing and then think; "what now?". People may also type l or le on a Str for autocomplete, see nothing and need to reach for the browser to find answers.


Last updated: Jun 16 2026 at 16:19 UTC