Article View: comp.lang.misc
Article #6197Re: Bondage and Discipline Languages
From: Peter da Silva
Date: Tue, 17 Jan 1989 14:03
Date: Tue, 17 Jan 1989 14:03
41 lines
1734 bytes
1734 bytes
In article <4246@enea.se>, sommar@enea.se (Erland Sommarskog) writes:
> But to throw some new wood on the fire, consider the following: Assume
> you have routine you want to call but whose name you don't know until
> run-time, thus you have the name in a string. Now in which langauges
> can you easily do this? Interpreting langauges like Lisp and Basic,
> support this I guess. But compiled langauges?
I do this all the time in 'C', for one reason or another. Many of my
interactive programs have the equivalent of this in them. It's more
painful to implement this in a language without aggregate initialisation,
of course. I can't imagine doing without this capability. Chopping up a
line into argv/argc is an excersize left to the reader.
struct {
char *fname;
int (*fcode)();
} funtab[] = {
"fname1", func1,
"fname2", func2,
"fname3", func3,
...
};
int nfuns = sizeof funtab / sizeof *funtab;
int call(name, argc, argv)
char *name;
int argc;
char *argv;
{
int i;
for(i = 0; i < nfuns; i++)
if(strcmp(name, funtab[i].fname) == 0)
return (*funtab[i].func)(argc, argv);
return 0;
}
--
Peter da Silva, Xenix Support, Ferranti International Controls Corporation.
Work: uunet.uu.net!ficc!peter, peter@ficc.uu.net, +1 713 274 5180. `-_-'
Home: bigtex!texbell!sugar!peter, peter@sugar.uu.net. 'U`
Opinions may not represent the policies of FICC or the Xenix Support group.
Technical Details
Message-ID:
<2794@ficc.uu.net>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!ficc!peterReferences:
<4246@enea.se>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.lang.misc Subject: Re: Bondage and Discipline Languages Message-ID: <2794@ficc.uu.net> Date: 17 Jan 89 14:03:33 GMT References: <4246@enea.se> Organization: Xenix Support Lines: 41