• 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. String expression evaluation

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 143
  • Views 6901
  • 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

String expression evaluation

lordosGouv
lordosGouv over 2 years ago

Hello,

I use the following functions to calculate the result of an expression that is saved in string format:

(lambda( (a b) evalstring( "a+2*b" ) ) 1 2)

is there any way to do the same thing when the parameters and their values are saved in lists whose length is not constant in runtime and variable names are saved as strings e.g.:

parameters = list("a" "b" "c" ...)

param_values = list(1 2 3 ...)

expression = "a+2*b+3*c+...."

Thank you in advance

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

    Generally it's not the most efficient to do this kind of run-time evaluation, but if you can't avoid it (i.e. the expressions have to be in strings), you could could achieve it this way:

    procedure(CCFevalExprWithParameters(expr paramNames paramValues)
      eval(
        `let(,foreach(mapcar (name value) paramNames paramValues 
    	list(concat(name) value))
          evalstring(expr)
        )
      )
    )

    Then you'd use:

    CCFevalExprWithParameters(expression parameters param_values)

    The idea is that it builds a let statement with name-value pairs according to the lists you provided, and evaluates the string within that context.

    Regards,

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to Andrew Beckett

    In fact, here's a small improvement which means it only does a single evaluation - instead of an eval with an evalstring inside, it uses the SKILL parser (using linereadstring) to parse the expression, but only calls the evaluator once.

    procedure(CCFevalExprWithParameters(expr paramNames paramValues)
      eval(
        `let(,foreach(mapcar (name value) paramNames paramValues 
    	list(concat(name) value))
          ,@linereadstring(evalstring(expr))
        )
      )
    )

    Andrew

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

    In fact, here's a small improvement which means it only does a single evaluation - instead of an eval with an evalstring inside, it uses the SKILL parser (using linereadstring) to parse the expression, but only calls the evaluator once.

    procedure(CCFevalExprWithParameters(expr paramNames paramValues)
      eval(
        `let(,foreach(mapcar (name value) paramNames paramValues 
    	list(concat(name) value))
          ,@linereadstring(evalstring(expr))
        )
      )
    )

    Andrew

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

    Thank you very much for your helpful and detailed response!!

    • 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