有人知道静态类型脚本语言吗?

发布于 2024-07-13 15:33:05 字数 1542 浏览 4 评论 0原文

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

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

发布评论

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

评论(5

慈悲佛祖 2024-07-20 15:33:05

通常,静态类型语言是编译语言。 我想原因是,类型的静态分析相当昂贵,您必须深入查看正在处理的所有代码。 完成此操作后,如果不将所有信息写入文件,感觉就像是一种浪费,这样下次就不必再这样做了。 所以你很快就会得到一种编译语言。

另一方面,将编译语言转变为“非编译”语言相当容易。 您只是不将编译结果存储在任何地方而是直接执行它们。 我知道提供这样一个包装器的编译器是 GHC,标准的 Haskell 编译器。 您可以将 #!/usr/bin/runhaskell 添加到源文件中,然后直接执行它们。 既然你打算远离常态,Haskell 似乎是一个完美的选择;)。 但预计脚本的启动时间会相当长,因为所有“编译时”分析和优化都不是免费的。

Haskell 不是为 shell 脚本编写的,它是一种函数式语言,因此如果您以前从未见过它,可能需要一些时间来习惯。 但它的语法开销非常小,而且函数式语言的优势在于抽象,所以我不明白为什么你不能创建一个让 shell 脚本变得有趣的库。 甚至还有一些 实验性 Haskell shell,但是它似乎更像是一个概念验证,而不是一个真正的解决方案。

一般来说,我会说所有类型分析的开销都很大,但我建议您选择您最喜欢的静态类型编译语言,并寻找像 runhaskell 这样的包装器来执行用它编写的脚本。

Typically the statically typed languages are compiled languages. I guess the reason is, that statical analysis of types is rather expensive and you have to have an in depth look at all the code you're processing. After you've done that it feels like a waste to not write all that information into a file, so that you don't have to do it again next time. So you quickly end up with a compiled language.

On the other hand, to turn a compiled language in a "not-compiled" one is rather easy. You just don't store the results of the compilation anywhere but execute them directly. One compiler I know that provides such a wrapper is GHC, the standard Haskell compiler. You can add #!/usr/bin/runhaskell to your source files and then directly execute them. And since you're planning to be far off the norm, Haskell seems like a perfect fit ;). But expect some rather large startup time for your scripts, because all the "compile time" analysis and optimization isn't free.

Haskell isn't made for shell scripting and it's a functional language, so if you've never seen it before, it might take some time to get used to. But it has very little syntactical overhead and the strength of functional languages is abstraction, so I don't see why you couldn't create a library that makes shell scripting fun. There is even some experimental Haskell shell, but it does seem to be more a proof-of-concept than a real solution.

Generally I would say the overhead of all the type analysis is significant, but I would suggest you pick your favorite statically typed compiled language and look for a wrapper like runhaskell to execute scripts written in it.

扛起拖把扫天下 2024-07-20 15:33:05

快速谷歌。 F3,javaFX脚本,Linden脚本语言(第二人生的脚本),与第一个答案的评论不同F#可以用作脚本语言http://blogs.msdn.com/chrsmith/archive/2008/09/12/scripting-in-f.aspx

Felix、Tuga、CFGScript、Talc、Angelscript,猜测还有更多的快速搜索。

道格拉斯

quick google. F3, javaFX script, Linden Scripting Language (scripting for second life), Unlike the comment on the first answer F# can be used as a scripting language http://blogs.msdn.com/chrsmith/archive/2008/09/12/scripting-in-f.aspx

Felix, Tuga, CFGScript, Talc, Angelscript, and guessing there is more than that quick search.

Douglas

情深缘浅 2024-07-20 15:33:05

好极了。 默认情况下它是动态的、鸭子类型的。 而且还支持静态类型。

Groovy. By default it's dynamic, duck-typed. But also supports static typing.

A君 2024-07-20 15:33:05

F# 提供了“类型安全、简洁、性能、表现力和脚本”。

F# provides a combination of "type safety, succinctness, performance, expresivity and scripting".

葵雨 2024-07-20 15:33:05

查看您最喜欢的 shell 中的“typeset”命令。 bash 和 ksh93 都可以强制执行整数和字符串、使用引用(变量)等。使用 ksh93,您还可以进行浮点数学运算并使用具有属性的对象。 静态类型并不能真正给你带来任何在初始化脚本和类似脚本中有用的东西。 您主要将读取文件并运行系统命令 - 这是 shell 真正擅长的事情。 在决定所有其他 Unix 的设计都是愚蠢的之前,请花一些时间阅读 O'Reilly 的“学习 Korn Shell”一书……;)

Look in to the "typeset" command in your favorite shell. bash and ksh93 both can enforce integers and strings, use references (variable variables), etc. With ksh93, you can also do floating-point math and use objects with attributes. Static typing doesn't really buy you anything useful in init scripts and similar. You're primarily going to be reading files and running system commands - which is what the shell's really good at. Take some time with the O'Reilly "learning the Korn Shell" book before deciding that all those other Unixes are stupidly designed... ;)

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