• 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. how to simultaneously traverse varaiable number of lists...

Stats

  • Locked Locked
  • Replies 8
  • Subscribers 142
  • Views 15062
  • 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

how to simultaneously traverse varaiable number of lists?

archive
archive over 19 years ago

If I want to traverse, lets's say for example, 3 lists at one time, I would use:

list1 = '(1 2 3)
list2 = '(4 5 6)
list3 = '(7 8 9)
foreach((x y z) list1 list2 list3
printf("%L %L %L\n" x y z)
)
But, how do you do this, when you don't know how many lists that you will need to traverse? Is this easily done in SKILL? Or, will I have to brute force it using elemental list access, like so?
listOfLists = '((1 2 3) (4 5 6) (7 8 9))
for(j 1 length(car(listOfLists))
string = ""
foreach(l listOfLists
string = sprintf(nil "%s %L" string nthelem(j l))
)
printf("%s\n" string)
)
Do you know a better way?  Please remember that I do not know the number of lists in the listOfLists a priori (although I do know the lists are all the same length); otherwise, I would use the structure from the first example ...

Thanks!


Originally posted in cdnusers.org by m27315
  • Cancel
  • archive
    archive over 19 years ago

    The best thing here would be to use mapc and apply, as follows

    apply('mapc
    `(lambda((@rest entries)
    let((string)
    string=""
    foreach(entry entries string=sprintf(nil "%s %L" string entry))
    printf("%s\n" string)
    ) ; let
    ); lambda
    ,@listOfLists
    ) ; end of backquote list
    ) ; apply

    The backquote is being used as a readable way of building the arguments to the mapc - which would be a function object (created with lambda in this case) and the rest of the arguments which would be the list members of listOfLists. You
    could have just used cons instead:


    apply('mapc
    cons(lambda((@rest entries)
    let((string)
    string=""
    foreach(entry entries string=sprintf(nil "%s %L" string entry))
    printf("%s\n" string)
    ) ; let
    ); lambda
    listOfLists
    ) ; cons
    ) ; apply

    They do the same thing - but backquote tends to be used more with macros, for example.

    Regards,

    Andrew.


    Originally posted in cdnusers.org by adbeckett
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 19 years ago

    Apologies, I should have used the "Quote" button at the top - my code has had the indentation stripped as a result. It should have been:

    apply('mapc
    `(lambda((@rest entries)
    let((string)
    string=""
    foreach(entry entries string=sprintf(nil "%s %L" string entry))
    printf("%s\n" string)
    ) ; let
    ); lambda
    ,@listOfLists
    ) ; end of backquote list
    ) ; apply


    and:

    apply('mapc
    cons(lambda((@rest entries)
    let((string)
    string=""
    foreach(entry entries string=sprintf(nil "%s %L" string entry))
    printf("%s\n" string)
    ) ; let
    ); lambda
    listOfLists
    ) ; cons
    ) ; apply

    Regards,

    Andrew.


    Originally posted in cdnusers.org by adbeckett
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 19 years ago

    Posted By adbeckett on 5/26/2006 11:04 AM
    Apologies, I should have used the "Quote" button at the top - my code has had the indentation stripped as a result. It should have been:

    ...
    Hi Andrew,

    I am not sure if this forum supports BBcode... I had to switch to the HTML view tab and enclose my preformatted code in
    tags.

    I really wish this forum supported BBcode.  A preview function would be really nice.

    back to topic in the next post ... :-)


    Originally posted in cdnusers.org by m27315
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 19 years ago

    Sorry, the quoting seems to have gone wrong with the forum software. I'll give up and let you figure out the indentation yourself...

    Andrew.


    Originally posted in cdnusers.org by adbeckett
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 19 years ago

    Posted By m27315 on 5/26/2006 11:13 AM

    I am not sure if this forum supports BBcode... I had to switch to the HTML view tab and enclose my preformatted code in
    tags.

    Ahh!  I wrote out BLOCKQUOTE and PRE tags, but they got dropped!  And, I could not tell before posting, because I cannot find a Previw function.  Apparently, there is no way to edit existing posts either, so I can't clean it up.  Oh, well...

    Anyway, thanks again Andrew for the good tip.  I had tried something similar to the build entries list, but i did not make use of the apply function, so mapc kept complaining that the first argument was not a list of unquoted symbols.  ... Anyway, that's a very good trick!

    Many thanks!!


    Originally posted in cdnusers.org by m27315
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 19 years ago

    Posted By adbeckett on 5/26/2006 11:02 AM
    The best thing here would be to use mapc and apply, as follows ... The backquote is being used as a readable way of building the arguments to the mapc - which would be a function object (created with lambda in this case) and the rest of the arguments which would be the list members of listOfLists. You could have just used cons instead ... They do the same thing - but backquote tends to be used more with macros, for example.
    Do you think there are any performance penalties/advantages associated with any of these techniques for large lists and more complex lambda functions?


    Originally posted in cdnusers.org by m27315
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 19 years ago

    Well, many of the foreach forms actually use lambda inside to build a unnamed function object. That compilation is normally only done once - it is smart enough to avoid compiling at run time.

    The backquote is a macro - so in essence it ends up being the same as cons in this case. I don't think there would be an major performance penalties here.

    The best way to find out though is to use the SKILL profiler (part of the SKILL Development environment). This will allow you to figure out where the bottlenecks in the code are.

    Andrew.


    Originally posted in cdnusers.org by adbeckett
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 19 years ago

    sounds good - many thanks!


    Originally posted in cdnusers.org by m27315
    • 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