Parametric polymorphism: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, changed separator.
m (Sorry I meant C# not C++!)
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed separator.)
Line 870:
=={{header|REXX}}==
This REXX programming example is modeled after the   '''D'''   example.
<lang rexx>/*REXX program demonstrates (with displays) a method of parametric polymorphism in REXX.*/
call newRoot 1.00, 3 /*new root, and also indicate 3 stems. */
/* [↓] no need to label the stems. */
call addStem 1.10 /*a new stem and its initial value. */
call addStem 1.11 /*" " " " " " " */
call addStem 1.12 /*" " " " " " " */
call addStem 1.20 /*" " " " " " " */
call addStem 1.21 /*" " " " " " " */
call addStem 1.22 /*" " " " " " " */
call sayNodes call sayNodes /*display some nicely formatted values.*/
call modRoot 50 /*MODmodRoot will add 50fifty to all stems. */
call sayNodes call sayNodes /*display some nicely formatted values.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────MODROOT─────────────────────────────*/
modRootaddStem: nodes=nodes+1; do j=1 for nodesstems; root.nodes.j=arg(1); end; /*traipse through all the nodes. */return
/*──────────────────────────────────────────────────────────────────────────────────────*/
do k=1 for stems; _=root.j.k; ?=datatype(_,'N')
modRoot: do j=1 for nodes if ? then root.j.k=_+arg(1) /*cantraipse through stemall bethe addeddefined to?nodes*/
end do /*k*/=1 for /* [↑] only add if it's numeric.*/stems
end if datatype(root.j.k, 'N') then root.j.k=root.j.k + arg(1) /*jbias.*/
end /*k*/ /* [↑] only add if numeric stem value.*/
return
end /*j*/
/*──────────────────────────────────NEWROOT─────────────────────────────*/
return
newRoot: stems=arg(2); nodes=-1; /*set NODES to a kind of "null". */
/*──────────────────────────────────────────────────────────────────────────────────────*/
call addStem copies('─',9); call addStem arg(1)
newRoot: stems=arg(2); nodes= -1; /*set NODES to a kind of "null". */
return
call addStem copies('', 9); call addStem arg(1)
/*──────────────────────────────────SAYNODES────────────────────────────*/
return
sayNodes: say; do j=0 to nodes; _= /*each node gets shown*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
do k=1 for stems; _=_ right(root.j.k,9); end /*k*/
sayNodes: say; do j=0 to nodes; say substr(_,2)= /*ensure each of the nodes gets shown. /*ignore the 1st blank*/
do k=1 for stems; _=_ right(root.j.k;, ?=datatype(_,'N'9)
end /*k*/
say substr(_, 2) /*ignore the first (leading) blank. */
end /*j*/
 
say left('', stems*9+stems11) || '('nodes" nodes)" /*also show #number of nodes.*/
return</lang>
{{out|output|text=&nbsp; when using the default input:}}
/*──────────────────────────────────ADDSTEM─────────────────────────────*/
addStem: nodes=nodes+1; do j=1 for stems; root.nodes.j=arg(1); end /*j*/
return</lang>
'''output'''
<pre>
═════════ ═════════ ═════════
───────── ───────── ─────────
1.00 1.00 1.00
1.10 1.10 1.10
Line 915:
1.21 1.21 1.21
1.22 1.22 1.22
(7 nodes)
 
═════════ ═════════ ═════════
───────── ───────── ─────────
51.00 51.00 51.00
51.10 51.10 51.10
Line 925:
51.21 51.21 51.21
51.22 51.22 51.22
(7 nodes)
</pre>