1.11Basic I/O

Functions providing basic interface.

RTL Basic I/O functions are mainly meant to provide scripts with a very basic interface to interact with the outside world.

Functions

input

Get some text from the user (standard input stream).

input()

Reads a line from the standard input stream and returns a string containing the read data. This is mainly meant as a test/debugging function to provide the scripts with minimal console based user input support. When in need of reading lines from the standard input, prefer the readLine() method of the input stream object.

This function may also be overloaded by embedders to provide the scripts with a common general purpose input function, that returns a string that the user is queried for.

inspect

Displays the deep contents of an item.

inspect( item, [depth],[maxLen],[stream] )
item The item to be inspected.
depth Maximum inspect depth.
maxLen Limit the display size of possibly very long items as i.e. strings or membufs.
stream Different stream where to send the dump.

This is mainly a debugging function that prints all the available informations on the item on the auxiliary stream. This function should not be used except for testing scripts and checking what they put in arrays, dictionaries, objects, classes or simple items.

Output is sent to the VM auxiliary stream; for stand-alone scripts, this translates into the "standard error stream". Embedders may provide simple debugging facilities by overloading and intercepting the VM auxiliary stream and provide separate output for that.

This function traverses arrays and items deeply; there isn't any protection against circular references, which may cause endless loop. However, the default maximum depth is 3, which is a good depth for debugging (goes deep, but doesn't dig beyond average interesting points). Set to -1 to have infinite depth.

By default, only the first 60 characters of strings and elements of membufs are displayed. You may change this default by providing a maxLen parameter.

You may create personalized inspect functions using forward bindings, like the following:


   compactInspect = .[inspect depth|1 maxLen|15]

And then, you may inspect a list of item with something like:


   linsp = .[ dolist _compactInspect x ]
   linsp( ["hello", "world"] )

print

Prints the contents of various items to the standard output stream.

print( ... )
... An arbitrary list of parameters.

This function is the default way for a script to say something to the outer world. Scripts can expect print to do a consistent thing with respect to the environment they work in; stand alone scripts will have the printed data to be represented on the VM output stream. The stream can be overloaded to provide application supported output; by default it just passes any write to the process output stream.

The items passed to print are just printed one after another, with no separation. After print return, the standard output stream is flushed and the cursor (if present) is moved past the last character printed. The function printl must be used, or a newline character must be explicitly placed among the output items.

The print function has no support for pretty print (i.e. numeric formatting, space padding and so on). Also, it does NOT automatically call the toString() method of objects.

See also: printl.

printl

Prints the contents of various items to the VM standard output stream, and adds a newline.

printl( ... )
... An arbitrary list of parameters.

This functions works exactly as print, but it adds a textual "new line" after all the items are printed. The actual character sequence may vary depending on the underlying system.

See also: print.

See also: print.

Made with http://www.falconpl.org