comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Passing optional parameters through a wrapper routine
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Passing optional parameters through a wrapper routine [message #18830 is a reply to message #18829] Tue, 08 February 2000 00:00 Go to previous messageGo to previous message
bowman is currently offline  bowman
Messages: 121
Registered: September 1991
Senior Member
In article <MPG.130a910d141f1260989a21@news.frii.com>, davidf@dfanning.com
(David Fanning) wrote:

> Having said that, it absolutely behooves you to check
> each and every variable you plan to use in your program
> to make sure you have a defined variable at the time
> you use it. This is normally done with the N_Elements
> function, since this function returns a 0 if its argument
> is undefined.

I admit to a certain conceptual confusion between undefined and optional
parameters. If I omit an optional parameter, I have not defined it. So
what's the difference between passing an undefined optional parameter and
omitting it? Obviously, in practice the difference is in how you test for
whether the parameter is "there" or not.

> You would probably NOT use the odd syntax above for
> the simple reason that it would fail if the number
> of parameters was 0 or 1. What you probably *would* do
> if p1 and p2 are required parameters and p3 is optional,
> is something like this:
>
> IF N_Params() LT 2 THEN Message, 'Whoops, two parameters required'
> IF N_Elements(p3) EQ 0 THEN p3 = p3DefaultValue

My syntax is not odd! :-) (Although it should be LT rather than EQ.)
If you use optional parameters, you need to test for each possible set of
optional parameters and the existence of mandatory parameters.

IF N_Params() LT 1 THEN Message, 'Whoops, p1 required'
IF (N_PARAMS() LT 2) OR (N_ELEMENTS(p2) EQ 0)) THEN do the default thing for p2
IF (N_PARAMS() LT 3) OR (N_ELEMENTS(p3) EQ 0)) THEN do the default thing for p3

This does not add any fundamental complexity to handling optional parameters.

Your earlier solution of setting all the optional parameters in the
calling requires me to figure out all of the default values for those
parameters. This obviates the whole point of optional parameters
(convenient default values). If optional parameters are there as a
convenience, make them convenient.

On to more productive topics ... :-)

Ken
k-bowman@tamu.edu
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Object recognition
Next Topic: call C routine on a Linux computer

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 12:10:16 PDT 2025

Total time taken to generate the page: 0.95823 seconds