编译器的这个响应是否有效? [英] Is this response from the compiler valid?

查看:27
本文介绍了编译器的这个响应是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码调用错误.我在参考资料中找不到任何关于此的信息.'=' 运算符右侧缺少空格是一个错误.

The following code invokes an error. I could not find any information on this is in the reference. The lack of whitespace on the right hand side of the '=' operator is an error.

let names =["Anna", "Alex", "Brian", "Jack"]

此语法的任何其他组合都可以编译.有谁知道根据我们现在对 Swift 的了解,这是否是真正无效的语法?

Any other combination of this syntax compiles. Anyone know if this is truly invalid syntax per what we know of Swift right now?

错误响应为:Prefix/postfix '=' is reserved

ANSWER:这段摘录似乎回答了我的问题.就是找了很久都没找到:

ANSWER: This excerpt seems to answer my question. I just couldn't find it for the longest time:

运算符周围的空格用于确定运算符用作前缀运算符、后缀运算符或二进制操作员.此行为总结为以下规则:

The whitespace around an operator is used to determine whether an operator is used as a prefix operator, a postfix operator, or a binary operator. This behavior is summarized in the following rules:

如果一个操作符两边都有空格或者两边都没有空格方面,它被视为二元运算符.例如,+a+b 和 a + b 中的运算符被视为二元运算符.如果运算符仅在左侧有空格,它被视为前缀一元运算符.例如,++b 中的 ++ 运算符是视为前缀一元运算符.如果运算符上有空格仅右侧,它被视为后缀一元运算符.作为例如,a++ b 中的 ++ 运算符被视为后缀一元操作员.如果操作符左边没有空格但跟在后面紧接一个点 (.),它被视为后缀一元运算符.例如,a++.b 中的 ++ 运算符被视为后缀一元运算符(a++ . b 而不是 a ++ .b).

If an operator has whitespace around both sides or around neither side, it is treated as a binary operator. As an example, the + operator in a+b and a + b is treated as a binary operator. If an operator has whitespace on the left side only, it is treated as a prefix unary operator. As an example, the ++ operator in a ++b is treated as a prefix unary operator. If an operator has whitespace on the right side only, it is treated as a postfix unary operator. As an example, the ++ operator in a++ b is treated as a postfix unary operator. If an operator has no whitespace on the left but is followed immediately by a dot (.), it is treated as a postfix unary operator. As an example, the ++ operator in a++.b is treated as a postfix unary operator (a++ . b rather than a ++ .b).

摘自:Apple Inc.The Swift Programming Language".电子书.https://itun.es/us/jEUH0.l

Excerpt From: Apple Inc. "The Swift Programming Language." iBooks. https://itun.es/us/jEUH0.l

推荐答案

= 后添加一个空格.(<码> = [看起来太悲伤是一个运算符.)它可能看到<代码> =值作为使用(可能的,但不实施)前缀运算符.

Add a space after the =. (=[ looks too sad to be an operator.) It's probably seeing =value as a use of a (possible, but not implemented) prefix operator.

Swift 并不像 C 那样完全与空格无关……特别是,它使用空格来区分前缀和后缀运算符(因为 C 中的 ++i++ 是一种语法上的奇怪之处).但它也没有像 Python 那样对空格严格得可笑.

Swift isn't entirely whitespace-agnostic like C... in particular, it uses whitespace to distinguish prefix from postfix operators (because ++i++ in C is a grammar oddity). But it's not ridiculously strict about whitespace like Python either.

这篇关于编译器的这个响应是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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