I’m getting an Unknown Statement error when I try to use arraychange(
I copied the example out of Help
arraychange("red,green,blue","orange",2,",")
and pasted it into a new procedure - just that line
I still got and unknown statement error. ???
I’m getting an Unknown Statement error when I try to use arraychange(
I copied the example out of Help
arraychange("red,green,blue","orange",2,",")
and pasted it into a new procedure - just that line
I still got and unknown statement error. ???
It’s a function, not a statement. Therefore on its own in a procedure it gives rise to an unknown statement error, like a sentence without a verb. If you use the function as an argument to a statement it works, e.g.
message arraychange(“red,green,blue”,“orange”,2,“,”)
pcnewbie - Thank you.
You know, about 5:30 AM, I was lying there in bed, thinking, “I bet that’s a function and needs a left hand side.” Then my mind went off on how the documentation - for all functions - should give the left hand side as part of the syntex. like "result = arraychange(“red, green, blue”, "orange, 2, “,”)
Because that left hand side is necessary. Almost. because as you showed, the function doesn’t need a LHS if it’s used as an argurment.
My mistake was thinking arraychange( changed the array “in place”.
But. to be fair, the docs do say, " The arraychange( function … So all I have to do is learn to read.
I’m looping through array1 to find multiple occurring elements, getting their index, and using that the change an element in array2 at the same index.
so I just need to put myarray2 = arraychange(myarray2 …
and I’m good.
Onward!
And, more to the point, arraychange(
includes an opening parenthesis, which both is required for a function and shows that it is one.
Or as a formula in a form object.
That would require a “place” such as a field or variable to hold that array. In your example, there was no such place. Where were you expecting the result to appear?
I think that would be more misleading than helpful. A function can be used virtually anywhere a constant or literal could be used, including as an argument for another function. Thus examples such as
command function()
or
[let] variable=function()
might suggest its use is more limited than it actually is.
Dave, because the first parameter of ArrayChange is the array variable. Then the element you want to put in, and the index of where it goes, I figured it has everything it needs so after the “statement” the array variable itself would be changed (No left hand side required).
After all, I want to change the array, the array I specify as the first parameter - … wave the magic arraychange wand and presto-change the first parameter, the array variable, now was the designated element changed.
But I was wrong. Too much of a hurry as the the programming horse nears the barn of project completion.
While I was reviewing the code in my head, I thought, “The ArraySize is a function. By golly, I bet that ArrayChange is a function too.” Yes the “(” is also a Big clue But at that time, it was wee hours in the morning. I thought about getting out of bed and deleting my post to save the embarrassment. But … I didn’t.
Or it’s a case of, … As Paul Newman said in Cool Hand Luke, “What we have Herrrre is …” someone who has too many years and too many programming languages. When I was first introduced to functions in '66, they always appeared on the right hand side of an equal sign. Without that explicit equal sign, I messed up. Won’t happen again … at least any time soon.
BraveNewWorld = arraychange(BraveOldWorld,ideas-and-concepts,pickyourchoice,“thought-by-thought”)
What you are talking about is called a “side effect”. A side effect is when an operation performs some extra task on the side, outside of it’s normal operation. A function takes zero or more values (parameters) and returns a modified value. ALL functions return a value, which then can be used in an assignment, or as a parameter to another function or operation, or can be displayed in a form object. But every single function returns one (and only one) value.
There are two functions that do perform side effects - assign( and assignglobal(. Like all other functions, these functions return a value – but they also have an extra effect of modifying a field or variable “on the side”.
There are also two other functions that potentially could perform side effects - call( and execute(. Since these function allow you to execute arbitrary code, that code could perform operations unrelated to calculating the value returned by the function.
Side effects can be very handy sometimes, but they are also tricky and unstructured. They are kind of like using goto for flow control. You should generally avoid using side effects unless absolutely necessary.
Good for you. Yes, I can see how this could be slightly embarrassing for you, but you’re not the first person to get a bit crossed up on the difference between functions and statements. So you have provided all of us with an opportunity for a teaching moment.
One line synopsis:
There are some cases where Panorama has a pair of operations that work similarly as a function and a statement. For example arrayfilter( vs arrayfilter. It could be possible (in fact it would be trivial) to make an arraychange statement that works the way you were imagining, but that never happened.