You can format and write data with the Print statement. Each of its arguments contains an expression and an optional format descriptor. A quote can also be included to write literal text.
A space is written between each argument and an end-of-line is written after writing the values. Options are available to suppress these features and provide additional controls. To keep things simple these details won't be described here.
PRINT Expression ['|' Format], ...
The type of the data is inferred from variables in the expression. Expressions with conflicting variable types or expressions with only constants are not allowed. The optional Format can be quoted or left unquoted unless it contains special characters. When left off each primitive type uses a default format. Here are some simple examples for a variable, V, of type Word and set to 44.
PRINT V + 15 49 default decimal format PRINT ~V - 3 -49 default format for a negative number PRINT V + 25 |h# 3b lowercase hexadecimal PRINT V + 25 |"=#H#" #3B literal '#' and uppercase hexadecimal
You can also use the intrinsic Form function to return a formatted string:
String = form( Expression [, Format] )
To format a structure you can create a custom formatting function. It will be invoked when you print it or use the intrinsic Form function. In this example the fields for a point will be formatted when a variable with the type Point is printed.
type Point X cell, Y cell :Type declaration for a Point function FORM: Format a Point data strucure. entry Point, &Point to be formatted. Format = "" string :Format to apply to each coordinate. exit Result string :Point values as a formatted string Result = "(" ! form( $X, Format ) &Construct a formatted point. ! "," ! form( $Y, Format ) ! ")" return
When you print a point you will get output that looks like:
PRINT MyPoint; Output is: (1018, 7) PRINT MyPoint |h#; Output is: (3fa, 7)