On 1/14/2019 9:56 AM, Laurent wrote:
I'm not entirely sure where I got that from, but to me a procedure is
a ("impure") function with possible side effects (printing, mutating a
global variable, sending emails, etc.). By contrast, in any given
context, a function is (again, to me) synonymous with "pure
function"(*) and can be called with the same values and will always
return the same value, and could in principle be substituted with any
other function implementating the same input-output specification
without changing the meaning of the whole program.
(*) https://en.wikipedia.org/wiki/Pure_function
There is at least one language where the "subroutines" can't return
values ... so what would you call them?
[Before you ask, the answer is Prolog.]
I've been programming [in a variety of languages] since the early 80s,
and I've never heard this notion that "procedure" was synonymous with
"impure function". If you look through old texts, what distinguished
procedures from functions was the *absence* of return values - which in
turn meant that a procedure could do useful work only through side effects.
historically, most languages have conflated the two notions -
syntactically offering a single impure form that can be either a
function or a procedure. But for the compiler - even with impurity -
there can be considerable benefit to distinguish the form that returns
values from the form that does not. [Again, I would encourage people
to study compiler texts - there's a lot of benefit to seeing how things
are really done.]
Potentially, at least, there is even more benefit to knowing a function
is pure - in theory at least a call with a given set of arguments could
simply be replaced by the result. But in practice, pure functions
rarely are evaluated at compile time - far more often results computed
at runtime are cached in case the same arguments are seen again.
George
--
You received this message because you are subscribed to the Google Groups "Racket
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.