• 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. How to generically wrap a function to be called in a loop...

Stats

  • Locked Locked
  • Replies 12
  • Subscribers 143
  • Views 8056
  • 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

How to generically wrap a function to be called in a loop with for a parametric sweep

ItsMichael
ItsMichael over 1 year ago

Hello,

I would like to create a function which can wrap any function and execute it multiple times with a "sweep" of one of the arguments.

I guess I can do this with funcall() , but how can I parse the arguments in a generic way ?
Will that just involve string manipulation and some sort of evalstring() usage ?

To clarify what I want, let's say my wrapper function is called run_for_list:

run_for_list( plus 3 (1 2 3 4))

So basically I want loop through the plus() function for the list argument.
This is obviously just an example of the usage, my aim is to run a sweep of an argument for a calculator function and return a family of plots.

Any suggestion on how to implement such a thing ?

Thanks in advance,
Michael

  • Cancel
  • ItsMichael
    ItsMichael over 1 year ago in reply to Andrew Beckett

    Thanks Andrew,
    I just noticed your reply.
    Even though I have a working solution I think I will rewrite it to use the macro, it's much more elegant.

    Just wondering about the apostrophes, could you briefly explain the use of the apostrophe before the let statement and inside the first argument of famCreateFamily ? is this related to the syntax of the macro definition ?
    also, is the first argument of the foreach loop empty ?
    I also find the mixing of commas and spaces to separate arguments confusing, do they serve the same purpose ?

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 1 year ago in reply to ItsMichael
    ItsMichael said:
    Just wondering about the apostrophes, could you briefly explain the use of the apostrophe before the let statement and inside the first argument of famCreateFamily ? is this related to the syntax of the macro definition ?
    also, is the first argument of the foreach loop empty ?
    I also find the mixing of commas and spaces to separate arguments confusing, do they serve the same purpose ?

    The commas are not separators. There is an (undocumented) syntax in SKILL where commas can be used as an alternative separator to white space, but that's not what is going on here. What I'm using is the backquote operator (before the let) which is a macro that allows selective evaluation within a quoted list. If you use a normal quote (') rather than backquote (`) then everything inside the list is treated as unevaluated. If however you use backquote, then you can selectively evaluate things inside the list. The way it works is that anything preceded by a comma is evaluated, or if preceded by ,@ (not used in this case) then it's a list that is spliced in at that point.

    Put simply, this is a convenient shorthand for building complex lists with lots of symbol in - for example - I can build:

    `(a b (c d ,someVar) x y)

    rather more concisely than:

    liist('a 'b list('c 'd someVar) 'x 'y)

    In the case of macros it's particularly convenient because the resulting code structure looks like the code I'm trying to generate. Another way of looking at this is that with the surrounding backquote, everywhere that there's a comma-something expression, then the evaluated value of something is stuffed into the resulting code structure. Macros don't evaluate their arguments before they are called, and instead return a list which is the code to use instead - so can programmatically transform a set of arguments into some code which is used instead.

    The specific example I gave of using the macro ends up transforming into this code:

    let(((_family famCreateFamily('start 'double))
        )
        foreach(start '(2e-08 4e-08 5e-08)
            famAddValue(_family start
                clip(VT("/OUTP") start 2e-07))
        )
        _family
    )

    Hope that helps!

    Andrew

    • 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