Quiz 1.4: Primitive types and strings


Q1: Julia terminology

Which of the following definitions are correct?

RESOLUTION

All the above definitions are correct. Some of these definitions we haven't yet see, we'll discuss types and their characteristics in a further segment. But for now, we can note that we can categorize types according to different concepts, like primitive / composite / abstract, mutable vs. immutable, or still predefined vs. user defined. To query the kind of a type we can use functions such 'isstructtype(T)', 'isprimitivetype(T)', 'isconcretetype(T)', 'isabstracttype(T)', 'isbitstype(T)' or 'ismutabletype(T)'.

The correct answers are: - "primitive type: A type defined with the primitive type keyword. Objects of a primitive type have a given fixed memory size specified in the type definition." - "composite type: A type defined with the struct keyword. Composite types are formed by zero or more fields referencing other objects (of primitive or composite type)." - "singleton: An object instantiated from a composite type formed by zero fields." - "abstract type: A type defined with the abstract type keyword. Abstract types have no fields and objects can not be instantiated from it. Further, they can not be declared child of a concrete type." - "concrete type: A primitive or composite type." - "mutable type: A composite type defined with the mutable struct keyword. Mutable types can have their fields rebinded to other objects than those associated at the time of initialisation - "immutable type: All types except those defined with mutable struct." - "parametric type: A family of (mutable or immutable) composite or abstract types with the same fields names and type name net of the parameters' types. The individual type is then uniquely identified with the name of the parametric type and the type(s) of the parameter(s)." - "container or collection: A composite type (not necessarily mutable) designed to reference a variable number of objects and which provides methods to access, iterate and eventually mutate the reference to other objects." - "predefined types: A type whose definition is provided in Julia Base or in the Julia Standard Library." - "bits types: A primitive or immutable composite type whose fields are all bits type themselves"


Q2:

Given the following snippet:

a = "Hello"; b= "World"
c = join([string("$a",b)]," ")

Which of the following sentences are correct?

RESOLUTION

The string function put together the content of the variable a (that is, the string Hello) with the content of the variable b (World), altought in two different ways. The result is a single string HelloWorld. The outer function join then operates on a vector, but of a single string, and hence does nothing. Finally, c[2] uses an array-like indexing of the string to retrieve the second character, the Char e

The correct answers are:

  • "c is now HelloWorld"
  • "c[2] is now the Char e"