APL Notes: Block Jank

BQN

i←2 ⋄ {i-↩1 ⋄ •Show i}•_while_{𝕊:i>0} @    # immediate block. CPU busywait!
i←2 ⋄ {𝕊:i-↩1 ⋄ •Show i}•_while_{𝕊:i>0} @  # correct
{𝕊: •Show 1} @  # function with short header
{𝕤⋄ •Show 1} @  # function due to no-op self-reference
{𝕤⋄} @          # self-returning function
{𝕊:} @          # error, empty statement
{𝕤: •Show 1} @  # error, has to be 𝕊
{a‿b: •Show b} 1‿2  # destructuring header, prints 2
b←3 ⋄ {b: •Show b} # label, immediate block, prints 3

   # lexical variables and closures are straightforward. Compare to J↓
   Oddgen ← {𝕊: x←¯1 ⋄ {𝕊: x +↩ 2}}
(function block)
   gen ← Oddgen@
(function block)
   Gen¨↕3
⟨ 1 3 5 ⟩

   # not idiomatic at all, but replicating the J version:
   _j ← {_oddgen: {x⇐¯1⋄Set⇐{x↩𝕩}}⊸{𝕨.Set 𝕨.x+2}}
(1-modifier block)
   Gen ← @ _j
{x‿set⇐}⊸(function block)
   Gen¨↕3
⟨ 1 3 5 ⟩

   # this works too:
   f ← 3
3
   F "anything"
3

J

3: 'echo 1'        NB. constant 3, string argument ignored
(3 : 'echo 1') ''  NB. monadic function
(monad : 'echo 1') ''    NB. same with stdlib, not idiomatic
(monad def 'echo 1') ''  NB. same with stdlib, not idiomatic
(3 : ('echo 1';'echo 2')) 10   NB. multi-statement monad, rare!
{{echo 1}}''       NB. dfun syntax defaults to monadic function

NB. normal multiline syntax with y of 0
f =: 3 : 0
echo 1
)

NB. calling it while defining it
(f =: 3 : 0)''
echo 1
)

NB. just a multiline string
0 : 0
echo 1
)

   n=:1 
   f=:{{echo n}}  NB. special character, not the outer variable!
   f''
f('')

   NB. returning a function with closure-like state
   oddgen =: adverb define
ns =. cocreate ''  NB. explicit space to store the state
n__ns =: _1
ns&(dyad : 'n__x =: n__x + 2')
)
   gen =: '' oddgen
   gen"0 i.3
1 3 5