衛生宏

維基百科,自由的百科全書

衛生宏(英語:hygienic macro),又稱乾淨宏,是指其擴展保證不會導致意外捕獲標識符的Scheme[1]Dylan[2]Rust[3]NimJulia程式語言都有這一特性。在引入衛生宏之前,Lisp社區有眾所周知的意外捕獲的問題。宏編寫者會使用產生唯一標識符的語言特性(如gensym)或使用混淆的標識符來避免這一問題。衛生宏是對捕獲問題的一種程序化解決方案,集成在宏擴展器本身中。「衛生」這一術語是在Kohlbecker等人1986年的論文中創造的,靈感來自數學中使用的術語。[4]

參考文獻[編輯]

  1. ^ schemers.org: Documents: Standards: R5RS. schemers.org. [2022-08-19]. (原始內容存檔於2022-08-11). 
  2. ^ Barrett, Kim; Cassels, Bob; Haahr, Paul; Moon, David A.; Playford, Keith; Withington, P. Tucker. A monotonic superclass linearization for Dylan. Proceedings of the 11th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications - OOPSLA '96 (New York, New York, USA: ACM Press). 1996. doi:10.1145/236337.236343. 
  3. ^ Macros and metaprogramming - Rust for the Polyglot Programmer. www.chiark.greenend.org.uk. [2022-08-19]. (原始內容存檔於2021-10-06) (英語). 
  4. ^ Kohlbecker, E.; Friedman, D. P.; Felleisen, M.; Duba, B. Hygienic Macro Expansion (PDF). ACM conference on LISP and functional programming. 1986 [2022-08-19]. (原始內容存檔 (PDF)於2017-08-29).