• 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. can't understand what's happening when adding a property...

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 142
  • Views 1274
  • 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

can't understand what's happening when adding a property to a symbol

kkdesbois
kkdesbois over 2 years ago

Hello,

Let's consider the following code in Bold and in each indent the result displayed in CIW

(setq trial (makeSymbol "toto"))

CIW :  trial => toto
           trial->?? => nil

(foreach key '(AAA BBB CCC)
    (putprop trial '(nil) key)
)

CIW : trial->?? => (CCC (nil)     BBB (nil)     AAA (nil))

(putpropq (getq trial AAA) t test)

CIW : trial->?? => (CCC (nil test t)     BBB (nil test t)     AAA (nil test t))

I was expecting that test is added only to the property AAA.

Can anyone explain me why test is added to all the properties please.

Kk.

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago

    That's because you are using '(nil) to create the initial disembodied property list, and you're doing so in a loop. That means that the AAA, BBB, CCC properties on the trial symbol are all pointing to exactly the same list in memory - it's actually the literal list in the code. You are then destructively modifying that list with the final putpropq, and all three are still pointing at the same list. 

    You can see this if you do:

    eq(trial->AAA trial->BBB) => t

    Similarly, if you do this:

    (defun setThreeProps ()
      (foreach key '(AAA BBB CCC)
        (putprop trial '(nil) key)
      ))

    (setq trial (makeSymbol "toto"))
    (setThreeProps)
    (putpropq (getq trial AAA) t test)

    now do (pp setThreeProps) to see the code:

    procedure(setThreeProps()
        foreach(key
            '(AAA BBB CCC)
            putprop(trial
                '(nil test t) key
            )
        )
    )

    (of course, I could have pretty-printed it in non-infix mode if I'd done (sstatus printinfix nil) first). Anyway, the key is you'll see that the literal list in the code has also been updated - that's the literal list that the quote operator generates and everything points to.

    Very simply you can fix this by using (ncons nil) or (list nil) in the loop instead:

    (foreach key '(AAA BBB CCC)
      (putprop trial (ncons nil) key)
    )

    This way it is guaranteed that the list for each key is newly and separately created, and is not shared.

    Hope that makes sense!

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • kkdesbois
    kkdesbois over 2 years ago in reply to Andrew Beckett

    Thank you, it's so much clear now.

    I've also found an answer to a case about the same kind of issue.

    I share it for community people interested in that kind of topic.

    support.cadence.com/.../ArticleAttachmentPortal

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to kkdesbois
    kkdesbois said:

    I share it for community people interested in that kind of topic.

    support.cadence.com/.../ArticleAttachmentPortal

    Ah, that's one of my articles! I thought I remembered writing this up for Cadence Online Support!

    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