mirror of
https://github.com/kanaka/mal.git
synced 2024-09-20 10:07:45 +03:00
0068653bf9
It was necessary to rename some ambiguous variables. Some more names could probably be changed in order to reduce the diff with #450 (my names were choosen in order to reduce the diff with master...) Peek ideas from #450: - sort imports - skip a line between '->' or before 'else' - no indentation after 'in' - fix indentation when it was only intended to reduce diff - remove some unneeded parenthesis and - if .. return True else False -> ...
82 lines
1.3 KiB
Elm
82 lines
1.3 KiB
Elm
module Step0_repl exposing (..)
|
|
|
|
import IO exposing (..)
|
|
import Json.Decode exposing (decodeValue, errorToString)
|
|
import Platform exposing (worker)
|
|
|
|
|
|
main : Program Flags Model Msg
|
|
main =
|
|
worker
|
|
{ init = init
|
|
, update = update
|
|
, subscriptions =
|
|
\model -> input (decodeValue decodeIO >> (\x -> case x of
|
|
Err e -> Err (errorToString e)
|
|
Ok a -> Ok a
|
|
) >> Input)
|
|
}
|
|
|
|
|
|
type alias Flags =
|
|
{ args : List String
|
|
}
|
|
|
|
|
|
type alias Model =
|
|
{ args : List String
|
|
}
|
|
|
|
|
|
type Msg
|
|
= Input (Result String IO)
|
|
|
|
|
|
init : Flags -> ( Model, Cmd Msg )
|
|
init flags =
|
|
( flags, readLine prompt )
|
|
|
|
|
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
|
update msg model =
|
|
case msg of
|
|
Input (Ok (LineRead (Just line))) ->
|
|
( model, writeLine (rep line) )
|
|
|
|
Input (Ok LineWritten) ->
|
|
( model, readLine prompt )
|
|
|
|
Input (Ok (LineRead Nothing)) ->
|
|
( model, Cmd.none )
|
|
|
|
Input (Ok _) ->
|
|
( model, Cmd.none )
|
|
|
|
Input (Err msg2) ->
|
|
Debug.log msg2 ( model, Cmd.none )
|
|
|
|
|
|
prompt : String
|
|
prompt =
|
|
"user> "
|
|
|
|
|
|
read : String -> String
|
|
read ast =
|
|
ast
|
|
|
|
|
|
eval : String -> String
|
|
eval ast =
|
|
ast
|
|
|
|
|
|
print : String -> String
|
|
print ast =
|
|
ast
|
|
|
|
|
|
rep : String -> String
|
|
rep =
|
|
read >> eval >> print
|