-
-
Save m-doughty/1a22ce833f707303d84c4c630044c425 to your computer and use it in GitHub Desktop.
Pure & impure functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an impure function, calling double will return 2 the first time, then 4, then 8... | |
my $input = 1; | |
sub double { | |
$input = $input * 2; | |
return $input; | |
} | |
# This is a pure function, calling triple(1) will always return 3. | |
sub triple { | |
my $n = shift; | |
return $n * 3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment