A rosy look at Aphid... XCopy compatible embedded scripting and more
- Posted: Oct 21, 2013 at 6:00 AM
- 10,173 Views
- 3 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
And now for something a little different...
Today's project by John Leitch is one that I thought kind of neat in a number of ways. First, I've always liked the though of embedding scripting in my app's. Second, I like that his approach is pretty lightweight and self-contained. Finally that the source for the entire thing is included.
And even though this project is still in an Alpha state, this project will likely appeal to a number of audiences, from language builders to those just looking to add scriptability to their app's.
Aphid is an embeddable, cross-platform, multi-paradigm, and highly interoperable .NET scripting language. The Aphid interpreter is implemented entirely in C#. This article is intended to be an introduction to Aphid, and as such, only covers some of the features available. Further, Aphid is currently in an alpha state, so as it evolves, expect this article to change and grow with it. For the most recent version of Aphid, visit the CodePlex page.
What Languages is Aphid Inspired By?
Why Another Scripting Language?
Currently, few easily embeddable scripting languages exist for the .NET platform. Among those available, many have several dependencies, necessitating the inclusion of various assemblies. Still others are lacking in interoperability, requiring inordinate amounts of wire-up code. Aphid seeks to solve these problems by providing an easily embeddable, highly interoperable scripting language contained within a single DLL.
Getting started with Aphid is rather painless. First, add a reference to Components.Aphid.dll. Next, instantiate
AphidInterpreter. Finally, invoke the instance method
AphidInterpreter.Interpretto execute an Aphid script. Painless, huh? A complete C#/Aphid "Hello world" program is shown below, in listing 1.
The C# portion of the application should be self explanatory. The Aphid program, however, warrants a bit of an explanation. The program consists of two statements.
The first is a load script statement, consisting of the load script operator (
#) and the
'Std'. By default, the Aphid loader first searches the Library subdirectory of the directory in which Components.Aphid.dll resides. The loader automatically appends the ALX extension to script name passed, so in this instance it looks for <dll>\Library\Std.alx. Assuming everything is in order, it should find and load the file, which is the standard Aphid library, and contains helpful functions for manipulating strings, printing console output, etc.
The second statement is a call expression which invokes
When the program is run, the output is as expected (listing 2).
What is Aphid?Aphid is an embeddable, cross-platform, multi-paradigm, and highly interoperable .NET scripting language.
What nifty features does Aphid support?To name a few,
- Lambda expressions
- Partial function application
- Pattern matching
When can I try Aphid?
Now, if you'd like. While Aphid is technically in an early, alpha state, I am currently using it in a few production systems with great success. However, the alpha implementation has some quirks, current documentation is rather minimal, as are the libraries available, and the available development tools are not yet mature.
I grabbed the latest drop (made as I write this, Saturday the 19th, so yeah, it's an active project... and besides having to fix up an NUnit reference in the Components.Aphid.Tests.Integration project (NuGet is, as always, your friend in doing this), the source compiled and the samples all seemed to run as expected (which makes a code curator like me a happy camper)
Here's a snap of the Solution;
Besides the unit tests, there's a number of canned samples too;
One thing I found cool is that he's working on a language service to allow real integration with Visual Studio, which takes this entire project to another level...
Now that's pretty cool... Head on over and get your scripting on...
NOTE: This project is licensed as GPLv3, so ensure you understand that license and ramifications of including a such licensed project in your work...