1. Primers
  2. Julia: Functions, methods, and signatures
  • (Just enough) Julia for scientific informatics, modeling, and reasoning
  • Introduction
  • Basic frameworks and mechanisms
    • Orientation
    • Basics of setting up and running Julia
    • Basics of visualizing mathematical models
    • Basics of working with randomness and probabilities
    • Basics of working with data tables
  • Basics of specialized workflows
    • Basics of paleobiological fossil collection analyses
    • Basics of agent-based modeling: spatial epidemic dynamics with Agents.jl
      • Basics of agent-based modeling: spatial epidemic dynamics with Agents.jl
    • Basics of species distribution modeling
  • Primers
    • Bernoulli trial
    • Pathogen fitness as a function of virulence (Frank, 1996)
    • Virulence-transmission trade-off (Frank, 1996)
    • Julia – Environments – Global vs project
    • Julia: Functions, methods, and signatures
    • Markov property
    • Probabilty distributions–Essential concepts
    • Pseudo-random number generators
    • Pseudo-random number generators: best practices
    • Pseudo-random number generators: continuous values from discrete machines

On this page

  • 1 Functions
  • 2 Methods
  • 3 Signatures
  1. Primers
  2. Julia: Functions, methods, and signatures

Julia: Functions, methods, and signatures

Author

Jeet Sukumaran

1 Functions

In Julia, a function is a operation that can accept inputs and returns outputs. A function of a particular name (e.g. range, rand, my_custom_function) may have a number of different methods, or implementation that are distinguished by the pattern of arguments the function takes (called the signature of the function).

2 Methods

A method is a specific implementation of that function for particular input types or argument combinations. When you call rand(), rand(Int), or rand(1:6), you are calling different methods of the same function rand. Julia automatically selects the appropriate method based on the types and number of arguments you provide, as long as someone (the Julia programmers, package programmers, or yourself) has written a function that takes combination of arguments, a mechanism called multiple dispatch.

3 Signatures

Different methods of a functions are distiguished by their signature, which is the particular number (“arity”), order, and type of arguments: e.g.

  • foo(a, b)
  • foo(a::Int, b::String, c::Float64)
  • foo(a::Float64, b::Int)

Note that the names of the arguments do not matter, and the following all have the same signature:

  • foo(a::Int, b::Float64)
  • foo(first_input::Int, second_input::Float64)
Back to top
Julia – Environments – Global vs project
Markov property
  • © Jeet Sukumaran

Please share or adapt under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0).