what is the assignment expression return value?

Discussion in 'Cadence' started by vlsidesign, May 14, 2008.

  1. vlsidesign

    vlsidesign Guest

    I believe in C, an assignment expression returns the value of the left
    side of the assignment. For example, a = 2, would return 2.

    If this is true, is Skill similar? For instance, if I have the
    following, a = nil, would it return nil ?
     
    vlsidesign, May 14, 2008
    #1
  2. vlsidesign

    vlsidesign Guest

    It seems like it would return nil but for different reason than C. I
    believe it returns the value of the expression on the right side that
    happens to be what is assigned to a.
     
    vlsidesign, May 14, 2008
    #2
  3. vlsidesign

    Riad KACED Guest

    Dear vlsidesign,

    Why don't you give it a try into your CIW ? you will get the truth by
    yourself ;-)
    I guess you don't have cadence.

    Give a look at the function 'setq' in the following document :
    Cadence SKILL Language Reference ($CDSHOME/doc/sklangref.pdf).
    As you can see in this document setq is the same as the assignment (=)
    operator. It sets a variable to a new value and returns this new value
    (or the evaluated result if the assigned new value is an expression).
    I think that (=) is internally translated to setq (to be confirmed or
    not by the skill experts).

    ciw> x = 5
    => 5
    ciw> (setq x 5)
    => 5
    ciw> a = nil
    => nil

    Do mind that nil is a special atom in skill !

    Hope it helps !

    Riad.
     
    Riad KACED, May 14, 2008
    #3
  4. vlsidesign

    Riad KACED Guest

    Yes it is, it returns the value of the expression on the right side.
     
    Riad KACED, May 14, 2008
    #4
  5. vlsidesign wrote, on 05/14/08 22:55:
    The assignment operator is converted into functional equivalent, by working
    from right to left. Most operators work left to right:

    (setq a
    (setq b
    (setq c
    (setq d 5)
    )
    )
    )

    The above shows you the functional equivalent (i.e. how it is actually implemented)
    for a=b=c=d=5. So you can see precedence and left-to-right/right-to-left handling
    by looking at the output of that.

    So it behaves just like C in this respect - the compiler expands = operators right to left.

    Regards,

    Andrew.
     
    Andrew Beckett, May 15, 2008
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.