To write such an expressive code D

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 10 15:48:45 PST 2015


F#:

let f = function
     | 0 , 0 , 0 -> 0
     | 0 , 1 , 1 -> 0
     | 1 , 0 , 1 -> 0
     | 1 , 1 , 0 -> 0
     | _         -> 1

for a in 0..1 do
     for b in 0..1 do
         for c in 0..1 do
             printfn "%i xor %i xor %i = %i" a b c (f (a, b, c))

Output:

0 xor 0 xor 0 = 0
0 xor 0 xor 1 = 1
0 xor 1 xor 0 = 1
0 xor 1 xor 1 = 0
1 xor 0 xor 0 = 1
1 xor 0 xor 1 = 0
1 xor 1 xor 0 = 0
1 xor 1 xor 1 = 1

This man again took advantage of the fact that in D there is no 
such operation -> (analog switch).


More information about the Digitalmars-d-learn mailing list