HP Forums

Full Version: SWAPROW vs rowSwap in CAS
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I've been playing around in CAS and ran into this:

rowSwap([[1,2],[3,4]],1,2)
→ [[3,4],[1,2]]

SWAPROW([[1,2],[3,4]],1,2)
→ [[3,4],[1,2]]

Now let's introduce a variable

rowSwap([[1,2],[3,x]],1,2)
→ [[3,x],[1,2]]

So far so good, but then

SWAPROW([[1,2],[3,x]],1,2)
→ "Error: Invalid input"

I thought that rowSwap is just an alias of SWAPROW (or the other way around), but that doesn't seem to be the case.

Is this expected behavior? Is SWAPROW supposed to give me this error message in this case?
I didn't notice such a problem in CAS. Are you sure you're in CAS mode (there should be a "CAS" indicator in the upper left corner of the screen)? If you're in HOME mode, the variable 'x' is not treated as a symbol but as a numerical value. In this case, if 'x' doesn't have a numerical value assigned (meaning you're trying to substitute 'nothing' into a matrix field), it returns an error. A similar error will occur if 'x' is assigned a value that cannot be substituted into a matrix (e.g., a string).
When I did this in CAS mode, everything worked as expected.
[attachment=12598]

If you substitute a numerical value (e.g., 7) for 'x' in CAS mode, you will notice the difference in the behavior of these two functions.
[attachment=12599]
I just tested it again and was not able to reproduce the problem.

When I ran into the issue yesterday I was in CAS mode too though. So I'm not sure what the problem was.

Let's just hope that I don't run into it again. If I do I'll update this thread with more infos, but otherwise this issue can be considered to be resolved.

Thank you for your input, Piotr!
rowSwap and SWAPROW share the same implementation, but the second one is indeed quoted, arguments are not eval-ed.
Reference URL's