python使用宏定义定义符号常量pi_无法理解有关自定义Python宏语法的声明

Cody has been building a Pythonic Macro Syntax. He says

These macros allow you to define

completely custom syntax, from new

constructs to new operators. There's

no facility for doing this in Python

as it stands.

I am not sure what he means by

new constructs to new operators: Does he refer to binary operators such as +, - and multiplication in Math?

his main goal: Where do you benefit in customizing Python's macro syntax?

解决方案

No doubt Cody refers to completely new operators that are not currently in Python, such as (I dunno) ^^ or ++ or +* and so on, whatever they might mean. And he's explicitly saying that the macro system lets you define a completely new syntax for Python (his question was about the syntax of the macro definitions themselves).

Some people care burningly about syntax and for example would much prefer to see Python uses braces rather than group by indentation; but Python itself will never follow those people's preferences...:

>>> from __future__ import braces

File "", line 1

SyntaxError: not a chance

So these people might obtain what they crave by defining a completely new syntax for Python through this macro system.

Others might use it to define specific custom languages that mostly follow Python's general outlines but add special new keywords, let you call functions without using parentheses, and so on, and so forth.

Whether that's a good thing, in fact, is an ancient, moot issue—but some languages such as Lisp have always had macros of such power, and many people who came to Python from Lisp, such as Peter Norvig, would probably be quite happy to get back that syntax-making power they used to have in Lisp but lack in Python.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值