sutela@polaris.utu.fi (Kari Sutela) (04/25/91)
sutela@polaris.utu.fi (Kari Sutela) writes: >>2> Is there a way (aside from writing an External Function >> Library) to maintain a collection of Arexx functions which can be called >> from various scripts? >I have thought about this and it certainly should be possible to write an >ARexx `function server'. It was simpler than I thought. Here's a really simple example of one. It's far from perfect; for example, error handling isn't too good. One has to pass *values* in the argument list as Rexx variables aren't visible to external functions. I hope no-one minds my posting this short program on a non-source group. /* * fserv.rexx * * A simple example of an ARexx function `server'. Beware: the arglist * is a *single* string (possibly containing commas to indicate several * arguments). Examples: * * fserv(hello,'hello there') == 'Hello HELLO THERE' * - Notice upper case! * fserv('hello','''Hello There''') == 'Hello Hello There' * - We can get mixed case, too * * one = 'notone'; fserv(hello,'one') == 'ONE' * - variables are reinitialized at external functions * one = 'notone'; fserv(hello,one) == 'NOTONE' * - you must use the value of a variable in the call * * fserv(strcat,'hello, there') == 'HELLOTHERE' * - strcat receives two arguments * fserv(strcat, '''hello, there''') == 'hello, there' * - now strcat receives one argument only (no-one said this is * perfect) * * fserv(eval, 'length(5**2)') == 2 * fserv(eval, '''length(5**2)''') == 2 * - same result but the latter evaluates the expression later. * * fserv(nonexistentfuntion) == 15 * - error handling could be better. At least, it returns the * proper ARexx error code. * * As you can see, this is far from perfect, but could be enough in * simple cases. * * Kari Sutela, 1991 */ parse arg function, arglist signal on syntax interpret 'locres = 'function'('arglist')' return locres hello: PROCEDURE parse arg str say 'Hello' str return 0 strcat: PROCEDURE parse arg str1, str2 return str1 || str2 eval: PROCEDURE parse arg expr interpret 'test =' expr return test /* * The entry point for syntax error signals. * Here the variable RC will contain the ARexx error code. */ syntax: exit RC /* end of fserv.rexx */ -- Kari Sutela sutela@polaris.utu.fi