Parametric polymorphism: Difference between revisions

m
→‎{{header|REXX}}: added labels to each of the node's output, added/changed comments and whitespace.
m (→‎{{header|REXX}}: added labels to each of the node's output, added/changed comments and whitespace.)
Line 952:
=={{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. */
Line 966:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
addStem: nodes=nodes + 1; do j=1 for stems; root.nodes.j=arg(1); end; return
newRoot: parse arg @,stems; nodes=-1; call addStem copies('═',9); call addStem @; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
modRoot: arg #; do j=1 for nodes /*traipse through all the defined nodes*/
do k=1 for stems
if datatype(root.j.k, 'N') then root.j.k=root.j.k + arg(1)# /*add bias.*/
end /*k*/ /* [↑] only add if numeric stem value.*/
end /*j*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
newRootsayNodes: stemsw=arg(2)9; nodes=do -1 j=0 to nodes; _= /*setensure each NODESof the tonodes agets kind of "null"shown. */
do k=1 for stems; _=_ rightcenter(root.j.k, 9w) /*concatenate a node*/
call addStem copies('═', 9); call addStem arg(1)
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
sayNodes: say; do j=0 to nodes; _= /*ensure each of the nodes gets shown. */
do k=1 for stems; _=_ right(root.j.k, 9)
end /*k*/
say substr$=word(_'node='j, 2) 1 + (j<1) ) /*ignoredefine the first (leading)a blank.label for this line's output*/
end say center($, w) substr(_, 2) /*jignore 1st (leading) blank which was */
end /*j*/ /* [↑] caused by concatenation.*/
 
say left('', stems*11) || '('nodes" nodes)" /*also show numbera blank line to ofseparate nodes.outputs*/
return /* [↑] extreme indentation to terminal*/</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
═════════ ═════════ ═════════
node=1 1.00 1.00 1.00
node=2 1.10 1.10 1.10
node=3 1.11 1.11 1.11
node=4 1.12 1.12 1.12
node=5 1.20 1.20 1.20
node=6 1.21 1.21 1.21
node=7 1.22 1.22 1.22
(7 nodes)
 
═════════ ═════════ ═════════
node=1 51.00 51.00 51.00
node=2 51.10 51.10 51.10
node=3 51.11 51.11 51.11
node=4 51.12 51.12 51.12
node=5 51.20 51.20 51.20
node=6 51.21 51.21 51.21
node=7 51.22 51.22 51.22
(7 nodes)
</pre>