⍝ Macros.tc ⍝ ---------------------------------- ⍝ Test the equivalence of: ⍝ 1. the build-in dyadic EACH operator (A f ¨ B when f is primitive) ⍝ 2. the build-in dyadic EACH macros (A f ¨ B when f is defined) ⍝ ⍝ initialize ⎕RVAL ⊣0 ⎕RVAL 8↑256|⎕TS ⍝ set A and B to values with the same structure but different ravels ⍝ A←B←10000∣⎕RVAL 2 2 (0 10 0 0 1) 3 (∈A)←1⌽∈B ⍝ set S to a random integer scalar ⍝ S←100 | ⎕RVAL '' ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ ⍝ compute the build-in operator dyadic EACH for the primitive + ⍝ SS←S +¨ S ⍝ scalar /scalar SB←S +¨ B ⍝ scalar /array AS←A +¨ S ⍝ array /scalar AB←A +¨ B ⍝ array /array ⍝ create a defined function ⍝ ∇Z←A PLUS B Z←A + B ∇ ⍝ check that EACH with the defined function ⍝ is equivalent to EACH with the prmitive function ⍝ SS ≡ S PLUS ¨ S 1 SB ≡ S PLUS ¨ B 1 AS ≡ A PLUS ¨ S 1 AB ≡ A PLUS ¨ B 1 ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ ⍝ compute the build-in operator dyadic EACH for the primitive , ⍝ SS←S ,¨ S ⍝ scalar /scalar SB←S ,¨ B ⍝ scalar /array AS←A ,¨ S ⍝ array /scalar AB←A ,¨ B ⍝ array /array ⍝ create a defined function which changes the shape ⍝ ∇Z←A COMMA B Z←A , B ∇ ⍝ check that EACH with the defined function ⍝ is equivalent to EACH with the prmitive function ⍝ SS ≡ S COMMA ¨ S 1 SB ≡ S COMMA ¨ B 1 AS ≡ A COMMA ¨ S 1 AB ≡ A COMMA ¨ B 1 ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ ⍝ compute the build-in operator dyadic EACH for the primitive ≡ ⍝ SS←S ≡¨ S ⍝ scalar /scalar SB←S ≡¨ B ⍝ scalar /array AS←A ≡¨ S ⍝ array /scalar AB←A ≡¨ B ⍝ array /array ⍝ create a defined function ⍝ ∇Z←A EQUIV B Z←A ≡ B ∇ ⍝ check that EACH with the defined function ⍝ is equivalent to EACH with the prmitive function ⍝ SS ≡ S EQUIV ¨ S 1 SB ≡ S EQUIV ¨ B 1 AS ≡ A EQUIV ¨ S 1 AB ≡ A EQUIV ¨ B 1 ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ ⍝ ∇Z←A RANDOM_REPLACE B;VB;VS ⍝ ⍝ randomly replace half of the top-level items of B with A ⍝ VB←,B ⍝ keep it simple VS←{2|⎕RVAL '' ⊣ ⍵ } ¨VB ⍝ random 0/1 vector of length ⍴VB (VS/VB)←A ⍝ replace random subset with A Z←(⍴B)⍴VB ∇ QA←S RANDOM_REPLACE A QB←S RANDOM_REPLACE B (QA , ¨ QB) ≡ (QA COMMA ¨ QB) 1 )SIC )ERASE A B S SS SB AS AB PLUS COMMA