<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Comments for page &quot;Where are Python macros?&quot;</title>
		<link>http://250bpm.com/forum/t-1269209/where-are-python-macros</link>
		<description>Posts in the discussion thread &quot;Where are Python macros?&quot;</description>
				<copyright></copyright>
		<lastBuildDate>Sat, 01 Aug 2015 21:46:52 +0000</lastBuildDate>
		
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2347493</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2347493</link>
				<description></description>
				<pubDate>Tue, 28 Jul 2015 12:19:31 +0000</pubDate>
				<wikidot:authorName>crocket</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Clojure is a modern reincarnation of lisp that has a decent support for macro.<br /> And, macro is fine in the lisp languages.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2342296</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2342296</link>
				<description></description>
				<pubDate>Tue, 21 Jul 2015 15:50:09 +0000</pubDate>
				<wikidot:authorName>Gunnar</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>A big problem with languages that allow macros is that they make it very hard to write static analysis tools for them. Having macros also means that the syntax of the language isn't fixed, just look at all the trouble the C preprocessor can cause (#define BEGIN {) or how godawful (La)TeX is. There are real reasons why people have turned away from macros.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2340768</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2340768</link>
				<description></description>
				<pubDate>Sat, 18 Jul 2015 20:43:21 +0000</pubDate>
				<wikidot:authorName>Sean Jensen-Grey</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Python has many great facilities for macros. At the lowest level code can be generated dynamically and integrated in to the running program via <tt>eval</tt> and <tt>exec</tt>.</p> <p>In the std lib <a href="https://github.com/python/cpython/blob/2.7/Lib/collections.py#L236">namedtuple</a> which builds a class from a textual template and then calls <tt>exec</tt> to compile it. You can see the generated code by passing <tt>verbose=True</tt> in the <a href="https://gist.github.com/seanjensengrey/9b27a241e26bae445950">construction function</a>.</p> <p>At at much higher level <a href="https://github.com/lihaoyi/macropy">macropy</a> gives you full syntactic macros like you would get in a Scheme or Lisp.</p> <p>If that isn't enough, there is <a href="https://github.com/hylang/hy">Hy language</a> which is a full Lisp hosted on Python. Full Python semantics with Lisp syntax, including <a href="https://hy.readthedocs.org/en/latest/">macros</a>.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2332750</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2332750</link>
				<description></description>
				<pubDate>Mon, 06 Jul 2015 22:43:03 +0000</pubDate>
				<wikidot:authorName>Marcos</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>I'll have to agree with the GP. In Python you simply load the module, insert your functions types and whatever there, and rewrite the name at the global scope.</p> <p>That is, Python macros are written in Python (and sometimes they are even useful). It also supports goto and multiple inheritance.</p> <p>I'd argue that Lisp is plenty of inspiration for people to not run away from macros. It's just that we already have a good set of macro oriented languages, so people aren't rushing to replace it.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2332668</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2332668</link>
				<description></description>
				<pubDate>Mon, 06 Jul 2015 21:07:09 +0000</pubDate>
				<wikidot:authorName>Jack O&#039;Connor</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>You can do that sort of thing in Python too; it's all dynamic in the end. Even if you were willing to put up with the nastiness though, there could be other drawbacks. For example, if you use mypy to do typechecking, you can't typecheck the functions you're generating at runtime. But if macros had been part of the language, mypy could learn how to expand them.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2332322</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2332322</link>
				<description></description>
				<pubDate>Mon, 06 Jul 2015 13:43:27 +0000</pubDate>
				<wikidot:authorName>Charles Smith</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>You can generate functions like that dynamically in Ruby. I have helper functions generated dynamically in: <a href="https://github.com/twohlix/database_cached_attribute/blob/master/lib/database_cached_attribute.rb#L62">https://github.com/twohlix/database_cached_attribute/blob/master/lib/database_cached_attribute.rb#L62</a></p> <p>so when I call<br /> database_cached_attribute :bollocks<br /> database_cached_attribute :silliness<br /> my class ends up with nice to have functions like</p> <p>invalidate_silliness, only_silliness_changed?, cache_silliness<br /> invalide_bollocks, only_bollocks_changed?, cache_bollocks</p> <p>etc&#8230;</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2331858</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2331858</link>
				<description></description>
				<pubDate>Sun, 05 Jul 2015 19:24:45 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Specifically, I wanted to generate a group of functions, all with the same prototype, without having to repeat same list of arguments each time.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2331837</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2331837</link>
				<description></description>
				<pubDate>Sun, 05 Jul 2015 18:43:39 +0000</pubDate>
				<wikidot:authorName>fjardon</wikidot:authorName>				<wikidot:authorUserId>424263</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Perl hasn't got a &quot;standard&quot; preprocessor because it has got a better tool: filters.</p> <p>A filter is a Perl module which reads the initial source code and produces the Perl code passed to the final Perl interpreter.</p> <p>This allows everyone to create its own new syntax or DSL in Perl.</p> <p>See: perldoc Filter::Simple , perldoc Filter::Util::Call</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2331804</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2331804</link>
				<description></description>
				<pubDate>Sun, 05 Jul 2015 17:07:54 +0000</pubDate>
				<wikidot:authorName>Brendan Long</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>What would you even use macros for in Python? You can already define functions and classes anywhere, and do pretty much anything you want. C needs them because the language is so restrictive, but I can't think of anything similar in Python.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2331788</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2331788</link>
				<description></description>
				<pubDate>Sun, 05 Jul 2015 16:25:25 +0000</pubDate>
				<wikidot:authorName>Lyubomyr</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Yeah.. Macroses as well as goto, multiple inheritance and others undeservedly retired just because they have a bad luck to be used improperly.<br /> Rust looks promising in this regard.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2331682</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2331682</link>
				<description></description>
				<pubDate>Sun, 05 Jul 2015 14:03:16 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Good to know. I've heard good things about Nim. I should have a look&#8230; but there's still Haskell and Rust on my todo list :(</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1269209#post-2331673</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1269209/where-are-python-macros#post-2331673</link>
				<description></description>
				<pubDate>Sun, 05 Jul 2015 13:47:22 +0000</pubDate>
				<wikidot:authorName>Sergey Drannikov</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Nim?</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>