如何判断一种语言是否是“动态语言”?

发布于 2024-08-09 19:50:51 字数 1652 浏览 8 评论 0原文

我试图更好地理解语言“动态”的真正含义。我对 Lingo 有相当多的经验,它是 Adob​​e(以前称为 Macromedia)Director 产品线的脚本语言,我只是想知道它是否会被视为“动态语言”。

对我来说,处理变量和列表的方式似乎非常“动态语言”。

对于变量,您只需编写 foo = 3bar = "Hello World"。您无需将变量声明为 intstring——它会按原样计算出来。

对于列表,您可以编写类似 miscCollection = [3, "Hello World", #helloWorld, ["Embedded List", "Goes Here", 3], [#phrase: "Property List gone Here", #值:3]]。这不是类似于元组吗?

这些功能是否足以获得“动态语言”地位?

有趣的是,我更多地使用 C#,而更少地使用 Director/Lingo,但随着这些天对动态语言的兴奋,我想知道我是否真的在违背常规。

编辑

关于下面Mark Rushakoff的回答,这里尝试使用此维基百科文章

  1. Eval - Lingo 具有 dovalue 关键字。 do 将执行整个命令,例如 do "foo = 23"do "foo = sum(20, 3)"value 尝试将字符串转换为数字,但它不仅仅是一个解析运算符 - 它实际上可以将变量的字符串表示形式转换为其数字,例如,假设 foo = 23,语句 value("foo") 将计算为 23。

  2. 高阶函数 - 如果我理解正确的话,这基本上就是我所说的C# 中的“委托”。据我所知,Lingo 并不直接支持这一点,尽管您可以创建一个具有函数的类型(称为“父脚本”)并传递该类型的实例。

  3. 闭包 - 据我所知,不支持此操作。

  4. 继续 - 据我所知,不支持此操作。

  5. 反思 - 至少在某种意义上,是的。实际上,您使用字符串创建类型的新实例,例如,fooInstance = script("Foo").new(bar)。还可以将类型的实例转换为包含类型名称的字符串(因此您可以模仿 C# 的 GetType() 功能)。您还可以在不知道属性名称的情况下查询类型的属性(例如,通过索引查找属性)并通过索引找出属性的名称。

  6. 宏 - 维基百科文章描述宏的方式,我不这么认为。然而,可以在运行时编辑脚本,所以也许这很重要。

因此,看起来 Lingo 在动态功能方面得分为 2 到 3(满分 6 分),但我对闭包和延续还不够清楚,无法确定 Lingo 不支持它们。我想我不知道该得出什么结论。欢迎评论。

I'm trying to get a better handle on what it really means for a language to be "dynamic". I have quite a bit of experience with Lingo, which is the scripting language for the Adobe (formerly Macromedia) Director product line, and I'm just wondering if it would be considered a "dynamic language".

The way variables and lists are handled seems very "dynamic language"-ish to me.

With variables, you would just write foo = 3 or bar = "Hello World". You don't declare a variable as an int or string--it figures that out as is goes.

With lists, you can just write something like miscCollection = [3, "Hello World", #helloWorld, ["Embedded List", "Goes Here", 3], [#phrase: "Property List goes here", #value: 3]]. Would this not be similar to a tuple?

Are these features enough to qualify for "dynamic language" status?

Interestingly, I've been using C# a lot more and Director/Lingo a lot less, but with all the excitement over dynamic languages these days, I wonder if I'm actually going against the grain.

EDIT

Regarding Mark Rushakoff answer, below, here's an attempt to analyze whether Lingo qualifies as "dynamic" using this Wikipedia article:

  1. Eval - Lingo has do and value keywords. do will execute an entire command, e.g., do "foo = 23" or do "foo = sum(20, 3)". value attempts to convert a string into a numeric, but it is more than just a parsing operator--it can actually convert a string representation of a variable into its number, e.g., assuming foo = 23, the statement value("foo") will evaluate to 23.

  2. Higher-Order Functions - If I'm understanding this right, this is basically what I would be called a "delegate" in C#. Lingo doesn't support this directly as far as I know, although you could create a type (called a "parent script") that has a function and pass an instance of the type.

  3. Closures - No support for this as far as I know.

  4. Continuation - No support for this as far as I know.

  5. Reflection - In a sense at least, yes. You actually create new instances of types using a string, e.g., fooInstance = script("Foo").new(bar). It is also possible to convert an instance of a type into a string that contains the name of the type (so you can sort of mimic c#'s GetType() functionality). You can also query the properties of a type without knowing the names of the properties (e.g., look up a property by index) and find out the names of the properties by index.

  6. Macros - The way the Wikipedia article describes a macro, I don't believe so. It is possible to edit scripts at runtime, however, so maybe that counts.

So, it seems that Lingo scores a 2 to 3 out of 6 on dynamic features, but I'm not clear enough on closures and continuations to know for sure that Lingo doesn't support them. I guess I'm not sure what to conclude. Comments welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

○闲身 2024-08-16 19:50:51

类型推断(例如您的 foo = 3bar = "Hello World" 示例)并不意味着动态语言。 C# 中的 var 关键字在编译时推断变量类型,Haskell 还可以对所有变量使用隐式类型,即使在已编译的程序中也是如此。

“动态编程语言”是一个定义相当松散的术语,但我认为如果你必须限制如果将其传递给一个限定符,则这将是运行时反射。如果您可以进行反射,那么您可能可以执行维基百科文章中列出的其他限定符(eval、对象运行时更改、闭包、宏...)。

我对 Lingo 语言一无所知,但我想说,通常来说,取消某种语言的动态性比限定一种语言更容易。 Lingo 可以执行维基百科文章中的任何/所有限定符吗?如果不是,那么它可能不是动态的。如果它可以做任何事情,那么它可能至少是“足够动态”的。

Type inferencing (such as your examples of foo = 3 and bar = "Hello World") does not imply a dynamic language. The var keyword in C# infers the variable type at compile-time, and Haskell also can use implicit typing for all variables, even in compiled programs.

"Dynamic programming language" is a pretty loosely defined term, but I think if you had to restrict it to one qualifier, it would be runtime reflection. If you can do reflection, you can probably do the other qualifiers listed in the Wikipedia article (eval, object runtime alteration, closures, macros...).

I don't know anything about the Lingo language, but I'd say it's generally easier to disqualify a language as being dynamic than it is to qualify a language. Can Lingo do any/all of the qualifiers in the Wikipedia article? If not, then it's probably just not dynamic. If it can do any, then it's probably at least "dynamic enough".

○闲身 2024-08-16 19:50:51

“动态”是很流行的词之一,但实际上的意思只不过是“我所做的很酷”......它没有精确的定义。

话虽如此,我可以回答您有关类型的问题,或者至少尝试更好地解释类型化语言和非类型化语言(有些人称之为动态或动态类型化)语言之间的区别。

类型化语言会检查您永远不会尝试使用变量执行在运行程序之前无法执行的操作。无类型语言不会执行此检查 - 它只是希望得到最好的结果,并且如果它具有不适合其需要的值,则会给出错误。

这是两个极端。就像生活中的一切一样,在实践中语言介于两个理论上的极端之间。因此,有时很难说一种语言是类型化的还是非类型化的——通常你只能说“X 语言在编译时比 Y 语言有更好的类型检查,因为这些错误在 X 中被捕获,但在 Y 中却没有:... ”

考虑到这个定义,您可能会担心 (1) 类型化语言在程序中需要更多文本(因为您需要说明每个值的类型)以及 (2) 类型化语言可能会不必要地限制您可以执行的操作(因为类型系统不够智能,无法让您看到的东西起作用)。

这两者都可能是问题。但随着类型化语言变得更好,这两个问题都变得不那么重要了。例如,为什么有这样的代码:

String s = "hello"

当很明显

s = "hello"

“s”必须是字符串时?像这样“智能”的语言,你不需要说出所有类型是什么,但它们仍然会被检查,通常被称为“Hindley Milner”,因为这些人是第一个弄清楚如何做到这一点的人详细。

因此,当您查看为具有 Hindley Milner 类型系统的语言编写的程序时,它可能看起来没有类型。但这是一个错误。在程序运行之前,它仍然会计算出所有变量的所有类型必须是什么,并检查您是否不会因尝试使用错误类型执行某些操作而出现任何错误(我认为这太棒了 - 它接近于一种人工智能......)

这意味着有时了解一种语言是否是类型化的唯一方法是了解它是如何实现的。仅仅看源码可能并不明显。

编辑:我刚刚重新阅读了上面的内容,我本来可以更清楚一点。我试图区分具有类型系统的语言和不具有类型系统的语言。类型系统包括两部分:类型本身和检查类型是否正确的逻辑。

我称之为“无类型”(或动态类型)的语言确实有类型。例如,在 Python(一种无类型的动态语言)中,字符串和整数之间仍然存在差异。但他们没有额外的逻辑来在程序运行之前检查程序。因此更准确的说法是它们有类型,但没有类型系统。

相比之下,正如我所说,“类型化”语言会在程序运行之前进行检查,因此不仅必须具有类型,还必须具有完成该工作的额外逻辑。

"dynamic" is one of those words that's fashionable, but really means little more than "What I do is cool"... it doesn't have a precise definition.

Having said that, I can answer your question about types, or at least try and explain the difference between typed and untyped (what some people call dynamic, or dynamically typed) languages better.

A typed language checks that you will never end up trying to do something with a variable that you cannot do before you run the program. An untyped language does not do this check - it simply hopes for the best and, if it any point it has a value that is unsuitable for what it needs, gives an error.

Those are two extremes. Like everything in life, in practice languages lie somewhere between the two theoretical extremes. So it's sometimes hard to say that a language is typed or untyped - often all you can say is something like "language X has better type checking at compile time than language Y because these errors are caught in X but not in Y:...."

Given that definition you might worry that (1) a typed language requires a lot more text in the program (because you need to say what type each value is) and (2) that a typed language might restrict what you can do unnecessarily (because the type system isn't smart enough to allow something that you can see would work).

Both of those can be problems. BUT they are both problems that are getting less important as typed languages get better. For example, why have code like:

String s = "hello"

when it's obvious with just

s = "hello"

that "s" must be a String? Languages that are "smart" like this, and where you don't need to say what all the types are, but they are still checked, are often called "Hindley Milner" because those are the people that first worked out how to do that in detail.

So when you look at a program written for a language with a Hindley Milner type system it may look like it doesn't have types. But that's a mistake. It will still, before the program is run, work out what all the types of all the variables must be, and check that you cannot get any errors for trying to do something with the wrong type (I think this is amazing - it's close to a kind of artificial intelligence...)

That means that sometimes the only way to know whether a language is typed or not it to know how it is implemented. It may not be obvious from just looking at the source.

Edit: I just re-read the above, and I could have been a little clearer. The distinction I was trying to make was between languages that have a type system and languages that don't. A type system includes two things: types themselves and logic to check that the types are correct.

The languages I was calling "untyped" (or dynamically typed) do have types. In Python, for example (which is an untyped, dynamic language), there is still a difference between a String and an Integer. But they don't have the extra logic that checks the program before it runs. So it would be more accurate to say that they have types, but don't have a type system.

In contrast "typed" languages, as I said, do check before the program runs, and so must have not just types, but the extra logic to do that work.

彼岸花似海 2024-08-16 19:50:51

当人们谈论“动态”编程语言时,他们通常指的是动态类型系统。我读过的关于动态类型系统是什么(以及它不是什么)的最佳定义是 Chris Smith 的优秀文章 在讨论类型系统之前需要了解什么

一旦您阅读了这篇文章,我认为您应该对任何给定语言是否符合静态类型或动态类型的标准有自己的答案。

When people talk about a programming language being "dynamic", they are usually referring to a dynamic type system. The best definition of what a dynamic type system is (and what it isn't) that I've ever read is Chris Smith's excellent article What to Know Before Debating Type Systems.

Once you've read that article, I think you should have your answer as to whether any given language qualifies as being statically or dynamically typed.

孤星 2024-08-16 19:50:51

我想表明 Lingo 是一种动态语言。

我已经为 Lingo 编写了 LingoF 函数式编程框架。
这个框架完全是用Lingo编写的,没有xtra,没有使用低级组件,所以如果语言不是动态的,就不可能开发这样的框架。

考虑到该框架,以下是我对 Lingo 作为动态语言的评估:

1 - Eval - Lingo 有 dovalue 关键字。另外,您可以在执行时编译脚本。请参阅 LingoF 的功能“Lingo 表达式”。

2 - 高阶函数 - LingoF 展示了在 Lingo 中广泛使用高阶函数的可能性。

3 - 闭包 - LingoF 再次展示了如何在 Lingo 中使用闭包。

4 - 延续 - LingoF 语法助手是使用延续技术定义的。可以用连续传递风格编写函数。检查这个(取自 LingoF 模块):

on public_factorialCPS_2
on fac me, n,k
  x = LingoF().var()
  if ( n = 0 ) then return k [1] 
  else return me.factorialCPS[$(#-,n,1) ] [ LingoF().fun(x) [ k [ $(#*,n,x) ]  ] ]
end

5 - 反思 - 已经回答是,我同意。例如,LingoF 模块管理器是使用 DanM 提到的 Lingo 的反射功能来实现的。

6 - 宏 - 我将不得不在这个领域做更多的研究。
由于Director 支持链接脚本(存储在外部文本文件中的脚本),因此可以实现某种宏。也许宏管理器可以拦截一些事件,例如 startMovie (展开它们)和 stopMovie (再次压缩它们)。
另一种可能性是使用字段作为脚本并在脚本成员中扩展它们,我确信它会正常工作。

所以我的动态特征得分是 5 到 6 分(满分 6 分)。

I would like to show that Lingo is a dynamic language.

I've did LingoF a Functional Programming Framework for Lingo.
This Framework is entirely written in Lingo, no xtra, no low level components used, so it wouldn't be possible to develop such framework if the language was not dynamic.

Considering that framework, here is my evaluation for Lingo as Dynamic language:

1 - Eval - Lingo has do and value keywords. Plus you can compile a script in execution time. See LingoF's Feature "Lingo Expressions".

2 - Higher-Order Functions - LingoF shows how possible is to do extensive use of Higher order functions in Lingo.

3 - Closures - Again LingoF shows how is possible to work with Closures in Lingo.

4 - Continuation - LingoF syntax helpers are defined with continuation techniques. It is possible to write functions in Continuation Passing Style. Check this (taken from LingoF module):

on public_factorialCPS_2
on fac me, n,k
  x = LingoF().var()
  if ( n = 0 ) then return k [1] 
  else return me.factorialCPS[$(#-,n,1) ] [ LingoF().fun(x) [ k [ $(#*,n,x) ]  ] ]
end

5 - Reflection - Already answered yes and I agree. For example LingoF module manager is implemented using Lingo's Reflection features mentioned by DanM.

6 - Macros - I will have to do more research in this field.
Since Director supports Linked Scripts (scripts stored in external text files) it is possible to implement some kind of macros. Maybe the macro manager can intercept some events like startMovie (to expand them) and stopMovie (to compress them again).
Another possibility is to use fields as scripts and expand them in script members, I'm sure it will work fine.

So my score is 5 to 6 out of 6 on dynamic features.

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