'if' as a _function_, in Scheme and Python

Andy Gaynor silver at mail.webspan.net
Fri Aug 20 01:12:54 CEST 1999


Consider:

    (define (boolean->integer x)
      (if x 1 0))

    (define (if-function condition consequent-thunk alternate-thunk)
      ((vector-ref `#(,alternate-thunk ,consequent-thunk)
                   (boolean->integer condition))))

That is, `if' can well be thought of as syntactic sugar for a particularly
easy-to-optimize `case' expression.

Regards, [Ag]   Andy Gaynor   silver at mail.webspan.net




More information about the Python-list mailing list