Lisp (Clojure) 和 Tcl 在抽象和元编程能力方面如何比较?

发布于 2024-11-04 04:35:16 字数 82 浏览 3 评论 0原文

两者似乎都适合构建可扩展的 API 和代码生成。

它们之间的主要区别是什么?

您认为他们的优点、缺点是什么......

Both seem to be good for building extensible API's and code generation.

What are the main differences between them?

What do you see as their strengths, weaknesses, ...

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

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

发布评论

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

评论(2

清风疏影 2024-11-11 04:35:16

免责声明:我对 Clojure 比对 Tcl 更熟悉,所以如果我歪曲任何内容,请向所有 Tclers 表示歉意。然而,这里有一些我普遍知道的点:

  • 两者都非常灵活 - 您可以使用元编程在运行时生成和执行您喜欢的几乎任何代码。
  • Clojure 是一种JVM 语言,而 Tcl 是相对独立的。
    • 使用 JVM 的优势包括能够为其他 JVM 语言(例如 Java 和 Scala)生成可互操作的代码并充当其 DSL。您还可以访问大量的 Java 库。
    • 在 JVM 上的缺点是启动时间相对较长。因此,对于运行时间较长的服务器应用程序,您可能更喜欢 Clojure,而不是需要快速执行的命令行工具。
  • Clojure 元编程将编译为本机代码(通过 JVM 中的 JIT)。取决于您的应用程序,但我预计在大多数情况下这将比 Tcl 执行得更快
  • 这两种语言都是动态(平均来说对于元编程来说是一件好事!)并且支持函数式编程
  • Clojure 包含一些对元编程非常有用的有趣抽象 - 特别是对序列的大量语言内支持
  • 我个人认为 Lisp 语法的简单性对于元编程来说是一个很大的优势 - 它更容易生成当有代码时只需要担心一个语法结构(s-表达式)...

平均而言,两种语言都非常适合元编程,但如果我在两者之间进行选择:

  • 如果我正在构建服务器端应用程序,或者如果我在构建服务器端应用程序,我会选择 Clojure我对 JVM 互操作性有特殊需求,
  • 如果我想要一个 DSL 来在命令行管理脚本/工具,我会选择 Tcl

Disclaimer: I'm more familiar with Clojure than Tcl so apoligies to any Tclers if I misrepresent anything. However here are some points I'm generally aware of:

  • Both are extremely flexible - you can use meta-programming to generate and execute pretty much any code you like at runtime.
  • Clojure is a JVM language whereas Tcl is relatively standalone.
    • Advantages of being on the JVM include being able to generate interoperable code for and act as a DSL for libraries in other JVM languages like Java and Scala. Also you get access to the huge range of Java libraries.
    • Disadvantage of being on the JVM is relatively substantial start-up time. So you'd probably prefer Clojure for longer-running server applications rather than command line tools that need to execute quickly.
  • Clojure metaprogramming will get compiled to native code (via JIT in the JVM). Will depend on your application, but I expect this will perform faster than Tcl in most circumstances
  • Both languages are dynamic (a good thing for metaprogramming on average!) and support functional programming
  • Clojure contains some interesting abstractions that are very useful for metaprogramming - in particular the considerable in-language support for sequences
  • I personally find the simlicity of Lisp syntax to be a great advantage for metaprogramming - it's much easier to generate code when there is only one syntactical construct (the s-expression) to worry about...

On average both languages are great for metaprogramming, but if I was choosing between the two:

  • I'd choose Clojure if I was building a server-side application or if I had a particular need for JVM interoperability
  • I'd choose Tcl if I wanted a DSL for managing scripts / tools at the command line
第七度阳光i 2024-11-11 04:35:16

我认为米凯拉的回答非常好。

我只想补充一点,在 clojure 元编程倾向于关注宏(一个没有同行的大统一元编程解决方案)的地方,tcl 有几个可用于元编程的小工具,其中包括“未知”命令,可用于执行各种操作俏皮的技巧。同样有趣的是,尽管 clojure 只有少量关键字或“特殊形式”,但 tcl 实际上没有,这使得 tcl 成为自己的 dsl,并且可以更改(或扩展)任何命令的行为。

我不同意 mikera 的答案的一件事是 clojure 的语法更适合元编程的部分。当我接触 clojure 时,令我感到不愉快的惊喜之一实际上是 clojure 中存在如此多的语法变化,包括 () [] {} "" ^{} #' :key ... 的各种用法等等。我完全理解这种语法糖的合理性,但实际上我发现 tcl 的语法更容易处理“笨手笨脚”的元编程和代码生成。而 tcl 的“一切都是字符串”的性质又增加了简单性。

至于多处理能力、不可变的数据结构、纯函数性质以及 clojure 的许多其他独特之处,tcl 确实没有什么可比的。

我非常同意米凯拉的结论。

I think mikera's answer is excellent.

I would add only that where in clojure metaprogramming tends to focus on macros, a grand unified metaprogramming solution without peer, tcl has several small sharp tools available for metaprogramming, among them the "unknown" command, which can be used to do all sorts of nifty tricks. Also interesting is that even though clojure has only a small number of keywords or "special forms", tcl actually has none, which sort of makes tcl it's own dsl, and changing (or extending) the behavior of any command is possible.

One thing i have to disagree with from mikera's answer is the part about clojure's syntax being more amenable to metaprogramming. One of the unpleasant surprises for me when coming to clojure is actually how much syntactic variation there is in clojure, with the various uses of () [] {} "" ^{} #' :key ... and on and on. I totally grok the justification of this type of syntactic sugar, but i actually find tcl's syntax easier to deal with for "ham-handed" metaprogramming and code generation. And tcl's "everything is a string" nature adds to the simplicity.

As for mulit-processing capabilities, immutable data structures, purely functional nature and many other instances of clojure's distinctives, there really is nothing comparable in tcl.

I couldn't agree more with mikera's conclusion.

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