每个文字都是一个表达式吗?

发布于 12-17 10:28 字数 230 浏览 5 评论 0原文

让我们从一些定义开始:

  • 表达式 是一个生成(返回)值的构造。
  • literal 是表示固定值的符号。

我可以假设该文字是一个仅返回一个值的表达式。例如,文字 1 是一个返回值 1 的表达式。

我的方法有什么问题吗?还是文字总是意味着是表达式?

谢谢您的澄清。

Let's begin with some definitions:

  • An expression is a construct that produces (returns) a value.
  • A literal is a notation for representing a fixed value.

I could assume the literal is a expression that returns exactly one value. E.g. the literal 1 is an expression that returns the value 1.

Is there anything wrong in my approach or does being a literal always imply being an expression?

Thank you for clarification.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稚然2024-12-24 10:28:48

如果您考虑了特定于语言的异常(Python 文档字符串、C 宏等),那么您是正确的。一般来说,每个文字都是一个表达式。

If you account for language-specific exceptions (Python docstrings, C macros, etc.), you are correct. In general, every literal is an expression.

丢了幸福的猪2024-12-24 10:28:48

这是我的理解。换句话说:

4-3 是表达 1 的一种方式

1 是表达 1 的另一种方式>

它们都是表达式,因为它们都表达一个值 (1)。但 1 也是一个文字 - 因为它是字面上 1

That's my understanding. To think of it another way:

4-3 is one way of expressing 1

1 is another way of expressing 1

They are both expressions, because they both express a value (1). But 1 is also a literal - because it's literally 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文