11
\$\begingroup\$

Is there any game engine using a functional programming language similar to Scheme, Common Lisp, Clojure or JavaScript?

I've tried Unity3D but their "JavaScript" is not actually JavaScript, is strongly typed and is not functional.

\$\endgroup\$
8
  • 2
    \$\begingroup\$ I'm using ThreeJS, but, while it's full of awesomeness, it's lack of an active community and documentation are a serious problem. \$\endgroup\$
    – MaiaVictor
    Dec 27, 2012 at 10:39
  • 5
    \$\begingroup\$ Why would you want to program in a functional programming language? What is the problem you are facing? Please be more specific. As it stands, this question is too general to yield one correct answer and it is prone to generate a list of (all equally "correct") answers like this: - How about Clojure combined with any Java game engine? - How about adopting a functional programming style in a language that is not functional per se? (Read Functional Programming in C++ by Carmack.) - etc. \$\endgroup\$
    – Eric
    Dec 27, 2012 at 11:12
  • 2
    \$\begingroup\$ Unity3D's Javascript is as functional as regular Javascript, you just need to use C# 4.0 types, something like: var add : Func<int, int, int> = ... \$\endgroup\$
    – fableal
    Dec 27, 2012 at 12:34
  • 2
    \$\begingroup\$ See the FAQ about "Which technology to use" questions. This question, as the answers show, is just generating a list. It's not constructive since there's no single correct answer (other than "Yes there is"). This isn't the place to compile lists. \$\endgroup\$
    – House
    Dec 27, 2012 at 15:20
  • 2
    \$\begingroup\$ This is sort of a "right tool for the right job" problem. Functional programming is strongly focused on minimizing, and eliminating wherever possible, mutable state. That may work well for certain classes of applications, but it's completely antithetical to the way just about any game works. \$\endgroup\$ Dec 27, 2012 at 18:37

4 Answers 4

7
\$\begingroup\$

There is LambdaCube which is written in Haskell (it's not exactly game engine but more like graphics engine).

\$\endgroup\$
2
  • 2
    \$\begingroup\$ This might also be of interest to you (general comentary from Tim Sweeney from Epic) \$\endgroup\$
    – tumdum
    Dec 28, 2012 at 10:17
  • \$\begingroup\$ Interesting link, there's a ppt here \$\endgroup\$
    – bobobobo
    Jul 5, 2013 at 4:49
2
\$\begingroup\$

You can always use f# or iron python (yes i do know, python isn't functional) or any other .netified language with XNA on .net platform.

http://fsharpgamedev.codeplex.com/ http://www.ironpython.info/index.php/XNA_Example_with_a_Bouncing_Sprite

edit: One more engine, written in Lisp: http://code.google.com/p/blackthorn-engine/

\$\endgroup\$
2
\$\begingroup\$

I don't have an answer to the question as written, but I believe you are possibly trying to ask "why aren't there more functional game engines" rather than looking for a specific one to use. If that's correct, you should rephrase the question. If not... ignore me. :)

A pure functional approach is not a good fit for games. Games (and graphics, and physics, and AI) and basically all about state changes. The correct functional approach to these problems would be to compute an entire new state once per loop, which will have a very severe performance penalty compared to coding more directly to how actual hardware works.

It is for that reason that you don't see any functional-style game engines in production. It is simply the wrong programming paradigm for the majority of problems a game engine is meant to solve. It is the wrong programming paradigm for the majority of problems that need to be solved in higher-level scripting and game logic code, too. While it is almost certainly possible to make a functional game engine, it would be slow, difficult and cumbersome to use, and would serve no real purpose other than being a neat demo/toy to show off.

That's not to say that functional programming doesn't have a place somewhere in games. I use a very functional style of coding (where appropriate) in C#, Unity JavaScript, and even C++11. Some very specific problems are best or at least most easily solved with a functional style, and most of the popular languages today support that form of programming, albeit in a more cumbersome manner than "real" functional languages. Usually these problems solved with functional approaches are not in the core engine code, nor in code that runs in the game itself. Functional coding can be quite beneficial for tools and offline data processing (baking models and other assets, for instance). It's also arguable that GPU programming is vaguely functional in how algorithms are written, even though the actual coding is done in a hardware-efficient procedural manner.

Of course it can still be best to avoid functional approaches outside very specific circumstances since you want these offline tools to be as fast as possible. Functional languages excel at parallelism, which is good for some problems, but the abstractions from the hardware tend to lead to very inefficient single-threaded performance. (Languages like LISP do well here because they are not pure functional, and in fact Common LISP is multi-paradigm.) The absolute single worst thing for a game engine or related toolkit is to be a bottleneck for content iteration. A fancy engine with a lot of features that takes artists or level designers hours to do what could be done in 5 minutes (or ideally, near-instantly) will just lead to low quality games or cancellation due to budget escalation.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ See: Clean Game Library (Clean) and Nikki and the Robots (Haskell). \$\endgroup\$
    – Andres F.
    Apr 16, 2013 at 17:07
  • 1
    \$\begingroup\$ This answer is mostly wrong and appears to be based on a very poor understanding of actual functional languages. \$\endgroup\$ Apr 16, 2013 at 17:29
  • 1
    \$\begingroup\$ Do you have any actual counter points? \$\endgroup\$ Apr 16, 2013 at 18:34
  • 4
    \$\begingroup\$ ... How much experience do you have shipping industry-quality games in functional languages? If you have experience, share it. Make statements with explanations and justifications, not appeals to expertise or authority, or personal accusations. The likelihood of this kind of indignant arguing and personal bickering is exactly why this question was closed. \$\endgroup\$ Apr 16, 2013 at 23:15
  • 4
    \$\begingroup\$ You're putting words in my mouth. I'm not stating my experience level because your opinion of my expertise is utterly irrelevant to the topic. Don't claim you have no time to state facts while having time to attack personal skill levels. You probably have real corrections, but you need to state them. "That guy is wrong," is not valuable answer feedback for anyone. I can just claim that you are wrong, and then we have an endless and pointless cycle of bickering. Please say why an answer is wrong. \$\endgroup\$ Apr 17, 2013 at 18:42
0
\$\begingroup\$

The Naugthy Dog company used List on its Game Engines and it was called Game Oriented Assembly Lisp.

Some information can be found here: http://en.wikipedia.org/wiki/Game_Oriented_Assembly_Lisp

Some code samples: http://web.archive.org/web/20070127022728/http://lists.midnightryder.com/pipermail/sweng-gamedev-midnightryder.com/2005-August/003804.html

It is not available for public usage.

\$\endgroup\$
1
  • \$\begingroup\$ If you look at Wikipedia's description, it quickly becomes apparent that GOAL was hardly a functional language, LISP ancestry notwithstanding. \$\endgroup\$ Dec 27, 2012 at 18:35

Not the answer you're looking for? Browse other questions tagged .