{"id":98,"date":"2008-04-21T22:33:07","date_gmt":"2008-04-22T04:33:07","guid":{"rendered":"http:\/\/www.philhassey.com\/blog\/2008\/04\/21\/tinypy-did-i-mention-metaprogramming\/"},"modified":"2008-04-21T22:33:07","modified_gmt":"2008-04-22T04:33:07","slug":"tinypy-did-i-mention-metaprogramming","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2008\/04\/21\/tinypy-did-i-mention-metaprogramming\/","title":{"rendered":"tinypy: did i mention metaprogramming?"},"content":{"rendered":"<p>For the sake of this post, I&#8217;m going to pretend to know what metaprogramming* is.\u00c2\u00a0 Yeah, so <a href=\"http:\/\/www.tinypy.org\">tinypy<\/a>** totally has that.\u00c2\u00a0 At least, since the parser and compiler in tinypy is written in tinypy, you are able to modify those modules on-the-fly and add new features into the tinypy language.\u00c2\u00a0 (Not that you&#8217;d want to, but certain other languages get so uppity about being able to do that, I figured I&#8217;d plug for tinypy here.)<\/p>\n<p>For example, (at present) tinypy doesn&#8217;t have support for decorators.\u00c2\u00a0 I&#8217;ve always liked decorators, so I made <a href=\"https:\/\/www.philhassey.com\/blog\/wp-content\/uploads\/2008\/04\/deco.zip\" title=\"deco.zip\">this code<\/a> (a zip of main.py, deco.py***, and test.py) so that if you have a main.py:<\/p>\n<p>import deco<br \/>\nimport test<\/p>\n<p>When the deco module is loaded, it cleanly**** adds decorator support into the tokenize, parse, and encode modules of tinypy.\u00c2\u00a0 Then when the test module is loaded, it is able to use decorator syntax.\u00c2\u00a0 Yay!\u00c2\u00a0 This mostly thanks to the <a href=\"http:\/\/javascript.crockford.com\/tdop\/index.html\">top down operator precedence<\/a> implementation in tinypy.<\/p>\n<p>So now, if say, you have some crazy idea for how the $ operator should be used in bigpy, you can go ahead and use metaprogramming to add it into tinypy and show all your friends how awful your new syntax looks and have a working proof-of-concept!\u00c2\u00a0 Yay!<\/p>\n<p>* feel free to enlighten me<br \/>\n** it&#8217;s got a <a href=\"http:\/\/www.tinypy.org\/community.html\">mailing list<\/a> now, join in on all the fun!!<br \/>\n*** only 611 bytes :)\u00c2\u00a0 They were pretty simple to implement, since they really just mean: &#8220;given &#8216;@a \\n def b &#8230;&#8217; do &#8216;def b &#8230; \\n b=a(b)'&#8221;<br \/>\n**** Since all the language features are stored in dictionaries, it&#8217;s &#8220;pretty easy&#8221; to add new symbols \/ operators.\u00c2\u00a0 (Or remove features, or whatever!)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the sake of this post, I&#8217;m going to pretend to know what metaprogramming* is.\u00c2\u00a0 Yeah, so tinypy** totally has that.\u00c2\u00a0 At least, since the parser and compiler in tinypy is written in tinypy, you are able to modify those modules on-the-fly and add new features into the tinypy language.\u00c2\u00a0 (Not that you&#8217;d want to, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,6,8,2,32],"tags":[42,41,40],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-crazy","category-development","category-languages","category-python","category-tinypy","tag-decorators","tag-macros","tag-metaprogramming"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":0,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}