newbie question on using optional in procedures

Discussion in 'Cadence' started by vlsidesign, Jan 3, 2007.

  1. vlsidesign

    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.
     
    vlsidesign, Jan 3, 2007
    #1
  2. vlsidesign

    Poojan Wagh Guest

    As suspected, you need to use the @key syntax.
     
    Poojan Wagh, Jan 3, 2007
    #2
  3. vlsidesign

    vlsidesign Guest

    Thanks :)
     
    vlsidesign, Jan 4, 2007
    #3
  4. 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, Jan 4, 2007
    #4
  5. vlsidesign

    vlsidesign Guest

    It does. Thanks Bernd :)
     
    vlsidesign, Jan 4, 2007
    #5
  6. 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 Jeevanandam, Jan 5, 2007
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.