🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #2722

Re: On whether C has first-class composable functions

#2722
From: Douglas E. Quale
Date: Tue, 29 Jan 1991 15:35
37 lines
1758 bytes
My question:

>> Show me an implementation that doesn't have a fixed limit on the number of
>> functions that can be composed.  The only portable C implementation 
>> demonstrated so far has an arbitrary limit compiled in.  How do I
>> dynamically allocate function objects in C??
>

And the answer:

>details.  The main idea, though, is that you invent a structure...
>
>   struct Func { int (*f)( void *, int ); void *instanceVariables; };
>
>...and an "apply" function (it's dangerous as a macro):
>
>   int apply ( f, arg )
>      struct Func *f;
>      int arg;
>      {
>      return (f)->f ( (f)->instanceVariables, arg );
>      }
>
>The struct Funcs can be alloc'ed as you like.  Mail me if you want the
>details.  Or, if anybody wants, I'll repost it.

Sorry, this doesn't work because compose returns a structure, not a function.

Suppose I want to use the library function twalk(3c).
It takes a function as an argument.  Will it accept the output of your
compose, or do I have to rewrite every library function that takes functional
parameters to provide two versions?

Note:  The interpreter hack fails here as well.

-- Doug Quale
quale@picard.cs.wisc.edu
Technical Details
Message-ID: <1991Jan29.153549.19220@spool.cs.wisc.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!caen!uwm.edu!uwvax!picard.cs.wisc.edu!quale
References: <4408:Jan421:44:3391@kramden.acf.nyu.edu> <1991Jan26.132913.11358@spool.cs.wisc.edu> <307@smds.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!caen!uwm.edu!uwvax!picard.cs.wisc.edu!quale
From: quale@picard.cs.wisc.edu (Douglas E. Quale)
Newsgroups: comp.lang.misc
Subject: Re: On whether C has first-class composable functions
Message-ID: <1991Jan29.153549.19220@spool.cs.wisc.edu>
Date: 29 Jan 91 15:35:49 GMT
References: <4408:Jan421:44:3391@kramden.acf.nyu.edu> <1991Jan26.132913.11358@spool.cs.wisc.edu> <307@smds.UUCP>
Sender: news@spool.cs.wisc.edu (The News)
Organization: U of Wisconsin CS Dept
Lines: 37