Where 0. Definition Monadic function: ⍸⍵ Commonly, ⍸⍵ (where) is ⍵/⍳⍴⍵ for boolean vector ⍵ ;
in general, ⍵ is a boolean array and ⍸⍵ is (,⍵)/,⍳⍴⍵ .
1. Examples ⎕io←1 ⍸ 1 0 1 0 0 0 0 1 0 1 3 8 3 4⍴0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 ⍸ 3 4 ⍴ 0 1 1 ┌───┬───┬───┬───┬───┬───┬───┬───┐ │1 2│1 3│2 1│2 2│2 4│3 1│3 3│3 4│ └───┴───┴───┴───┴───┴───┴───┴───┘ ⍸ 3 1 4 2 DOMAIN ERROR ⍸3 1 4 2 ∧ 2. Model I←{(,~~⍵)/,⍳⍴⍵} The ~~ is to enforce that ⍵ must be boolean. 2.1 Tests assert←{⍺←'assertion failure' ⋄ 0∊⍵:⍺ ⎕SIGNAL 8 ⋄ shy←0} Err ←{0::⎕IO⊃⎕DM ⋄ 0=⎕NC'⍺':⍺⍺ ⍵ ⋄ ⍺ ⍺⍺ ⍵} z←test_where io;⎕io ⍝ tests on monadic ⍸ ⎕io←io assert(⎕io+1 3)≡⍸0 1 0 1 assert(⎕io+(0 1)(1 0)(1 2))≡⍸2 3⍴0 1 assert(0 1/¨⊂⊂⍬)≡(⍸0)(⍸1) assert(⎕io+1 3)≡⍸1+0 1 0 1-1 assert(⎕io+1 3)≡⍸⊃11 83 ⎕DR 0 1 0 1 assert(⎕io+(0 1)(1 1)(1 2))≡⍸2 3⍴1+0 1 0 0 1 1-1 assert(⎕io+(0 1)(1 1)(1 2))≡⍸2 3⍴0 1 0 0 1 1 assert(⎕io+1 4 5)≡⍸1+0 1 0 0 1 1-1 assert(⎕io+1 4 5)≡⍸0 1 0 0 1 1 assert'DOMAIN ERROR'≡⍸Err 2 3⍴⍳6 assert'DOMAIN ERROR'≡⍸Err 1 2 3 z←1⊣2 ⎕NQ'.' 'wscheck' 3. Symbol ⍸ (Unicode 0x2378) is the proposed symbol for where.
4. Notes Where is a primitive in NARS2000 (⍸), J (I.), k (&), and q (where) and is an idiom in Dyalog APL (b/⍳⍴b or b/⍳n). ⍸ is as efficient as the idioms b/⍳⍴b and b/⍳n .
|