This project is read-only.

Print operator

The print operator outputs one or more objects to the console. It works with virtually any type.

print 1
print 1.1
print "hello"
print new [ 1 2 3 ]
print new matrix 5, 5, 13.37 

By default, passing custom objects to print is useless. It would just output the type of the object:

type some
{
  int @a = 1
}

var obj = new some
print obj // "some" 

However, you can define a to_s method in your type that would be called when an object of the type is to be printed:

type some
{
  int @a = 1

  string to_s
  {
    return "<some @a=" + @a.to_s + ">"
  }
}

var obj = new some
print obj // "<some @a=1>" 

Print line

The print operator has it's evil twin, the println operator. It does just the same, but also prints a line break after the last operand.

Configuring print

The print operator can insert separators between arguments. To enable the feature, set the io:arg_separator property:

print 1, 2, 3 // "123"

io:arg_separator = "; "
print 1, 2, 3 // "1; 2; 3" 

The newline character at the end of println output can also be replaced with something else by setting the io:line_separator property.
Related pages: IO namespace

Last edited Mar 16, 2011 at 11:39 PM by impworks, version 3

Comments

No comments yet.