slang-users mailing list

[2019 Date Index] [2019 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] Limitations of eval()?


Am 04.11.2019 um 19:20 schrieb John E. Davis:
Bernd Eggink <bernd.eggink@xxxxxxxxxx> wrote:
The real problem I was trying to solve is the following. I need a
wrapper function which works exactly like 'printf', except that it first
makes some changes to the format parameter. My first attempt was to
change the corresponding stack element and then call printf() - but then
printf thinks it has zero parameters and generates a stack underflow
error. And as _NARGS can't be set from outside, I'm stuck.

It's not _that_ important, but I'd be interested to know if this could
be solved in an elegant way, without using eval.

Here is an example of a function that modifies to format parameter to
replace commas to '|' and writes the result using fprintf:

define fprintf_wrap ()
{
    variable args = __pop_list (_NARGS);
    if (length (args) < 2)
      throw UsageError, "Usage: ret=fprintf_wrap(fp, format, ...);";
    variable format = args[1];
    format = strreplace (format, ",", "|");
    args[1] = format;
    return fprintf (__push_list (args));
}

This is exactly what I was looking for. I couldn't find any information about the return value of __push_list() in the documentation. Thanks again! And let me say that I like S-Lang very much. It has nearly all features I missed in other programming languages. Considering the emptiness in this list, I hope I'm not the only user!

Regards,
Bernd

--
http://www.sudrala.de
_______________________________________________
For list information, visit <http://jedsoft.org/slang/mailinglists.html>.


[2019 date index] [2019 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]