3 ms·
Excellent points. > In a language with good metaprogramming facilities, the parser is written in the language ... it integrates better with the language. Your
by arohner 17y ago
Excellent points.
> In a language with good metaprogramming facilities, the parser is written in the language ... it integrates better with the language.
Your point was about how a good language makes it easy to parse another language into your desired langauge. I recently noticed the converse is true too. A good language makes it easy to output code in another language
In Clojure (and I suspect other lisps), it is quite common to see clojure literals used to generate code in other languages. i.e. in compojure, a webapp framework, the html generation code is entirely clojure literals:
(html [:body [:div [:a {:href "www.google.com"} "click me"]]])
generates:
<body><div><a href="www.google.com">click me</a></div></body>
There are plenty of examples of this for html generation, SQL generation, and in one CL library, even C source code generation.
- catch404 17y agoIs it possible to do a similar construct in python? This is what I'm really after, a Lisp like ability to generate html, sql combined with the rest of the Python language. Perhaps I should be looking into ruby more? or a python parser? I'm working on a similar technique for python (using lists and function lookups but it's still more verbose than the lisp style ones) ('p','this is a paragraph') vs (p, "this is a paragraph") as a small example