Apply a callback to an array: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added DO-END labels, added comments, added whitespace. -- ~~~~) |
|||
Line 1,517: | Line 1,517: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program to apply a callback to |
<lang rexx>/*REXX program to apply a callback to a stemmed (REXX) array. */ |
||
a.=; b.= |
a.=; b.= |
||
a.0= 0 |
a.0= 0 |
||
Line 1,534: | Line 1,534: | ||
call bangit 'a','b' /*factorialize the A array, store results in B */ |
call bangit 'a','b' /*factorialize the A array, store results in B */ |
||
call listab ' after' |
call listab ' after' |
||
exit /*stick a fork in it, we're done.*/ |
|||
exit |
|||
/*──────────────────────────────────BANGIT subroutine───────────────────*/ |
|||
/*─────────────────────────────────────BANGIT subroutine────────────────*/ |
|||
bangit: do |
bangit: do i=0 |
||
_=value(arg(1)'.' |
_=value(arg(1)'.'i); if _=='' then return |
||
call value arg(2)'.' |
call value arg(2)'.'i,fact(_) |
||
end |
end /*i*/ |
||
/*──────────────────────────────────FACT subroutine─────────────────────*/ |
|||
/*─────────────────────────────────────FACT subroutine──────────────────*/ |
|||
fact: procedure; !=1; do j=2 to arg(1); !=!*j; end; return ! |
fact: procedure; !=1; do j=2 to arg(1); !=!*j; end; return ! |
||
/*──────────────────────────────────LISTAB subroutine───────────────────*/ |
|||
/*─────────────────────────────────────LISTAB subroutine────────────────*/ |
|||
listab: do j=0 while a.j\=='' |
listab: do j=0 while a.j\==''; say arg(1) 'a.'j"="a.j; end /*j*/ |
||
say arg(1) ' |
say; do k=0 while b.k\==''; say arg(1) 'b.'k"="b.k; end /*k*/ |
||
end |
|||
say |
|||
do j=0 while b.j\=='' |
|||
say arg(1) 'b.'j"="b.j |
|||
end |
|||
return</lang> |
return</lang> |
||
'''output''' |
'''output''' |