Re: Calculator
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Sat, 14 May 2005 20:34:01 GMT
"Malcolm" <regniztar@xxxxxxxxxxxxxx> writes:
> "Flash Gordon" <spam@xxxxxxxxxxxxxxxxxx> wrote
[...]
>> What about a "procedure" the prime purpose of which is to modify it's
>> input parameters, such as qsort? It definitely "returns" something, i.e. a
>> sorted array.
>>
> Exactly. The designers of Pascal were trying to express the difference
> between a function and a procedure, but did't do so in a way that is useful
> to the programmer.
No, they did it in a way that's extremely useful to the programmer; I
certainly found it so back when I was a Pascal programmer. A function
directly returns a result, and a function call can occur as part of an
expression. A procedure does not return a result, and a procedure
call can appear only as a statement. (C, of course, doesn't make
quite the same distinction between void and non-void functions.)
In my (perhaps somewhat limited) experience, these meanings of the
terms "procedure" and "function" are nearly universal.
[...]
>> If you are defining a different concept it is best to use a different
>> name, rather than one which already as a meaning people are familiar with.
>> You also need to realise that the world is not a simple place.
>>
> We can't really surrender the term "function" to ANSI. Essentially I am
> using the same concept as Pascal, but defining it in a better way.
No, you're not. You're using the same terms that Pascal uses, but
you're assigning different meanings to them.
I'm not just talking about ANSI. I'm talking about the nearly
universal usage of the terms "procedure" and "function" over the past
several decades.
There is a related concept that may be close to what you're talking
about: a "pure" function. A pure function, loosely, is one that
computes a result using only its explicit parameters; it doesn't refer
to any global variables, none of its local variables are "static" in
the C sense, it has no side effects. The mathematical functions are
examples of this; time() is not, since it refers to an implicit
global. If an optimizer sees two calls to a pure function with the
same arguments, it can safely replace them with a single call.
Neither Pascal nor C makes any language-level distinction between
"pure" functions and other functions. (Ada does, if I recall
correctly.)
Note that the distinction involves side effects and global variables.
There's no mention of hardware. *All* code interacts with hardware,
at least with memory and the CPU.
Again, if you're going to make distinctions like this, *please* pick
terms other than "procedure" and "function". We know what they mean,
and it's not what you think they mean.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.
- Follow-Ups:
- Re: Calculator
- From: Dave Thompson
- Re: Calculator
- From: Malcolm
- Re: Calculator
- References:
- Calculator
- From: Flipke
- Re: Calculator
- From: Malcolm
- Re: Calculator
- From: Walter Roberson
- Re: Calculator
- From: Jonathan Adams
- Re: Calculator
- From: Keith Thompson
- Re: Calculator
- From: Jonathan Adams
- Re: Calculator
- From: Malcolm
- Re: Calculator
- From: Richard Bos
- Re: Calculator
- From: Malcolm
- Re: Calculator
- From: Keith Thompson
- Re: Calculator
- From: Malcolm
- Re: Calculator
- From: Flash Gordon
- Re: Calculator
- From: Malcolm
- Calculator
- Prev by Date: Re: Calculator
- Next by Date: Re: Calculator
- Previous by thread: Re: Calculator
- Next by thread: Re: Calculator
- Index(es):
Relevant Pages
|