Given the following two procs:
proc firstOne(): void =
echo "X"
proc secondOne(): void =
echo "X"
discard
What functional difference, if any, is there between them? And if they are the same, what is the purpose of discard if void type discards the result?
The discard
in the second procedure is superfluous. A discard
without an argument is simply a no-op. It is normally used (like pass
in Python) where the language syntax requires a statement, but where you don't want to do anything. An example would be an empty procedure:
proc doNothing() =
discard
You can still add discard
even where it is not syntactically necessary because as a no-op it doesn't do anything.
This is different from discard
with an argument, whose purpose is to call a function for its side effects and ignore the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With