std:mie/repl リファレンス
@import 'std:mie/repl' で取得する対話評価セッションモジュール。mie ソース文字列を環境を持ち越しながら 1 入力ずつ評価する Session (eval / check) と継続入力判定 needs_more を提供する。
needs_more
needs_more(src)
needs_more: { String | Bool }
src の開き括弧 ( [ { が末尾で閉じていなければ true (同期・純粋)。
REPL の継続入力判定に使う。
>>> repl := @import "std:mie/repl" >>> repl.needs_more "[1, 2,"
session
session()
session: { Session }
新しい対話評価セッション Session を返す (同期)。環境はセッション全体で
共有され、前の eval で束縛した名前を次の eval から参照できる。
>>> repl := @import "std:mie/repl" >>> s := repl.session()
Session メソッド
check
check(src)
check: { String | List(String) }
src を評価せず検査し、診断 (List(String)) を返す (同期)。パースエラーと
strict 型検査の診断を <pos>: <msg> 形式で返し、無ければ空 List。
>>> repl := @import "std:mie/repl" >>> s := repl.session() >>> s.check("f: {Int | Any} := {x | x}") >>> s.check("1 + 2")
eval
eval(src)
eval: { String | Future({ text: String, is_error: Bool, is_unit: Bool, is_binding: Bool, parse_errors: List(String) |}) }
src を 1 入力として評価し、Future (EvalResult) を返す。評価は fork と
同型の別フローで行われ、ユーザコードのエラーは Future のエラーではなく
EvalResult の事実 (is_error / text) として返る。
>>> repl := @import "std:mie/repl" >>> s := repl.session() >>> r := s.eval("1 + 2")! >>> r.text