1

Dyalog APL allows assigning a vector of multiple values to a corresponding number of multiple not yet defined variables:

      x y←1 2
      ]display x
 
1
 
      ]display y
 
2

How to assign a single value from a single-element vector to a single not yet defined variable?

What I tried:

      (⊂x)←,1
VALUE ERROR: Undefined name: x
      (⊂x)←,1
        ∧
      (,⊂x)←,1
VALUE ERROR: Undefined name: x
      (,⊂x)←,1
         ∧
      (,x)←,1
VALUE ERROR: Undefined name: x
      (,x)←,1
        ∧

This works, but it is too dirty:

      (x x)←,1
      ]display x
 
1

The singleton vector is obtained as one of results of a function, and I want to avoid an additional ←⊃ statement after calling the function.

Olexa
  • 577
  • 2
  • 16
  • 2
    Why do you want to avoid an additional `⊃`? The code `x←⊃MyFunction arg` isn't bad. – Adám May 06 '21 at 15:12
  • Depending on the use case, it might be appropriate to build the ⊃ into the defined function (if there is one). – Paul Mansour May 06 '21 at 15:32
  • Adam, the function returns *several* results. And kind of `foo bar x←{(⊃⍵)(2⊃⍵)(⊃3⊃⍵)}MyFunction` is also not nice. :) – Olexa May 07 '21 at 06:35
  • Paul, enhancing the function is worth considering, of course, but it could cause massive refactoring, so I'd like to check whether an easier way exists first. – Olexa May 07 '21 at 06:38
  • @Olexa Could `foo bar x←⊃@3⊢MyFunction` work for you? – Adám May 09 '21 at 05:40

1 Answers1

0
x _ ← ,1

While this might also be considered a "workaround", I think it's the cleanest and a similar pattern is fairly common in other programming languages, like the ML family (SML, Ocaml, Haskell), Python, JavaScript...

P Varga
  • 19,174
  • 12
  • 70
  • 108