• 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. forall() always returns t when the valueList is empty

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 149
  • Views 13825
  • 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

forall() always returns t when the valueList is empty

Quesar
Quesar over 5 years ago

Hi,

As the subject describes, the forall() function will always return t when the valueList is nil. For example:

forall(x nil (stringp x))  ---> t

forall(x nil (numberp x))  ---> t

This behaviour is mystifying to me, since forall() is only supposed to return t if every member of the valueList fulfills the predicate expression. If the valueList is empty (nil), then the example expressions above should be false, thus the return value should be nil.

For all other cases where the valueList is non-nil, forall() seems to work as expected. This isn't a particularly big problem, but I don't understand the rationale behind this behaviour when the valueList is empty.

Does anyone know the reason behind this?

Thanks.

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

    It's perfectly logical to me. Everything in the list did fulfil the predicate - there was nothing in the list though. The documentation puts it another way, that it "Verifies that an expression remains true for every element in a list" - well, it was never false, so the result should be true still. In fact to me I can't really see any sense in it returning nil because the predicate expressions in your examples are never evaluated - so nothing ever returns nil within the loop.

    Honestly though, I guess you could argue it either way for this boundary case, but this is the way it is. You can easily get what you want by doing:

    theList && forall(x theList numberp(x))

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Quesar
    Quesar over 5 years ago in reply to Andrew Beckett

    Hi Andrew, thanks for replying so quickly!

    Well, I guess that's one way of looking at it, both true and false can be correct depending on how the function should be interpreted for this case. Since the list is empty, my first instinct is that the result should be false (because nothing is evaluated in the first place), but I guess that wasn't how the developers looked at it.

    Thanks for explaining the other side of the coin  Slight smile

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

    Hi Andrew, thanks for replying so quickly!

    Well, I guess that's one way of looking at it, both true and false can be correct depending on how the function should be interpreted for this case. Since the list is empty, my first instinct is that the result should be false (because nothing is evaluated in the first place), but I guess that wasn't how the developers looked at it.

    Thanks for explaining the other side of the coin  Slight smile

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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