Dyadic: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
A '''dyadic''' function is one that takes an argument on the left and right of the function. Here is an example of a dyadic function named '''deal''' to deal hands of cards:<br/>
A '''dyadic''' function is one that takes an argument on the left and right of the function. Here is an example of a dyadic function named '''deal''' to deal hands of cards:<br/>
<apll>&nbsp;&nbsp;&nbsp;&nbsp;∇ k ← count deal cards;C<br/>
<apll>&nbsp;&nbsp;&nbsp;&nbsp;∇ k ← count deal cards;c<br/>
[1]&nbsp;&nbsp;&nbsp;c ← count<br/>
[1]&nbsp;&nbsp;&nbsp;c ← count<br/>
[2]&nbsp;&nbsp;&nbsp;k ←''<br/>
[2]&nbsp;&nbsp;&nbsp;k ←''<br/>

Revision as of 22:11, 27 February 2013

A dyadic function is one that takes an argument on the left and right of the function. Here is an example of a dyadic function named deal to deal hands of cards:
    ∇ k ← count deal cards;c
[1]   c ← count
[2]   k ←''
[3]   Q:
[4]   k ← k, cards ? 52
[5]   c ← c-1
[6]   →(c>0)/Q
[7]   k←count cards ⍴ k
    ∇
So an execution of this function to deal 6 hands of 7 cards could produce the following:
      6 deal 7
 28  1  8 24 32 47 27
 38 46  1 43  3 40  7
 47 28 26  7 39  2 37
 36 12 48 46 47 31 13
 24 52 13 25 20 30 47
 23 25 43 21 15 52 14

The numbers generated would have to be related to a rank and suit to display a particular card.

Some system functions are dyadic, in that you may present them one argument on each side of the function name, and it may return a value. The ⎕FMT function provides specialized formatting when used as a dyadic function.

See Also