Agent-based modelling, Konstanz, 2024
16 April 2024
=
operatormy_number
:1
, 2
, -100
, …3.14
, pi
, 1.0
, …true
, false
"John"
, "Mary"
[1, 2, 3, 4]
, [1 2 3 4]
*
operator for strings too:or
end
fetches the last element:1
to each number in my_array
add_elementwise
Write a function with the following properties:
announce_age
"John is 40 years old"
struct
mutable struct
instead of struct
mutable struct
:name::String
means the field called name
is of type string, etc.Int
is an integerFloat64
, the number specifies the precision of the floating-point number (related to how many decimals it can store)Person
custom type, a Person
object, and store it in a variable:Write three functions:
Person
object as argument and returns their shoe sizePerson
object and a string as argument, and sets the person’s name to be the string supplied as argumentPerson
object’s age by oneNote that it is possible (and often good practice) to explicitly set the types of function arguments:
Person
s? Easy:Person
s?population
variable:i
variable is a dummy variable that only exists for the duration of the array comprehension.+
can be broadcast over arraysHow can you obtain a random number from between 0 and 50?
How about between 50 and 100?
Comments