# REPLs

A REPL is an interactive command line program where a user responds to questions and things happen.

There's a package for Derw called [repl](https://github.com/derw-lang/repl), which provides a wrapper around Readline.

The structure is similar to the html package, in that everything revolves around a model-view-update loop.

```elm
import "../derw-packages/derw-lang/repl/src/Repl" exposing (RunningProgram, Program, View, Question, End, Statement, program)

type Page =
    Intro
    | ShowInput
    | Quit

type alias Model = {
    page: Page,
    name: string
}

initialModel: Model
initialModel =
    { page: Intro, name: "" }

type Msg =
    SetName { value: string }
    | Finish

setName: string -> Msg
setName name =
    SetName { value: name }

finish: string -> Msg
finish _ =
    Finish

view: Model -> View Msg
view model =
    case model.page of
        Intro ->
            Question { prompt: "What's your name? ", onInput: setName }
        ShowInput ->
            Question { prompt: `Your name is ${model.name}. Press enter to quit`, onInput: finish }
        Quit ->
            End

update: Msg -> Model -> (Msg -> void) -> Model
update msg model send =
    case msg of
        SetName { value } ->
            { ...model, name: value, page: ShowInput }

        Finish ->
            { ...model, page: Quit }

main: RunningProgram Model Msg
main =
    program { initialModel: initialModel, view: view, update: update }

© 2022 GitHub, Inc. 
```


---

# Agent Instructions: 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:

```
GET https://docs.derw-lang.com/building-things/repls.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
