• 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. list substitution problems

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 143
  • Views 13984
  • 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

list substitution problems

sparksu
sparksu over 16 years ago

I have a long list here:

listA=list(P1 P2 P3 ... Px-1 Px Px+1 ... Pn)

for a given Px, I want to substitute Px with 2 new elements Px1 Px2  :

ListB=list(P1 P2 P3 ... Px-1 Px1 Px2 Px+1 ... Pn)

I know how to do it using "reverse()" function.

But based on SKILL Language User Guide, reverse() can generate a lot of memeory.

Is there a more efficient way to do this? I don't care if it is destructive or nondestructive.

Here is my code using reverse():

;---------------------------------------------------------------------------------------------------------------------------------

listB2=rplaca(member(Px listA) Px2)                                     ;listB2=>list(Px2 ... Pn)

listB1=reverse(rplaca(member(Px2 reverse(listA) Px1)             ;listB1=>list(P1 P2 P3 ... Px-1 Px1)

listB=append(listB1 listB2)                ;ListB=>list(P1 P2 P3 ... Px-1 Px1 Px2 Px+1 ... Pn)

;---------------------------------------------------------------------------------------------------------------------------------

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 16 years ago

    Something like this:

    match=nil
    foreach(map rem listA
      when(cadr(rem)==Px match=rem)
    )
    listA2=cdr(match)
    rplacd(match nil)
    listA1=listA

    Note this doesn't handle the case where the match is at the beginning of the list - but that's cheap to check for and handle, as I did in the previous response. Potentially you could make the foreach stop as soon as it finds a match by doing:

    prog(()
      foreach(map rem listA
        when(cadr(rem)==Px
          match=rem
          return()
        )
      )
    )

    The surrounding prog allows you to use return() to exit the foreach early.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 16 years ago

    Something like this:

    match=nil
    foreach(map rem listA
      when(cadr(rem)==Px match=rem)
    )
    listA2=cdr(match)
    rplacd(match nil)
    listA1=listA

    Note this doesn't handle the case where the match is at the beginning of the list - but that's cheap to check for and handle, as I did in the previous response. Potentially you could make the foreach stop as soon as it finds a match by doing:

    prog(()
      foreach(map rem listA
        when(cadr(rem)==Px
          match=rem
          return()
        )
      )
    )

    The surrounding prog allows you to use return() to exit the foreach early.

    Regards,

    Andrew.

    • 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