• 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 words from list

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 144
  • Views 13198
  • 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 words from list

Gaga
Gaga over 9 years ago

Hello,
I'm new in Skill programming and trying different excercises. I try to read file, and count the rows, words on the single row, finding a unique words and checking how many times the unique word exists in the row.. 

inPort = infile( "filename" )

countRows = 0

when( inPort

while( str = lineread( inPort )

a = length( str )

++countRows

close( inPort )

countRows is for number of the rows, and "a" gives me the number of words.. I found procedures for that how many times the unique word exists.. but I don't know how to use it correctly.. 

procedure( trCountValues( aList )
let( ( ( countTable makeTable( "ValueTable" 0 ) ) )
foreach( element aList
countTable[ element ] = countTable[ element ] + 1
) ; foreach
foreach( key countTable
printf( " %L occurred %d times.\n"
key countTable[ key ] )
) ; foreach
tableToList( countTable ) ;; convert to assoc list
) ; let
) ; procedure

I'll be thankful on any help! 

  • Cancel
Parents
  • Quek
    Quek over 9 years ago

    Hi Gaga

    You can do it as follows:

    procedure( CCSreadAndCount(file uniqueWord)
       let( (inPort lineCount wordCount uniqueCount inLine inLineList

         reducedList)
          inPort=infile(file)
          unless( inPort error("Cannot open file %s" file))
          lineCount=1
          wordCount=0
          uniqueCount=0
          while( gets(inLine inPort)

             ; To keep things simple, we are assuming that the line really consists of just words and no brackets, commas, etc
             inLineList=parseString(inLine " \t\n")
             wordCount=length(inLineList)

             lineCount++
            
             reducedList=remove(uniqueWord inLineList)

             uniqueList=length(inLineList)-length(reducedList)

             printf("There are %d \"%s\" and total %d words in line %s"

               uniqueCount uniqueWord wordCount inline)

         ) ;while

         close(inPort)
         printf("There are %d lines\n" lineCount)

       ) ;let
    ) ;procedure

    The above procedure can be used as follows:

    a. Save the codes in a file named "getdata.il"
    b. Load the file in CIW:

    load "./getdata.il"

    c. Execute the procedure:

    CCSreadAndCount("/your-path/yourfile" "myUniqueWord")


    Best regards
    Quek

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Quek
    Quek over 9 years ago

    Hi Gaga

    You can do it as follows:

    procedure( CCSreadAndCount(file uniqueWord)
       let( (inPort lineCount wordCount uniqueCount inLine inLineList

         reducedList)
          inPort=infile(file)
          unless( inPort error("Cannot open file %s" file))
          lineCount=1
          wordCount=0
          uniqueCount=0
          while( gets(inLine inPort)

             ; To keep things simple, we are assuming that the line really consists of just words and no brackets, commas, etc
             inLineList=parseString(inLine " \t\n")
             wordCount=length(inLineList)

             lineCount++
            
             reducedList=remove(uniqueWord inLineList)

             uniqueList=length(inLineList)-length(reducedList)

             printf("There are %d \"%s\" and total %d words in line %s"

               uniqueCount uniqueWord wordCount inline)

         ) ;while

         close(inPort)
         printf("There are %d lines\n" lineCount)

       ) ;let
    ) ;procedure

    The above procedure can be used as follows:

    a. Save the codes in a file named "getdata.il"
    b. Load the file in CIW:

    load "./getdata.il"

    c. Execute the procedure:

    CCSreadAndCount("/your-path/yourfile" "myUniqueWord")


    Best regards
    Quek

    • 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