Mathematica 是一种无类型语言吗? [英] Is Mathematica an untyped language?

查看:27
本文介绍了Mathematica 是一种无类型语言吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与大多数编程语言不同,Mathematica 中的每个值都是一个表达式.将任何操作应用于任何表达式总是会产生另一个表达式.因此,Mathematica 实际上只有一种类型.Mathematica 不做静态类型检查,甚至可以说,甚至不动态检查类型(在运行时).

Unlike most programming languages, every value in Mathematica is an expression. Applying any operation to any expressions always yields another expression. Consequently, Mathematica effectively has only one type. Mathematica does no static type checking and, arguably, doesn't even check types dynamically (at run-time).

例如,将整数表达式 1 添加到 Mathematica 中的字符串表达式 "foo" 导致(无意义的)表达式 1 + "foo" 但没有错误.在其他情况下,Mathematica 提供有关无意义输入的反馈,但生成此反馈的检查必须由程序员明确执行.

For example, adding the integer expression 1 to the string expression "foo" in Mathematica results in the (nonsensical) expression 1 + "foo" but no error. In other cases, Mathematica provides feedback about nonsensical input but the checks that generate this feedback must be performed explicitly by the programmer.

因此,将 Mathematica 描述为一种无类型语言而不是静态或动态类型语言是否公平?

Thus, is it fair to describe Mathematica as an untyped language as opposed to a statically or dynamically typed language?

推荐答案

简短的回答:无类型或无类型.这就是 Wolfram Research 对产品本身的描述.参见此处.

The short answer: Untyped or typeless. This is how Wolfram Research describes the product themselves. See here.

长答案:乔恩,我认为你的问题真的取决于你所说的无类型是什么意思.为了吸引权威资源,即维基百科相比之下,一种无类型语言,例如大多数汇编语言允许对任何数据执行任何操作,这些数据通常被认为是各种长度的位序列."

Long answer: Jon, I think your question really hinges on what you mean by untyped. To appeal to the definitive resource that is Wikipedia "In contrast, an untyped language, such as most assembly languages, allows any operation to be performed on any data, which are generally considered to be sequences of bits of various lengths."

阅读前面的答案,似乎争论的核心是类型检查器在遇到错误时应该怎么做.通常的答案是停止评估并报告某种错误.从几个较早的问题 (1)(2) 在 Stackoverflow 上,我们可以看到没有优雅的Mathematica 内置的方法.(我要补充一点,在第 8 版中更加强调编译到 C,可以编写类型检查代码,但我不确定这是否应该算作主要语言的一部分.)

Reading the earlier answers, it seems the heart of the debate is what should a type checker when it encounters an error. The usual answer is to STOP evaluation and report some kind of error. From several earlier questions (1) and (2) on Stackoverflow, we can see that there isn't a graceful way of doing this built-in to Mathematica. (I would add the caveat that with more emphasis on compilation to C in version 8 that it is possible to write type checked code but I am unsure whether this should be counted as part of the main language.)

这篇关于Mathematica 是一种无类型语言吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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