'if' as a _function_, in Scheme and Python

Andy Gaynor silver at mail.webspan.net
Thu Aug 19 19:12:54 EDT 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