bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can a and d be the same for asort?


From: Andrew J. Schorr
Subject: Re: can a and d be the same for asort?
Date: Mon, 5 Jul 2021 14:17:33 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On Mon, Jul 05, 2021 at 12:56:25PM -0500, Neil R. Ormos wrote:
> I respectfully disagree that it's a pointless use
> case.  The destination array argument must be
> furnished in order to specify the "how" argument.

Oops, you're right, that's a fair point.

> If you want the original array sorted in-place, is
> asort(a, a, "@val_num_desc") permitted?  Or do you
> need to sort to a different destination array and
> copy the contents back to a[]?  (I know the answer
> (yes, no) in practice, but I don't think it's
> unambiguous from the manual.)

Yes. It's permitted. The code does the right thing.

> Calling asort() without an explicitly named
> destination array is (obviously) permitted.  But I
> believe the manual does not say that "If you
> supply a and d with the same value, it's just the
> same as not supplying d at all."  (If I missed
> that in the manual, I'm sorry.)  Maybe that
> statement is all that's needed.

Hmmm. It should work exactly as one would hope that it should, if I'm reading
the code correctly. So should the docs be enhanced to allay one's fears that it
might not work? One could always just try it. In my view, if it doesn't say
that it's forbidden to use the same source and destination arguments, then one
should assume that it's OK. We don't spell out every last detail. But I agree
with your point that it is a relevant usage case; my earlier response was
shortsighted for not recognizing that.

Regards,
Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]