The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Oct 23rd, 2019, 2:47am
Pages: 1
Send Topic Print
Sorting list numerically in Cadence SKILL Language (Read 6754 times)
cheap_salary
Senior Member
****
Offline



Posts: 162

Sorting list numerically in Cadence SKILL Language
Sep 14th, 2015, 5:41am
 
a = '(11 9 11 8 7 9 12 1 0 -5 11 6 7)

I want to sort above list, a and then generate new list, b.

b = '(-5 0 1 6 7 7 8 9 9 11 11 11 12)

And I want to remove duplicate elements and then generate new list, c

c = '(-5 0 1 6 7 8 9 11 12)

How can I do these tasks elegantly in Cadence SKILL Language ?

"sort(a, nil)" is not valid.

I can do these tasks for list very easily in Microsoft .NET environment by invoking sort method and association list, e.g. "hash table"or "dictionary".
Back to top
 
 
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Sorting list numerically in Cadence SKILL Language
Reply #1 - Sep 15th, 2015, 4:27am
 
Cheap_salary,cheap_salary wrote on Sep 14th, 2015, 5:41am:
"sort(a, nil)" is not valid.
I do not understand what your problem with sort is. Properly used it works just fine:
Code:
a = '(11 9 11 8 7 9 12 1 0 -5 11 6 7)
(11 9 11 8 7
    9 12 1 0 -5
    11 6 7
)
b=sort(copy(a), 'lessp)
(-5 0 1 6 7
    7 8 9 9 11
    11 11 12
) 

- B O E
Back to top
 
 
View Profile   IP Logged
cheap_salary
Senior Member
****
Offline



Posts: 162

Re: Sorting list numerically in Cadence SKILL Language
Reply #2 - Sep 15th, 2015, 6:41am
 
boe wrote on Sep 15th, 2015, 4:27am:
b=sort(copy(a), 'lessp)
(-5 0 1 6 7
  7 8 9 9 11
 11 11 12
)

Thanks for replying.
If I want to remove duplicate elements, how can I do it ?

I created my own awkward custom function like following.
I can do my favorite task with this custom function, but not cool.
Code:
procedure( list_sort(l_list,
	     @optional (my_mode 0), (rm_duplicate 0)
	   ); list_sort
prog( (i, k, ii, jj, n, p, my_value)
  n = length(l_list)

  declare(p[n])
  for(i, 0, n-1
    p[i] = nth(i, l_list)
  ); for

  for(ii, 0, n-2
    my_value = p[ii]
    k = ii
    for(jj, ii+1, n-1
    prog( ()
	if(my_mode == 0 then
	  when( my_value < p[jj], return() ) ; ascend
	else
	  when( my_value > p[jj], return() ) ; descend
	); if
	my_value = p[jj]
	k = jj
    ); prog
    ); for
    p[k] = p[ii]
    p[ii] = my_value
  ); for

  my_value = p[0]
  l_list = list(my_value)
  for(i, 1, n-1
    if(rm_duplicate != 0 then
	when(p[i] != my_value
	  my_value = p[i]
	  l_list = append1(l_list, my_value)
	); when
    else
	l_list = append1(l_list, p[i])
    ); if
  ); for
  return(l_list)
); prog
); procedure 


\i list_sort('(2 11 11 11 10 10 9 9 4 0 -1), 0)
\t (-1 0 2 4 9
\t     9 10 10 11 11
\t     11
\t )
\p >
\i list_sort('(2 11 11 11 10 10 9 9 4 0 -1), 0, 1)
\t (-1 0 2 4 9
\t     10 11
\t )
\p >
\i list_sort('(2 11 11 11 10 10 9 9 4 0 -1), 1)
\t (11 11 11 10 10
\t     9 9 4 2 0
\t     -1
\t )
\p >
\i list_sort('(2 11 11 11 10 10 9 9 4 0 -1), 1, 1)
\t (11 10 9 4 2
\t     0 -1
\t )

I can do same tasks very easily with MATLAB.
Back to top
 

matlab.png
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Sorting list numerically in Cadence SKILL Language
Reply #3 - Sep 16th, 2015, 9:52am
 
cheap_salary wrote on Sep 15th, 2015, 6:41am:
...
I can do same tasks very easily with MATLAB.
Congratulations. However, it just proves that you are more proficient in MATLAB than in SKILL.
- B O E
Back to top
 
 
View Profile   IP Logged
cheap_salary
Senior Member
****
Offline



Posts: 162

Re: Sorting list numerically in Cadence SKILL Language
Reply #4 - Sep 16th, 2015, 11:08am
 
I've translated some MATLAB scripts to SKILL and Visual-C#.
So I created many primitive custom functions with SKILL.

For example, I've translated many functions of Schreier's delsig Toolbox to SKILL.

The following is a Porting Project to Python of delsig Toobox.
https://github.com/ggventurini/python-deltasigma
Back to top
 
« Last Edit: Sep 16th, 2015, 9:05pm by cheap_salary »  
View Profile   IP Logged
boe
Community Fellow
*****
Offline



Posts: 615

Re: Sorting list numerically in Cadence SKILL Language
Reply #5 - Sep 17th, 2015, 8:50am
 
Cheap_salary,
Cadence documentation is your friend.
- B O E
Back to top
 
 
View Profile   IP Logged
cheap_salary
Senior Member
****
Offline



Posts: 162

Re: Sorting list numerically in Cadence SKILL Language
Reply #6 - Sep 17th, 2015, 9:29am
 
boe wrote on Sep 17th, 2015, 8:50am:
Cheap_salary,
Cadence documentation is your friend.
- B O E
Rather, Text books on CLisp and Emacs Lisp are very useful and helpful than Cadence documentation.
Back to top
 
 
View Profile   IP Logged
sheldon
Community Fellow
*****
Offline



Posts: 745

Re: Sorting list numerically in Cadence SKILL Language
Reply #7 - Sep 17th, 2015, 9:07pm
 
There are built in functions to extract unique members
from a list, if you look in the documentation.
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2019 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.