Re: Calculator



"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.
.



Relevant Pages

  • Re: What is a logical contradiction?
    ... Nowhere in the thread was there any overt ... to logical equivalence) of representing the meanings of these statements ... so in that rather restricted sense they ... that there are classical logical frameworks in which that distinction is ...
    (sci.logic)
  • Re: AmE just solution/gist in time
    ... John Swindle wrote: ... quick look at a couple of dictionaries. ... distinction was part of learning to read, ... My other "just," with its different set of meanings, sounded different ...
    (sci.lang)
  • Re: Malcolms new book
    ... To quote: ... Note that strlenis a "pure function". ... One of the features of C is that there is no distinction ... that goes to show that whoever originally wrote that has no idea ...
    (comp.lang.c)
  • Re: Expressiveness
    ... suspicion that the fine distinctions of meanings are not being lost by the ... sloppy language community but invented by hair-splitting language mavens. ... consensus among the speakers about the distinction of meanings. ...
    (sci.lang)
  • Re: Whats the right term?
    ... >>functions as parameters in C or return one, you must use pointers. ... > pure function. ... Well, actually, functional languages deal in global variables a lot, ... But most functional languages, like Scheme and those in the ML family, ...
    (alt.comp.lang.learn.c-cpp)