• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. pass variable value to procedure name

Stats

  • Locked Locked
  • Replies 11
  • Subscribers 143
  • Views 20960
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

pass variable value to procedure name

TAMBUR
TAMBUR over 7 years ago

Hi,

Is there any way to pass  variable value to procedure name.

i.e

for(i 1 10

 procedure(test{i}()     ;--> test{i} is changing for different values of i

 )

)

How to pass 'i' variable value to the procedure name? So that, there are 10 procedures are defined.

Or, is there some other options to do that.

Thanks and regards,

Basavaraj Tambur

  • Cancel
Parents
  • skillUser
    skillUser over 7 years ago

    Hi Basavaraj,

    Unless I misunderstood it looks like you want to call a different procedure for each iteration of the loop. You can do this as in the following example:

    
        funcall(concat('test i))
    

    or
        funcall(stringToSymbol(sprintf(nil "test%d" i)))

    You might also use the "apply" function, especially if you need to pass arguments to the function.

    Hopefully this is what you are looking for?

    Best regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to skillUser

    That might be it Lawrence - it wasn't clear whether Basavaraj was trying to create the function names based on the loop variable or call them.

    Either way, it may not be the best way to solve the problem. 

    Basavaraj - can you please explain what you're actually hoping to achieve (the main goal) as there may be a different approach which will be clearer and cleaner, given that function objects can be passed as data in SKILL.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to skillUser

    That might be it Lawrence - it wasn't clear whether Basavaraj was trying to create the function names based on the loop variable or call them.

    Either way, it may not be the best way to solve the problem. 

    Basavaraj - can you please explain what you're actually hoping to achieve (the main goal) as there may be a different approach which will be clearer and cleaner, given that function objects can be passed as data in SKILL.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
  • TAMBUR
    TAMBUR over 7 years ago in reply to Andrew Beckett

    Hi Lawrence/Andrew,

    Thanks a lot for the response.

    I want to define procedure names(not the function names) as below,

    procedure(test0() printf("0 printed\n"))
    procedure(test1() printf("1 printed\n"))
    procedure(test2() printf("2 printed\n"))
    procedure(test3() printf("3 printed\n"))

    I need help on to define above procedures using 'for loop' variable. like_

    for(i 0 3

    procedure(test{i}() printf("%d printed\n" i))  ==> how to pass 'i' variable value to the procedure name as test{i}

    )

    Thanks and regards,

    Basavaraj Tambur

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to TAMBUR

    Hi Basavaraj,

    You still didn't explain why you need to do this - i.e. what is the end goal. There's almost certainly a better way to achieve what you want - I'm assuming your example is an artificial one which is different from what you are really trying to achieve.

    There are several ways you could do the above, but here's how I'd do it. I'm using SKILL++ lexical scoping to create a local function which creates a new function which refers to a value (n) in its lexical environment. Then this is stored under each of the function names you want. Put this code in a file with a ".ils" suffix (it won't work with a .il suffix):

    ; make sure this file has a .ils suffix
    let(()
        procedure(makeTestFunc(n)
            procedure(test()
                printf("%d printed\n" n)
            )
            test
        )
        for(i 0 3
            putd(concat('test i) makeTestFunc(i))
        )
    )

    Note that whilst normally a let with an empty list of local variables is unnecessary, here it's used because the procedure() defined within a let is automatically added to the local variables when in SKILL++ mode. So that means that makeTestFunc is not globally accessible.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • TAMBUR
    TAMBUR over 7 years ago in reply to Andrew Beckett

    Hi Andrew,

     Thanks a lot!

     To make my question simple, I proposed the above simple lines of script (sorry that it made a confusion),

    Here is my goal,

    I have metalList = list("MET1" "MET2" "MET3" MET4")

    Ctrl<Key>1 ==> convert selected shape to MET1 layer

    Ctrl<Key>2 ==> convert selected shape to MET2 layer

    Ctrl<Key>3 ==> convert selected shape to MET3 layer

    Ctrl<Key>4 ==> convert selected shape to MET4 layer

    So for each bindkey I need to have corresponding/individual procedure.

    From your above reply of last line -- putd(concat('test i) makeTestFunc(i)) , I came to know we can pass the loop variable to procedure i.e inside if () brackets.

    And I done with what I wanted, Here is my code.

    for(i 0 length(metalList)-1
    if(nth(i metalList) then
    procedure(metConvert(i)
    shps = setof(obj geGetSelectedSet() obj~>isShape)
    leReplace(geGetEditCellView() shps list(list("layer" nil list(nth(i metalList) "drawing")) ) )
    )
    n = i + 1 sprintf(nn "%d" n)
    hiSetBindKey("Layout" strcat("Ctrl<Key>" nn) sprintf(nil "metConvert(%d)" i))
    )

    Thanks again!!

    Regards,

    Basavaraj Tambur

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to TAMBUR

    Hi Basavaraj,

    That's why I wanted to know what you were trying to do. It would be unusual to need to define function names automatically as you were asking, when actually all you really wanted was to pass an argument to a function. So by trying to simplify it, you'd actually made it more complicated than it needed to be.

    You could just do:

    procedure(metConvert(metalLayer)
      let((shps)
        shps=setof(obj geGetSelectedSet() obj~>isShape)
        leReplace(geGetEditCellView() shps list(list("layer" nil list(metalLayer "drawing"))))
      )
    )

    count=1
    foreach(metLayer metalList
      hiSetBindKey("Layout" sprintf(nil "Ctrl<Key>%d" count++) sprintf(nil "metConvert(%L)" metLayer))
    )

    That's a bit cleaner - then you're directly passing the metal layer name to the conversion function rather than having to use an index into a list. Note I didn't test the code above - but something along those lines would work. As you can see in both your code and my code, there's no need for a different function for each metal layer.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • TAMBUR
    TAMBUR over 7 years ago in reply to Andrew Beckett

    Thanks a lot Andrew!

    One query,

      In your code, last line --> hiSetBindKey..metLayer is string, but you mentioned it as list in "metConvert(%L)".

    I tried for "metConvert(%s)" , but it says as *Error* eval: unbound variable

    please let me know why %L? why not the %s?

    Thanks and regards,

    Basavaraj Tambur

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to TAMBUR

    Hi Basavaraj,

    %L doesn't mean list (although it's often used for lists). It actually uses the default print representation, which for strings includes the quotes around the string. Since we need to call metConvert("MET1"), the %L ensures that the string values has quotes around it in the command that is created for the bindkey. If you just use %s, then it will create metConvert(MET1) which will then be looking for a variable MET1.

    Of course, we could have done: sprintf(nil "metConvert(\"%s\")" metLayer)

    However, this is a bit more clunky compared with just using %L in this case...

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • TAMBUR
    TAMBUR over 7 years ago in reply to Andrew Beckett

    Thanks a lot Andrew!

    In above case we passed "MET1" string to the procedure as metConvert("MET1"),

    what if we need to pass 'list' instead of 'string' ? what is the change we need to do in below command,

    sprintf(nil "metConvert(%L)" metArray) of hiSetBindKey command.

    Thanks and regards,

    Basavaraj Tambur

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to TAMBUR

    Well, assuming that metArray is a list (note, do not confuse lists with arrays; they are not the same thing as lists are sequential, ordered structures, whereas arrays allow random-access), then probably you'd do:

    sprintf(nil "metConvert('%L)" metList)

    if a literal list is OK, or:

    sprintf(nil "metConvert(list%L)" metList)

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • TAMBUR
    TAMBUR over 7 years ago in reply to Andrew Beckett

    Hi Andrew,

     Thanks a lot again, sprintf(nil "metConvert('%L)" metList) is worked for me.

    Regards,

    Basavaraj Tambur

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information