ABS 1.1.0:更多Python和Bash提供最有趣的编程语言

by Alex Nadalin

通过亚历克斯·纳达林

ABS 1.1.0:更多Python和Bash提供最有趣的编程语言 (ABS 1.1.0: more Python and Bash for the most fun programming language out there)

If you missed my previous post, ABS is a programming language that allows you to interact with the underlying system with a modern syntax. This is an example of it as a version of Bash built in 2019.

如果您错过了我以前的文章 ,ABS是一种编程语言,它允许您使用现代语法与底层系统进行交互。 这是它作为2019年构建的Bash版本的一个示例。

In this article, I’ll discuss a fresh new release of the ABS programming language, bringing more syntax you should be familiar with, inspired both by Bash and Python.

在本文中,我将讨论ABS编程语言的新发行版,在Bash和Python的启发下,带来您应该熟悉的更多语法。

This release includes 8 new features and 2 bugfixes, so let’s discover them together!

此版本包含8个新功能和2个错误修正,因此让我们一起发现它们!

更好的会员测试 (Better membership testing)

The membership testing operator, in, now supports finding whether an object has a particular key as well as allowing it to find substrings in strings:

成员资格测试运算符in ,现在支持查找对象是否具有特定键,并允许其查找字符串中的子字符串:

some in {"some": "thing"} # TRUEsome in {} # FALSE
"str" in "string" # TRUE"hello" in "string" # FALSE

With these changes to in we are now deprecating the set.includes(member) function:

通过这些更改in我们现在不建议使用set.includes(member)函数:

"string".contains("str")[1, 2, 3].contains(2)

The function will keep working but, again, is deprecated. We will likely not remove it from future releases (even major ones) but…you’ve been warned!

该功能将继续工作,但再次不推荐使用。 我们可能不会从将来的版本(甚至主要版本)中将其删除,但是…您已经得到警告!

1〜1.1 (1 ~ 1.1)

The similarity operator, ~, now supports numbers:

相似运算符~现在支持数字:

1 ~ 1.23 # TRUE1 ~ 0.99 # FALSE

Numbers will be similar if their integer conversion is the same. This is a shorthand for:

如果数字的整数转换相同,则数字将相似。 这是以下内容的简写:

1.int() == 1.23.int() # TRUE1.int() ~ 0.99.int() # FALSE

为..在 (for .. in)

We’ve made a few changes to for .. in to make it more useful, as you can now loop through hashes:

我们for .. in进行了一些更改for .. in以使其更有用,因为您现在可以遍历散列了:

for k, v in {"some": "thing"} {    # k is some     # v is thing }

更多的破坏力 (More destructuring)

We introduced destructuring before ABS was stable, updated it right before 1.0, and we’ve now expanded it to be able to destructure hashes:

我们在ABS稳定之前就引入了销毁方法,并在1.0之前对其进行了更新 ,现在我们对其进行了扩展以能够对散列进行销毁:

some, thing = {"some": 1, "thing": 1}some + thing # 2

反引号命令 (Backtick commands)

My absolute favorite feature in this release is the ability to execute commands with the backtick shell syntax:

在此发行版中,我绝对喜欢的功能是能够使用反引号shell语法执行命令:

`ls -la`
# previously you could only do$(ls -la)

There were some limitations with the $() syntax (namely, a command needs to be on its own line) that are not there anymore with backticks. Now you can do things such as:

$()语法有一些限制(即,命令必须在其自己的行上),而反引号则不再存在。 现在,您可以执行以下操作:

if `somecommand`.ok {    ...do something...}
# This is not possible, $() needs its own line$(somecommand).ok

The same interpolation style available with $() is working with backticks:

$()可用的相同插值样式适用于反引号:

arg = "-la"`ls $arg`

睡眠(毫秒) (sleep(ms))

Well…every language has one!

好吧……每种语言都有一种!

You can now pause execution of a script by sleeping for a certain amount of milliseconds:

现在,您可以通过Hibernate一定的毫秒数来暂停脚本的执行:

echo("This will be printed immediately")sleep(10000)echo("This will be printed in 10s")

哈希内置函数 (Hash builtin functions)

With this release we’ve added a bunch of new built-in functionalities to hashes:

在此版本中,我们为哈希添加了许多新的内置功能:

hash = {"a": 1, "b": 2, "c": 3}
hash.keys() # ["a", "b", "c"]hash.values() # [1, 2, 3]hash.items() # [["a", 1], ["b", 2], ["c", 3]]hash.pop(a) # hash is now {"b": 2, "c": 3}

NULL比较 (NULL comparison)

In ABS 1.0.0 we introduced a bug that would make NULL comparison fail:

ABS 1.0.0中,我们引入了一个使NULL比较失败的错误:

null == null # FALSE

In 1.2.0 we fixed it (and backported it to 1.0.2).

在1.2.0中,我们对其进行了修复(并将其反向移植到1.0.2 )。

索引分配 (Index assignments)

Assigning to the index of a hash / array now works:

现在可以分配给哈希/数组的索引:

array = []array[0] = 1 # array is now [1]array[5] = 1 # array is now [1, null, null, null, null, 1]
hash = {}hash.x = 1 # hash is now {"x": 1}

你在等什么? (What are you waiting for?)

bash <(curl https://www.abs-lang.org/installer.sh)

…and start scripting like it’s 2019!

…开始编写脚本,就像2019年一样!

PS: Again, many thanks to Erich, who’s been helping me along the way and has become a crucial member of the team over the past few weeks. Just want to make sure his name is mentioned as most of this stuff would not have been possible without him!

PS:再次感谢Erich ,他一直在帮助我,并在过去几周内成为团队的重要成员。 只是想确保提到他的名字,因为没有他,大多数东西都是不可能的!

PPS: 1.2.0 is already well underway — expect it within the next 2 to 3 weeks. We’ll be introducing extremely interesting features such as background commands and REPL history, so it’s going to be an exciting release!

PPS: 1.2.0已经很好地进行了 -预计在接下来的2-3周内。 我们将引入非常有趣的功能,例如后台命令和REPL历史记录,因此它将是一个令人兴奋的发行版!

Originally published at odino.org.You can follow me on Twitter — rants are welcome! ?

最初在odino.org上发布。 您可以在Twitter上关注我-欢迎咆哮!

翻译自: https://www.freecodecamp.org/news/abs-1-1-0-more-python-and-bash-for-the-most-fun-programming-language-out-there-d62806b1cf53/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值