Book Image

Getting Started with Julia

By : Ivo Balbaert
Book Image

Getting Started with Julia

By: Ivo Balbaert

Overview of this book

Table of Contents (19 chapters)
Getting Started with Julia
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The Rationale for Julia
Index

Basic input and output


Julia's vision on input/output (I/O) is stream-oriented, that is, reading or writing streams of bytes. We will introduce different types of streams, such as file streams, in this chapter. Standard input (stdin) and standard output (stdout) are constants of the type TTY (an abbreviation for the old term, Teletype) that can be used in the Julia code to read from and write to (refer to the code in Chapter 8\io.jl):

  • read(STDIN, Char): This command waits for a character to be entered, and then returns that character; for example, when you type in J, this returns 'J'

  • write(STDOUT, "Julia"): This command types out Julia5 (the added 5 is the number of bytes in the output stream; it is not added if the command ends in a semicolon (;))

    STDIN and STDOUT are simply streams and can be replaced by any stream object in the read/write commands. readbytes is used to read a number of bytes from a stream into a vector:

  • readbytes(STDIN,3): This command waits for an input, for example...