Skip to content

prelude: input builtin - #19

Merged
simontreanor merged 1 commit into
mainfrom
prelude-input
Jul 27, 2026
Merged

prelude: input builtin#19
simontreanor merged 1 commit into
mainfrom
prelude-input

Conversation

@simontreanor

Copy link
Copy Markdown
Owner

Adds input : string ->{io} string to the unqualified prelude - Python''s input(prompt) name-for-name (input "" for promptless), the io effect coming in to pair with print''s going out. input "n? " |> String.toInt : Option int is the idiomatic total parse, which should make for good lesson material later.

One PRELUDE entry + one seeded scheme; arity registration, lowering, and LSP completion all ride the existing PRELUDE table. DESIGN.md documents the environment caveats: the REPL''s worker protocol owns stdin (the already-documented hazard), and the Pyodide playground cannot block on stdin - pyfun run scripts and Jupyter are the home turf.

Tests: typecheck (type, io-effect flow into let pure rejection, prompt must be a string), lowering shape (input("who? ")), an e2e that pipes a real stdin line through the emitted program, and a roundtrip entry. Full suite green; clippy clean.

Python's input(prompt) name-for-name, the io effect coming in to pair
with print's going out; `input "n? " |> String.toInt` is the idiomatic
total parse. Monomorphic, seeded next to print; arity rides PRELUDE so
lowering and completion need nothing new. DESIGN documents the
environment caveats (REPL worker protocol owns stdin; the Pyodide
playground cannot block on stdin - pyfun run and Jupyter are the home
turf).
@simontreanor
simontreanor merged commit 63a16a0 into main Jul 27, 2026
11 checks passed
@simontreanor
simontreanor deleted the prelude-input branch July 27, 2026 10:39
@simontreanor simontreanor mentioned this pull request Jul 31, 2026
simontreanor added a commit that referenced this pull request Jul 31, 2026
Two user-visible additions since 0.2.0 -- the `input` prelude builtin
(`string ->{io} string`, #19) and caller-supplied `extern` keyword slots
(`kw = ...`, #21) -- plus five fixes, four of them from the first program
written in Pyfun in anger:

* imported schemes reused the exporting module's type-variable ids, silently
  blocking generalization in the importing module and cascading to its
  consumers (#26 / #27)
* a recursive function of arity >= 2 could not perform any effect -- the shape
  of every loop in a language with no `while` (#24 / #28)
* a module that only matched an imported `Option` emitted `None_` without
  importing it (#25 / #29)
* user identifiers collided with Python keywords, builtins the emitter calls,
  and modules an `extern` imports (#23 / #30)
* the local-binder module-alias shadowing residual (#18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant