2

I'm looking for the name of the programming concept that eval is---eval being the function which executes a string as an expression.

I'm interested in the term for both executing raw strings in code eval('print("hello")'), and also from file, like executing any .php extension. The term I think is appropriate is "runtime metaprogramming" but am looking to know whether this is correct and whether there are other concepts the eval function presents.

4

1 回答 1

1

“解释器”是用于处理表示某种程序的字符串(直接提供或在文件中提供)并返回答案的函数的术语。

通常,解释器在获取答案的过程中不会“编译”字符串。如果您知道它可以编译字符串,那么解释器就不是真正正确的词,您可能只需将其称为“eval(uator)”。(当然,由于您的示例是一个黑匣子,您并不真正知道它在内部做了什么,构建此类工具的人希望它们能够快速运行)。

[元编程是关于操纵其他程序的程序,有时仅限于“检查”其他程序。您可能会争辩说,您的函数要计算其答案,正在执行(元编程)“检查”。如果你这样做了,你最终会将经典编译归为元编程,这不是元编程的典型观点。通常元编程是关于非编译/解释活动。]

于 2019-01-20T11:06:51.790 回答