• 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. How to flatten a disembodied property list (DPL)?

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 143
  • Views 2444
  • 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

How to flatten a disembodied property list (DPL)?

Sheppie
Sheppie 7 months ago

Hi,

I have a disembodied property list (DPL) which looks like this:

test = list(nil 'a '(1 2 3) 'b nil 'c '( nil 'd '(7 8 9) 'e '(10 11 12) ) 'f '( nil ) 'g '(13 14 15) )

test
(nil a (1 2 3) b nil
c (nil 'd '
    (7 8 9) 'e '
    (10 11 12)
) f (nil) g
(13 14 15)
)

So, every value of the symbol-value pair is either a list (see 'a or 'd or 'e or 'g), an other DPL (see 'c) an empty DPL (see 'f) or nil (see 'b).

After flattening, test should look like:

test
(1 2 3 7 8
    9 10 11 12 13
    14 15
)

So, the DPL has many "hierarchical levels", which all should collapse into one long list. Where an empty DPL and nil should not be included.
The problem I'm having is that I'm having difficulties finding the lowest point, and traversing back.
Or should I just create a procedure that starts at the top and calls itself when it encounters an other DPL?

Any suggestion is appreciated.

Thank you in advance.

With kind regards,

Sjoerd

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett 7 months ago

    Sjoerd,

    I assume your list is really like this:

    test = list(nil 'a '(1 2 3) 'b nil 'c '( nil d (7 8 9) e (10 11 12) ) 'f '( nil ) 'g '(13 14 15) )

    rather than

    test = list(nil 'a '(1 2 3) 'b nil 'c '( nil 'd '(7 8 9) 'e '(10 11 12) ) 'f '( nil ) 'g '(13 14 15) )

    (otherwise it has quotes embedded within the quoted lists, which wouldn't make sense). Once you quote the outer list, everything within it is quoted.

    This recursive (non-destructive) function does (I think) what you want. It seems a rather unusual requirement...

    procedure(CCFflattenStrangeDPL(dpl)
      let((key value result)
        dpl=cdr(dpl)
        while(dpl
          key=car(dpl)
          value=cadr(dpl)
          dpl=cddr(dpl)
          result=lconc(result
            copy(
              if(listp(value) && !car(value) then
                CCFflattenStrangeDPL(value)
              else
                value
              )
            )
          )
        )
        car(result)
      )
    )
    

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • AaronSymko
    AaronSymko 7 months ago in reply to Andrew Beckett

    Andrew responded as I was coding up a solution, but figured I would post mine as well. Also, please refer to Andrew's post on fixing your DPL structure:

    procedure(flatten(data)
      cond(
        (dplp(data)
          foreach(mapcan key reverse(data->?)
            let((val)
              val = get(data key)
              if(listp(val)
                flatten(copy(val)) ; then
                ncons(val)
              )
            )
          )
        )
        (listp(data)
          foreach(mapcan val data
            if(listp(val)
              flatten(copy(val)) ; then
              ncons(val)
            )
          )
        )
        (t
          error("Unexpected value: %L\n" data)
        )
      )
    )
    test = '(nil a (1 2 3) b nil c (nil d (7 8 9) e (10 11 12)) f (nil) g (13 14 15))
    flatten(test) == '(1 2 3 7 8
        9 10 11 12 13
        14 15
    )
    
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Sheppie
    Sheppie 7 months ago in reply to AaronSymko

    Hi AAronSymko,

    Thank you very much foryour solution and time. Please see my response to Andrews solution as well.

    With kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Sheppie
    Sheppie 7 months ago in reply to AaronSymko

    Hi AAronSymko,

    Thank you very much foryour solution and time. Please see my response to Andrews solution as well.

    With kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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