Wednesday, February 08, 2012     Register | Login | Search | Contact Us
     

Many of you already received communications about the move of the Cadence user community into cadence.com. And many of you have already joined, with over 4000 registrations in the first two weeks.

The new Cadence Community enhances the ability of Cadence users to connect and collaborate. In addition to moving the community into cadence.com -- enabling single sign-on for community, Sourcelink and Cadence events -- the new site is organized around nine technology segments, giving you easy access to product information, training, forums and blogs. Some of the new features include:
  • Ability to respond to posts via e-mail
  • Technology-specific blogs
  • Latest Web 2.0 social networking capabilities
  • Public profile options
  • Private messaging
  • Friends lists
Visit the new Cadence Community today at www.cadence.com/community and join the discussions!

Registration note: Due to the scope of the enhancements and the new SSO registration system, we were not able to migrate existing cdnusers.org member accounts. So new registrations are required, but this enables a broader set of functionality we think you'll enjoy.

Forum note: Under the guidance of forum moderators, we have taken the 20+ cdnusers.org forums and consolidated them into 11 forums on the new site. Posts have been brought over so you can leverage that posting history. CDNusers forums will be set to read only starting 7/30, and cdnusers.org will be redirected to the new community on 8/4.

Best regards,
Mike and Tom

Michael A. Catrambone - Steering Committee Chairman
Distinguished Engineer
PCB/Mechanical
UTStarcom, Inc.

Tom Diederich
Cadence Community Manager
Home
Forums
Subject: how to simultaneously traverse varaiable number of lists?
Posting to forums is available to community members only.
Login or Register
Rate this topic:
   
Author Messages
m27315
Posts: 24
Online: User is Offline
5/26/2006 10:16 AM  
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!
adbeckett
Posts: 248
Online: User is Offline
5/26/2006 11:02 AM  
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.

adbeckett
Posts: 248
Online: User is Offline
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:

[quote]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[/quote]

and:

[quote]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[/quote]
Regards,

Andrew.
m27315
Posts: 24
Online: User is Offline
5/26/2006 11:13 AM  
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:

[quote]...[/quote]
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 ... :-)
adbeckett
Posts: 248
Online: User is Offline
5/26/2006 11:20 AM  
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.
m27315
Posts: 24
Online: User is Offline
5/26/2006 12:05 PM  
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!!
m27315
Posts: 24
Online: User is Offline
5/30/2006 9:10 AM  
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?

adbeckett
Posts: 248
Online: User is Offline
5/30/2006 9:39 AM  
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.
m27315
Posts: 24
Online: User is Offline
5/30/2006 9:41 AM  
sounds good - many thanks!
Posting to forums is available to community members only.
Login or Register

Forums > Custom IC > Shared code - SKILL > how to simultaneously traverse varaiable number of lists?


ActiveForums 3.6
     
Copyright 2006 Cadence Design Systems, Inc.