Parametric polymorphism: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Removed blank line from output.)
m (→‎{{header|REXX}}: added/changed comments and whitespace.)
Line 1,073: Line 1,073:
=={{header|REXX}}==
=={{header|REXX}}==
This REXX programming example is modeled after the   '''D'''   example.
This REXX programming example is modeled after the   '''D'''   example.
<lang rexx>/*REXX program demonstrates (with displays) a method of parametric polymorphism. */
<lang rexx>/*REXX program demonstrates (with displays) a method of parametric polymorphism. */
call newRoot 1.00, 3 /*new root, and also indicate 3 stems.*/
call newRoot 1.00, 3 /*new root, and also indicate 3 stems.*/
/* [↓] no need to label the stems. */
/* [↓] no need to label the stems. */
Line 1,087: Line 1,087:
exit /*stick a fork in it, we're all done. */
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
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
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*/
modRoot: arg #; do j=1 for nodes /*traipse through all the defined nodes*/
do k=1 for stems
do k=1 for stems /*add bias ──►───────────────────────┐ */
if datatype(root.j.k,'N') then root.j.k=root.j.k + # /*add bias.*/
if datatype(root.j.k, 'N') then root.j.k= root.j.k + # /* ◄───┘ */
end /*k*/ /* [↑] only add if numeric stem value.*/
end /*k*/ /* [↑] add if stem value is numeric.*/
end /*j*/
end /*j*/
return
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
sayNodes: w=9; do j=0 to nodes; _= /*ensure each of the nodes gets shown. */
sayNodes: w= 9; do j=0 to nodes; _= /*ensure each of the nodes gets shown. */
do k=1 for stems; _=_ center(root.j.k, w) /*concatenate a node*/
do k=1 for stems; _= _ center(root.j.k, w) /*concatenate a node.*/
end /*k*/
end /*k*/
$=word('node='j, 1 + (j<1) ) /*define a label for this line's output*/
$= word('node='j, 1 + (j<1) ) /*define a label for this line's output*/
say center($, w) substr(_, 2) /*ignore 1st (leading) blank which was */
say center($, w) substr(_, 2) /*ignore 1st (leading) blank which was */
end /*j*/ /* [↑] caused by concatenation.*/
end /*j*/ /* [↑] caused by concatenation.*/
say /*show a blank line to separate outputs*/
say /*show a blank line to separate outputs*/
return /* [↑] extreme indentation to terminal*/</lang>
return</lang>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>