[comp.lang.lisp] Functions vs. Procedures in Lisp

marsh@mitre-bedford.ARPA (Ralph J. Marshall) (06/14/88)

In article <1350016@otter.hple.hp.com> psa@otter.hple.hp.com (Patrick Arnold) writes:
>(function? I don't believe lisp has functions) 
>
>Just because the black box notion of a procedure didn't originate in Lisp
>doesn't mean we shouldn't allow Lisps to incorporate these VERY IMPORTANT
>SOFTWARE ENGINEERING PRINCIPLES. Indeed I think tha case for using Lisp
>(actually I prefer pop) for serious software engineering becomes much
>stronger if we do (how many other languages have real first class
>procedures? Pascal definitely no, Modula2, Ada, C).
>
>			Patrick.
	What is this all about ??? Why don't you think Lisp has functions,
and what do you mean by first-class procedures ?  I'm willing to believe that
"first-class procedure" means something special about which I am ignorant,
but where I come from a "function" is a subroutine call that returns a value
to the caller (possibly without any global side-effects, depending on how
you interpret the term.)  I think that this is the _MAIN_ type of subroutine
call in LISP, since you have to go out of your way to return nothing, and
global variables have to be declared or the compiler gets all uptight.

	If you have some definitions for these terms that back up your
assertions above, I'd love to hear them, and see some references.

	(BTW, I think the Common Lisp approach to lexical scoping by default
is a much more practical idea, especially since the compiler and interpreter
actually have to work the same way (what a concept !)).


---------------------------------------------------------------------------
Ralph Marshall (marsh@mitre-bedford.arpa)

Disclaimer: Often wrong but never in doubt...  All of these concepts
are mine, so don't gripe to my employer if you don't like them.
---------------------------------------------------------------------------


Newsgroups: comp.lang.lisp
Summary: Procedures vs. Functions 
Expires: 
References: <499@sequent.cs.qmc.ac.uk> <1350016@otter.hple.hp.com>
Sender: 
Reply-To: marsh@mbunix (Ralph Marshall)
Followup-To: 
Distribution: 
Organization: The MITRE Corporation, Bedford, Mass.
Keywords: 

[line counter food]
[soup]
[salad]
[entree]
[dessert]
[cognac]
[bill]
[doof retnuoc enil]

In article <1350016@otter.hple.hp.com> psa@otter.hple.hp.com (Patrick Arnold) writes:
>(function? I don't believe lisp has functions) 
>
>Just because the black box notion of a procedure didn't originate in Lisp
>doesn't mean we shouldn't allow Lisps to incorporate these VERY IMPORTANT
>SOFTWARE ENGINEERING PRINCIPLES. Indeed I think tha case for using Lisp
>(actually I prefer pop) for serious software engineering becomes much
>stronger if we do (how many other languages have real first class
>procedures? Pascal definitely no, Modula2, Ada, C).
>
>			Patrick.
	What is this all about ??? Why don't you think Lisp has functions,
and what do you mean by first-class procedures ?  I'm willing to believe that
"first-class procedure" means something special about which I am ignorant,
but where I come from a "function" is a subroutine call that returns a value
to the caller (possibly without any global side-effects, depending on how
you interpret the term.)  I think that this is the _MAIN_ type of subroutine
call in LISP, since you have to go out of your way to return nothing, and
global variables have to be declared or the compiler gets all uptight.

	If you have some definitions for these terms that back up your
assertions above, I'd love to hear them, and see some references.

	(BTW, I think the Common Lisp approach to lexical scoping by default
is a much more practical idea, especially since the compiler and interpreter
actually have to work the same way (what a concept !)).


---------------------------------------------------------------------------
Ralph Marshall (marsh@mitre-bedford.arpa)

Disclaimer: Often wrong but never in doubt...  All of these concepts
are mine, so don't gripe to my employer if you don't like them.
---------------------------------------------------------------------------



Newsgroups: comp.lang.lisp
Subject: Re: Other Lisps for the Mac (was: What's the value of lexical scoping?)
Summary: 
Expires: 
References: <499@sequent.cs.qmc.ac.uk> <1350016@otter.hple.hp.com>
Sender: 
Reply-To: marsh@mbunix (Ralph Marshall)
Followup-To: 
Distribution: 
Organization: The MITRE Corporation, Bedford, Mass.
Keywords: 

gateley@mips.csc.ti.com (John Gateley) (06/15/88)

In article <34296@linus.UUCP> marsh@mbunix (Ralph Marshall) writes:
>In article <1350016@otter.hple.hp.com> psa@otter.hple.hp.com (Patrick Arnold) writes:
>>(function? I don't believe lisp has functions) 
>	What is this all about ??? Why don't you think Lisp has functions,
>and what do you mean by first-class procedures ?  I'm willing to believe that

A first class object is one that can be passed to a procedure as an argument,
and returned as a value by procdedures. I dont have the references, but it
is in common use (especially among Schemers). I dont wish to speak for Patrick,
but "function" has (at least) two different meanings: the definition you gave,
and the definition mathematicians use.

manis@faculty.cs.ubc.ca (Vincent Manis) (06/16/88)

I first heard the term ``function'' in high-school algebra, to describe a 
particular type of relationship between quantities. In university mathematics, 
we spent a lot of time talking about mappings, bijective and otherwise. None
of these ideas have anything to do with the programming concept of a 
``function'', which returns a value after perhaps assigning some variables or 
doing some I/O. 

Languages with state change operators (such as assignment, data structure 
mutation [rplaca/set-car!], or I/O) do not have functions in the mathematical
sense. We've all been sloppy in the past, and talked as if they did. The
authors of the Scheme report did us all a service in eschewing ``function'',
and using ``procedure'' instead. 

Procedures are ``first-class citizens'' of a language if they may be passed
as parameters, returned as procedure values, and stored in data structures. 
CL, Scheme and most purely functional languages extend these rights; C, and
Modula-2 extend all these rights with limits (they don't allow such procedures
to encapsulate anything except the static global environment).

Vincent Manis                    | manis@cs.ubc.ca
The Invisible City of Kitezh     | manis@cs.ubc.cdn
Department of Computer Science   | manis@ubc.csnet
University of British Columbia   | uunet!ubc-cs!manis
<<NOTE NEW ADDRESS>>             |      

psa@otter.hple.hp.com (Patrick Arnold) (06/16/88)

John Gately is quite right to point out that function has sevral meanings
depending on the context of the conversation. I'm afraid it's one of my
"religious beliefs" that functions are expressions which denote values and
that calling a function with the same actual parameters will always produce
the same result and will have no insidious effects on other parts of the
system (i.e. side effects). This is the mathematical concept of a function.
I am quite happy with the other use provided the meaning is agreed at the
outset. 

I tend to use the term procedure for a parameterised piece of code which
may return a value (or even many values) and may have side effects. This is
sometimes a useful distinction to make. LISP and indeed most other
languages don't support the real notion of a function because there is
always the ability to access (and change destructively) other values or
parameters.

I hope this explanation gives you some hints as to why I don't think LISP
has functions in the true sense (although you can write inefficient Lisp
programs that are functional).

First class procedures are a very powerful programming tool enabling the
use of generic operations over data structures and object oriented style
programming using procedures with local state (closures) as objects. There
is quite heavy use of them in Abelson and Sussman (a must for any serious
Lisp programmer) and the book illustrates their use in a number of
different programming paradigms including an object oriented style.
(Interesting that what Lisp like languages have been able to do for years
is now in fashion in a different guise!!).

By the way I would just like to say that I don't get anything for plugging
Structure and Interpretation of Computer Programs, but it is quite the best
book on Lisp (Scheme actually) in particular and some programing techniques
in general that I have come across.

				Patrick.

markh@csd4.milw.wisc.edu (Mark William Hopkins) (06/17/88)

In article <1350017@otter.hple.hp.com> psa@otter.hple.hp.com (Patrick Arnold) writes:
>John Gately is quite right to point out that function has sevral meanings
>depending on the context of the conversation. I'm afraid it's one of my
>"religious beliefs" that functions are expressions which denote values and
>that calling a function with the same actual parameters will always produce
>the same result and will have no insidious effects on other parts of the
>system (i.e. side effects).

After having seen countless examples of this kind of thing in Math texts:

	      "Let g(x) = f(x, a)"
or
	      "We will suppress the subscripts in the following ..."
or
	      "A XXX space is a tuple <U, V, W>, but we will denote
	       such a space by U unless confusion precludes our doing so."

I am more reluctant to believe that Mathematical functions do not have anything
that corresponds to insiduous side-effects.

Remember, a side-effect is just a function parameter (or returned value) that
has not been explicitly parametrized in the definition of the function.  This
applies to I/O as well ... except that in most languages it would be impossible
make the parameters explicit in function with I/O side-effects.

Conclusion: Mathematical functions and programming language functions are MUCH
more closely related than anybody has realised up to now.

Sorta like: "I just found out yesterday that the Prince of Cambodia 
	     is my brother."
--------------------------------------------------------------------------------
Disclaimer: the poster of this article bears no relation to Prince Sihanouk
	    ... to the best of his knowledge.

gateley@mips.csc.ti.com (John Gateley) (06/18/88)

In article <6024@uwmcsd1.UUCP> markh@csd4.milw.wisc.edu (Mark William Hopkins) writes:
>[Examples of side-effecting mathematics deleted]
>Conclusion: Mathematical functions and programming language functions are MUCH
>more closely related than anybody has realised up to now.

I dont follow this, but if what you are saying is true, you should be able
to write a mathematical function with side effects. Show me how to do this.
I would like to see, for example, two functions f and g where g always returns
the last argument passed to f.

John Gateley

bouma@cs.purdue.EDU (William J. Bouma) (06/18/88)

In article <1350017@otter.hple.hp.com> psa@otter.hple.hp.com (Patrick Arnold) writes:
>John Gately is quite right to point out that function has sevral meanings
>depending on the context of the conversation. I'm afraid it's one of my
>"religious beliefs" that functions are expressions which denote values and
>that calling a function with the same actual parameters will always produce
>the same result and will have no insidious effects on other parts of the
>system (i.e. side effects). This is the mathematical concept of a function.
>I am quite happy with the other use provided the meaning is agreed at the
>outset. 
>
...
>
>I hope this explanation gives you some hints as to why I don't think LISP
>has functions in the true sense (although you can write inefficient Lisp
>programs that are functional).

    Whether a language has functions or not seems to me a very different thing
from whether a language is FUNCTIONAL (ie. everything is a function). I believe
one can write functionally in LISP and have the result be as efficient as the
non-functional equivalent. For one thing some compilers will optimize out tail
recursion into an iterative loop. For the other part it depends on what you are
programming and what algorithms you use.

    I don't know what version of LISP you are talking about, but I don't
remember any language since BASIC that FORCED me to write a FUNCTION (or
whatever the crap ypu want to call it) that had side effects. THUS LISP
DOES have functions in the mathematical sence. Isn't + a FUNCTION? How about
(lambda (x) x)? Aren't these TRUE enough functions for you???

    Personally I am sick of this whole discussion. What is the point? Who cares
if what one person calls a FUNCTION, another calls a "Procedure with returned
value"? Yes, in the context of a specific conversation it would be important
for the parties to have equivalent definitions, but in general NO. Who cares
what mathematics' definition of function is? Mathematics is NOT programming!
Any mathematicians reading this USE MACSYMA.

    ASSIDE: I cast my vote FOR Common Lisp. I have never had much problem 
writting programs in it whether I used dynamic binding or not. There is one
little thing that annoys me about it, but it is hardly enough to get all
excited and write 100+ line article about. Well, maybe tomorrow...
-------------------------------------------------------------------------------
bouma@medusa.cs.purdue.edu   | Just spending my days,
...!purdue!bouma             |   Soaking up those cathode rays.

markh@csd4.milw.wisc.edu (Mark William Hopkins) (06/19/88)

In article <51742@ti-csl.CSNET> gateley@mips.UUCP (John Gateley) writes:
>In article <6024@uwmcsd1.UUCP> markh@csd4.milw.wisc.edu (Mark William Hopkins) writes:
>>[Examples of side-effecting mathematics deleted]
>>Conclusion: Mathematical functions and programming language functions are MUCH
>>more closely related than anybody has realised up to now.
>
>I dont follow this, but if what you are saying is true, you should be able
>to write a mathematical function with side effects. Show me how to do this.
>I would like to see, for example, two functions f and g where g always returns
>the last argument passed to f.
>
>John Gateley

This is a tall order, but here it goes:

   Given a function f, let f' be the corresponding function defined on finite 
sequences:

	     f'({x1, x2, ... , xn}) = {f(x1), f(x2), ... , f(xn)}

Let F be an ordered pair (f', g) with f defined as above and g defined for 
sequences as follows:

	                g({x1, x2, ... , xn}) = xn

(Here's where the mathematical correlates of side-effects come in)

"For brevity we will suppress the prime on f' unless confusion otherwise
dictates, and we will refer to g as the 'last-argument' function of f."

... or something like that.