SKILL: how to convert from a struct to association list

Discussion in 'Cadence' started by m774, Aug 10, 2009.

  1. m774

    m774 Guest

    What's the best and what's the easiest way to convert a struct to an
    association list?

    Say I have a structure named s. I can access the property list with s-
    However I need an association list: ((name1 value1) (name2
    value2) ...)

    I thought a function exist to perform this basic (i.e. converting from
    data-structures), but couldn't find anything in the documentation.

    Thanks for any hint!
     
    m774, Aug 10, 2009
    #1
  2. m774

    Riad KACED Guest

    Hi m774,

    I don't know of any built-in Skill function that does what your are
    asking.
    You could try a foreach/mapcar.
    Say:
    ISW> defstruct(mosfet w l nf modelName)
    ISW> nmosStruct=make_mosfet(?w "1u" ?l "0.1u" ?nf "2" ?modelName
    "nmosfet")
    Then:
    ISW> nmosAssocList=foreach( mapcar prop nmosStruct~>? list(prop get
    (nmosStruct prop)))
    will return the Assc List you are looking for:

    ((modelName "nmosfet")
    (nf "2")
    (l "0.1u")
    (w "1u")
    )

    BTW, the '??' builds a DPL out of the structure, i.e.
    nmosDPL=nmosStruct~>??

    (modelName "nmosfet" nf "2" l
    "0.1u" w "1u"
    )

    This might be a quick solution If you don't mind DPLs ...

    You could go for Eyn's otherwise ...

    Cheers,
    Riad.
     
    Riad KACED, Aug 10, 2009
    #2
  3. m774

    m774 Guest

    Thanks. This works, but if you modify how you access the prop value:
    myStruct->prop could be changed into get(myStruct prop), as in Riad
    code.
     
    m774, Aug 11, 2009
    #3
  4. m774

    m774 Guest

    Thank you all. Both code are ok for me. the code by Eyn retrieve the
    properties in reverse order, but I don't care here.
    Thanks a lot!
     
    m774, Aug 11, 2009
    #4
  5. m774

    Riad KACED Guest

    Hi,

    The reverse order in Eyn's comes out the 'cons' function. cons adds
    elements to the front of the list, giving a result that is “back to
    front”. You might consider using 'tconc' if the order really matters.
    tconc is more efficient than using 'reverse'.

    Cheers,
    Riad.
     
    Riad KACED, Aug 11, 2009
    #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.