Stata 图灵完备吗?

发布于 2024-10-06 10:44:59 字数 123 浏览 0 评论 0原文

我最近一直在用 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 技术交流群。

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

发布评论

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

评论(5

<逆流佳人身旁 2024-10-13 10:44:59

我以前从未听说过 Stata,但网页吹嘘它有“if, while”和“ 循环和分支”。

Wikibooks 有这个例子

local k = 1
file open myfile using toto.txt, read text
file read myfile line
while r(eof) == 0 {
    local k = `k' + 1
    di "`k' `line'"
    file read myfile line
    }
file close myfile

我不知道什么是“正确的”编程语言 意味着但乍一看它绝对是图灵完备的。

I've never heard of Stata before but the webpage brags that it has "if, while" and "looping and branching".

Wikibooks has this example:

local k = 1
file open myfile using toto.txt, read text
file read myfile line
while r(eof) == 0 {
    local k = `k' + 1
    di "`k' `line'"
    file read myfile line
    }
file close myfile

I don't know what "proper" programming language means but at first glance it definitely appears to be Turing-complete.

摘星┃星的人 2024-10-13 10:44:59

一种“合适的”编程语言,是指您可以用它构建网页或 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.

泪意 2024-10-13 10:44:59

Stata 的 ado 语言具有所有常见的条件语句:

然而,重要的是,不会混淆两者:

此外,Stata 的 ado 语言循环结构包括:

Mata,Stata的矩阵编程语言还支持:

因此,Stata 的 adomata 编程语言似乎
满足图灵完备的标准。

但值得注意的是,这些不是一般编程
语言,而是成熟的统计语言。

Stata's ado language has all the usual conditional statements:

However, it is important that one does not confuse the two:

In addition, Stata's ado language loop constructs include:

Mata, Stata's matrix programming language also supports:

Consequently, both Stata's ado and mata programming languages appear to
satisfy 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.

就此别过 2024-10-13 10:44:59

@eric.a.booth:我认为你的例子很奇怪。我不确定我是否见过 while { ... } else {...}

另外,请注意,Stata 在运行循环之前不会对其进行测试,并且会允许自己陷入无限循环。

local x = 0
while `x'<5 {
   display `x' / 2
   local ++x
}

@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.

local x = 0
while `x'<5 {
   display `x' / 2
   local ++x
}
帅冕 2024-10-13 10:44:59

虽然您可以使用 -while-、-if、-else- 命令执行循环直到满足条件,但在 Stata 中使用 -foreach- 或 -forvalues- 循环代替它们通常是更好的主意。
因此,与其说:

while "`1'" != "" {
<do something>
} 

或者

if "`a'" == "" {
<do something>
}
else {
<do something else>
}

通常更好(而且更直观)的是:

forvalues x = 1/100 {
<do something>
}

-- 不需要 -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:

while "`1'" != "" {
<do something>
} 

or

if "`a'" == "" {
<do something>
}
else {
<do something else>
}

it's usually better (and more intuitive) to instead to do:

forvalues x = 1/100 {
<do something>
}

-- 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.

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