Python与Io [英] Python vs. Io

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

问题描述

Io( www.iolanguage.com )是一种新的编程语言纯粹

面向对象(但有原型),通过actor有一个强大的并发性和b $ b机制,并使用极其灵活的语法,因为

all代码是可修改的消息树。像Python一样,它是动态的b
类型,有一个非常干净的语法,产生短代码,并且是极其缓慢的(在与其他人相同的水平上)。 Io有一个独特的

语法结合了Lisp'的流控制功能的概念和传统的函数语法和类似于类似的类似语法来获得
$的插槽b $ b对象。 Io没有关键字,所有内容,甚至多行

代码,都可以用作表达式。即使作为Io的初学者,我也只能用43行写一些东西,让你在Io中做一些像这样(和更多)的事情:
每个
(地图中的(键,值)(x = 1,y = 2,z = 3),

write(key,":",价值,\ n;)




每个函数和地图函数都没有内置(Io有

这种事情的其他机制,但它们的效率较低。)

任何人都可以告诉我如何别名for for 每个在Python中

或允许块语法完全没有破解C源代码?


Io没有使用__methods_with_this_annoying_syntax__因为没有什么

应该仅供内部使用,并且只有大约三个

函数,如果被覆盖则会导致问题。


对于嵌入,Io没有不必使用Py_ALL_CAPS,而只是

使用IoCamelCase,看起来好多了。与C的接口很多

更加面向对象。


Io的许多用户(包括我自己)已经从Python转换为
这些原因。

我想Python仍有明显的优势,比如Io,

包括

*大社区

*更多绑定东西

*严格的编码约定

*不灵活所以一切都一样

*不需要关闭街区

但除非有其他问题,前两个很快就会消失

(考虑到Io最初是在两年前创建的)。最后的

三是有点小事,甚至可能是Io的优势。


Daniel Ehrenberg

Io (www.iolanguage.com) is a new programming language that''s purely
object-oriented (but with prototypes), has a powerful concurrency
mechanism via actors, and uses an extremely flexible syntax because
all code is a modifiable message tree. Like Python, it is dynamically
typed, has a very clean syntax, produces short code, and is
excruciatingly slow (on the same level as eachother). Io has a unique
syntax combining Lisp''s idea of functions for flow control with
traditional function syntax and smalltalk-like syntax to get slots of
objects. Io has no keywords and everything, even multiple lines of
code, can be used as an expression. Even as a beginner to Io, I was
able to write something in just 43 lines to let you do something like
this (and more) in Io:

each((key, value) in map(x=1, y=2, z=3),
write(key, ": ", value, "\n")
)

Neither the each function nor the map function were built in (Io has
other mechanisms for that kind of thing, but they are less efficient).
Can anyone show me how to so much as alias "for" to "each" in Python
or allow block syntax at all without hacking the C source code?

Io doesn''t use __methods_with_this_annoying_syntax__ because nothing
is supposed to be for internal use only and there are only about three
functions that would cause a problem if overridden.

For embedding, Io doesn''t have to use Py_ALL_CAPS, instead it just
uses IoCamelCase, which looks much better. Interfaces to C are much
more object oriented.

Many users of Io (myself included) have switched over from Python for
these reasons.

I guess there are still the obvious advantages of Python over Io,
including
*large community
*more bindings to stuff
*strict coding conventions
*inflexible so everything is the same
*no need to close blocks
But unless there are other problems, the first two go away soon
(considering that Io was first created just two years ago). The last
three are somewhat trivial and may even be to Io''s advantage.

Daniel Ehrenberg

推荐答案



" Daniel Ehrenberg" <黎************ @ yahoo.com>在消息中写道

news:71 ************************* @ posting.google.co m ...

"Daniel Ehrenberg" <Li************@yahoo.com> wrote in message
news:71*************************@posting.google.co m...
任何人都可以告诉我如何使用别名for和 每个在Python中


在没有进入语言战争的情况下,我认为你正在寻找的是
for被称为访客模式(Design Patterns:GOF)。只要你不寻求内置支持,实际上实际上只需要很少的工资。


这样的东西在任何你想要的对象

来实现一个集合的访问者:


class aCollection:

def visit(self,instance ):

for x in self._collection:

instance.visitor(x)

return instance.result()


最后的调用比裸访问者模式稍微多一点,但是

允许访问者实例传回结果,所以你可以使用

表达式。


访问者看起来像这样:


类fubar:

def __init __(自我):

self.whatever = 0

def visitor(self,value):

self.whatever + = value

def结果(个体经营):

返回self.whatever


您可以这样使用它:


ohWow = aCollection.visit(fubar())

与例如Ruby中的块不同,访问者实例

可以预先初始化,它可以有多种方法和

它可以持续存在反对集合。


当然,您也可以使用更复杂的数据结构,

请参阅编译器的内容,了解所使用的访问者模式的示例

over Python Abstract Syntax Tree。


访问者模式对文件系统也非常有用

导航;我一直使用它。


John Roth

Daniel Ehrenberg
Can anyone show me how to so much as alias "for" to "each" in Python
Without getting into the language wars, I think what you''re looking
for is called the Visitor Pattern (Design Patterns: GOF). It''s actually
trivial to implement as long as you''re not looking for built-in support.

Something like this works quite well in any object where you want
to implement a visitor over a collection:

class aCollection:
def visit(self, instance):
for x in self._collection:
instance.visitor(x)
return instance.result()

The final call is a little more than the bare visitor pattern, but it
allows the visitor instance to pass back a result so you can use
it in expressions.

A visitor then looks like this:

class fubar:
def __init__(self):
self.whatever = 0
def visitor(self, value):
self.whatever += value
def result(self):
return self.whatever

and you use it like this:

ohWow = aCollection.visit(fubar())

Unlike a block in, for example, Ruby, a visitor instance
can be pre-initialized, it can have multiple methods and
it can persist after being passed against the collection.

Of course, you can use more complex data structures as well,
see the compiler stuff for examples of the visitor pattern used
over the Python Abstract Syntax Tree.

The visitor pattern is also very useful for file system
navigation; I use it consistently.

John Roth

Daniel Ehrenberg



John Roth写道:
John Roth wrote:
" Daniel Ehrenberg" <黎************ @ yahoo.com>在消息中写道
新闻:71 ************************* @ posting.google.co m ...

"Daniel Ehrenberg" <Li************@yahoo.com> wrote in message
news:71*************************@posting.google.co m...

任何人都可以告诉我如何使用别名for和 每个在Python中
Can anyone show me how to so much as alias "for" to "each" in Python



如果没有进入语言战争,我认为你正在寻找的是什么叫做访客模式(Design Patterns:GOF)。只要你不寻求内置支持,它实际上是微不足道的。


Without getting into the language wars, I think what you''re looking
for is called the Visitor Pattern (Design Patterns: GOF). It''s actually
trivial to implement as long as you''re not looking for built-in support.




我想丹尼尔的例子有点复杂。这个
类似于更糟糕的lisp-ish宏,这些宏在前一段时间被讨论过死亡。


请注意,在他的代码:
每个
(地图中的(键,值)(x = 1,y = 2,z = 3),

write(key,":" ,value," \ n")




键和值是在函数调用中使用的变量名。


这是我的pythonic(?)版本,但它需要一个lambda来绑定

变量名。


def map( ** kw):

返回kw.items()


def每个(seq,func):

for v in seq:

apply(func,v)


来自sys import stdout

write = stdout.write


each(map(x = 1,y = 2,z = 3),

lambda key,value:write("%s:%s \ n" %(键,值)))


Brian



I think Daniel''s example is a little bit more complicated than that. It
resembles more closly the lisp-ish macros that were discussed to death a
while ago.

Note that in his code:
each((key, value) in map(x=1, y=2, z=3),
write(key, ": ", value, "\n")
)

key and value are variable names that get used inside the function call.

Here is my pythonic(?) version, however it requries a lambda to bind the
variable names.

def map(**kw):
return kw.items()

def each(seq, func):
for v in seq:
apply(func, v)

from sys import stdout
write = stdout.write

each(map(x=1,y=2,z=3),
lambda key, value: write("%s: %s\n"%(key, value)))

Brian


在某些时候, Li ************ @ yahoo.com (Daniel Ehrenbe rg)写道:
At some point, Li************@yahoo.com (Daniel Ehrenberg) wrote:
Io( www.iolanguage.com )是一种新的编程语言,它纯粹是面向对象的(但有原型),通过actor有一个强大的并发机制,并且使用极其灵活的语法,因为
所有代码都是可修改的消息树。像Python一样,它是动态类型的,具有非常干净的语法,产生短代码,并且极其缓慢(与彼此处于同一水平)。 Io有一个独特的语法结合了Lisp'的流控制功能的概念,传统的函数语法和类似于类似语法的语法来获取
对象的插槽。 Io没有关键字,所有内容,甚至多行代码都可以用作表达式。即使作为Io的初学者,我也只能用43行写一些东西,让你在Io中做这个(以及更多)的事情:

每个((地图中的键,值)(x = 1,y = 2,z = 3),
写(键,:,值,\\n)
) />
每个函数和map函数都没有内置(Io有其他机制用于那种事情,但效率较低)。
任何人都可以告诉我如何这样做别名for 每个在Python中
或者允许块语法而不破解C源代码?


嘿,如果我想,我可以添加函数和所有那些使得Python看起来像Lisp,IO或其他任何内容的东西。


但是,为什么?如果我想写Lisp或Io,我会使用它们。


你的例子我会用Python编写


对于键,dict中的值(x = 1,y = 2,z = 3):

print''%s:%s \ n" %(键,值)


我没有写过43行支持代码,而且还有两行

行。我不认为这不是内置的是一个卖点 - 你

需要足够大量的内置来使语言变得有用。

Io没有使用__methods_with_this_annoying_syntax__因为没有什么是
仅供内部使用,并且只有大约三个功能,如果被覆盖则会导致问题。
对于嵌入,Io不必使用Py_ALL_CAPS,而只是使用IoCamelCase,它看起来好多了。与C的接口更加面向对象。


好​​的,这两点是装饰性的:轻微的拼写和

标点问题(这似乎是大多数语言战争的内容)。 />

哎呀,对C ++接口使用boost :: python;这些功能名称更简单。
更短。或者使用pyrex生成包装器,用

Pythonesque语言编写它们。

Io的许多用户(包括我自己)已经从Python切换了
这些原因。

我想Python仍然有明显的优势,包括
*大型社区
*更多绑定到


是的。那就是*大*差异,我会说。

*严格的编码约定
*不灵活所以一切都是一样的


你能详细说明为什么Python不灵活吗?我发现Python要非常灵活。

*无需关闭块
但除非有其他问题,前两个很快就会消失(考虑到Io最初是在两年前创建的)。最后的三个有点微不足道,甚至可能是Io的优势。
Io (www.iolanguage.com) is a new programming language that''s purely
object-oriented (but with prototypes), has a powerful concurrency
mechanism via actors, and uses an extremely flexible syntax because
all code is a modifiable message tree. Like Python, it is dynamically
typed, has a very clean syntax, produces short code, and is
excruciatingly slow (on the same level as eachother). Io has a unique
syntax combining Lisp''s idea of functions for flow control with
traditional function syntax and smalltalk-like syntax to get slots of
objects. Io has no keywords and everything, even multiple lines of
code, can be used as an expression. Even as a beginner to Io, I was
able to write something in just 43 lines to let you do something like
this (and more) in Io:

each((key, value) in map(x=1, y=2, z=3),
write(key, ": ", value, "\n")
)

Neither the each function nor the map function were built in (Io has
other mechanisms for that kind of thing, but they are less efficient).
Can anyone show me how to so much as alias "for" to "each" in Python
or allow block syntax at all without hacking the C source code?
Hey, if I wanted to to, I could add functions and all that that would
make Python look like Lisp, or IO, or whatever.

But, why? If I wanted to write Lisp or Io, I''d use those.

Your example I''d write in Python as

for key, value in dict(x=1, y=2, z=3):
print ''%s: %s\n" % (key, value)

I didn''t have to write 43 lines of support code, and it''s also two
lines. I don''t think "this isn''t builtin" is a selling point -- you
need a critical mass of builtins to make a language useful.
Io doesn''t use __methods_with_this_annoying_syntax__ because nothing
is supposed to be for internal use only and there are only about three
functions that would cause a problem if overridden. For embedding, Io doesn''t have to use Py_ALL_CAPS, instead it just
uses IoCamelCase, which looks much better. Interfaces to C are much
more object oriented.
Ok, these two points are window-dressing: minor spelling and
punctuation issues (which seems to be what most language wars are about).

Heck, use boost::python for C++ interfaces; those function names are
even shorter. Or use pyrex to generate wrappers, writing them in a
Pythonesque language.
Many users of Io (myself included) have switched over from Python for
these reasons.

I guess there are still the obvious advantages of Python over Io,
including
*large community
*more bindings to stuff
Yep. That''s a *big* difference, I''d say.
*strict coding conventions
*inflexible so everything is the same
Can you elaborate a bit on why Python is inflexible? I find Python to
be extremely flexible.
*no need to close blocks
But unless there are other problems, the first two go away soon
(considering that Io was first created just two years ago). The last
three are somewhat trivial and may even be to Io''s advantage.




Python已经14岁了,而且还在工作关于全球统治;

Io'有一些赶上来做:-)


-

|> | \ / |<

/ ---------------------------------- ---------------------------------------- \

| David M. Cooke

| cookedm(at)physics(dot)mcmaster(dot)ca



Python is 14 years old, and it''s still working on global domination;
Io''s got some catching up to do :-)

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca


这篇关于Python与Io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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