Utilities#
In this section, we define some utility functions that will be used throughout the book.
Display Variable Info#
Since it is essential to understand how variables work internally, although that not be the case for everyone. I wanted to good deep into the language from the very beginning of the book, hence the term distilled; thus, I designed another function display_var_info to display detailed information about a variable. This includes the variable’s name, value, type, and memory size. This function is particularly useful for debugging and educational purposes, where understanding the characteristics of a variable is crucial.
# Function to display the type and size of a variable
function display_var_info(var_name::String, var_value)
println("$var_name:")
println(" Value : $var_value")
println(" Type : $(typeof(var_value))")
println(" Memory Size : $(sizeof(var_value)) bytes")
println()
end
Here is an example how to use this function
# Define a variable
x = 42
# Display information about the variable
display_variable_info("x", x)
Here is the output
x:
Value : 42
Type : Int64
Memory Size : 8 bytes
To do
As we continue writing this book, additional utility functions might be introduced and documented in this section.