1

Are "procedure" and "function" synonymous in Racket (a dialect of Scheme)? It seems to be implied by the documentation. For example, the documentation for compose describes it as a procedure that

[r]eturns a procedure that composes the given functions...The compose function allows the given functions to consume and produce any number of values...

(All of the above italicization was added by me.)

I understand that procedure? is a library procedure and function? is not. My question is whether it is correct to use the terms interchangeably when discussing programs (such as when teaching a class or writing documentation).

Ellen Spertus
  • 6,576
  • 9
  • 50
  • 101

2 Answers2

3

TL;Dr It's just lingo and means the same. function, procedure, and static method is the same in programming.

Historically a function is in the mathematical sense a mapping between arguments to a result. A procedure is a block of code that does something and its output does not need to be tied to any specific input. Thus you could say a function is a procedure with no side effects.

The Scheme standard uses only the term procedure. You won't find any hints about function at all. Racket is historically a standard Scheme implementation made for education purposes and is pretty much still compatible with Scheme for the most part today, but they have made a split and does not consider themselves to follow a Scheme standard. How to design programs and lots of documentation uses the term function and in this documentation it is meant as a synonym to procedure.

Common Lisp uses the term function consistently and its predecessors too, which predates Scheme.

I think I have even translated a SO answer between languages and changed the code as well as just switched function and procedure for consistency with the languages lingo itself. I would love to see Racket clean up some day and stay with one name to rule them all.

Ellen Spertus
  • 6,576
  • 9
  • 50
  • 101
Sylwester
  • 47,942
  • 4
  • 47
  • 79
  • I would love to see Racket with some consistency here too. Maybe useful to contrast _procedure_ vs. _process_ here too? – Mulan Jan 14 '19 at 18:25
  • I disagree with your first paragraph. Some languages, such as Pascal, distinguish between functions and procedures. – Ellen Spertus Jan 23 '19 at 19:57
  • @EllenSpertus Pascal does, but both can have side effects and both takes arguments and since Pascal was based on Algol that used procedures for both I bet void functions (procedures) was first and then they added function as a procedure that returned a value. Procedures can easily be used as a function by defining an argument to hold the return value as reference. All in all Pascal doesn differentiate on the actual differences between procedures and functions but just use the words to difference varieties of the same concept. – Sylwester Jan 23 '19 at 23:16
  • @Sylwester It's true that both can have side effects, but there still is a distinction in some languages. – Ellen Spertus Jan 23 '19 at 23:43
  • @EllenSpertus How I see it the distinction isn't on the actual differences between imperative procedure and mathematical function rather than they needed a new name for an extended version to keep old code compatible. Pascal was a new take on Algol which used procedure for both while I guess pascal started off with just procedures and procedures with return values that they called functions later. Do you know a language that does the words justice? – Sylwester Jan 24 '19 at 16:19
2

The short version: yes.

The longer version: a number of folks have done good work on aligning vocabulary for use in teaching. This is the first paper that comes to mind, although it does not specifically address the procedure/function choice:

https://cs.brown.edu/~sk/Publications/Papers/Published/mfk-measur-effect-error-msg-novice-sigcse/paper.pdf

From a pedagogic standpoint, of course, it's unhelpful to have two names for the same thing, sigh.

Finally, you'll get a more authoritative answer (and frankly, I'd like to know what the state of things here is) if you ask this question on the Racket Mailing List.

[EDIT] Ooh, further, I would not at all say that the word procedure is more likely to denote something defined in a library.

John Clements
  • 16,895
  • 3
  • 37
  • 52
  • Thanks. I was thinking of asking Shriram or the Racket Mailing List. I'll report back. – Ellen Spertus Jan 13 '19 at 16:15
  • I don't see where the linked paper discusses aligning vocabulary. Could you point me to the right part? – Ellen Spertus Jan 23 '19 at 19:56
  • I did a bit more digging, and it looks like this 2011 paper more directly addresses vocabulary, specifically in section 5, "Vocabulary": https://cs.brown.edu/~sk/Publications/Papers/Published/mfk-mind-lang-novice-inter-error-msg/ – John Clements Jan 24 '19 at 21:59