newbie question on using optional in procedures

V

vlsidesign

Guest
I am using using procedure and want to give it 2 optional parameters
but may specify one and/or the other. Here is the procedure name and
options:
procedure( findLayer(@optional (layer "M7") (hier 32) )
When I call the procedure from the CIW, I can place the call like this:
findLayer("M7" 32)
But what if I wanted to just specify the hier and go with the default
for layer. It seems like I cannot really do that? Should I try to use
the @key? Any tips would be appreciated, thanks.
 
As suspected, you need to use the @key syntax.

On Jan 3, 12:49 pm, "vlsidesign" <ford...@gmail.com> wrote:
I am using using procedure and want to give it 2 optional parameters
but may specify one and/or the other. Here is the procedure name and
options:
procedure( findLayer(@optional (layer "M7") (hier 32) )
When I call the procedure from the CIW, I can place the call like this:
findLayer("M7" 32)
But what if I wanted to just specify the hier and go with the default
for layer. It seems like I cannot really do that? Should I try to use
the @key? Any tips would be appreciated, thanks.
 
Poojan Wagh wrote:
vlsidesign wrote:
I am using using procedure and want to give it 2 optional parameters
but may specify one and/or the other. Here is the procedure name and
options:
procedure( findLayer(@optional (layer "M7") (hier 32) )
When I call the procedure from the CIW, I can place the call like this:
findLayer("M7" 32)
But what if I wanted to just specify the hier and go with the default
for layer. It seems like I cannot really do that? Should I try to use
the @key? Any tips would be appreciated, thanks.

As suspected, you need to use the @key syntax.
Thanks :)
 
Optional parameters will be assigned through there order in the
procedure call.

e.g.

procdure( myProcedure( @optional ( paramA someValue ) ( paramB someValue ) )

Call:
1. myProcedure( ) ;; takes defaults for paramA and paramB
2. myProcedure( newValueA ) ;; overwrite default for paramA and take
default for paramB
3. myProcedure( newValueA newValueB ) ;; overwrites defaults for
paramA and paramB
4. myProcedure( newValueB ) ;; does not work


Keyword parameters don't need a specific order and are always optional as well.

e.g.

procdure( myProcedure( @key ( paramA someValue ) ( paramB someValue ) )

Call:
1. myProcedure( ) ;; takes defaults for paramA and paramB
2. myProcedure( ?paramA newValueA ) ;; overwrite default for paramA and
take default for paramB
3. myProcedure( ?paramA newValueA ?paramB newValueB )
;; overwrites defaults for paramA and paramB

4. myProcedure( ?paramB newValueB ) ;; takes default for paramA and
overwrite default for paramB

This should make things clear.


Bernd
 
Bernd Fischer wrote:
Optional parameters will be assigned through there order in the
procedure call.

snip

This should make things clear.


Bernd
It does. Thanks Bernd :)
 
vlsidesign wrote:
I am using using procedure and want to give it 2 optional parameters
but may specify one and/or the other. Here is the procedure name and
options:
procedure( findLayer(@optional (layer "M7") (hier 32) )
When I call the procedure from the CIW, I can place the call like this:
findLayer("M7" 32)
But what if I wanted to just specify the hier and go with the default
for layer. It seems like I cannot really do that? Should I try to use
the @key? Any tips would be appreciated, thanks.
You can use @key as suggested in the thread. There is another way also:

procedure( findLayer( @optional (layer "") (hier nil))
when(member(layer list("" nil))
layer = "M7'
)
unless(hier
hier = 32
)
;Rest of the program
printf("%L %L\n" layer hier)
)

Now both the arguments are optional, when you want to pass value for the
second argument pass nil as the value for the first argument.

--
Suresh
 

Welcome to EDABoard.com

Sponsor

Back
Top