将Common Lisp代码移植到Clojure [英] Porting Common Lisp code to Clojure

查看:197
本文介绍了将Common Lisp代码移植到Clojure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Common Lisp应用程序移植到Clojure有多么实用?更具体地说,Common Lisp中存在什么特性,在Clojure中不存在,并且必须重写?

解决方案

p> Clojure和其他Lisps之间有一个 clojure.org上的列表。我注意到使用Clojure的其他一些事情:




  • 惯用的Clojure倾向于不可变的数据结构。在任何地方,你在CL中看到 SETF 可能需要在Clojure中更改以充分利用。 (你总是可以选择在Clojure中使用可变的Java数据结构,但大多数人没有。)


  • Clojure的多重方法类似于CL强大的,因为你可以派遣类型以外的事情),但是一个完全成熟的CLOS不可用在Clojure。 Clojure使用 struct ,这只是一个花哨的哈希。当然,Java的OOP系统也是可用的。


  • Clojure宏的工作方式与CL略有不同宏涉及到符号/命名空间分辨率。我不知道我是否理解得足以澄清差异。


  • Clojure没有像CL那样的条件系统。您只有Java的 try / catch / finally


  • Clojure不允许用户定义的阅读器宏。

    没有多个返回值。解构在Clojure是非常好的(支持列表,向量,哈希映射,集等),它被内置在更多的地方比CL默认情况下,所以这是不是一个问题比它可以是。




根据应用程序及其编写方式,从CL移植到Clojure可能是实用和直接的,或者更实用的是重写它从一个更加功能,线程安全的方式,以更好地适应Clojure风格。


How practical is it to port a Common Lisp application to Clojure? To be more specific, what features exist in Common Lisp that do not exist in Clojure, and would have to be re-written?

解决方案

There's a list on clojure.org of differences between Clojure and other Lisps. Some other things I've noticed using Clojure:

  • Idiomatic Clojure leans heavily toward immutable data structures. Anywhere you see SETF in CL may have to be changed in Clojure to take full advantage. (You always have the option of using mutable Java data structures in Clojure, but most people don't.)

  • Clojure's multimethods are similar to CL's (arguably more powerful, because you can dispatch on things other than type) but a full-blown CLOS is not available in Clojure. Clojure uses struct instead, which is just a fancy hashmap. Java's OOP system is also available, of course. Some people are working on porting CLOS to Clojure but I'm not sure how far along those efforts are at this point.

  • Clojure macros work slightly differently than CL macros when it comes to symbol/namespace resolution. I'm not sure if I understand well enough to elucidate the differences. You don't have to mess with gensyms quite as much in Clojure though, which is nice.

  • Clojure doesn't have a condition system like CL's. You have only Java's try/catch/finally for exception handling.

  • Clojure doesn't allow user-defined reader macros.

  • Clojure doesn't have multiple return values. Destructuring in Clojure is very nice (supports lists, vectors, hash-maps, sets etc.) and it's built into more places than CL by default, so this is less of an issue than it could be.

Depending on the app and how it's written, it may be practical and straightforward to port from CL to Clojure, or it may be more practical to rewrite it from the ground up in a more functional, thread-safe way to fit better with Clojure style.

这篇关于将Common Lisp代码移植到Clojure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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