Skip to content
/ yTuple Public

λTuple makes it possible to write some Lisp directly in your C# code.

License

Notifications You must be signed in to change notification settings

yuretz/yTuple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

λTuple

GitHub

Scheme for your tuples

What is it?

This small library implements a Scheme-inspired Lisp dialect allowing you to write some lisp directly in your C# code.

In other words, by exploiting certain C# language features λTuple aims to to provide Lisp's glorious syntax and semantics from within the C#/.NET environment.

Among other things, it is:

  • 🏎️ Highly dynamic, as any Lisp shall be: data and code are the same.
  • ⚡ Pretty fast, because it's not an interpreter: all your code is compiled using System.Linq.Expressions.
  • 🤝 Well integarted with C# and .NET: mix and match your normal C# and Lisp code as you like
  • 🌀 Optimizing tail calls when possible.
  • ❓ Work in progress, more goodies to come...

Show me the code

First things first, let's add λTuple to the usings section of your program.

using yTuple;
using static yTuple.Elementary;

This should make it possible to write the following code.

var fib = Lisp.Parse(n =>
    (begin,
        (define, _.loop, (lambda, (_.i, _.curr, _.prev),
            (cond,
                ((eq, _.i, 0), 0),
                ((eq, _.i, 1), _.curr),
                (@else, 
                    (_.loop, (sub, _.i, 1), (add, _.curr, _.prev), _.curr))))),
        (_.loop, n, 1, 0))
).Compile();

Console.WriteLine(fib(42));

This creates a tail-recursive lambda function fib(), that computes n-th number in the Fibonacci sequence and then uses it to output the result for n = 42.

Another good place to get a look and feel of it would be in the test code. More examples are coming soon.

Future features & ideas

  • More C# interop features
  • Better static typing to avoid unnecessary boxing and dynamic type casts
  • Serialization, so that it's possible to load code from external source
  • Support macros
  • Use FastExpressionCompiler for even better performance

Futher info

If you have a question, or think you found a bug, or have a good idea and don't mind sharing it, please open an issue and I would be happy to discuss it.

About

λTuple makes it possible to write some Lisp directly in your C# code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages