Home > Community > Forums > Custom IC SKILL > confused about the apply() operation

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 confused about the apply() operation 

Last post Tue, Mar 4 2008 1:35 PM by archive. 4 replies.
Started by archive 04 Mar 2008 01:35 PM. Topic has 4 replies.
Page 1 of 1 (5 items)
Sort Posts:
  • Tue, Mar 4 2008 1:35 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,740
    confused about the apply() operation Reply

    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
    • Post Points: 0
  • Tue, Mar 4 2008 3:09 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,740
    RE: confused about the apply() operation Reply

    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
    • Post Points: 0
  • Tue, Mar 4 2008 10:04 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,740
    RE: confused about the apply() operation Reply

    Hello Andrew,

    Thanks for the explanation. What made me confused was that nor Virtuoso Skill Functions Skill Quick Reference nor full skill reference mention that and is a syntax form, meanwhile e.g. in the case of foreach they do.
    Actually the full skill reference says about and() :

    Evaluates from left to right its arguments to see if the result is nil. As soon as an argument evaluates to nil, and returns nil without evaluating the rest of the arguments. Otherwise, and evaluates the next argument. If all arguments except for the last evaluate to non-nil, and returns the value of the last argument as the result of the function call. Prefix form of the && binary operator.

    what hints on the syntax form, but I thought that "evaluate" just means "look on" and not "call eval()".
    Once more, thanks.
    Miro


    Originally posted in cdnusers.org by miro
    • Post Points: 0
  • Wed, Mar 5 2008 7:13 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,740
    RE: confused about the apply() operation Reply

    Hi Miro,

    Well, it doesn't explicitly call it out as being a syntax form, but the fact that it says that it evaluates the arguments in turn suggests that.

    Note it doesn't strictly call eval() on each argument, because this is done at the byte code level, but you can visualize it as working that way.

    Most functions in SKILL (aka "lambda" functions) have their arguments evaluated for them before the function is called. Macros don't evaluate the arguments at all, but in fact run at compile time and transform the arguments into another form. syntax forms (and older "nlambda" functions) are called and passed the unevaluated arguments, and then choose within to selectively evaluate the arguments as needed. An obvious example is procedure() - clearly that would not make sense to evaluate the arguments before it is called!

    Regards,

    Andrew.

    Best Regards,

    Andrew.


    Originally posted in cdnusers.org by adbeckett
    • Post Points: 0
  • Wed, Mar 5 2008 8:09 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,740
    RE: confused about the apply() operation Reply

    Hi Andrew,

    Thanks for the comments, that clarifies much. I would be interested a bit about how does the SKILL work "in behind" - the byte code, more about GC etc. Could you maybe recommend me some resources ?

    Btw. I am thinking about taking one of the SKILL trainings offered by Cadence (either "Skill Language Programming" or "Advanced SKILL Language Programming"). I have ~1 year experience with SKILL, working on scripts for PDK regression testing. Do you know something about these trainings - number of people on trainings, what kind of tasks are solved in "project" part of the training, etc. Any comments or suggestions would be appreciated.

    Thanks,
    Miro


    Originally posted in cdnusers.org by miro
    • Post Points: 0
Page 1 of 1 (5 items)
Sort Posts:
Started by archive at 04 Mar 2008 01:35 PM. Topic has 4 replies.