Re: DOLIST with empty list?



On Sun, 26 Feb 2006 03:43:12 -0600, VPN wrote:

Since HPQ is at this terrible bug

Minor, really.

why not check for an empty list?
It's a feature,
but it's about time to change this for the better.

What exactly do you mean?

(a) To give the original "Invalid Dimension" error (as usual)?

(b) To decide to return the empty list, unaltered?

(c) To decide not to return anything (without error)?

It's unfortunately not possible to decide between (b) and (c),
at least not without psychic powers, as I will attempt
to illustrate below once again (I think it must be
ten years since the last time, so my lease needs renewing :)

I did once post "normalized" DOLIST/DOSUBS user programs,
but this was predicated on a fundamental change in the definition
of the "normalized" functions, which was not only that
they should consider empty argument list(s) valid,
but that they should also *always* return an output list,
no matter what, even if empty (which can not now occur);
anyone who had no use for that could then DROP that result,
knowing for sure that it would *always* be there.

But this fundamentally redefines DOLIST/DOSUBS in a manner
which would break so many existing programs that rely on
the original definitions, which say that if you generate
any new results on the stack, you get a list of those
as an output, but if you generate none, you get no output at all,
rather than being able to count on getting back a list anyway,
in this case just empty.

However appealing it may have seemed, to save the need
to say DROP after DOLIST/DOSUBS if you knew in advance
that you were not leaving any results on the stack,
it was a flaw to think that everyone knows in advance
whether they will or won't be generating results.

For example, if the input is a list of variables
and I replace each by recalling the variable's contents,
then I'm sure that I will get a result list,
whereas if I instead am simply purging every variable,
then I'm sure that nothing will be left on the stack
when I'm finished, and I won't get any result list
that would need to be DROPped.

What if, however, I want to recall the contents of each variable
which contains an array, and to purge every other variable which doesn't?

Do I know in advance whether I will end up with any output,
or no output at all? Unfortunately not, because it would
have depended on conditional testing at run time,
which could have turned out either way,
and unlike CHOOSE, say, which leaves a True/False "flag"
to let me know whether anything was chosen,
DOLIST and DOSUBS do not by themselves tell me anything
afterwards -- they expect me to have known *in*advance*
how things would have turned out,
i.e. whether I would end up choosing anything at all.

And when your input list is empty to begin with,
you can not even invoke the program at all,
because there is no input available to present to it
[except for this bug, which hands my program
an entirely unexpected "null program" as an input,
and thus provokes an error],
so there is no way (without psychic powers)
to guess what the program would have done,
if only it had had anything to do at all :)

There are all sorts of ways to compensate for
not knowing in advance what the outcome would be,
such as by setting your own flag, keeping your own count,
putting a "marker" on the stack,
comparing before/after stack DEPTH, etc.,
but all this is a band aid on an original mistake,
requiring extra, defensive, and non-obvious programming,
throwing away some of the simplicity and elegance
that the right original, universal approach would have provided.

Now where was I?

Oh yeah, so (a) is the only available way to go :)

[r->] [OFF]
.



Relevant Pages

  • Re: LIFO in C, need your suggestions
    ... printf(" stack is not empty yet, ... interpretation will be stack_remove() will remove the stack and stack_free ... if(sfree!= NULL) ... the memory held by 100 elements. ...
    (comp.lang.c)
  • Re: Beat Toudai
    ... of empty pdf pages. ... KPDF got empty little, and empty big, pages. ... But still it and evince ... Execution stack: ...
    (sci.lang.japan)
  • Re: LIFO in C, need your suggestions
    ... struct sstack_node * next; ... stnode = pop; ... printf(" stack is not empty yet, ...
    (comp.lang.c)