Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Facilities for script languages, Scheme in particular

Discussion in 'Wish List' started by hww, Feb 1, 2011.

  1. hww


    Nov 23, 2007
    I was not sure where to post this thread, scripting, support or wish list? Still do not know. Let's try it here.

    I love Lisp and Scheme. Of course I know that C# is good language, but Scheme is what I really like. The first thing I want to know about any game engine is, "How can it be used with Lisp or Scheme?"

    The first place where I checked for Unity is this forum. Result: almost nothing apropos. Then this page. And I think this interface is not useful for Scheme/Lisp implementations based on C or C++, because "Calling C# / JavaScript back from native code" will be slow. That is very bad because it limits scriptability to only infrequent high-level control. The ideal solution would be a fast interface, so a C-based Scheme like Gambit-C could be used for low-level operations like animation stacking, game object state controls, and so on.

    My next step was to check around for Scheme implementations on Mono. In my opinion, there is no perfect project for Mono yet. The IronScheme and Clojure NET looks most interesting. There are other Mono/CLR Scheme and Lisp implementations but IronScheme looks most usable right now.

    After some experiments I figured out that to get IronScheme I must compile it on my machine, which I did with MSVC. Then I copied IronScheme files to the Assets folder.

    Code (csharp):
    1. ironscheme.boot.dll
    2. IronScheme.Closures.dll
    3. IronScheme.dll
    4. Microsoft.Scripting.dll
    5. Oyster.IntX.dll
    Code (csharp):
    1. Also folders
    2. IronScheme/lib
    3. IronScheme/ironscheme
    So my final structure is
    Code (csharp):
    2. Assets/Plugins/Scheme/[lib|ironscheme]
    3. Assets/Plugins/Scheme/[ironscheme.boot.dll|IronScheme.Closures.dll|IronScheme.dll|Microsoft.Scripting.dll|Oyster.IntX.dll]
    Inside the Unity editor scheme REPL works nice. There are big problems though with the Unity build pipeline and file processing. Specifically:

    1) How I can a new file type to the Project Manager? For example I want to register SchemeScript type and see it included in the context menu Create option.
    2) How I can tell to Unity to process some particular file type (for example .sls) with an external tool like a Scheme compiler or C# custom preprocessor? How I can control when this processing happens: before C# compiler or after?
    3) How I can tell Unity that this file must be re-processed when it has changed?
    4) How I can tell Unity that some files (Scheme libraries, other data files) should be copied to some designated target during the application build?
    5) How I can tell Unity to different file types with specific editors when clicked on?
    6) How add "preview content of file" feature for custom file types when they are selected in the project manager?

    At this point, I have made a few experiments with some simple GUI projects using IronScheme in Unity. These projects run OK in Unity, but fail to run when published as standalone applications.

    P.S. Attachment has a UnityPackage with my project. You can try enter the next sequences in the Scheme console

    For simple Math
    Code (csharp):
    2. > (+ 1 2)
    3. 3
    For function definition
    Code (csharp):
    2. > (define (foo n) (* n n))
    3. #<unspecified>
    4. > (foo 5)
    5. 25
    Just a closure example
    Code (csharp):
    2. > (define (foo n) (lambda (m) (set! n (+ n m)) n))
    3. #<unspecified>
    4. > (define bar (foo 10))
    5. #<unspecified>
    6. > (bar 1)
    7. 11
    8. > (bar 1)
    9. 12
    10. > (bar 19)
    11. 22
    Access to the Unity's Transform and Vector3
    Code (csharp):
    2. > (clr-call Transform Translate (clr-prop-get MonoBehaviour transform 'this) (clr-new Vector3 100 100 100))
    3. #<unspecified>
    Load external script file. Make in the Assets folder
    Code (csharp):
    2. (import (rnrs))
    3. (define (fib n)
    4.   (if (< n 2)
    5.       n
    6.       (+ (fib (- n 2)) (fib (- n 1)))))
    Then inside console
    Code (csharp):
    2. (include "Assets/fib.scm")
    3. (fib 10)

    Attached Files:

    Last edited: Jan 18, 2013