the cedar ledge

Implicit Returns

Date: May 19 2020

Summary: How Julia performs implicit returns

Keywords: ##zettel #julialang #programming #implicit #return #archive

Bibliography

Not Available

Table of Contents

  1. How To Cite
  2. References
  3. Discussion:
function is_leap_year(year)
    if (year % 4 == 0) && !(year % 100 == 0) || (year % 400 == 0)
        return true
    else
        return false
    end

is equivalent to the expression

julia> is_leap_year(year) = (year % 4 == 0) && !(year % 100 == 0) || (year % 400 == 0)

julia> is_leap_year(1995)
false

This works because Julia performs implicit returns in their functions by returning the result of the function's last evaluated expression.

How To Cite

Zelko, Jacob. Implicit Returns. https://jacobzelko.com/05192020171152-implicit-return. May 19 2020.

References

Discussion:

CC BY-SA 4.0 Jacob Zelko. Last modified: May 19, 2024. Website built with Franklin.jl and the Julia programming language.