1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 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

    hww

    Joined:
    Nov 23, 2007
    Posts:
    58
    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):
    1.  
    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):
    1.  
    2. > (+ 1 2)
    3. 3
    4.  
    For function definition
    Code (csharp):
    1.  
    2. > (define (foo n) (* n n))
    3. #<unspecified>
    4. > (foo 5)
    5. 25
    6.  
    Just a closure example
    Code (csharp):
    1.  
    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
    12.  
    Access to the Unity's Transform and Vector3
    Code (csharp):
    1.  
    2. > (clr-call Transform Translate (clr-prop-get MonoBehaviour transform 'this) (clr-new Vector3 100 100 100))
    3. #<unspecified>
    4.  
    Load external script file. Make fib.ss in the Assets folder
    Code (csharp):
    1.  
    2. (import (rnrs))
    3. (define (fib n)
    4.   (if (< n 2)
    5.       n
    6.       (+ (fib (- n 2)) (fib (- n 1)))))
    7.  
    Then inside console
    Code (csharp):
    1.  
    2. (include "Assets/fib.scm")
    3. (fib 10)
    4.  
     

    Attached Files:

    Last edited: Jan 18, 2013