Page 1 of 1

Unary minus

Posted: Sat May 30, 2020 3:00 am
by anmldr
In the LC Dictionary, it states,
The unary minus cannot be used with an array.
I assume that this means that "-myArray" cannot be used. Or, does this mean that you cannot have

Code: Select all

myArray1 - myArray2 
?

Linda

P.S. Am going through the dictionary. Which version is usually the "latest"? The online version or the stack within the IDE? I am finding the most typos in the online version than in the IDE stack.

Re: Unary minus

Posted: Sat May 30, 2020 7:22 am
by FourthWorld
The online version should be the same as the most recent Stable build. If you're using a DP or RP preview build you may see more fixes than the one on the web site.

Re: Unary minus

Posted: Sat May 30, 2020 2:44 pm
by dunbarx
Linda.

Yes, you cannot subtract one array from another. The idea itself makes no sense, at least to me.

If you have elements of an array that you want to subtract from the elements of another array, I would break out that data of each with the "combine" command, do the math, and then restore the data back into an array with "split". The arrays do not have to be of the same "size".

You could also do it by successively extracting elements of one array and doing the math on the corresponding element of the other array directly:

Code: Select all

put array1["x"] - array2["y"] into array1["x"]
That is a matter of style. In that case, again, everything would be under script control, and the two arrays do not have to be of the same size.

You could write a simple function to do any of that. But it would only automate what I suggested above.

Craig

Re: Unary minus

Posted: Sat May 30, 2020 4:10 pm
by jacque
FourthWorld wrote:
Sat May 30, 2020 7:22 am
The online version should be the same as the most recent Stable build. If you're using a DP or RP preview build you may see more fixes than the one on the web site.
They should be the same but they aren't always. The web version can fall behind after every new build since it has to be updated manually. The most recent version will always be the embedded dictionary.

Re: Unary minus

Posted: Sat May 30, 2020 4:29 pm
by jacque
you cannot subtract one array from another. The idea itself makes no sense, at least to me.
It might be referring to the ways you can manipulate an array with the difference command, which "subtracts" keys from an array based on another array.

Re: Unary minus

Posted: Sat May 30, 2020 5:26 pm
by dunbarx
Jacque.

Ah, maybe. I was thinking in terms of the array elements.

So Linda, what did you mean? Can you give a simple example?

Craig