Stream: beginners

Topic: Trouble defining a function in the REPL


view this post on Zulip Liam Dyer (Jun 23 2023 at 20:05):

Did some browsing of the tutorial and wanted to try out some stuff in the REPL

» f = \n -> n * 2
── MISSING FINAL EXPRESSION ────────────────────────────────────────────────────

I am partway through parsing a definition, but I got stuck here:

1│  app "app" provides [replOutput] to "./platform"
2│
3│  replOutput =
4│      f = \n -> n * 2
                       ^

This definition is missing a final expression. A nested definition
must be followed by either another definition, or an expression

    x = 4
    y = 2

    x + y

I got this, so I thought maybe I was doing something wrong so I directly copied the example from the tutorial for defining funcitons.

» addAndStringify = \num1, num2 ->
…     Num.toStr (num1 + num2)
── MISSING FINAL EXPRESSION ────────────────────────────────────────────────────

I am partway through parsing a definition, but I got stuck here:

1│  app "app" provides [replOutput] to "./platform"
2│
3│  replOutput =
4│      addAndStringify = \num1, num2 ->
5│          Num.toStr (num1 + num2)
                                   ^

This definition is missing a final expression. A nested definition
must be followed by either another definition, or an expression

    x = 4
    y = 2

    x + y

Am I messing something up or is this a bug?

To be clear: this is in the online WASM repl at https://www.roc-lang.org/repl

view this post on Zulip Brendan Hansknecht (Jun 23 2023 at 20:40):

The web repl currently has limitations

view this post on Zulip Brendan Hansknecht (Jun 23 2023 at 20:40):

It basically has no memory

view this post on Zulip Brendan Hansknecht (Jun 23 2023 at 20:40):

So you can save a value for lster

view this post on Zulip Brendan Hansknecht (Jun 23 2023 at 20:41):

So you have to define the function and then use it to returns a result

view this post on Zulip Liam Dyer (Jun 23 2023 at 20:58):

_Oh_ you can't do _any_ variable assignment I see

view this post on Zulip Brendan Hansknecht (Jun 23 2023 at 21:17):

I mean you can, but you have to use it immediately in the web repl currently cause it has no history

view this post on Zulip Brendan Hansknecht (Jun 23 2023 at 21:18):

f = \x -> x + 1
f 2

view this post on Zulip Brendan Hansknecht (Jun 23 2023 at 21:18):

That should work

view this post on Zulip Brendan Hansknecht (Jun 23 2023 at 21:21):

Note: just an issue with the web repl. Should work as expected in CLI repl

view this post on Zulip Anton (Jun 25 2023 at 12:19):

I've created #5603 to inform users about this difference in features.


Last updated: Jul 06 2025 at 12:14 UTC