Date: May 19 2020
Summary: How Julia performs implicit returns
Keywords: ##zettel #julialang #programming #implicit #return #archive
Not Available
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.
Zelko, Jacob. Implicit Returns. https://jacobzelko.com/05192020171152-implicit-return. May 19 2020.