git @ Cat's Eye Technologies Robin / master stdlib / xor.robin
master

Tree @master (Download .tar.gz)

xor.robin @masterraw · history · blame

;'<<SPEC'

    -> Tests for functionality "Evaluate Robin Expression (with Boolean)"

`xor` evaluates both of its arguments to boolean, then evaluates to
the "exclusive-or" of those booleans.

    | (xor #t #t)
    = #f

    | (xor #t #f)
    = #t

    | (xor #f #t)
    = #t

    | (xor #f #f)
    = #f

`xor` expects exactly two arguments.

    | (xor #f)
    ? abort (illegal-arguments

    | (xor #t #f #f)
    ? abort (illegal-arguments

`xor` expects both of its arguments to be booleans.

    | (xor 100 #t)
    ? abort (expected-boolean 100)

    | (xor #t 99)
    ? abort (expected-boolean 99)

This test demonstrates that these functions really do evaluate their
arguments.

    | (and (or (xor (and #t (not (not #t))) #f) #f) #t)
    = #t

'<<SPEC'

(define xor (fun (a b)
  (or (and a (not b)) (and (not a) b))))