# Getting \`unexpected reserved word: end\` when returning string from function

**URL:** <https://forum.elixirforum.com/t/getting-unexpected-reserved-word-end-when-returning-string-from-function/54280>\
**Category:** Questions\
**Tags:** strings, functions\
**Created:** [March 2, 2023, 3:48pm UTC](https://forum.elixirforum.com/t/getting-unexpected-reserved-word-end-when-returning-string-from-function/54280 "2023-03-02T15:48:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coen.bakker](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/coen.bakker/32/39732_2.png) [@coen.bakker](https://forum.elixirforum.com/u/coen.bakker)\
**Post date:** [March 2, 2023, 3:48pm UTC](https://forum.elixirforum.com/t/getting-unexpected-reserved-word-end-when-returning-string-from-function/54280/1 "2023-03-02T15:48:30Z")

</div>

When I define successive functions that return a `string` I get the error:

```elixir
unexpected reserved word: end

    HINT: it looks like the "end" on line 3 does not have a matching "do" defined before it

    (elixir 1.14.0) lib/kernel/parallel_compiler.ex:346: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/7

```

The error refers to `line 3` of this function:

```elixir
defmodule ModuleA do
  @start "@"
  @end "#"

  defmacro start, do: @start
  defmacro end, do: @end
end

```

However, the error also occurs in a simpler setup, like:

```elixir
defmodule ModuleB do
  def start, do: "@"
  def end, do: "#"
end

```

The error does not occur in a module with only one function that returns a `string`.

```elixir
defmodule ModuleC do
  def start, do: "@"
end

```

I reckon it something small I am overlooking, but it bugs me that I don’t understand why it fails. Any ideas?

---

<div class="post-metadata">

**Author:** ![patrickdm](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/patrickdm/32/7579_2.png) [@patrickdm](https://forum.elixirforum.com/u/patrickdm)\
**Post date:** [March 2, 2023, 3:57pm UTC](https://forum.elixirforum.com/t/getting-unexpected-reserved-word-end-when-returning-string-from-function/54280/2 "2023-03-02T15:57:11Z")

</div>

Because `end` is a reserved word?  
from: [Syntax reference — Elixir v1.12.3](https://hexdocs.pm/elixir/1.12/syntax-reference.html)

> Reserved words  
> These are the reserved words in the Elixir language. They are detailed throughout this guide but summed up here for convenience:
> 
> true, false, nil - used as atoms  
> when, and, or, not, in - used as operators  
> fn - used for anonymous function definitions  
> do, **end** , catch, rescue, after, else - used in do/end blocks

```elixir
Interactive Elixir (1.14.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> defmodule ModuleB do
...(1)> def start, do: "@"
...(1)> def end, do: "f" 
** (SyntaxError) iex:3:8: syntax error before: ','
    |
  3 | def end, do: "f"
    | ^
    (iex 1.14.2) lib/iex/evaluator.ex:292: IEx.Evaluator.parse_eval_inspect/3
    (iex 1.14.2) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.14.2) lib/iex/evaluator.ex:32: IEx.Evaluator.init/4
    (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

```

---

<div class="post-metadata">

**Author:** ![benwilson512](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/32/1457_2.png) [@benwilson512](https://forum.elixirforum.com/u/benwilson512)\
**Post date:** [March 2, 2023, 4:00pm UTC](https://forum.elixirforum.com/t/getting-unexpected-reserved-word-end-when-returning-string-from-function/54280/3 "2023-03-02T16:00:03Z")

</div>

Yeah as @patrickdm notes `end` is reserved, I would pick a different function / macro name. Even if you can successfully construct a function / macro named `end` it’s going to be very difficult to call.

---

<div class="post-metadata">

**Author:** ![coen.bakker](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/coen.bakker/32/39732_2.png) [@coen.bakker](https://forum.elixirforum.com/u/coen.bakker)\
**Post date:** [March 2, 2023, 4:03pm UTC](https://forum.elixirforum.com/t/getting-unexpected-reserved-word-end-when-returning-string-from-function/54280/4 "2023-03-02T16:03:37Z")

</div>

Oh boy. I knew that. Must be tired. 🫥

Makes all sense now. Thank you!
