来自D. [英] From D

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

问题描述

我觉得我喜欢D语言的各种各样的东西

Python也可以享受。这里有几个部分(主要是语法部分):


1)(我们在过去讨论了部分内容)你可以在数字文字中加上

下划线,如1_000_000,编译器

并没有强制执行这些下划线的位置,所以你也可以像这样把它们放在

:1_00_000。你可以把它们放在小数字的文字,

二进制,十六进制等等。我认为这是非常有用的,因为在Python中使用
代码我有一个像:
$ x $ b for x in xrange(1000000):

我需要一些时间来计算零,因为我的

视觉系统的较低级别不能快速计算/分组(感知)。虽然在

a语法中如下:

for x in xrange(1_000_000):

我的眼睛帮我一次分组。

2)基数为2的数字文字,基数2为%b。使用writefln进行打印。

在Python代码中,Base-2数字不太常见,但偶尔我会用
来使用它们。例如:

import std.stdio;

void main(){

auto x = 0b0100_0011;

writefln("%b",x);

writefln("%。8b",x);

writefln(x);

}

打印:

1000011

01000011



3)所有字符串文字都是多行的。所以你可以写:

a =怎么样

你;

没有必要使用" """。

4)DI已经创建了一个xsplit()生成器,从我的测试开始它比分割()快得多b $ b ,特别是如果你想要分割的字符串/行是多少百个字符长或更多(如果你想要分割非常小的字符串,它就不会更快) 。所以我认为Python也可以享受这样的

字符串方法(你可以模拟一个带有常规

表达式的xsplit,但对于其他一些字符串方法也是如此) 。


再见,

熊宝宝

There are various things I like about the D language that I think
Python too may enjoy. Here are few bits (mostly syntactical ones):

1) (we have discussed part of this in the past) You can put
underscores inside number literals, like 1_000_000, the compiler
doesn''t enforce the position of such underscores, so you can also put
them like this: 1_00_000. You can put them in literals of decimals,
binary, hex, etc. I think it''s quite useful, because when in Python
code I have a line like:
for i in xrange(1000000):
I need some time to count the zeros, because the lower levels of my
visual systems can''t count/group them quickly (perceptually). While in
a syntax like:
for i in xrange(1_000_000):
my eyes help me group them at once.
2) Base 2 number literals, and base 2 "%b" printing with the writefln.
Base-2 numbers are less common in Python code, but once in a while I
use them. For example:
import std.stdio;
void main() {
auto x = 0b0100_0011;
writefln("%b", x);
writefln("%.8b", x);
writefln(x);
}
Prints:
1000011
01000011
67
3) All string literals are multi line. So you can write:
a = "how are
you";
There''s no need for """ """.
4) With D I have created an xsplit() generator, and from my tests it''s
quite faster than the split(), expecially if the string/lines you want
to split are few hundred chars long or more (it''s not faster if you
want to split very little strings). So I think Python can enjoy such
string method too (you can probably simulate an xsplit with a regular
expression, but the same is true for some other string methods too).

Bye,
bearophile

推荐答案

开2007年7月24日星期二03:19:53 -0700,bearophileHUGS写道:
On Tue, 24 Jul 2007 03:19:53 -0700, bearophileHUGS wrote:

我觉得有很多关于D语言的东西我觉得Python

也可以享受。这里有几个部分(主要是语法部分):


1)(我们在过去讨论了部分内容)你可以在数字文字中加下下划线

,如1_000_000,编译器没有强制执行这些下划线的

位置,所以你也可以这样设置:

1_00_000。你可以把它们放在小数,二进制,十六进制等文字中。我认为它非常有用,因为在Python代码中我有一行如下:

for x in xrange(1000000):

我需要一些时间来计算零,因为我的

视觉系统的较低级别不能计算/分组它们快速(感性)。虽然在

语法中如下:

for x in xrange(1_000_000):

我的眼睛帮助我立刻将它们分组。
There are various things I like about the D language that I think Python
too may enjoy. Here are few bits (mostly syntactical ones):

1) (we have discussed part of this in the past) You can put underscores
inside number literals, like 1_000_000, the compiler doesn''t enforce the
position of such underscores, so you can also put them like this:
1_00_000. You can put them in literals of decimals, binary, hex, etc. I
think it''s quite useful, because when in Python code I have a line like:
for i in xrange(1000000):
I need some time to count the zeros, because the lower levels of my
visual systems can''t count/group them quickly (perceptually). While in a
syntax like:
for i in xrange(1_000_000):
my eyes help me group them at once.



听起来很不错,但任意定位都没有任何意义。另外,在这种情况下我会建议10 ** n(例如10 ** 6)。

Sounds like a good thing to be but the arbitrary positioning doesnt make
any sense. Additionally, I''d suggest 10**n in such cases (eg. 10**6).


2)Base 2数字文字,基数2 ;%b"使用writefln进行打印。

在Python代码中,Base-2数字不常见,但偶尔我会使用

。例如:

import std.stdio;

void main(){

auto x = 0b0100_0011;

writefln("%b",x);

writefln("%。8b",x);

writefln(x);

}

打印:

1000011

01000011

67
2) Base 2 number literals, and base 2 "%b" printing with the writefln.
Base-2 numbers are less common in Python code, but once in a while I use
them. For example:
import std.stdio;
void main() {
auto x = 0b0100_0011;
writefln("%b", x);
writefln("%.8b", x);
writefln(x);
}
Prints:
1000011
01000011
67



接受。 http://www.python.org/dev/peps / pep-3127 /#abstract


3)所有字符串文字都是多行的。所以你可以写:a =怎么样

你;

没有必要使用" """ ;.
3) All string literals are multi line. So you can write: a = "how are
you";
There''s no need for """ """.



嗯,我认为视觉识别更好。如果你读`foo =

""" ...``,很明显你可以跳过接下来的几行,因为它们是最好的

可能是一大块数据,而不是程序代码。单引号使

清除这只是整行中的一个非常小的标记。 (是的,有可能

是例外,可能有语法高亮。)

Well, I think it''s just better to recognize visually. If you read ``foo =
"""...``, it''s clear you can skip the next few lines because they''re most
likely a chunk of data, not program code. Single quotation mark makes
clear this is just a very small token in the whole line. (Yes, there may
be exceptions, there may be syntax highlighting.)


4)用DI创建了一个xsplit()生成器,从我的测试来看,它比分裂()快得多b / b,特别是如果要分割的字符串/行需要几百个字符长或更多(如果你想要分割很少的字符串,那就不会更快。)所以我认为Python也可以享受这样的字符串

方法(你可以模拟一个带有常规

表达式的xsplit,但对于其他一些字符串方法也是如此) 。
4) With D I have created an xsplit() generator, and from my tests it''s
quite faster than the split(), expecially if the string/lines you want
to split are few hundred chars long or more (it''s not faster if you want
to split very little strings). So I think Python can enjoy such string
method too (you can probably simulate an xsplit with a regular
expression, but the same is true for some other string methods too).



是的,这是一个好主意 - 符合当前的动向,即b $ b发电机的一切。但是(IIRC)这个想法早些时候出现了,并且那里也有b $ b补丁。在sf.net快速搜索没有找到任何东西

相关,tho。

Yea, that''s a good idea -- fits into the current movement towards
generator''ing everything. But (IIRC) this idea came up earlier and there
has been a patch, too. A quick search at sf.net didn''t turn up anything
relevant, tho.


再见,

bearophile
Bye,
bearophile



问候,

Stargaming

Regards,
Stargaming


Stargaming写道:
Stargaming wrote:

On Tue,2007年7月24日03:19:53 -0700,bearophileHUGS写道:
On Tue, 24 Jul 2007 03:19:53 -0700, bearophileHUGS wrote:


>在语法中如下:
for x in xrange(1_000_000):
我的眼睛帮助我立刻将它们分组。
>While in a syntax like:
for i in xrange(1_000_000):
my eyes help me group them at once.



听起来好像是好事但是任意定位

没有任何意义。


Sounds like a good thing to be but the arbitrary positioning
doesnt make any sense.



检查下划线位置只会增加复杂性。为什么不

只是忽略它们,无论它们在哪里?

Checking underscore positions would only add complexity. Why not
just ignore them, no matter where they are?


另外,在这种情况下我会建议10 ** n (例如10 ** 6)。
Additionally, I''d suggest 10**n in such cases (eg. 10**6).



如果你碰巧在右侧

那边只有零,那就失败了。


问候,

Bj?


-

BOFH借口#97:


小动物神风攻击电源

This fails if you happen to have more than only zeros at the right
side.

Regards,
Bj?rn

--
BOFH excuse #97:

Small animal kamikaze attack on power supplies


2007年7月24日星期二20:09:00 +0200,Bjoern Schliessmann写道:
On Tue, 24 Jul 2007 20:09:00 +0200, Bjoern Schliessmann wrote:

Stargaming写道:
Stargaming wrote:

> 2007年7月24日星期二03:19:53 -0700,bearophileHUGS写道:
>On Tue, 24 Jul 2007 03:19:53 -0700, bearophileHUGS wrote:


>>在语法中如下:
for x in xrange(1_000_000 ):我的眼睛帮我把它们分组。
>>While in a syntax like:
for i in xrange(1_000_000):
my eyes help me group them at once.


听起来像是一件好事,但任意定位
没有任何意义。


Sounds like a good thing to be but the arbitrary positioning
doesnt make any sense.



检查下划线位置只会增加复杂性。为什么不

只是忽略它们,无论它们在哪里?


Checking underscore positions would only add complexity. Why not
just ignore them, no matter where they are?



数字中的下划线是UGLY。为什么不从隐式

字符串连接中取出一个叶子并允许数字文字隐式连接?


Python已经做了:

" hello-" "世界" =" hello-world"


建议:

123 456 789 = 123456789

123.456 789 = 123.456789

-

史蒂文。


Underscores in numerics are UGLY. Why not take a leaf out of implicit
string concatenation and allow numeric literals to implicitly concatenate?

Python already does:
"hello-" "world" ="hello-world"

Propose:
123 456 789 =123456789
123.456 789 =123.456789
--
Steven.


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

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