What is the Gist of the Double-Colon “::” in Julia?

There are two different ways to use the double colon “::” in Julia. First, it can be used to check to make sure a variable is of the correct type. Secondly, it can be used to force a local variable to always (locally) be of a certain data type.

The syntax for making sure the variable is the correct type is “x::type”. If x is the same type as “type,” then x is returned. If not, a TypeError is returned. For example:

julia> (1+2)::AbstractFloat
ERROR: TypeError: in typeassert, expected AbstractFloat, got Int64

julia> (1+2)::Int
3

(Code example from “Type Declarations,” JuliaLang.org)

The syntax for forcing a local variable to (locally) always have a certain data type is “x::type = value”. Trying to make x become a value that isn’t “type” will cause an error. For example:

julia> function foo(num)
           x::Int8 = num
           x
       end
foo (generic function with 1 method)

julia> foo(100)
100

julia> typeof(ans)
Int8

julia> foo(3.5)
ERROR: InexactError: Int8(3.5)

(Code example based on code found in “Type Declarations,” JuliaLang.org, which also has an example of how to do this to force the outputs of functions to be a certain type)

.

Sources:

.

Disclaimer:

I am not a professional in this field, nor do I claim to know all of the jargon that is typically used in this field. I am not summarizing my sources; I simply read from a variety of websites until I feel like I understand enough about a topic to move on to what I actually wanted to learn. If I am inaccurate in what I say or you know a better, simpler way to explain a concept, I would be happy to hear from you :).

What is the Gist of an “IOStream” or an “I/O Stream” in Programming?

(Note: this post is based on two Java-based sources and one C++-based source. It may not be true for every program)

First, the “I” in IOStream seems to stand for “Input” and the “O” seems to stand for “Output.” So these might be thought of as “Input/Output Streams“. But what is a stream? A stream can be thought of as either the source or destination of a sequence of data or as the sequence of data itself [1,2,3]. The source/destination can be varied and the types of data can be varied [1]. “A program uses an input stream to read data from a source, one item at a time… [and] an output stream to write data to a destination, one item at time” [1]. “Once a file stream is used to open a file, any input or output operation performed on that stream is physically reflected in the file” [2]. “No matter where the data is coming from or going to and no matter what its type, the algorithms for sequentially reading and writing data are basically the same:” [3]

Source: [3]

[1]: “I/O Streams,” Oracle Java Documentation

[2]: “Input/Output,” cplusplus.com

[3]: “Overview of I/O Streams,” The JavaTM Tutorial

.

Disclaimer:

I am not a professional in this field, nor do I claim to know all of the jargon that is typically used in this field. I am not summarizing my sources; I simply read from a variety of websites until I feel like I understand enough about a topic to move on to what I actually wanted to learn. If I am inaccurate in what I say or you know a better, simpler way to explain a concept, I would be happy to hear from you :).