• 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. Replace list elements based on input criteria

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 143
  • Views 8913
  • 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

Replace list elements based on input criteria

MorrisDH
MorrisDH over 2 years ago

Example input to the function is a string  "0.0 0.12u -0.12u 0.18u".

What I need is something that will replace any value below 0 with 0 and replace any value above a given maximum to the maximum. For example, if the given maximum in 0.16u then the above example input should return "0.0 0.12u 0.0 0.16u".

I made it work with the following but I'm wondering if there is a better way.

input = "0.0 0.12u -0.12u 0.18u"

threshold = "0.16u"

listInput = parseString(input)

newList = list()

foreach(element listInput
  if(evalstring(element) > evalstring(threshold) element = threshold)
  if(evalstring(element) < 0 element = "0.0")
  newList = append1(newList element)
)

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 2 years ago

    For a start, do not use evalstring for this. It's a bad idea - because if your string happened to contain SKILL function calls, it will execute them.

    I would use a foreach mapcar and generalise like this:

    procedure(CCFlimitStringList(strNumList lower upper "ttt")
      let((num (lowerNum aelNumber(lower)) (upperNum aelNumber(upper)))
        buildString(
          foreach(mapcar elem parseString(strNumList)
            num=aelNumber(elem)
            cond(
              (num<lowerNum lower)
              (num>upperNum upper)
              (t elem)
            )
          )
        )
      )
    )

    Then you can use:

    CCFlimitStringList("0.0 0.12u -0.12u 0.18u" "0.0" "0.16u")

    I'm using aelNumber; if this was going to be for use in a PCell, then cdfParseFloatString might be a better alternative. Or even num=car(linereadstring(elem))

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 2 years ago

    For a start, do not use evalstring for this. It's a bad idea - because if your string happened to contain SKILL function calls, it will execute them.

    I would use a foreach mapcar and generalise like this:

    procedure(CCFlimitStringList(strNumList lower upper "ttt")
      let((num (lowerNum aelNumber(lower)) (upperNum aelNumber(upper)))
        buildString(
          foreach(mapcar elem parseString(strNumList)
            num=aelNumber(elem)
            cond(
              (num<lowerNum lower)
              (num>upperNum upper)
              (t elem)
            )
          )
        )
      )
    )

    Then you can use:

    CCFlimitStringList("0.0 0.12u -0.12u 0.18u" "0.0" "0.16u")

    I'm using aelNumber; if this was going to be for use in a PCell, then cdfParseFloatString might be a better alternative. Or even num=car(linereadstring(elem))

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
  • MorrisDH
    MorrisDH over 2 years ago in reply to Andrew Beckett

    That's beautiful! This is for a pcell callback so the aelNumber is OK.

    I've not used "cond" before. It looks very handy.

    Thanks,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to MorrisDH

    I’m not sure what you mean by a “pcell callback” but assuming you really meant a CDF callback, I’d change it to use cdfParseFloatString - that would be safer. 

    Glad it was useful!

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • MorrisDH
    MorrisDH over 2 years ago in reply to Andrew Beckett

    Yes, cdf callback is what I meant. And will follow your advice and replace aelNumber with the cdf command.

    • 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