Anonymous user
Rosetta Code/Rank languages by popularity: Difference between revisions
Rosetta Code/Rank languages by popularity (view source)
Revision as of 21:51, 28 July 2016
, 7 years ago→REXX program: added/changed comments, whitespace, elide the use of the CUTOFF variable, simplified some statements.
m (→{{header|REXX}}: updated the number of languages.) |
m (→REXX program: added/changed comments, whitespace, elide the use of the CUTOFF variable, simplified some statements.) |
||
Line 3,834:
<lang rexx>/*REXX program reads two files and displays a ranked list of Rosetta Code languages.*/
sep='█'; L.=0; #.=0; u.=0; catHeap=; old.= /*assign some REXX variable defaults. */
parse arg
if
if
if
call tell center('timestamp: ' date() time("Civil"),79,'═'), 2, 1 /*timestamp,title.*/
langs=0; call reader '
call reader '
#=0 /*the number of categories (so far). */
do j=1 until catHeap=='' /*process the heap of categories. */
parse var catHeap cat.j (sep) catHeap /*get a category from the catHeap. */
parse var cat.j cat.j '<' "(" mems . /*untangle the strange-looking string. */
cat.j=space(cat.j);
if
if \datatype(mems,'W') then iterate /*is the "members" not numeric ? */
#.0=#.0 +
if u.
#.f=#.f + mems; iterate
end
▲ #=#+1; #.#=#.#+mems; @.#=cat.j; @u.#=_ /*bump the counter; assign it (upper).*/
end /*j=1 until ··· */
!.= /*array holds indication of TIED langs.*/
call tell
call tell
call tell
call eSort #,0 /*sort the languages along with number.*/
if tied=='' then pR=r;
if #.j==#.jp | #.j==#.jm then do; !.j= '[tied]'; tied=!.j; end
if #.j==#.jp then do; tR=pR; !tR.j=pR; end
else pR=r
end /*j=# by ···*/
call eSort #, 1 /*sort the languages along with entries*/
rank=0
do t=# by -1 for #
call tell right('rank:' right(!tR.t, w), 20-1) right(!.t, 7),
right('('#.t left("entr"s(#.t, 'ies', "y")')', 9), 20) @.t
end /*#*/
call tell left('', 27) '☼ end─of─list. ☼', 1, 2
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: procedure;
/*──────────────────────────────────────────────────────────────────────────────────────*/
eSort: procedure expose #. @. !tr.; arg N,p2; h=N /*sort by number entries.*/
Line 3,895 ⟶ 3,887:
@=@.j; #=!tR.j; @.j=@.k; !tR.j=!tR.k; @.k=@; !tR.k=#
if h>=j then leave; j=j-h; k=k-h
end /*while !tR
else do while #.k<#.j /*this uses a hard swap ↓*/
@=@.j; #=#.j; @.j=@.k; #.j=#.k; @.k=@; #.k=#
Line 3,904 ⟶ 3,896:
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
reader: arg which 2;
if which=='L' then inFID=
if which=='C' then inFID=
Uyir = 'உயிர்/Uyir'
old.1= 'ΜC++' ; new.1=
old.2= 'UC++' ; new.2=
old.3= 'МК-' ; new.3=
old.4= 'Déjà' ; new.4=
old.5= 'Déjà' ; new.5=
old.6= 'Caché' ; new.6=
old.7= '??-61/52' ; new.7=
old.8= Uyir ; new.8=
do recs=0 while lines(inFID)\==0
$=translate( linein(inFID), , '9'x)
$$=space($); if $$=='' then iterate
do v=1 while old.v\==''
if pos(old.v, $$)
end /*v*/
if
if which=='L' then do
▲ if pos('RETRIEVED FROM',$u)\==0 then leave /*is this a pseudo End-Of-Data (EOD)?*/
if
if left($$, 1)=='*' then $$=sep || space( substr($$, 2) )▼
catHeap=catHeap
end /*recs*/▼
▲ if left($$,1)=='*' then $$=sep || space(substr($$,2))
▲ end /*recs*/
call tell right( commas(recs), 9)
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizer.*/
Line 3,944 ⟶ 3,934:
tell: do '0'arg(2); call lineout outFID," " ; say ; end
call lineout outFID,arg(1) ; say arg(1)
do '0'arg(3); call lineout outFID," " ; say ; end
return /*show BEFORE blank lines (if any), message, show AFTER blank lines.*/</lang>
Some older REXXes don't have a '''changestr''' BIF, so one is included here: ───► [[CHANGESTR.REX]].
<br><br>
|