Stream: beginners

Topic: Reserved keywords in tutorial


view this post on Zulip Aurélien Geron (Aug 02 2024 at 04:21):

The tutorial lists the following reserved keywords:
ifthenelsewhenasisdbgimportexpectexpect-fxcrashmoduleapppackageplatformhostedexposeswithgeneratespackagesrequires

Are these up to date? I opened a Roc REPL, and I was able to write x = 123 for x in:
module, app, package, platform, hosted, exposes, with, generates, packages, requires
If these are still reserved keywords, shouldn't the compiler complain if you use them this way?

view this post on Zulip Brendan Hansknecht (Aug 02 2024 at 04:23):

I think we restricted some of them to specific scopes. So they aren't truly reserved anymore.

view this post on Zulip Brendan Hansknecht (Aug 02 2024 at 04:23):

Probably should update that

view this post on Zulip Aurélien Geron (Aug 02 2024 at 04:24):

Are you saying we should update the tutorial, or the compiler?

view this post on Zulip Aurélien Geron (Aug 02 2024 at 04:24):

How about exposing?

view this post on Zulip Luke Boswell (Aug 02 2024 at 04:27):

There are different reserved keywords when parsing the module header verse the rest of the file I think

view this post on Zulip Luke Boswell (Aug 02 2024 at 04:28):

crates/compiler/parse/src/keyword.rs

// These keywords are valid in expressions
pub const IF: &str = "if";
pub const THEN: &str = "then";
pub const ELSE: &str = "else";
pub const WHEN: &str = "when";
pub const AS: &str = "as";
pub const IS: &str = "is";
pub const DBG: &str = "dbg";
pub const IMPORT: &str = "import";
pub const EXPECT: &str = "expect";
pub const EXPECT_FX: &str = "expect-fx";
pub const CRASH: &str = "crash";

// These keywords are valid in imports
pub const EXPOSING: &str = "exposing";

// These keywords are valid in types
pub const IMPLEMENTS: &str = "implements";
pub const WHERE: &str = "where";

// These keywords are valid in headers
pub const PLATFORM: &str = "platform";

pub const KEYWORDS: [&str; 11] = [
    IF, THEN, ELSE, WHEN, AS, IS, DBG, IMPORT, EXPECT, EXPECT_FX, CRASH,
];

view this post on Zulip Aurélien Geron (Aug 02 2024 at 07:14):

Interesting, thanks @Luke Boswell .
So what would you like me to do?

view this post on Zulip Luke Boswell (Aug 02 2024 at 07:20):

I think we would like to have a language reference at some point, and this probably shouldn't live in the tutorial.

I'm not sure we need to start on a language reference right now, so I think it's reasonable to update the tutorial section so it is at least up to date.

Point three is too much detail I think for now.

view this post on Zulip Aurélien Geron (Aug 02 2024 at 08:38):

Here's one proposal, with keywords listed in alphabetical order, for convenience:


These are reserved keywords in Roc. You can't choose any of them as names, except as record field names.

as, crash, dbg, else, expect, expect-fx, if, import, is, then, when

Other keywords are used in unambiguous contexts, so they are not reserved. This includes:

app, exposes, exposing, generates, implements, module, package, packages, platform, requires, where, with


We can drop the second part if you prefer, but it's quite short and some people might be happy to know that they can use names like app, module, package, packages, platform, or where if it's legal and safe.

view this post on Zulip Luke Boswell (Aug 02 2024 at 08:39):

That sounds good. Thank you

view this post on Zulip Aurélien Geron (Aug 02 2024 at 08:51):

My pleasure. Please see PR #6953.


Last updated: Jul 06 2025 at 12:14 UTC