博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ABS 1.1.0:更多Python和Bash提供最有趣的编程语言
阅读量:2522 次
发布时间:2019-05-11

本文共 4633 字,大约阅读时间需要 15 分钟。

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 , 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 , bringing more syntax you should be familiar with, inspired both by Bash and Python.

在本文中,我将讨论新发行版,在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 , , and we’ve now expanded it to be able to destructure hashes:

我们引入了销毁方法,并 ,现在我们对其进行了扩展以能够对散列进行销毁:

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 we introduced a bug that would make NULL comparison fail:

在我们引入了一个使NULL比较失败的错误:

null == null # FALSE

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

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

索引分配 (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 , 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:再次感谢 ,他一直在帮助我,并在过去几周内成为团队的重要成员。 只是想确保提到他的名字,因为没有他,大多数东西都是不可能的!

PPS: — 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: -预计在接下来的2-3周内。 我们将引入非常有趣的功能,例如后台命令和REPL历史记录,因此它将是一个令人兴奋的发行版!

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

最初在发布。 您可以在关注我-欢迎咆哮!

翻译自:

转载地址:http://pfewd.baihongyu.com/

你可能感兴趣的文章
(转)arguments.callee移除AS3匿名函数的侦听
查看>>
onNewIntent调用时机
查看>>
MYSQL GTID使用运维介绍(转)
查看>>
04代理,迭代器
查看>>
解决Nginx+PHP-FPM出现502(Bad Gateway)错误问题
查看>>
Java 虚拟机:互斥同步、锁优化及synchronized和volatile
查看>>
2.python的基本数据类型
查看>>
python学习笔记-day10-01-【 类的扩展: 重写父类,新式类与经典的区别】
查看>>
查看端口被占用情况
查看>>
浅谈css(块级元素、行级元素、盒子模型)
查看>>
Ubuntu菜鸟入门(五)—— 一些编程相关工具
查看>>
PHP开源搜索引擎
查看>>
12-FileZilla-响应:550 Permission denied
查看>>
ASP.NET MVC 3 扩展生成 HTML 的 Input 元素
查看>>
LeetCode 234. Palindrome Linked List
查看>>
编译HBase1.0.0-cdh5.4.2版本
查看>>
结构体指针
查看>>
迭代器
查看>>
Food HDU - 4292 (结点容量 拆点) Dinic
查看>>
Ubuntu安装Sun JDK及如何设置默认java JDK
查看>>