3 ms·
The with-x style macros can indeed be replaced by functions that take a closure. E.g. in Scheme you have the function (call-with-input-file string proc). The m
by pg314 11y ago
The with-x style macros can indeed be replaced by functions that take a closure. E.g. in Scheme you have the function (call-with-input-file string proc).
The macro is slightly more concise. Contrast
(with-input-file (x "x") (print (read x))) ; Common Lisp
with
(call-with-input-file "x" (lambda (x) (print (read x)))) ; Scheme
- chaoky 11y agoNo runtime consing of closures either! In fact, in Common Lisp there is a style of writing call-with-foo that takes a closure and wrapping that with a macro with-foo. Since the macro abstracts that detail of having call-with, it is much more flexible. For example the macro could expand some stuff known at compile time and do some compile time computation too., instead of the closure consing function.