无法理解有关自定义Python宏语法的声明 [英] Unable to understand a statement about customizing Python's Macro Syntax

查看:104
本文介绍了无法理解有关自定义Python宏语法的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

库迪已在构建Pythonic宏语法.他说

Cody has been building a Pythonic Macro Syntax. He says

这些宏允许您定义 全新的完全自定义语法 构造新的运营商.有 没有在Python中执行此操作的工具 就这样.

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.

我不确定他的意思

  • 面向新运算符的新构造:他是否在数学中引用了+,-和乘法等二进制运算符?
  • 他的主要目标:自定义Python的宏语法在哪里有好处?
  • 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?

推荐答案

毫无疑问,Cody指的是Python中当前不存在的全新运算符,例如(I dunno)^^+++*和等等,不管它们意味着什么.而且他明确地说,宏系统允许您为Python定义全新的语法 (他的问题是关于宏定义本身的语法).

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).

有些人非常关心语法,例如,更希望看到Python使用大括号而不是按缩进进行分组.但是Python本身永远不会遵循这些人的喜好...:

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 "<stdin>", line 1
SyntaxError: not a chance

因此,这些人可能会通过此宏系统为Python定义全新的语法,从而获得渴望的东西.

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

其他人可能会使用它来定义特定的自定义语言,这些语言通常遵循Python的概述,但添加特殊的新关键字,让您无需使用括号即可调用函数,依此类推,等等.

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.

事实上,这是否是一件好事,这是一个古老的,有争议的问题,但是某些语言(例如Lisp)一直具有这种功能的宏,而许多从Lisp到Python的人(例如Peter Norvig)可能会很高兴找回他们以前在Lisp中却在Python中所缺乏的语法制定能力.

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.

这篇关于无法理解有关自定义Python宏语法的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆