> For the complete documentation index, see [llms.txt](https://elixir.petrolidas.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://elixir.petrolidas.com/exhort/day-20.md).

# Day 20

## Exercises

* [x] [RPN Calculator](#rpn-calculator)

### RPN Calculator

[Exercise on Exercism](https://exercism.org/tracks/elixir/exercises/rpn-calculator) **|** [View my solution](https://exercism.org/tracks/elixir/exercises/rpn-calculator/solutions/petros)

#### Solution

<details>

<summary>Expand to see code (spoiler alert)</summary>

{% code lineNumbers="true" %}

```elixir
defmodule RPNCalculator do
  @spec calculate!(list(), Function.t()) :: :ok
  def calculate!(_stack, operation) do
    operation.(1)
  end

  @spec calculate(list(), Function.t()) :: {:ok, String.t()} | :error
  def calculate(_stack, operation) do
    try do
      operation.(1)
      {:ok, "operation completed"}
    rescue
      _ -> :error
    end
  end

  @spec calculate_verbose(list(), Function.t()) :: {:ok | :error, String.t()}
  def calculate_verbose(_stack, operation) do
    try do
      operation.(1)
      {:ok, "operation completed"}
    rescue
      e in ArgumentError -> {:error, e.message}
    end
  end
end

```

{% endcode %}

[View gist on GitHub](https://gist.github.com/petros/7cbaacb697de6a52c1931703dd92039e)

</details>

#### Notes

I was trying to figure out how to call an anonymous function assigned to a variable when the anonymous functions has no arguments. It's `the_variable.()`. However, it turns out this exercise expects an anonymous function with an arity of 1. But the parameter is not being used. So you can pass anything really: `the_variable.(1)`.

## Overall progress

<figure><img src="/files/WGux1b1kKk4HdQyNRf0k" alt="An image showing my progress on Exercism. It&#x27;s 21.8% as of Saturday, 27 August 2022."><figcaption><p>Progress</p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://elixir.petrolidas.com/exhort/day-20.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
