关键字或语句与函数调用之间有什么区别? [英] What's the difference between a keyword or a statement, and a function call?

查看:277
本文介绍了关键字或语句与函数调用之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近才考虑这个问题,因为Python 3正在将 print 从语句更改为函数。

I was thinking about this recently since Python 3 is changing print from a statement to a function.

然而,Ruby和CoffeeScript采用相反的方法,因为你经常省略函数的括号,从而模糊了关键字/语句和函数之间的区别。 (没有括号的函数调用看起来很像关键字。)

However, Ruby and CoffeeScript take the opposite approach, since you often leave out parentheses from functions, thereby blurring the distinction between keywords/statements and functions. (A function call without parentheses looks a lot like a keyword.)

一般来说,关键字和函数有什么区别?在我看来,一些关键字只是真正的功能。例如, return 3 也可以被认为是 return(3)其中返回函数在语言。或者在JavaScript中, typeof 是一个关键字,但它看起来非常像一个函数,可以用括号调用。

Generally, what's the difference between a keyword and a function? It seems to me that some keywords are really just functions. For example, return 3 could equally be thought of as return(3) where the return function is implemented natively in the language. Or in JavaScript, typeof is a keyword, but it seems very much like a function, and can be called with parentheses.

想法?

推荐答案

关键字是比功能低级的构建块,可以做功能不能做的事情。

Keywords are lower-level building blocks than functions, and can do things that functions can't.

您在问题中提到 return ,这是一个很好的例子:在您提及的所有语言中,方法使用函数提供与 return x 相同的行为。

You cite return in your question, which is a good example: In all the languages you mention, there's no way to use a function to provide the same behavior as return x.

这篇关于关键字或语句与函数调用之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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