[comp.lang.misc] Re^2: On whether C has first-class composable functions

kend@data.UUCP (Ken Dickey) (01/07/91)

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes:

>In article <442@data.UUCP> kend@data.UUCP (Ken Dickey) writes:
>> There is an important property of "first-class" objects missing here.
>> A first-class object does not have to be named.  

>Do you have a reference? As always, I'm doing my best to use standard
>terminology; I just haven't seen any references that demand a syntactic
>restriction like that.

I believe that most references come from the Scheme literature.

The reference you want is Guy Steele's Masters thesis: "RABBIT: A
Compiler for SCHEME (A Study in Compiler Optimization)", MIT tech.
report: AI-TR-474, (May 1978).  [I suspect earlier references, but
have not yet found them].  From the introduction (pg 8):

  SCHEME also permits the treatment of functions as full flegded data
  objects; they may be passed as arguments, returned as values, made
  part of composite data structures, and notated as independent, unnamed
  ("anonymous") entities.  {Contrast this with most ALGOL-like
  languages, in which a function can be written only by declaring it and
  giving it a name; imagine being able to use an integer value only by
  giving it a name in a declaration!).
  
More recently, [Kent Dybvig, "The Scheme Programming Language",
Prentice Hall, 1987]

  ...procedures are not always named.  Instead, procedures are
  first-class data objects similar to strings or numbers;  identifiers
  are bound to procedures in the same way they are bound to other
  objects. 

I can dredge up more references if you like (most are at work and I am
at home).


>> By the way, what function would "apply(compose(compose,f),x);" return in C?
>> Strike "composable"?

>What are you talking about? 

I admit that my C syntax is a bit rusty.

>It doesn't make sense to compose a function
>that takes two arguments, at least not without a more general notation.
>I can't make heads or tails of your example.

Why should the number of arguments make a difference to composability?
One should certainly be able to compose the function COMPOSE!  {After
all it is a function, yes?}  So a composition of COMPOSE should be a
function.

So compose(compose,f) should return a function which takes another
function argument [e.g. x] and returns a function which takes, say, 2
arguments.  So I should be able to do something like compose the 2
functions, compose and f, to another function, x, to further
arguments: compose(compose,f)(x)(y,z).  C is rather weak, and I
presumed that you would need a help function, APPLY, to do this.


-Ken

[Someone else's signature, but it expresses the situation:]
 = The C Programming Language -- A language which combines the             =
 = flexibility of assembly language with the power of assembly language.   =

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (01/08/91)

In article <443@data.UUCP> kend@data.UUCP (Ken Dickey) writes:
>   SCHEME also permits the treatment of functions as full flegded data
>   objects; they may be passed as arguments, returned as values, made
>   part of composite data structures, and notated as independent, unnamed
>   ("anonymous") entities.  {Contrast this with most ALGOL-like
>   languages, in which a function can be written only by declaring it and
>   giving it a name; imagine being able to use an integer value only by
>   giving it a name in a declaration!).

``Full-fledged data objects,'' yes; but ``first-class'' doesn't mean
``full-fledged.''

> More recently, [Kent Dybvig, "The Scheme Programming Language",
> Prentice Hall, 1987]
>   ...procedures are not always named.  Instead, procedures are
>   first-class data objects similar to strings or numbers;  identifiers
>   are bound to procedures in the same way they are bound to other
>   objects. 

Okay, that'd do it; but if that's the definition of ``first-class'' then
you can have first-class objects that you can't pass as function
arguments! I don't think any of us agree with that.

Anyone want to contribute more definitions?

> > > By the way, what function would "apply(compose(compose,f),x);" return in C?
> > > Strike "composable"?
> > What are you talking about? 
  [ explanation ]

Okay, you're saying that you want compose() to apply to the first
argument of a function with many arguments. This would be more useful
if you also had a way to switch around the arguments to a function---
e.g., to convert f(x,y) to g(y,x). There's no reason that these things
can't be done with exactly the same techniques as the one-argument
compose(), so I don't think your example is a reason to say that we're
not talking about composable functions.

---Dan

kers@hplb.hpl.hp.com (Chris Dollin) (01/09/91)

Dan says:

   >    o Objects never die.

   Question 2: Do you realize that if the properties you posted are taken
   to define ``first-class,'' then nothing in Ada is ``first-class''?

Not even integers?
--

Regards, Kers.      | "You're better off  not dreaming of  the things to come;
Caravan:            | Dreams  are always ending  far too soon."