IBIO Examples

Hello, World


send qq{Hello, world!\n}

send is IBIO's output operator; in this case, it takes a list of runes and writes it to the standard output channel.

qq{...} is IBIO syntax for a string-of-runes literal; the delimiters can be arbitrary as long as they match. IBIO supports the standard C-like escape sequences.



for (module 'opts ← getopts{n}) send $ (concat $ intersperse qq{ } opts.args) <> analyze opts.n case true. qq{} case false. qq{\n}

The syntax for (gens) expr is Global Script's local binding syntax; IBIO uses the operator to name the result of a sub-program.

getopts{...} is a short-hand syntax for a sub-program to do option processing; if, as in this case, the text between the delimiters lacks whitespace, each character will be interpreted as an option name. The sub-program denoted by this expression returns a record whose fields have the same names as the options; the syntax of the options will be determined (at compile time) by the inferred types of the returned record's fields.

The syntax module 'opts tells Global Script to take each field of the returned



(for ('as ← env.args.get) analyze as case nil. cat case _. foreachM as $ λ 'a. for ('i ← either abend unit =<< file.open o/r/ fn<§a>) cat << i ) where 'cat = for ('s ← receive $ many symbol) send s

env.args.get returns the command-line arguments, without any option processing.

either abend unit =<< is an idiom for converting error returns, like file.open's, into immediate termination (abend).

file.open is the general-purpose file-open function; the mode is supplied with an argument like o/r/. The string between the //s, is the same as in C's stdio fopen function. A special o// syntax is used to give you a run-time error on syntax errors, and because in IBIO read-only, write-only, and read-write open modes have different types.

fn<...> is IBIO's file name literal syntax; file names have a different Global Script type than strings in IBIO. § indicates interpolation; §a interpolates the variable a. Strings interpolated into file name literals are spliced in without any modification or formatting, so fn<§a> is an idiom for converting the string variable a to a file name.

<< is input re-direction. Re-direction is only supported from open files, channels, and the like; re-direction that would have side-effects, such as from files, is prohibited.

receive is IBIO's input operator; the argument indicates how much input to read in (and permits light parsing, such as splitting into lines). Input occurs concurrently with on-going execution, but with an upper bound on how much input is performed that the program has yet to use. Parsing of the result is lazily driven by Global Script evaluation.

many symbol tells IBIO to read in the entire input and return it as a list of symbols (in this case, runes).