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

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

问题描述

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

解决方案

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

在我看来,Scheme是一种出色的嵌入式语言,因为它灵活且不会过分膨胀. Gambit-C在这方面特别出色,因为它使您既可以运行解释后的脚本,也可以将代码编译为C.在我的测试中,Gambit-C生成的C代码仅比手写C慢一点(例如,在C中运行0.030秒的特定测试在Gambit中为0.040!). Gambit还有一个非常不错的FFI(外部函数接口),它实际上只是Scheme,具有用于将绑定写到C库的特殊语法(也直接支持ObjC和C ++). Gambit还有一个很好的代表,它具有一些调试功能.

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

Lua具有闭包,但是您不会像Scheme中那样获得延续,也不会得到宏.尽管如此,仍然有可能做一些合理的功能性工作.它不会具有功能齐全的对象系统(如CL中的CLOS),但是它确实具有表,并且可以轻松地用于实现基于类的继承和基于原型的继承.而且,Lua具有 excellent C API,使用它真的很高兴.它是基于堆栈的,其设计方式完全不必担心内存管理的Lua方面.该API非常清晰且组织良好,并且那里有很多很棒的文档和示例代码. Lua不能向下编译,但确实使用字节码(总是-当您将代码发送到Lua VM时,它总是先将字节码编译为该代码,然后然后运行它)

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

因此,我认为无论Gambit-C,Guile还是Lua都不会出错.他们会真的很好. CL功能强大,但我认为它太大了,无法嵌入.

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

解决方案

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

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.

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天全站免登陆