• 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. Compare list items in if condition.

Stats

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

Compare list items in if condition.

gs748
gs748 over 10 years ago

Hello,

I am running issues while comparing below 2 list items. can you please help me identify the bug.

pline = '( "State" "4" "time")
    i=length(pline)
    item3 = nth(i-1 pline)
    item2 = nth(i-2 pline)
    item1 = nth(i-3 pline)

line = '("4" "Done")
     len_line=length(line)
     item5=nth(len_line-1 line)
     item4=nth(len_line-2 line)

if( (item2 == item4); compare fails and executes else part but if condition should pass as item2 & item4 has "4"!
    then
    lista = list(item1 item2 item3 item4 item5)

else

   item5 = "UNKNOWN"
   lista = list(item1 item2 item3 item4 item5)
 );end if 

printf("List is %L\n" lista)

  • Cancel
  • skillUser
    skillUser over 10 years ago
    This worked for me, i.e. I didn't get the "UNKNOWN" value. Perhaps remove the parentheses around the item2==item4 condition? Have you sent the exact code you are testing with?
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • gs748
    gs748 over 10 years ago

    Thanks for the reply! I was not sharing the actual code as the logic I use if not that good :)

    But here I am sharing my actual code. I am reading 2 files, one line at a time.

    From the first file, each line is split by ‘,’ and listed as item1-7.

    From second file, each line is split by ‘:’ and listed as item8-7

    Item 2 and item9 are numbers that being compared in IF condition – which doesn’t work. Can you please help look into this. Thanks!

    procedure(readcsv(ln)
     cline=ln;
     pline=parseString(cline ",")
      i=length(pline)
      printf("Length is %d\n" i)
       item7 = nth(i-1 pline)
       item6 = nth(i-2 pline)
       item5 = nth(i-3 pline)
       item4 = nth(i-4 pline)
       item3 = nth(i-5 pline)
       item2 = nth(i-6 pline)
       item1 = nth(i-7 pline)
     ; printf("ITEM'S 1-7:\n %L\n %L\n %L\n %L\n %L\n %L\n" item1 item2 item3 item4 item5 item6 item7)
    port1=infile("codes.csv")
      when(port1
       while(gets(lne port1)
         lne = substring(lne 1 strlen(lne)-1)
        ;printf("LINE: %s\n" ln)
         line=parseString(lne ":")
         len_line=length(line)
         item8=nth(len_line-1 line)
         item9=nth(len_line-2 line)
        ;printf("ITEM'S 8-9:\n %L\n %L\n" item7 item8)
         if( (item2 == item9); if condition is always skipped

           then
           item10 = item8    
           printf("ITEM 10 is:%L\n" item8)
           lista=list(item1 item2 item3 item4 item5 item6 item7 item10)
          else
          item10 = "UNKNOWN"

           lista=list(item1 item2 item3 item4 item5 item6 item7 item10)
         );end if
        );end while
       );end when
    printf("LIST ITEM'S:%L\n" lista)
    lista
    );end proc readcsv openok post

    ;-----------------------------------
    myTable = makeTable("atable1" 0)
    port=infile("postout1")
    count=0
    listN='()
    listNew='()
    when(port
       while(gets(ln port)
    ln = substring(ln 1 strlen(ln)-1)
    ;   printf("PORT LINE: %s\n" ln)
         listb=readcsv(ln)
         listN = cons(listb listN)
        )
    )

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 10 years ago

    Given that you're just comparing strings here (the parseString is going to produce lists of strings, and using nth() will either give you one of those strings or nil if it was an entry that didn't exist), the most likely scenario is that the strings really are NOT equal. == doesn't lie. The one case that causes confusion is where you are comparing floating point numbers, because you may have rounding errors which make two numbers look the same bit actually differ by a tiny amount, smaller than the printing resolution. That's not the case here.

    You've not provided the data, or shown an example of the data that produces the problem. So expecting the community to debug it is a bit optimistic! Your previous cut-down example didn't even have a problem at all (I would have expected you to try it before you posted it)...

    As a wild guess, maybe there is a space in one of the values  you've read but not in the other - you've got different delimiters in the files being read, but maybe there are other differences? Try printing them out - in your code you're not even printing item9 to check it. Or use the SKILL debugger (in the SKILL IDE in IC615/IC616) and put a breakpoint just before the condition and then  you can inspect the local variables in the CIW.

    It's highly unlikely (I'd say that with 100% certainty) that either == or if() are doing anything wrong here - it'll be your data that is different. When debugging, always look for the most likely scenario - if a conditional statement or == were wrong in a language that has been around for so long, it would break all sorts of code, so that's not very likely to have such a fundamental problem.

    Kind Regards,

    Andrew.

    • 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