一些语言提案。 [英] Some language proposals.

查看:66
本文介绍了一些语言提案。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此很陌生,所以我不知道应该怎么做?b $ b介绍这个,也不知道这些想法是否值多少

但是这里去吧。


我想改变的是访问

中间范围的变量。鉴于以下示例


def fun_1()


a = some_value


def fun_2()


#a永远不是上面那个。

#在声明的左边。

我听到的解决方案建议使用

a变量变量。像

def fun_1():


a = [some_value]


def fun_2();


a [0] = new_value


当然如果你有一些这样的变量

你可以分组然后在一个对象中

def fun_1():


class var_1:

pass


var_1.a = some_value

var_1.b = a_value_too

def fun_2():


var_1 .a = new_value

var_1.b = next_value

现在我的想法是查看

a函数中的局部变量,如成员变量一个对象,这样你就可以写出



def fun_1():


a = some_value

b = a_value_too


def fun_2():


fun_1.a = new_value

fun_1.b = next_value

这可能甚至可以进一步扩展,看看函数

就像某种模块一样,可以像

这样的东西欠

def fun_1():


a = some_value

b = a_value_too


def fun_2():


来自fun_1导入a,b


a = new_value

b = next_value

人们对此有何看法?

据我所知,该提案并没有破坏现有的

代码,这似乎符合python的精神。

在旁注中,人们会怎样考虑来自...... import ...语句的概念

a可用于任何对象?所以

我们可以做到:


A级:

通过


Aa = ...

Ab = ...


来自A进口a,b


#来自这里是一个并且可以参考Aa和Ab


-

Antoon Pardon

I''m rather new at this, so I don''t know how I should
introduce this, nor whether these ideas are worth much
but here goes.

What I would like to change is access to variables on
an intermediate scope. Given the following example

def fun_1()

a = some_value

def fun_2()

# a is never the one above.
# on the left side of a statement.
The solution that I heard proposed was to use
a mutable variable. Something like
def fun_1():

a = [some_value]

def fun_2();

a[0] = new_value

And of course if you had a number of such variables
you could group then in an object
def fun_1():

class var_1:
pass

var_1.a = some_value
var_1.b = a_value_too

def fun_2():

var_1.a = new_value
var_1.b = next_value
Now my idea would be to look at the local variables in
a function like member variables of an object so that
you could write
def fun_1():

a = some_value
b = a_value_too

def fun_2():

fun_1.a = new_value
fun_1.b = next_value
This could maybe even extended further is seeing functions
like some kind of module which would allow something like
the following
def fun_1():

a = some_value
b = a_value_too

def fun_2():

from fun_1 import a, b

a = new_value
b = next_value
What do people think about this?
As far as I know the proposal doesn''t break existing
code and seems in the spirit of python.
On a side note, what would people think about the idea of
a from ... import ... statement usable on any object? So
that we could do:

class A:
pass

A.a = ...
A.b = ...

from A import a, b

# from here a and be refer to A.a and A.b

--
Antoon Pardon

推荐答案

2004年2月24日星期二,下午03:53:42 +0000,Antoon Pardon写道:
On Tue, Feb 24, 2004 at 03:53:42PM +0000, Antoon Pardon wrote:
现在我的想法是看一下函数中的局部变量喜欢一个物体的成员变量,这样就可以写出

def fun_1():

a = some_value
b = a_value_too

def fun_2():

fun_1.a = new_value
fun_1.b = next_value


这与现有代码不兼容。 ''fun_1.a = new_value''

已经有了意义(它在

函数对象上创建或修改了一个属性),因此无法使用修改

特定的fun_1调用的locals()。

def fun_1():

a = some_value
b = a_value_too
def fun_2():

来自fun_1导入a,b

a = new_value
b = next_value

人们对此有何看法?
据我所知,该提案并没有破坏现有的代码,而且似乎符合python的精神。


这不是Python的精神。


这已经有了意义:来自m import的
a

a = 3

....它几乎和

导入m一样_m

a = ma

del _m

a = 3

....基本上只设置为3(它没有修改模块m )

在旁注中,人们会想到
a from ... import ...语句可用于任何对象?所以我们可以这样做:
Now my idea would be to look at the local variables in
a function like member variables of an object so that
you could write
def fun_1():

a = some_value
b = a_value_too

def fun_2():

fun_1.a = new_value
fun_1.b = next_value
This is not compatible with existing code. ''fun_1.a = new_value''
already has a meaning (it creates or modifies an attribute on the
function object), so it can''t be used to modify the locals() of a
particular invocation of fun_1.
def fun_1():

a = some_value
b = a_value_too

def fun_2():

from fun_1 import a, b

a = new_value
b = next_value
What do people think about this?
As far as I know the proposal doesn''t break existing
code and seems in the spirit of python.
This is not in the sprit of Python.

This already has a meaning:
from m import a
a = 3
.... it almost is the same as
import m as _m
a = m.a
del _m
a = 3
.... which basically just sets a to 3 (it doesn''t modify the module m)
On a side note, what would people think about the idea of
a from ... import ... statement usable on any object? So
that we could do:




不,那不行。考虑以下Python程序:

sys = 64738

来自sys import exit

exit()

模块''import''和'from from ...''中的名称并不是指当前模块命名空间中的
对象,而是在
的命名空间中
模块。


无论如何,因为''from .. import''不是魔法,只是分配,

有没有有理由更喜欢你的建议

从A进口a,b



a,b = Aa,Ab

...例如,它不能使'a = 3''改变A.它有一个小的

优势,你不需要键入''a''一次在左边和一次在

右边的''='',但那是关于它的。


Jeff



No, that won''t do. Consider the following Python program:
sys = 64738
from sys import exit
exit()
The module name in ''import'' and ''from ... import'' doesn''t refer to
objects in the current module''s namespace, but in the namespace of
modules.

Anyway, because ''from .. import'' is not magic, but just assignment,
there''s no reason to prefer your proposed
from A import a, b
to
a, b = A.a, A.b
... for instance, it can''t make ''a = 3'' change A. It has a small
advantage that you don''t need to type ''a'' once on the left and once on
the right of ''='', but that''s about it.

Jeff


Antoon Pardon< ap ***** @ forel.vub.ac.be>写道:
Antoon Pardon <ap*****@forel.vub.ac.be> wrote:
我对此很陌生,所以我不知道应该如何介绍这个,也不知道这些想法是否值得更多
但是这里。


我批评新语言提案时我很陌生,请原谅我

不要狠狠地反对新想法:-)但是说真的,我认为

最好关注新提案。即使之前讨论过的事情已经讨论过了,但同样的想法再次出现并且再次出现这个事实本身就意味着什么。还有很多建议来自

公司尚未评估的新想法。

现在我的想法是查看
像对象的成员变量一样的函数,这样你就可以写

def fun_1():

a = some_value
b = a_value_too

def fun_2():

fun_1.a = new_value
fun_1.b = next_value

这甚至可能会进一步延伸功能
喜欢某种类型的模块可以允许下面的内容

def fun_1():

a = some_value
b = a_value_too
def fun_2():

来自fun_1导入a,b

a = new_value
b = next_value

人们对此有何看法?
据我所知,该提案并没有破坏现有的代码,而且似乎符合python的精神。


我没有看到太多的优点,因为功能被设计为一旦执行后就会出现
的范围。尽管像/

" properties"这样的新开发项目,但子范围更改名称更高的价值被认为是Python中的禁忌。已经从这个

概念中蚕食了一小块。


然而,在*生成器函数的情况下*这种情况发生了变化

戏剧性地,所以你可能会在那里得分。采取

的道路将是实用性超过纯度的方式。

在旁注中,人们会想到什么
a from ... import ...语句可用于任何对象?所以我们可以这样做:

A级:


Aa = ...
Ab = ...
#来自这里a并参考Aa和Ab
I''m rather new at this, so I don''t know how I should
introduce this, nor whether these ideas are worth much
but here goes.
I''m rather new at criticizing new language proposals so forgive me for
not fighting new ideas ferociously enough :-) But seriously, I think
it''s better to keep an eye open to new proposals. Even if things have
been discussed before, the fact that the same ideas come up again and
again should mean something in itself. Also a lot of proposals come in
the company of new ideas that have not yet been evaluated.
Now my idea would be to look at the local variables in
a function like member variables of an object so that
you could write
def fun_1():

a = some_value
b = a_value_too

def fun_2():

fun_1.a = new_value
fun_1.b = next_value
This could maybe even extended further is seeing functions
like some kind of module which would allow something like
the following
def fun_1():

a = some_value
b = a_value_too

def fun_2():

from fun_1 import a, b

a = new_value
b = next_value
What do people think about this?
As far as I know the proposal doesn''t break existing
code and seems in the spirit of python.
I don''t see much merit in this, since functions are designed to go out
of scope once they are executed. Having sub-scopes change names higher
up is considered a no-no in Python, although new developments like
"properties" are already nibbling little chunks away from this
concept.

However, in the case of *generator functions* this situation changes
dramatically, so you might score some points there. The road to take
would be something along the lines of "practicality beats purity".
On a side note, what would people think about the idea of
a from ... import ... statement usable on any object? So
that we could do:

class A:
pass

A.a = ...
A.b = ...

from A import a, b

# from here a and be refer to A.a and A.b




这引起了为什么不使用课程开始甚至

为您的早期提案。无论如何,这可以轻松实现

with:


a,b = Aa,Ab


如果你还是想看看这个,请看看这个链接:

http://us.st5.yimg.com/store4.yimg.c...s_1780_2263455


Anton



This raises the question of why not to use a class to begin with even
for your earlier proposals. Anyway, this can be accomplished easily
with:

a,b = A.a,A.b

If you still want to go through with this, have a look at this link:

http://us.st5.yimg.com/store4.yimg.c...s_1780_2263455

Anton




" Antoon Pardon" < AP ***** @ forel.vub.ac.be>在留言中写道

news:sl ******************** @ trout.vub.ac.be ...

"Antoon Pardon" <ap*****@forel.vub.ac.be> wrote in message
news:sl********************@trout.vub.ac.be...
我想改变的是访问中间范围的变量。
What I would like to change is access to variables on
an intermediate scope.




据我所知,你想要写入(重新绑定)访问权限除了阅读

访问权限 - 无需将变量包装在一个可变的内容中,目前可以执行
。有关这方面的建议已在PyDev

列表中讨论过。它们应该列在Brett Cannon的摘要中,这些摘要是在Python.org上存档的。


到目前为止的底线:假设写访问权限是只有笨拙(有时候,通过包装才能获得
)而不是不可能,没有任何提案能够让人们感到麻烦,因为语法改变的麻烦。嵌套函数比unnested更罕见

。需要重新绑定一个外部本地人,而不仅仅是阅读
或变异,现在还是比较少见的。


Terry J. Reedy




As I understand, you want write (rebind) access in addition to read
access -- without having to wrap the variable in a mutable, which one can
do at present. Some proposals to do this have been discussed on the PyDev
list. They should be listed in Brett Cannon''s summaries, which are
archived on Python.org.

Bottom line so far: given that write access is only clumsy (sometimes,
through wrapping) rather than impossible, no proposal struck enough people
as worth the bother of a syntax change. Nested functions are much rarer
than unnested. Needing to rebind an outer local, rather than merely read
or mutate, is rarer still.

Terry J. Reedy



这篇关于一些语言提案。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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