Unary minus

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
anmldr
Posts: 459
Joined: Tue Sep 11, 2012 11:13 pm

Unary minus

Post by anmldr » Sat May 30, 2020 3:00 am

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Unary minus

Post by FourthWorld » 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Unary minus

Post by dunbarx » Sat May 30, 2020 2:44 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7392
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Unary minus

Post by jacque » Sat May 30, 2020 4:10 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7392
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Unary minus

Post by jacque » Sat May 30, 2020 4:29 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Unary minus

Post by dunbarx » Sat May 30, 2020 5:26 pm

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

Post Reply