Anonymous user
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. */
do k=1 for #envs▼
▲ do k=1 for #envs
env_.k=env_.k hailstone(k) /*where the rubber meets the road*/
end /*k*/
end /*forever*/
/*
count=0; do lines=-1 until _==''; _=▼
do j=1 for #envs▼
▲ do lines=-1 until _==''; _=
when count== 1 then _=_ right(words(env_.j)-1,3)
▲ do j=1 for #envs
when
▲ 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)▼
▲ if count==1 then count=2
▲ _=strip(_,'T')
▲ if _=='' then count=count+1
▲ if _\=='' then say substr(_,2)
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>
|