功能语言是飞行模拟器的不错选择吗? Lisp怎么样? [英] Is a functional language a good choice for a Flight Simulator? How about Lisp?

查看:163
本文介绍了功能语言是飞行模拟器的不错选择吗? Lisp怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年来,我一直在做面向对象编程,而且我还没有做过太多的函数式编程。我对飞行模拟器感兴趣,并对Lisp的功能编程方面感到好奇。飞行模拟器或任何其他真实世界的模拟器在面向对象的范例中对我都有意义。



以下是我的问题:

面向对象是表示真实世界模拟域的最佳方式吗?

/ p>

我知道Common Lisp具有CLOS(用于lisp的OO),但是我的问题实际上是用功能语言编写飞行模拟器。所以如果你打算用Lisp编写它,你会选择使用CLOS还是以功能性的方式编写它?



有没有人对编写飞行模拟器有任何想法在lisp或任何函数式语言中?



UPDATE 11/8/12 - 对于那些感兴趣的类似SO问题 - > 函数式编程如何应用于模拟? 解决方案

将Lisp视为一种功能性语言是一种常见的错误。真的,最好把它当作一个语言家族来考虑,但是现在人们说Lisp时他们通常指的是Common Lisp。

Common Lisp允许使用函数式编程,但它本身不是一种功能性语言。而是一种通用语言。 Scheme是一个小得多的变体,它在方向上更具功能性,当然还有其他的。

至于你的问题是不是一个好的选择?这真的取决于你的计划。 Common Lisp对于这类事情特别有一些真正的优势。它既是交互式的,也是内省的,通常在所谓的脚本语言中看到,因此开发起来非常迅速。同时它的编译和编译效率也很高,因此您可以期待与其他高效编译器相同的性能(c的两倍是典型的时间)。虽然是一种大型语言,但它具有比c ++更一致的设计,并且元编程功能可以为您的特定应用程序制作非常简洁易懂的代码。如果你只看这些方面
常见的lisp看起来很棒。



然而,它有缺点。社区很小,如果这就是你想要的,你不会找到很多人来帮忙。虽然内置的库很大,但您不会找到第三方库,因此您可能会从头开始编写更多的库。最后,虽然它绝不是一个有围墙的花园,但CL没有像蟒蛇那样与外国图书馆顺利融合。这并不意味着你不能调用c代码,有很好的工具。



通过他们的方式,CLOS是我能想到的最强大的面向对象系统的,但是如果你来自主流的c ++ / java / c#/ etc,这是一种完全不同的方法。面向对象的背景(是的,他们有所不同,但超出了单对多的inh。不是那么多),你可能会发现它有点奇怪,几乎翻了一番。



如果你走这条路线,如果你用CLOS自己写的话,你将不得不注意一些与实际渲染流水线性能有关的问题。类系统具有令人难以置信的运行时灵活性(即,在运行时更新类定义,而不是通过猴子修补程序等,但通过实际更改类和更新实例),但是您需要为此付出一定的调度费用。

对于它的价值,过去我使用CL来研究需要数值效率的代码,即不同类型的模拟。这对我来说很有用。在这种情况下,我并不担心使用现有的代码 - 它不存在,所以我从头开始写几乎所有的东西。



总之,它可能是这个项目的语言选择,但不是唯一的选择。如果你不使用同时具有高级方面和良好性能的语言(如CL和OCaml一样,还有其他一些语言),我肯定会考虑使用lua这样的语言或者可能使用两种语言的方法python(大量的libs)在一些c或c ++代码的基础上进行繁重的工作。


I have been doing object-oriented programming for a few years now, and I have not done much functional programming. I have an interest in flight simulators, and am curious about the functional programming aspect of Lisp. Flight simulators or any other real world simulator makes sense to me in an object-oriented paradigm.

Here are my questions:

Is object oriented the best way to represent a real world simulation domain?

I know that Common Lisp has CLOS (OO for lisp), but my question is really about writing a flight simulator in a functional language. So if you were going to write it in Lisp, would you choose to use CLOS or write it in a functional manner?

Does anyone have any thoughts on coding a flight simulator in lisp or any functional language?

UPDATE 11/8/12 - A similar SO question for those interested -> How does functional programming apply to simulations?

解决方案

It's a common mistake to think of "Lisp" as a functional language. Really it is best thought of as a family of languages, probably, but these days when people say Lisp they usually mean Common Lisp.

Common Lisp allows functional programming, but it isn't a functional language per se. Rather it is a general purpose language. Scheme is a much smaller variant, that is more functional in orientation, and of course there are others.

As for your question is it a good choice? That really depends on your plans. Common Lisp particularly has some real strengths for this sort of thing. It's both interactive and introspective at a level you usually see in so-called scripting languages, making it very quick to develop in. At the same time its compiled and has efficient compilers, so you can expect performance in the same ballpark as other efficient compilers (with a factor of two of c is typical ime). While a large language, it has a much more consistent design than things like c++, and the metaprogramming capabilities can make very clean, easy to understand code for your particular application. If you only look at these aspects common lisp looks amazing.

However, there are downsides. The community is small, you won't find many people to help if that's what you're looking for. While the built in library is large, you won't find as many 3rd party libraries, so you may end up writing more of it from scratch. Finally, while it's by no means a walled garden, CL doesn't have the kind of smooth integration with foreign libraries that say python does. Which doesn't mean you can't call c code, there are nice tools for this.

By they way, CLOS is about the most powerful OO system I can think of, but it is quite a different approach if you're coming from a mainstream c++/java/c#/etc. OO background (yes, they differ, but beyond single vs. multiple inh. not that much) you may find it a bit strange at first, almost turned inside out.

If you go this route, you are going to have to watch for some issues with performance of the actual rendering pipeline, if you write that yourself with CLOS. The class system has incredible runtime flexibility (i.e. updating class definitions at runtime not via monkey patching etc. but via actually changing the class and updating instances) however you pay some dispatch cost on this.

For what it's worth, I've used CL in the past for research code requiring numerical efficiency, i.e. simulations of a different sort. It works well for me. In that case I wasn't worried about using existing code -- it didn't exist, so I was writing pretty much everything from scratch anyway.

In summary, it could be a fine choice of language for this project, but not the only one. If you don't use a language with both high-level aspects and good performance (like CL has, as does OCaml, and a few others) I would definitely look at the possibility of a two level approach with a language like lua or perhaps python (lots of libs) on top of some c or c++ code doing the heavy lifting.

这篇关于功能语言是飞行模拟器的不错选择吗? Lisp怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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