Purpose: Ordered Input and Output

(m stands for Monad)


(;) \m \handler

The sequencing operator.

Results in an IO action, that, when run, runs m, passes the resulting value to handler and then runs the result.

This specifies the order in which actions are executed.

Example:

puts! "Hello world" ;\_
puts! "Second line"

Output:

Hello world
Second line

liftIO! \value

Constructs an IO action, that, when run, returns value.


return! \value

Constructs an IO action, that, when run, returns value.


ioValue \m

Given an IO action, results in the value of the monad.


ioWorld \m

Given an IO action, results in the World State of the monad.


skipUntil! \condition \body

Given a condition (predicate) and a body, does the following:

  1. Run body, resulting in value.
  2. Check whether condition is true for value. If it is, just return value.
  3. If not, keep running body (goto 1).

skipWhile! \condition \body

Given a condition (predicate) and a body, does the following:

  1. Run body, resulting in value.
  2. Check whether condition is true for value. If it is, keep running body.
  3. If not, just return value.

accumrUntil! \condition \connector \terminator \body

(Eventually) does the following:

  1. Run body, resulting in value.
  2. Check whether condition (for this value) is true. If it is, just return terminator.
  3. If not, keep connecting results of recursive runs of accumrUntil! using connector.

Example:

FIXME

defer! \finalizer \body

(Eventually) does the following:

  1. Run body, resulting in value.
  2. Run finalizer, ignoring the result (this is traditionally so).
  3. Return value.

Example:

... get f somehow ...
defer! (File.fclose! f)
	File.fgets! file 2000

use! \opener \closer \body

(Eventually) does the following:

  1. Run opener, resulting in f.
  2. defer! running (closer f) after (body f), the latter returning value.
  3. Return value.

This is convenient for resource management where you have some clean-up action that has to execute no matter what.

Example:

use! (File.fopen! "/etc/passwd" "r") File.fclose! \file
	File.fgets! file 2000

with! \obj \body

Using obj, does body (see use! above for what "using" means).

Example:

let passwd := 
	let open! := File.fopen! "/etc/passwd" "r" in
	let close! := File.fclose! in 
	let gets! := File.fgets! in 
	Composition.dispatch
	(#exports [open! close!])
	OO.Object
in 
with! passwd \file
	let passwd := wrap passwd file in 
	passwd.gets! file 2000