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

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 15562
  • 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

Merging Lists

SBrickles
SBrickles over 16 years ago

I am writing some code which uses lists.
I need a way to be able merge two lists into one such that

list1:

( x "foo"
     (
        ( a "a" "func1()" )
        ( b "b" "func2()" )
        ( c "c" (
                    ( d "d" "func3()" )
                  )
     )
)

and list2: 

( x "foo"
     (
        ( e "e" "func4()" )
        ( c "c" (
                    ( f "f" "func5" )
                  )
     )
)

merge so that you end up with:

( x "foo"
     (
        ( a "a" "func1()" )
        ( b "b" "func2()" )
        ( c "c" (
                    ( d "d" "func3()" )
                    ( f "f" "func5" )
                  )
        ( e "e" "func4()" )
     )
)

The code needs to be able to merge at multiple levels depending on
whether the  'key' element (the car of the list at any level) is the same value or not.

If the item in the second list is of the form (a "a" "func()" ) then it should overwrite the
value when it gets merged with the first list.  So in the example above if the second list
had  ( a "a" "func8()" ) in it then it would have overwritten the ( a "a" "func1()" ) in the first list
- but only if it was at the same level of hierachy  as in the first list.

Any ideas ?

Stephen 

  • Cancel
Parents
  • SBrickles
    SBrickles over 16 years ago

    Andrew - Many many thanks for your help and prompt response on this.
    It completely solved my problem !!

    I made the following modification to the SBmergeLists procedure to allow a list
    to be replaced by an item:

    procedure( SBmergeLists(l1 l2)
    let( ( match )
    foreach( l2el l2
    match = assoc( car( l2el ) l1 )
    if( match then
    if( listp( caddr( match ) ) then
              if( listp( nth( 2 l2el ) ) then
    SBmergeLists( caddr( match ) caddr( l2el ) )
    else
    rplaca( member( match l1 ) l2el )
    )
    else
    rplaca( cddr( match ) caddr( l2el ) )
    )
    else
    rplacd(last( l1 ) list( l2el ) )
    )
    )
    l1
    )
    )

    This allows the case below to work as well:

    list1=
    '( x "foo"
    (
    ( a "a" "func1()" )
    ( b "b" "func2()" )
    ( c "c" (
    ( d "d" "func3()" )
    )
    )
    )
    )

    list2=
    '( x "foo"
    (
    ( c "c" "func4()" )
    )
    ) 

    Resulting in:

    pp( list1 )
    ( x "foo"
    (
    ( a "a" "func1()" )
    ( b "b" "func2()" )
    ( c "c" "func4()" )
    )
    )

    The opposite case of turning an item into a list works fine as well.

    Again, many thanks,

    Stephen.

     
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • SBrickles
    SBrickles over 16 years ago

    Andrew - Many many thanks for your help and prompt response on this.
    It completely solved my problem !!

    I made the following modification to the SBmergeLists procedure to allow a list
    to be replaced by an item:

    procedure( SBmergeLists(l1 l2)
    let( ( match )
    foreach( l2el l2
    match = assoc( car( l2el ) l1 )
    if( match then
    if( listp( caddr( match ) ) then
              if( listp( nth( 2 l2el ) ) then
    SBmergeLists( caddr( match ) caddr( l2el ) )
    else
    rplaca( member( match l1 ) l2el )
    )
    else
    rplaca( cddr( match ) caddr( l2el ) )
    )
    else
    rplacd(last( l1 ) list( l2el ) )
    )
    )
    l1
    )
    )

    This allows the case below to work as well:

    list1=
    '( x "foo"
    (
    ( a "a" "func1()" )
    ( b "b" "func2()" )
    ( c "c" (
    ( d "d" "func3()" )
    )
    )
    )
    )

    list2=
    '( x "foo"
    (
    ( c "c" "func4()" )
    )
    ) 

    Resulting in:

    pp( list1 )
    ( x "foo"
    (
    ( a "a" "func1()" )
    ( b "b" "func2()" )
    ( c "c" "func4()" )
    )
    )

    The opposite case of turning an item into a list works fine as well.

    Again, many thanks,

    Stephen.

     
    • 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