in lisp, program's code valid data structure. example, adds 1 , 2 together, it's list of 3 items.
(+ 1 2) what benefit provide? enable that's impossible and/or less elegant in other languages?
to make things little clearer respect code representation, consider in every language code data: need strings. (and perhaps few file operations.) contemplating how helps mimic lisp benefits of having macro system way enlightenment. better if try implement such macro system. you'll run advantages of having structured representation vs flatness of strings, need run transformations first , define "syntactic hooks" tell apply them, etc etc.
but main thing you'll see in of macros convenient facility compiler hooks -- ones hooked on newly created keywords. such, thing needed way have user code interact compiler code. flat strings 1 way it, provide little information macro writer left task of implementing parser scratch. on other hand, expose internal compiler structure pre-parsed ast trees, tend expose information convenient and means compiler needs somehow able parse new syntactic extension intend implement. s-expressions nice solution latter: compiler can parse since syntax uniform. they're solution former, since they're simple structures rich support language taking them apart , re-combining them in new ways.
but of course that's not end of story. example, it's interesting compare plain symbolic macros in cl , hygienic macros in scheme implementations: implemented adding more information represented data, means can more macro system. (you can more cl macros since information available, instead of making part of syntax representation, it's passed environment argument macros.)
Comments
Post a Comment