• 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. Comparing list of lists

Stats

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

Comparing list of lists

LakshmanQual
LakshmanQual over 7 years ago

Hi Team,

I had a list of lists like ll1=(("a" "3") ("b" "2") ("c" "4") ("d" "2") ("f" "1"))

ll2= (("d" "3") ("a" "3") ("g" "1") ("b" "3") ("f" "1") ("y" 2") ("z" "6")) 

while comparing those list of lists for the availability of characters and numbers, i am not able to use break statements in foreach loops to break corresponding loop. Could you please help me in my code??

foreach(char1 ll1

    value=0

   foreach(char2 ll2

     if(car(char1)==car(char2) && cdr(char1)==cdr(char2) then

         value=1)         ;I dont have any breaks statements in SKILL to use once the character is available and break the loop here

    if(car(char1)==car(char2) && cdr(char1)!=cdr(char2) then

         value=2)           ;I dont have any breaks statements in SKILL to use once the character is available and break the loop here

    if(car(char1) != car(char2) then

         value=2)         ;I dont have any breaks statements in SKILL to use once the character is available and break the loop here

) ;inner foreach loop

if(value==1 then   printf("character is available and repetitions matched for %L\n" car(char1))

   else

       if(value ==2 then printf("character is available but repetitions mismatched for %L\n" car(char1))

        else

           if(value == 3 then printf("character not available %L\n" car(char1)))))

)   ;outer foreach loop

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago

    I don't think your logic is quite right (even if you had the break()) because the inner loop would always break on the first element of the inner loop. You can implement a "break" using prog and return (although personally I dislike this approach, as it offends my ideas about structured programming). I think you want:

    foreach(char1 ll1
       value=3
       prog(()
         foreach(char2 ll2
           if(car(char1)==car(char2) && cdr(char1)==cdr(char2) then
               value=1
               return()
           )     
          if(car(char1)==car(char2) && cdr(char1)!=cdr(char2) then
               value=2
               return()
          )    
        ) ;inner foreach loop
      )

      if(value==1 then
        printf("character is available and repetitions matched for %L\n" car(char1))
      else
        if(value ==2 then
            printf("character is available but repetitions mismatched for %L\n" car(char1))
          else
             if(value == 3 then
               printf("character not available %L\n" car(char1)))))
    )   ;outer foreach loop

    I'd probably write it like this instead, which avoids the use return (which is a glorified goto and is hard to follow the code because you have code that sometimes jumps out of the middle of a loop):

    foreach(char1 ll1
      value=3
      forall(char2 ll2
        cond(
          (car(char1)==car(char2) && cdr(char1)==cdr(char2)
             value=1
             nil
          )     
          (car(char1)==car(char2) && cdr(char1)!=cdr(char2)
             value=2
             nil
          )  
          (t
             t
          )
         ) 
       ) ;inner forall loop

      case(value
        (1
          printf("character is available and repetitions matched for %L\n" car(char1))
        )
        (2
          printf("character is available but repetitions mismatched for %L\n" car(char1))
        )
        (3
          printf("character not available %L\n" car(char1))
        )
      )
    )   ;outer foreach loop

    Regards,

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • LakshmanQual
    LakshmanQual over 7 years ago in reply to Andrew Beckett

    hi Andrew, Thanks for the corrections. Its working as i desire.

    • 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