new ← old ##.enss reps                  ⍝ Emulate (∊⍺)←⍵.

Result  [new]  has  the  same  nesting structure as left argument [old] but with
items replaced in enlist order from the (possibly reshaped) array [reps].

[enss]  emulates  enlisted selected specification in that (var←var enss reps) is
the same as (∊var)←reps, where ∊ is enlist (⎕ml>0).

This function was supplied by Veli-Matti Jantunen.

[enss]  is  permissive  about the shape of its right argment. A stricter version
might be:

    enss←{                              ⍝ Emulate (∊⍺)←⍵.
        ⎕ML←2                           ⍝ (∊ is enlist).
        ⍬≡⍴⍵:⍺ ∇(⍴∊⍺)⍴⍵                 ⍝ extend scalar.
        (⍴∊⍺)≢⍴⍵:⎕SIGNAL 5              ⍝ conformability check.
        ⍺{                              ⍝ inner dfn for speed.
            2>≡⍺:(⍴⍺)⍴⍵                 ⍝ simple: shaped values.
            q←∊{(⍴∊⍵)↑1}¨⍺              ⍝ nested: partition vector.
            ⍺ ∇¨(⍴⍺)⍴(~∊0∊¨⍴¨⍺)\q⊂⍵     ⍝ substitute partitioned values.
        }⍵
    }

Examples:

    var←1 2,2+⊂2 3⍴(⍳2),(⊂2+2 3⍴⍳6),9 10,10+,∘⊂/⍳5

    disp var                        ⍝ nastily nested variable.
┌→┬─┬────────────────────────────┐ 
│ │ │┌→─┬──┬────────────────────┐│ 
│ │ │↓3 │4 │       5 6  7       ││
│ │ ││  │  │       8 9 10       ↓│
│ │ │├~─┼~─┼~──────────────────→┤│ 
│ │ ││  │  │┌→─┬───────────────┐││ 
│1│2││  │  ││  │┌→─┬──────────┐│││ 
│ │ ││  │  ││  ││  │┌→─┬─────┐││││ 
│ │ ││11│12││13││14││15│16 17│││││
│ │ ││  │  ││  ││  │└~─┴~───→┘││││ 
│ │ ││  │  ││  │└~─┴─────────→┘│││ 
│ │ ││  │  │└~─┴──────────────→┘││ 
│ │ │└~─┴~─┴───────────────────→┘↓ 
└─┴─┴───────────────────────────→┘ 

    disp var enss 17↑⎕a             ⍝ emulate: (∊var)←17↑⎕a
┌→┬─┬────────────────────┐ 
│ │ │┌→┬─┬──────────────┐│ 
│ │ │↓C│D│     EFG      ││
│ │ ││ │ │     HIJ      ↓│
│ │ │├─┼─┼─────────────→┤│ 
│ │ ││ │ │┌→┬──────────┐││ 
│A│B││ │ ││ │┌→┬──────┐│││ 
│ │ ││ │ ││ ││ │┌→┬──┐││││ 
│ │ ││K│L││M││N││O│PQ│││││
│ │ ││ │ ││ ││ │└─┴─→┘││││ 
│ │ ││ │ ││ │└─┴─────→┘│││ 
│ │ ││ │ │└─┴─────────→┘││ 
│ │ │└─┴─┴─────────────→┘↓ 
└─┴─┴───────────────────→┘ 

    disp var enss 0                 ⍝ scalar 0 extends.
┌→┬─┬─────────────────────┐ 
│ │ │┌→┬─┬───────────────┐│ 
│ │ │↓0│0│     0 0 0     ││
│ │ ││ │ │     0 0 0     ↓│
│ │ │├─┼─┼~─────────────→┤│ 
│ │ ││ │ │┌→┬───────────┐││ 
│0│0││ │ ││ │┌→┬───────┐│││ 
│ │ ││ │ ││ ││ │┌→┬───┐││││ 
│ │ ││0│0││0││0││0│0 0│││││
│ │ ││ │ ││ ││ │└─┴~─→┘││││ 
│ │ ││ │ ││ │└─┴──────→┘│││ 
│ │ ││ │ │└─┴──────────→┘││ 
│ │ │└─┴─┴──────────────→┘↓ 
└─┴─┴────────────────────→┘ 

    disp var enss 2/¨17↑⎕a          ⍝ right arg nesting preserved.
┌→───┬────┬────────────────────────────────────────┐ 
│    │    │┌→───┬────┬────────────────────────────┐│ 
│    │    │↓    │    │         ┌→─┬──┬──┐         ││ 
│    │    ││┌──┐│┌──┐│         ↓EE│FF│GG│         ││
│    │    │││CC│││DD││         ├─→┼─→┼─→┤         ││ 
│    │    ││└─→┘│└─→┘│         │HH│II│JJ│         ││ 
│    │    ││    │    │         └─→┴─→┴─→┘         ↓│ 
│    │    │├────┼────┼───────────────────────────→┤│ 
│┌──┐│┌──┐││    │    │┌→───┬─────────────────────┐││ 
││AA│││BB│││    │    ││    │┌→───┬──────────────┐│││ 
│└─→┘│└─→┘││    │    ││    ││    │┌→───┬───────┐││││ 
│    │    ││┌──┐│┌──┐││┌──┐││┌──┐││┌──┐│┌→─┬──┐│││││ 
│    │    │││KK│││LL││││MM││││NN││││OO│││PP│QQ││││││
│    │    ││└─→┘│└─→┘││└─→┘││└─→┘││└─→┘│└─→┴─→┘│││││ 
│    │    ││    │    ││    ││    │└────┴──────→┘││││ 
│    │    ││    │    ││    │└────┴─────────────→┘│││ 
│    │    ││    │    │└────┴────────────────────→┘││ 
│    │    │└────┴────┴───────────────────────────→┘↓ 
└────┴────┴───────────────────────────────────────→┘ 

See also: mesh enlist sam

Back to: contents

Back to: Dyalog APL

Trouble seeing APL font?