• 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. Apply 'and/'or to a list of lists

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 142
  • Views 1459
  • 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

Apply 'and/'or to a list of lists

FormerMember
FormerMember over 3 years ago

Hello,

I have a function, which generates a list of results. The results are lists, which can also be nil in case of an error.

I want to check if, all results are valid with 'and' or if some are invalid with 'or'. However, when I use the 'apply' function, I get an error because the lists are tried to be evaluated. Here is an example with 'and' but the same happens with 'or'

and( '(1) '(2) '(3)) -> '(3)
and( '(1) '(2) nil) -> nil

apply('and '((1) (2) (3))) -> *Error* eval: not a function - 1

I can achieve the same result with a 'forall' loop but it requires more code and is probably slower? Also, it requires an ugly inversion, to emulate the 'or' behavior.

Is there a way to prevent the evaluation of the arguments in an 'apply' call with 'and' or 'or'? Also, is there a way to know, which functions cause this? So far, I only observed this with and/or.

Best regards
Paul

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    Paul,

    That's because and is a syntax form - usually it selectively evaluates its arguments - this allows "expression short-circuiting" which means that the later arguments are only evaluated if the earlier arguments are true. So that allows things like:

    boundp('someVar) && someVar

    to work - if the variable is not bound, it will never get to the second expression.

    As an alternative, you could use:

    forall(x yourList x)

    which will return t if all values in yourList were non-nil.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • AurelBuche
    AurelBuche over 3 years ago in reply to Andrew Beckett

    Andrew gave you the equivalent for (apply 'and ...) with forall

    The equivalent for (apply 'or ...) is exists

    (exists x yourList x)

    Cheers

    Aurélien

    • Cancel
    • Vote Up +1 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