Skip to main content
non-scalar example
Source Link
Adám
  • 656
  • 3
  • 11

I'm writing a small utility operator which applies two functions to an argument pair and strands the results. The pair can either be given as two arguments or as a single argument with two elements. Either way, the left operand is applied to the left value and the right operand to the right value:

_n_←{⍺←⊢ ⋄ (a b)←⍺ ⍵ ⋄ (⍺⍺ a)(⍵⍵ b)}

Here is example usage for computing the factorial and the negation:

      4 !_n_- 10
16 ¯10
      !_n_- 4 10
16 ¯10

And here's the reverse and the unique:

      3 1 4 1 5⌽_n_∪2 7 1 8
┌─────────┬───────┐
│5 1 4 1 3│2 7 1 8│
└─────────┴───────┘
      ⌽_n_∪(3 1 4 1 5)(2 7 1 8)
┌─────────┬───────┐
│5 1 4 1 3│2 7 1 8│
└─────────┴───────┘

However, this seems like a lot of plumbing for what is essentially a trivial operator. Can it be done more elegantly?

I'm writing a small utility operator which applies two functions to an argument pair and strands the results. The pair can either be given as two arguments or as a single argument with two elements. Either way, the left operand is applied to the left value and the right operand to the right value:

_n_←{⍺←⊢ ⋄ (a b)←⍺ ⍵ ⋄ (⍺⍺ a)(⍵⍵ b)}

Here is example usage for computing the factorial and the negation:

      4 !_n_- 10
16 ¯10
      !_n_- 4 10
16 ¯10

However, this seems like a lot of plumbing for what is essentially a trivial operator. Can it be done more elegantly?

I'm writing a small utility operator which applies two functions to an argument pair and strands the results. The pair can either be given as two arguments or as a single argument with two elements. Either way, the left operand is applied to the left value and the right operand to the right value:

_n_←{⍺←⊢ ⋄ (a b)←⍺ ⍵ ⋄ (⍺⍺ a)(⍵⍵ b)}

Here is example usage for computing the factorial and the negation:

      4 !_n_- 10
16 ¯10
      !_n_- 4 10
16 ¯10

And here's the reverse and the unique:

      3 1 4 1 5⌽_n_∪2 7 1 8
┌─────────┬───────┐
│5 1 4 1 3│2 7 1 8│
└─────────┴───────┘
      ⌽_n_∪(3 1 4 1 5)(2 7 1 8)
┌─────────┬───────┐
│5 1 4 1 3│2 7 1 8│
└─────────┴───────┘

However, this seems like a lot of plumbing for what is essentially a trivial operator. Can it be done more elegantly?

Source Link
Adám
  • 656
  • 3
  • 11

Dyalog APL dyadic operator deriving ambivalent function to pair two function results

I'm writing a small utility operator which applies two functions to an argument pair and strands the results. The pair can either be given as two arguments or as a single argument with two elements. Either way, the left operand is applied to the left value and the right operand to the right value:

_n_←{⍺←⊢ ⋄ (a b)←⍺ ⍵ ⋄ (⍺⍺ a)(⍵⍵ b)}

Here is example usage for computing the factorial and the negation:

      4 !_n_- 10
16 ¯10
      !_n_- 4 10
16 ¯10

However, this seems like a lot of plumbing for what is essentially a trivial operator. Can it be done more elegantly?