1. Oops! I threw a return value in the trash by mistake
- Posted by ryanj May 31, 2016
- 1314 views
See a problem here?
atom idx = 0 find(tabname, cntxNames) if idx > 0 then
Oops! No wonder idx is always equal to 0. *facepalm*
2. Re: Oops! I threw a return value in the trash by mistake
- Posted by ghaberek (admin) May 31, 2016
- 1285 views
See a problem here?
atom idx = 0 find(tabname, cntxNames) if idx > 0 then
Oops! No wonder idx is always equal to 0. *facepalm*
I'm surprised there doesn't seem to be a warning for discarded function return values. See Complex with / without options.
I think this would have been a logical addition to the warning system when the ability to discard return values was introduced. Unless I missed something.
-Greg
3. Re: Oops! I threw a return value in the trash by mistake
- Posted by ryanj May 31, 2016
- 1280 views
I'm surprised there doesn't seem to be a warning for discarded function return values. See Complex with / without options.
I think this would have been a logical addition to the warning system when the ability to discard return values was introduced. Unless I missed something.
-Greg
I agree.
4. Re: Oops! I threw a return value in the trash by mistake
- Posted by petelomax Jun 01, 2016
- 1235 views
In Phix you have to code an explicit discard:
{} = find(tabname, cntxNames)
5. Re: Oops! I threw a return value in the trash by mistake
- Posted by jimcbrown (admin) Jun 01, 2016
- 1219 views
In Phix you have to code an explicit discard:
{} = find(tabname, cntxNames)
I proposed an explicit discard as well, but Jeremy turned it down and IIRC the votes were in his favor.
6. Re: Oops! I threw a return value in the trash by mistake
- Posted by petelomax Jun 01, 2016
- 1188 views
The other one me and my clumsy fingers are often grateful for is
if length(x=0) then
which in Phix generates the compile-time error "incompatible type for routine signature" - unlike OE you would need sq_eq(x,0) to deliver anything other than a single T/F, and length(atom) is fatal, not 1.
Obviously I meant
if length(x)=0 then
and I probably make that error roughly once every other month, especially when writing expressions containing several nested brackets.
Then again maybe I get a bit careless because I know the compiler will help me.
7. Re: Oops! I threw a return value in the trash by mistake
- Posted by Spock Jun 01, 2016
- 1190 views
The other one me and my clumsy fingers are often grateful for is
if length(x=0) then
which in Phix generates the compile-time error "incompatible type for routine signature" - unlike OE you would need sq_eq(x,0) to deliver anything other than a single T/F, and length(atom) is fatal, not 1.
When length() was updated to include atoms the change caught me completely by surprise. But it's more of a nuisance than a big problem so I never did anything about it. I would have coded this line as:
if not ~x then
But this has its own problem since the tilde, while quick to type, is also easy to omit. So then would I ever return to using length()? - N e v e r
As for discarded return values, I think I had this in Orac before OE. What I also added at the time was a method to analyse the program (wholly or by module) which could find all functions invoked as if they were procedures.
Spock