• 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. SKILL Lists

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 143
  • Views 16370
  • 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

SKILL Lists

Leonardo Vinci
Leonardo Vinci over 5 years ago

Hi, 

List_Original=

(

((x1, y1) (x2 y2))

((x3 y3) (x4 y4))

((x5 y5) (x6 y6))

...

)

List_Original is a list of coordinates. 

I want to copy this list and make changes to the new copy(say, List_A) while preserving List_Original. The change what i want to do is +/- the y-coordinates by 0.5, I do it as follows:

List_A=nil

List_A=List_Original

foreach(val List_A

a=cadr(nth(0 val)) + 0.5

b=cadr(nth(1 val)) - 0.5

cadr(nth(0 val))=a

cadr(nth(1 val))=b

)

Now the problem coming is List_A is not getting updated and is remaining same as List_Original. Why is that? I am not getting any error or warning in code.

I even checked the variables "a" and "b" and they are getting updated as I wanted, but List_A is not getting updated and is the same as List_Original.

Please tell me what am i doing wrong?

Regards,

Leo

  • Cancel
Parents
  • AurelBuche
    AurelBuche over 5 years ago

    Hi Leonardo,

    You are doing two things wrong:

    1. if you do:

    List_Original='(
                              ((0 1)  (2 3))
                             )

    and

    List_A=List_Original

    then List_A and List_Original will point to the same object, if you modify one it means you modify the other one

    You will have to store a copy version in order to do whatever suits you:

    List_A = (copy List_Original)

    2. you cannot use = with a function call on the left side:

    you can use setf to achieve what you want:

    (setf cadr(nth(0 val))  cadr(nth(0 val)) + 0.5)

    should work

    I really don't like the combined use of both cadr and nth (those are two ways of doing the same thing, I think you should stick to one)

    In your case, you can use topEdge (bottomEdge, leftEdge or rightEdge works as well)

    Your final code should look like this:

    List_A = (copy List_Original)

    (foreach bbox List_A

      (setf (bottomEdge bbox) (bottomEdge bbox)+.5)

      (setf (topEdge bbox)       (topEdge bbox)+.5)

      )

     

    Cheers,

    Aurel

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • AurelBuche
    AurelBuche over 5 years ago

    Hi Leonardo,

    You are doing two things wrong:

    1. if you do:

    List_Original='(
                              ((0 1)  (2 3))
                             )

    and

    List_A=List_Original

    then List_A and List_Original will point to the same object, if you modify one it means you modify the other one

    You will have to store a copy version in order to do whatever suits you:

    List_A = (copy List_Original)

    2. you cannot use = with a function call on the left side:

    you can use setf to achieve what you want:

    (setf cadr(nth(0 val))  cadr(nth(0 val)) + 0.5)

    should work

    I really don't like the combined use of both cadr and nth (those are two ways of doing the same thing, I think you should stick to one)

    In your case, you can use topEdge (bottomEdge, leftEdge or rightEdge works as well)

    Your final code should look like this:

    List_A = (copy List_Original)

    (foreach bbox List_A

      (setf (bottomEdge bbox) (bottomEdge bbox)+.5)

      (setf (topEdge bbox)       (topEdge bbox)+.5)

      )

     

    Cheers,

    Aurel

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
  • Andrew Beckett
    Andrew Beckett over 5 years ago in reply to AurelBuche

    I would do it this way, which is much more immune to side effects:

    List_A=foreach(mapcar bBox List_Original
        list(
            xCoord(lowerLeft(bBox)):yCoord(lowerLeft(bBox))+0.5
            xCoord(upperRight(bBox)):yCoord(upperRight(bBox))-0.5
        )
    )

    Unfortunately Aurel, your approach still destructively modifies the original list. That's because copy() doesn't do a deep copy - it only generates a new top-level list, and your destructive operations are one level down.

    Regards,

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • AurelBuche
    AurelBuche over 5 years ago in reply to Andrew Beckett

    My bad,

    you're definitely right, the foreach mapcar approach is much more robust and natural (even though the foreach mappings might not be obvious for users experienced with other languages)

    Thanks for your rectification

    Cheers,

    Aurel

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • Leonardo Vinci
    Leonardo Vinci over 5 years ago in reply to AurelBuche

    Hi Aurel, and  Andrew Beckett

    = is an assignment operator, so the value of variable on RHS is assigned to the value of variable in LHS. Then why after I change the variable on LHS, which is List_A, when i do the foreach, is not reflected? Since the code runs serially, the latest foreach loop should update the values of List_A right?  

    Please correct me.

    Thanks,

    Leo.

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

    Leo,

    You can assign to a variable, but you cannot assign to the result of a function - that is not a variable. So when you were doing:

    cadr(nth(0 val))=a

    that will not work. You could use setf() to do this kind of assignment, but then you'd be modifying the original list, which you explicitly said you don't want to do.

    Andrew 

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