On 2024-02-17 10:51, Darren Duncan wrote:
> FWIW, from a general language design perspective, I prefer those
> languages that make functions and procedures very structurally
> different routines in how they are declared. So functions must return
> a value and be invoked within expressions, and procedures must not
> return a value and must be invoked as statements. Examples of
> languages like this include SQL and Pascal. In that context, there is
> no "void" result type, instead you have a "procedure".
A procedure-call can still end in failure,
so it further depends on the definition of "return value".
Some functions use out-of-domain values to return error status.
I don't like that, IMO return value and state must be kept separate.
As Perl subs kan return lists, one could use
the first element for the return value
and the second element for the status:
my ($rv, $err) = mysub(....);
But then mysub() needs to use wantarray()
(which actually means wantlist())
to find out what it should return.
Procedures generally have side effects.
Procedures can be allowed to change the contents of ("output") parameters,
which is much like a return value.
Functions are cleanest if they don't have side effects.
But for example memoization already blurs that.
-- Ruud
> FWIW, from a general language design perspective, I prefer those
> languages that make functions and procedures very structurally
> different routines in how they are declared. So functions must return
> a value and be invoked within expressions, and procedures must not
> return a value and must be invoked as statements. Examples of
> languages like this include SQL and Pascal. In that context, there is
> no "void" result type, instead you have a "procedure".
A procedure-call can still end in failure,
so it further depends on the definition of "return value".
Some functions use out-of-domain values to return error status.
I don't like that, IMO return value and state must be kept separate.
As Perl subs kan return lists, one could use
the first element for the return value
and the second element for the status:
my ($rv, $err) = mysub(....);
But then mysub() needs to use wantarray()
(which actually means wantlist())
to find out what it should return.
Procedures generally have side effects.
Procedures can be allowed to change the contents of ("output") parameters,
which is much like a return value.
Functions are cleanest if they don't have side effects.
But for example memoization already blurs that.
-- Ruud