嵌入式语言:Lua 与 Common Lisp (ECL) [英] Embedded language: Lua vs Common Lisp (ECL)

查看:18
本文介绍了嵌入式语言:Lua 与 Common Lisp (ECL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有人有将 Common Lisp 作为嵌入式语言(使用 ECL)的经验吗?如果是这样,ECL 与 Lua 相比有多好?

Does anybody here have a experience with Common Lisp as a embedded language (using ECL)? If so, how good is ECL compared to Lua?

推荐答案

我以前没有嵌入 CL,但我已经用 Lua 和两个特定的 Scheme 实现(Gambit-C 和 GNU Guile)完成了.

I haven't embedded CL before, but I've done it with both Lua and two particular Scheme implementations (Gambit-C and GNU Guile).

在我看来,Scheme 是一种很棒的嵌入式语言,因为它灵活且不太臃肿.Gambit-C 在这方面特别棒,因为它允许你运行解释脚本,也可以将代码编译成 C.在我的测试中,Gambit-C 生成的 C 代码只比手写 C 慢一点(例如,一个在 C 中运行 0.030 秒的特定测试在 Gambit 中运行了 0.040!).Gambit 也有一个非常好的 FFI(外部函数接口),它本质上只是具有特殊语法的 Scheme,用于编写与 C 库的绑定(也直接支持 ObjC 和 C++).Gambit 也有一个非常好的 repl 和一些调试功能.

Scheme makes a great embedded language in my opinion, because it is flexible and not too bloated. Gambit-C is particularly awesome for this because it allows you to both run interpreted scripts, and also compile your code down to C. In my tests, Gambit-C's generated C code was only a little slower than handwritten C (for example, a particular test that ran 0.030s in C was 0.040 in Gambit!). Gambit also has a really nice FFI (foreign function interface), which is essentially just Scheme with special syntax for writing bindings to C libraries (ObjC and C++ are directly supported also). Gambit also has a very nice repl with some debugging capabilities.

Guile 也很不错,它实际上比 Lua 运行得更快(我目前所知道的最快的解释性语言——Guile 近年来取得了很大的进步).但是由于 Gambit-C 可以编译为非常快的代码,所以我通常不会使用 Guile,除非我打算在最终版本中使用解释代码.

Guile is also pretty nice, and it actually runs faster than Lua (fastest interpreted language that I currently know of -- Guile has made great progress in recent years). But since Gambit-C can compile to really fast code, I generally don't use Guile as much unless I intend to use interpreted code in the final version.

Lua 有闭包,但你不会像 Scheme 那样得到延续,你也不会得到宏.尽管如此,仍然可以做一些合理数量的功能性的东西.它不会有一个功能齐全的对象系统(如 CL 中的 CLOS),但它确实有表,并且它们可以很容易地用于实现基于类的继承和基于原型的继承.此外,Lua 有一个优秀的 C API,使用起来真的很愉快.它是基于堆栈的,并且以一种您根本不必担心内存管理的 Lua 方面的方式设计.API 非常清晰且组织良好,并且有很多很棒的文档和示例代码.Lua 无法向下编译,但它确实使用字节码(总是——当您将代码发送到 Lua VM 时,它总是先将代码编译为字节码,然后 然后 运行它).

Lua has closures, but you won't get continuations like in Scheme, and you also won't get the macros. It's still possible to do a reasonable amount of functional stuff though. It won't have a fully featured object system (like CLOS in CL), but it does have tables and they can be used to implement both class-based inheritance and prototype-based inheritance quite easily. Also, Lua has an excellent C API that is really a pleasure to work with. It's stack-based, and designed in a way that you don't have to worry about the Lua side of memory management at all. The API is very clear and well organized, and there is a lot of great documentation and example code out there. Lua can't compile down, but it does use byte-code (always -- when you send code to the Lua VM, it always compiles that code down the byte-code first and then runs it).

现在,对于 Common Lisp,我认为它可能不会成为一种非常好的嵌入语言.这样做的原因只是 CL 是巨大的.一般来说,嵌入轻量级语言是可取的,因为它将使用提供给它的平台/库,而不是太多的外部内容.

Now, as for Common Lisp, I think that it would probably not make a very good language for embedding. The reason for this is just that CL is huge. Generally, it's desirable to embed a lightweight language because it's going to be using the platform/libs that you provide to it, and not so much external stuff.

所以,我认为 Gambit-C、Guile 或 Lua 都不会出错.他们都会非常好.CL 很强大,但我只是觉得嵌入太大了.

So, I think you can't go wrong with either Gambit-C, Guile or Lua. They'll all really nice. CL is powerful, but I just think it's too big for embedding.

这篇关于嵌入式语言:Lua 与 Common Lisp (ECL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆