Article View: comp.lang.misc
Article #4792Re: H.O.Functions + Polymorphism
From: Will Clinger
Date: Thu, 09 Jul 1987 23:33
Date: Thu, 09 Jul 1987 23:33
32 lines
1627 bytes
1627 bytes
In article <441@unisoft.UUCP> jef@unisoft.UUCP (Jef Poskanzer) writes:
>int p1(x)
>int x;
> {
> return x + 1;
> }
>
>Or if you want to be polymorphic:
>
>#define p1(x) ((x) + 1)
These aren't higher order functions. In Doug Pase's example, plus was the
higher order function, not p1. It's hard to explain what plus does to a C
programmer because C can't express it. Here's a stab at explaining what
plus does using a mix of Pascal and C and illegal syntax:
function plus (y : number) : (function __ (__ : number): number);
function p1 (x : number) : number;
begin
return x + y
end;
begin
return p1
end
The key thing to observe is that the function p1 must remember the value of
y that was in effect when it was created, even after the plus function has
returned. This is why stack-based languages like Pascal and C don't support
higher order functions.
Peace, Will Clinger
Tektronix Computer Research Lab
Technical Details
Message-ID:
<1432@tekchips.TEK.COM>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!seismo!husc6!mit-eddie!uw-beaver!tektronix!tekcrl!tekchips!willcReferences:
<1345@ogcvax.UUCP> <441@unisoft.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!seismo!husc6!mit-eddie!uw-beaver!tektronix!tekcrl!tekchips!willc From: willc@tekchips.TEK.COM (Will Clinger) Newsgroups: comp.lang.misc Subject: Re: H.O.Functions + Polymorphism Message-ID: <1432@tekchips.TEK.COM> Date: Thu, 9-Jul-87 19:33:37 EDT Article-I.D.: tekchips.1432 Posted: Thu Jul 9 19:33:37 1987 Date-Received: Sun, 12-Jul-87 07:29:56 EDT References: <1345@ogcvax.UUCP> <441@unisoft.UUCP> Reply-To: willc@tekchips.UUCP (Will Clinger) Distribution: world Organization: Tektronix, Inc., Beaverton, OR. Lines: 32