{"id":20,"date":"2003-05-21T20:54:08","date_gmt":"2003-05-21T19:54:08","guid":{"rendered":"http:\/\/www.nobugs.org\/blog\/archives\/2003\/05\/21\/this-sentence-is-false\/"},"modified":"2003-05-21T20:54:08","modified_gmt":"2003-05-21T19:54:08","slug":"this-sentence-is-false","status":"publish","type":"post","link":"https:\/\/www.nobugs.org\/blog\/archives\/2003\/05\/21\/this-sentence-is-false\/","title":{"rendered":"This sentence is false"},"content":{"rendered":"<ul>\n<li>I write programs to solve problems.<\/li>\n<li>I spend a lot of time writing these programs.<\/li>\n<li>During this time, <i>problems relating to programming<\/i> pop up.<\/li>\n<li>I want to solve <i>these<\/i> problems too!<\/li>\n<\/ul>\n<p>If you want to start writing tools which manipulate programs, you require a vocabulary which includes nouns like &#8220;type&#8221; and &#8220;function&#8221; and &#8220;literal&#8221;.   Most sane people think of, say, <a href=\"http:\/\/www.mozilla.org\">mozilla<\/a> as a program which you execute, but today I&#8217;m thinking of it as a <i>dataset<\/i>.  I&#8217;m not going to run mozilla &#8211; I&#8217;m going to process it!<br \/>\n<!--more--><br \/>\nLisp fans are used to this program\/data duality.  The list <tt>(+ 1 2)<\/tt> consists of three elements &#8211; the &#8220;plus&#8221; symbol, the &#8220;one&#8221; symbol and the &#8220;two&#8221; symbol.  It looks like plain old data until you pass it to the eval function, whereupon it reveals its true guise as a program for calculating the sum of one and two.  But, it&#8217;s still data.  We can ask how long the list is.  We can append\/cons another element onto the end of the list and make a new program.  And then we can run that new program!<\/p>\n<p>Lispers are lucky.  The main data structure in lisp also happens to be the construct uses to express programs.  What are the chances of that, eh?  It&#8217;s very handy.<\/p>\n<p>C++ monkeys have a harder time.  When we write source code, we edit an ASCII text document.  The compiler processes it and spits out a binary.  At no point does our C++ source take on the guise of a C++ dataset.  You never see CppFunction or CppDeclaration objects flying around the office.<\/p>\n<p>Well, that&#8217;s not totally true.  The compiler does build up an internal representation of your source code, but it&#8217;s safely locked away from you.  It&#8217;s called an abstract syntax tree.  Even if you could get at the AST, each compiler uses it&#8217;s own different representation for the tree and it&#8217;s associate type and location information.   It&#8217;s hard to contemplate writing programs to manipulate C++ programs, when there&#8217;s no standard way to represent C++ source code as C++ data.<\/p>\n<p>Furthermore, the task of transforming ASCII C++ source code into a structure dataset is pretty formidable.  It&#8217;s certainly <i>do-able<\/i>, since all C++ compilers do it.  It&#8217;s just really quite difficult to do properly, and it&#8217;d probably take you  years rather than months to write a black box to do it. <\/p>\n<p>Lisp doesn&#8217;t have this problem.  You go from &#8220;lisp source&#8221; to &#8220;lisp data&#8221; in one trivial step.  Smalltalk doesn&#8217;t have this problem either.   It&#8217;s a bit closer to C++ than lisp in that you write the smalltalk source code as ascii text, and then it gets parsed into objects.  So, the source code for your &#8220;foo&#8221; method gets transformed into a MethodNode object, and from there into compiler bytecode.  But if you want to turn your smalltalk source code into smalltalk data, there&#8217;s a black box which you can pick up and use.<\/p>\n<p>But there&#8217;s no such black box to turn C++ source code into C++ data.   The best I&#8217;ve seen is <a href=\"http:\/\/www.csg.is.titech.ac.jp\/~chiba\/openc++.html\">OpenC++<\/a>, which is pretty damn good, but it&#8217;s a shame that it isn&#8217;t integrated with a compiler.  Hey, that&#8217;d require that everyone agreed on a standard representation of C++ source as C++ data.  The gcc compiler uses it&#8217;s own abstract syntax tree representation, which is different from the one used by OpenC++, so you can&#8217;t just plug them together.<\/p>\n<p>This annoys me.  I want to write tools which manipulate C++ source code.  There is a hard, but solved, problem of turning C++ source code into C++ data.  But there&#8217;s very few people out there who have produced a black boxes to do it.  EDG sell a compiler front-end which does it, and OpenC++ exposes visitor-pattern access to it.  Everyone else&#8217;s effort is tangled up in some-or-other compiler.<\/p>\n<p>I&#8217;ve wrote this entry from a C++ programmer&#8217;s point-of-view.  Actually, I&#8217;d be quite happy to receive a black box which turned my C++ source into  a dataset which ocaml or smalltalk could play with.  The best of all worlds would be a language-independent presentation.  I&#8217;ve just reminded myself of the <a href=\"http:\/\/asdl.sourceforge.net\/\">ASDL<\/a> project which does exactly that.<\/p>\n<p>A program language which can be used to describe itself is a very powerful thing.  You can build all sorts of useful tools with it. These tools can do all the hard work, and you get to go home early.<\/p>\n<p>Must now have a deeper look at <a href=\"http:\/\/www.csg.is.titech.ac.jp\/~chiba\/openc++.html\">OpenC++<\/a>, <a href=\"http:\/\/asdl.sourceforge.net\/\">ASDL<\/a>, <a href=\"http:\/\/www.southern-storm.com.au\/treecc.html\">TreeCC<\/a> and <a href=\"http:\/\/ivs.cs.uni-magdeburg.de\/~puma\/\">PUMA<\/a>.<\/p>\n<p>Update:  I came across <a href=\"http:\/\/www2.parc.com\/csl\/groups\/sda\/publications\/papers\/Kiczales-TUT95\/\">this online book<\/a> which describes exactly what I&#8217;m talking about.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I write programs to solve problems. I spend a lot of time writing these programs. During this time, problems relating to programming pop up. I want to solve these problems too! If you want to start writing tools which manipulate programs, you require a vocabulary which includes nouns like &#8220;type&#8221; and &#8220;function&#8221; and &#8220;literal&#8221;. Most [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":0,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nobugs.org\/blog\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}