So this might be tied in with nested omits but omitted isnt a compiler directive, hence the question
ProcedureName(<*cstring pName>)
Code
!do some stuff
Return ProcedureProcess(pName)
ProcedureProcess(<*cstring pName>)
Map
NewVariables Procedure
End
Code
NewVariables()
If Not Omitted(pName)
! No compiler error - code works fine
End
NewVariables Procedure
Code
If not omitted(pName)
! No compiler error and this code does nothing
End
If not omitted(pPairOfElliptoids)
!compiler error Unknown identifier
End
So if the compiler can spot pPairOfElliptoids dont exist, why cant it spot pName in the same local procedure?
A compiler error would at least be nice if nothing else.
So is this also a confirmed bug along with the nested compile/omit directives?
My login doesnt work on the sv ptss so I cant file anything last time I tried so I cant check if this is a known bug.
OMITTED only works with parameters in the procedure or method where it is used.
In your case pName is in scope for use as a variable because of the way Clarion handles procedure variables being in scope for local procedures/methods.
However, that does not apply to OMITTED.
In an ABC procedure, if you want to test if a parameter to the procedure is OMITTED you need to do that in a routine to the procedure itself, not in a method like ThisWindow.Init()
FYI, you can format your Clarion code by surrounding it will three Backticks (`) before and after the code block. Add the “clarion” key word after the leading Backticks and it is “clarion aware”.
```clarion
Code
```
It works the same with 3 Tildes ~~~ … which on my keyboard is the same key.
Only one workaround I can find is to create a new procedure (seen the appgen tree) and do some not all of the tests there.
Size will wont return the correct size if the parameter is omitted.
I cant duplicate the parameters from the procedure to the local procedure because the compiler throws label duplicated, second used: parametername errors unless I change the parameter names just for the local procedure, which is an option I guess.
So the compiler is aware of the parameter in the local procedure so to me its looking like a bug in omitted() !
Note specifically the bit “is an identifier that matches the name of any procedure parameter it is called from”.
#Edit 1. Maybe I am misunderstanding you Richard - are you saying the code where you have “! No compiler error and this code does nothing” is not performed even when pName was in fact passed to ProcedureProcess.
eg. if you have
NewVariables Procedure
Code
If omitted(pName)
stop('pName was omitted')
else
stop('pName = ' & pname)
end
#Edit 2
I now see the bug or “known issue” that Richard and Rick are referring to. I tested it myself and in NewVariables Procedure it thinks pName was omitted in the example code I gave above.
Perhaps a work-around for Richard is to just use len(pName) and see if it is zero.
Ok lets go with docs, yes I agree using it in a local proc is technically out of scope, but I dont get a compiler error stating this. Either way, I dont get a compiler error when I would expect to get one.
Secondly the docs are ambiguous. Theres no mention of scope in the docs.
Sure it probably works in a routine but you cant pass parameters to a routine.
Plus I can do local procedure overloading because I cant do appgen procedure overloading. This is one of the things I discovered when I wrote my work in progress class writing template so I can use the appgen to write a class although I had to come up with a work around.
But wouldnt it be nice if omitted could work with parent proc parameters and throw an error when its used out of context? The latter would be nice and the docs page made less ambigous.
Edit.
Another point on the scope is other language commands/functions dont complain about the scope, eg band(var,bitmaskequate) can use a parameter from its local procedure or the parent procedure.
It just seems short sighted to have omitted() work the way its currently working, unless there is an undocumented compiler flag to alter its behaviour?