blueznl wrote:default values are (in this form) not a good idea, as you cannot see if there was a parameter or not
Code: Select all
Procedure alpha( a.l , b.l , c.l = 5 , d.l , e.l )
;
; a.l, b.l and d.l must exist, c.l and e.l are optional
;
;
If IsParameter(c.l)
;
; ah, it was passed
;
EndIf
EndProcedure
alpha( 1,2,,3)
Hmm! that would be very bad coding! optionals are always at the end.
Even still, there is no need to check if one was set or not,
because the default would be used anyway.
Because that is the reason for optionals in the first place,
to provide a default but useable value in case none was specified
or if the default actualy is the wanted one.
As far as syntax/usage goes, do it the "common" way that most uses.
Procedure alpha( a.l=5 , b.l=5 , c.l = 5 , d.l=5 , e.l=5 )
alpha(1,2,3,4)
alpha(1,2,3)
alpha(1,2)
alpha(1)
alpha()
Here all where optional.
and there is no ,,, mess, and it should be DLL/lib compatible.
(DLL's and libs as far as I know only allow optional args at the end not in the middle).
Procedure alpha( a.l , b.l , c.l , d.l=5 , e.l=5 )
alpha(1,2,3,4)
alpha(1,2,3)
alpha(1,2)
Here only the last two are optional!
Procedure alpha( a.l , b.l , c.l , d.l , e.l )
alpha(1,2,3,4)
And for completness sake, here none are optional.
I would not recommend the way blueznl showed,
as that could cause issues with ProcedureDLL and so on
as I'm not sure DLL's and libs makes it possible to do that or supported at all.
At least I can't ever recall ever seeing a API function or DLL function
that does it, nor can I imagine how to do that properly.
The only language I know that permits this is PHP,
,,, may be practical in a scipting language,
but a proper programing language it would just be a headache.
(either for Fred or us)
So I really have to advice the more common way.
Heck, the common way (only allow optionals at the end,
or all, but never in he middle)
should allow making dll's, so's and .library (Amiga) and (what does mac call it?)
with optionals very easy.
And it would be silly if Procedure and ProcedureDLL differed,
they really have to handle optionals identicaly to maintain continuity!