Multiple Return Syntax Error
Dear all,
I would like a general idea about the syntax for multiple returns and whether it's possible to return multiple waves from a function, but I'm finding myself stuck returning multiple variables and strings. I'm using Igor Pro 9.01.
Firstly, I understand from reading the documentation that if one wants a function to return one wave, one must use the /WAVE flag in the function declaration:
variable a
Make /O /N=3 exampleWave = {a, 2, 3}
return exampleWave
end
which can then be called from a subroutine:
variable b
wave waveReturn = exampleReturn(b)
print waveReturn
end
Which works well.
Likewise, multiple variable or string returns can in principle be performed by using inline syntax (defining all parameters in a single function declaration line). However I cannot get the example to run from:
DisplayHelpTopic "Multiple Return Syntax"
If I call the following compiled function from the command line (using Subroutine(10) for example):
return [1+a, "hello"]
End
I just get a generic 'syntax error' message.
Likewise, I get the same outcome if I try an example I came up with:
c = a + b
d = a - b
return [c , d]
end
Again, calling exampleMultipleReturn(3,5) for example returns a 'syntax error' message; both the examples above compile in the procedure window however.
I'm trying to work my way up to returning multiple waves from a function, but I'm assuming there's something fundamentally flawed about my understanding.
Provided I can correct the error of my ways, what would be the correct syntax for returning multiple waves. Must I still use the /WAVE flag? For example, if I follow the above examples, is this redundancy necessary?
Function /WAVE [ wave v, wave s ] Subroutine(variable a )
All the best,
Ryan
Have you tries to call your MRS function from the commandline only?
The following works here with 9.01 r39200.
return [1+a, "hello"]
End
Function CallSubroutine()
variable v_result
string s_result
[v_result, s_result] = SubRoutine(1)
print V_result, S_result
End
October 23, 2022 at 02:43 am - Permalink
In reply to Have you tries to call your… by thomas_braun
Dear Thomas,
Yes, that appears to work but I'm being slow: is this outcome useful?
All the best,
Ryan
October 23, 2022 at 07:53 pm - Permalink
What do you mean with 'being useful'? This depends on your use case, no?
By the way, here is an example with multiple-wave return, you asked for:
Make/O/N=3 exampleWave1 = {a, 2, 3}
Make/O/N=3 exampleWave2 = {2*a, 6, 7}
return [exampleWave1, exampleWave2]
end
Function test(Variable a)
Wave v,s
[v, s] = exampleReturn(a)
print v, s
return 0
End
October 23, 2022 at 11:25 pm - Permalink
In reply to What do you mean with 'being… by chozo
Thanks, I was commenting on the idea that if I can't call a function from the command line, it doesn't appear incredibly useful.
Many thanks for the example!
All the best,
Ryan
October 24, 2022 at 01:20 am - Permalink
In reply to What do you mean with 'being… by chozo
For the example given here, why does calling e.g. exampleReturn(3) return a syntax error but the test function runs just fine?
All the best,
Ryan
October 24, 2022 at 03:54 am - Permalink
> I was commenting on the idea that if I can't call a function from the command line, it doesn't appear incredibly useful.
That depends on your usage of Igor I guess. There are a lot of specialities (free waves, multiple return syntax, pass-by-reference parameters, functions returning waves/dfrs, ...) which only work in function code where function A calls function B. But if you require that it is always callable from the command line, well you can't use these specialities.
October 24, 2022 at 07:56 am - Permalink