• 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. confused about the apply() operation

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 142
  • Views 15277
  • 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

confused about the apply() operation

archive
archive over 17 years ago

I am confused about the operation of the apply(), when applied on and().

As far as I know, the apply() works in a way, that the elements of the second list argument are bouned to the formal argumets of a function provided as a first argument and then the function is called.
If I try
    apply('and list(list(1 2)) )
I obtain the following error :
*Error* eval: not a function - 1
However when trying and(list(1 2)) (what should be IMHO the same), the result is :
(1 2)

OK, so it looks like the apply() function calls eval on each element of the second argument. However, when trying
apply('print list(list(1 2) ) )
I obtain
(1 2)
nil

, what means that the eval is not called by apply(). Can someone explain this?

Thanks,
Miro








Originally posted in cdnusers.org by miro
  • Cancel
Parents
  • archive
    archive over 17 years ago

    Hi Miro,

    It's and() which is doing the eval on its arguments. and is a "syntax" form - this is because if you do something like:

    and(boundp('fred) fred)

    it will work successfully if fred isn't defined - sometimes known in some languages as "expression short circuting" - it's only going to evaluate the second (or third, or fourth etc) argument if the preceding arguments are non-nil.

    So when you do:

    and(list(1 2))

    The list() doesn't get evaluated until the and decides it should be.

    If you do:

    apply('and list(list(1 2)))

    then the list is evaluated before the apply gets called - and so the and call is like:

    and((1 2))

    which is why you have the problem. You need to prevent the arguments from being evaluated.

    So something like:

    apply('and '(list(1 2)))

    will do it. Chances are you wanted something to be evaluated in the argument though, so it might need to be something like:

    a=1
    b=2
    apply('and `(list(,a ,b)))

    Hope that helps!

    Put simply, you have to be careful with using apply with syntax forms, nlambda functions, and macros, to make sure that the evaluation occurs at the right time.

    Regards,

    Andrew.


    Originally posted in cdnusers.org by adbeckett
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • archive
    archive over 17 years ago

    Hi Miro,

    It's and() which is doing the eval on its arguments. and is a "syntax" form - this is because if you do something like:

    and(boundp('fred) fred)

    it will work successfully if fred isn't defined - sometimes known in some languages as "expression short circuting" - it's only going to evaluate the second (or third, or fourth etc) argument if the preceding arguments are non-nil.

    So when you do:

    and(list(1 2))

    The list() doesn't get evaluated until the and decides it should be.

    If you do:

    apply('and list(list(1 2)))

    then the list is evaluated before the apply gets called - and so the and call is like:

    and((1 2))

    which is why you have the problem. You need to prevent the arguments from being evaluated.

    So something like:

    apply('and '(list(1 2)))

    will do it. Chances are you wanted something to be evaluated in the argument though, so it might need to be something like:

    a=1
    b=2
    apply('and `(list(,a ,b)))

    Hope that helps!

    Put simply, you have to be careful with using apply with syntax forms, nlambda functions, and macros, to make sure that the evaluation occurs at the right time.

    Regards,

    Andrew.


    Originally posted in cdnusers.org by adbeckett
    • 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