Stata 图灵完备吗?
我最近一直在用 Stata 做一些统计工作,但不太喜欢它。
我觉得它不是一种“正确的”编程语言:特别是我不认为有一种方法可以循环直到满足条件。
我的感觉是否正确,或者 Stata 真的是图灵完备的吗?
I have been doing some statistics work with Stata recently and not enjoying it very much.
It doesn't feel to me like it's a "proper" programming language: in particular I don't think there's a way to loop until a condition is met.
Am I right in my feeling, or is Stata truly Turing-complete?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我以前从未听说过 Stata,但网页吹嘘它有“if, while”和“ 循环和分支”。
Wikibooks 有这个例子:
我不知道什么是“正确的”编程语言 意味着但乍一看它绝对是图灵完备的。
I've never heard of Stata before but the webpage brags that it has "if, while" and "looping and branching".
Wikibooks has this example:
I don't know what "proper" programming language means but at first glance it definitely appears to be Turing-complete.
一种“合适的”编程语言,是指您可以用它构建网页或 GUI?当然不是。但这有点极端。您当然可以使用 .ado 和 .do 文件编写循环;我想说它是图灵完备的。
A "proper" programming language in the sense that you could build a webpage or GUI with it? Of course not. But that's a bit extreme. You can certainly write loops with .ado and .do files; i would say it is turing complete.
Stata 的
ado
语言具有所有常见的条件语句:if 编程命令
if exp 限定符
然而,重要的是,不会混淆两者:
此外,Stata 的
ado
语言循环结构包括:for(从 Stata 8 开始是一个过时的命令)
foreach
forvalues
同时
Mata
,Stata的矩阵编程语言还支持:如果和其他
for
同时
因此,Stata 的
ado
和mata
编程语言似乎满足图灵完备的标准。
但值得注意的是,这些不是一般编程
语言,而是成熟的统计语言。
Stata's
ado
language has all the usual conditional statements:if programming command
if exp qualifier
However, it is important that one does not confuse the two:
In addition, Stata's
ado
language loop constructs include:for (an out-of-date command as of Stata 8)
foreach
forvalues
while
Mata
, Stata's matrix programming language also supports:if and else
for
while
Consequently, both Stata's
ado
andmata
programming languages appear tosatisfy the criteria for being characterized as Turing complete.
It is important to note though that these are not general programming
languages, but full-fledged statistical languages.
@eric.a.booth:我认为你的例子很奇怪。我不确定我是否见过
while { ... } else {...}
另外,请注意,Stata 在运行循环之前不会对其进行测试,并且会允许自己陷入无限循环。
@eric.a.booth: I think your example is strange. I'm not sure I've ever seen
while { ... } else {...}
Also, note that Stata doesn't test the loop before you run it, and will allow itself to get caught in an infinite loop.
虽然您可以使用 -while-、-if、-else- 命令执行循环直到满足条件,但在 Stata 中使用 -foreach- 或 -forvalues- 循环代替它们通常是更好的主意。
因此,与其说:
或者
通常更好(而且更直观)的是:
-- 不需要 -if-、-else- 或 -break- 条件。有关详细信息,请参阅 Stata 中的 -help forvalues- 或 -help foreach-。
^注意:我原来的帖子中的 while-else 循环已被删除 - 感谢您的提醒,Keith。 -else- 部分仅用于 if{] else{} 循环示例。无论如何,我的文章的目的不是建议使用 while/else 或 if/else 循环,而是 -foreach-/-forvalues- 通常是首选方法。
While you can use the -while-, -if, -else- commands to perform looping until a condition is met, it's usually a better idea in Stata to use the -foreach- or -forvalues- loops in their place.
So, instead of saying:
or
it's usually better (and more intuitive) to instead to do:
-- No -if-, -else-, or -break- conditions needed. See -help forvalues- or -help foreach- in Stata for details.
^NOTE: the while-else loop in my original post was removed--thanks for the heads-up, Keith. The -else- part was intended for the if{] else{} loop example only. Regardless, the point of my post wasn't to suggest the use of a while/else or if/else loop, it was that -foreach-/-forvalues- are usually a preferred approach.