Jump to content

First class environments: Difference between revisions

m
→‎{{header|REXX}}: changed comments and indentations and outout glyphs. -- ~~~~
(Omit from Go)
m (→‎{{header|REXX}}: changed comments and indentations and outout glyphs. -- ~~~~)
Line 420:
=={{header|REXX}}==
<lang rexx>/*REXX program illustrates first-class environments (using hailstone #s)*/
parse arg #envs .; env_.=; if #envs=='' then #envs=12
 
/*═════════════════════════════════════initialize (twelve) environments.*/
parse arg #envs .; env_.=; if #envs=='' then #envs=12
do init=1 for #envs; env_.init=init; end
 
/*═════════════════════════════════════process environments until done. */
/*─────────────────────────────────────initialize (twelve) environments.*/
do init=1 for #envs;do forever until env_.init=init0; end env_.0=1
do k=1 for #envs
 
/*─────────────────────────────────────process environments until done. */
do forever until env_.0; env_.0=1
do k=1 for #envs
env_.k=env_.k hailstone(k) /*where the rubber meets the road*/
end /*k*/
end /*forever*/
 
/*─────────────────────────────────────show═════════════════════════════════════show results in tabular form. */
count=0; do lines=-1 until _==''; _=
count=0
do j=1 for #envs
 
end /* select*/
do lines=-1 until _==''; _=
when count== 1 then _=_ right(words(env_.j)-1,3)
do j=1 for #envs
select when lines==-1 then _=_ right(j,3)
when countlines== 10 then _=_ right(words(env_.j)-1'',3,'─')
when lines==-1 then otherwise _=_ right(word(env_.j,lines),3)
when lines== 0 then _=_ right('',3,'-') end /*select*/
otherwise end _=_ right(word(env_. /*j,lines),3)*/
end /*select*/
end /*j*/
if count==1 then count=2
_=strip(_,'T')
if _=='' then count=count+1
if count==1 then _=copies(' ===',#envs)
if _\=='' then say substr(_,2)
end /*lines*/
 
if count==1 then count=2
exit
_=strip(_,'T')
if _=='' then count=count+1
if count==1 then _=copies(' ===═══',#envs)
if _\=='' then say substr(_,2)
end /*jlines*/
exit /*stick a fork in it, we're done.*/
 
/*─────────────────────────────────────HAILSTONE (Collatz) subroutine───*/
hailstone: procedure expose env_.; arg n; _=word(env_.n,words(env_.n))
if _==1 then return ''; env_.0=0; if _//2==0 then return _%2; return _*3+1</lang>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 11 12
─── ─── ─── ─── ─── ─── ─── ─── ─── ─── ─── ───
--- --- --- --- --- --- --- --- --- --- --- ---
1 2 3 4 5 6 7 8 9 10 11 12
1 10 2 16 3 22 4 28 5 34 6
Line 481 ⟶ 478:
2
1
═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══ ═══
=== === === === === === === === === === === ===
0 1 7 2 5 8 16 3 19 6 14 9
</pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.