librarylib/Play.xtl

Play: reading what a player types at the terminal, shared by the games' play.xtl programs. Every function prints its prompt, reads a line ([]R_EAD) and returns what it found; it never asks again itself (a game decides what is acceptable and asks again).

source

ˡl̲ine : Any a => a -> Char

function · line 8

The line typed, as it was typed.

ˡl̲ine ← { prompt →
  shown ← p̲rint! prompt
  ⎕R̲EAD @
}

ˡn̲umbersIn : Char -> Int

function · line 18

The whole numbers in a line (other characters dropped first), a vector that may be empty.

      ᵖ⁼u̲se< "Play"
      ᵖn̲umbersIn "move 3 to 12, then -1"
3 12 -1
ˡn̲umbersIn ← { line → f̲loor n̲umbers (line m̲ember? "0123456789 -") r̲eplicate line }

ˡn̲umbers : Any a => a -> Int

function · line 21

The numbers typed, a vector that may be empty.

ˡn̲umbers ← { prompt → ˡn̲umbersIn ˡl̲ine prompt }

ˡn̲umber : Any a => a -> Int

function · line 24

The first number typed, or -1 when there is none.

ˡn̲umber ← { prompt → f̲irst (ˡn̲umbers prompt) c̲at -1 }

ˡl̲etter : Any a => a -> Char -> Int

function · line 28

Which of the letters the line starts with, 1 to the number of letters (one more when it is none of them): "MOVE ?" p:l_etter "adws".

ˡl̲etter ← { prompt letters → letters i̲ndexOf f̲irst (ˡl̲ine prompt) c̲at " " }