3 ms·
One example is the magical introduction of special variables. Here's "aif", implemented in PLT Scheme: (require (lib "defmacro.ss")) (define-macro (aif a b
by vegashacker 19y ago
One example is the magical introduction of special variables. Here's "aif", implemented in PLT Scheme:
(require (lib "defmacro.ss"))
(define-macro (aif a b c)
`(let ((it ,a))
(if it ,b ,c)))
(aif (* 10 10) (+ it 1) 'oops) ==> 101
The "aif" form makes it so you don't have to create a temporary variable name first -- the temp var is just assumed to be named "it".
If you're thinking, "whatever, I don't need that" you are wrong. :) Somehow this turns into the most wonderful little line-saver. At my last company, we used it all over the place.
- abstractbill 19y agoYup, I've used aif a lot, but had never got around to implementing it for myself and so hadn't made the connection with variable capture.