[This is preliminary documentation and subject to change]

A first .NET call

Liogo has been natively built to be easily integrated with existing .NET code. So with Liogo, your Logo application can now take advantage of investments Microsoft has done one its last platform: .NET (or MONO on a Linux platform).

To call .NET from Liogo you need to make a DLL with each entry point you want call. Here is a C# example called "hellodotnet.cs" and built in "hellodotnet.dll":



using System;
using LIOGO.Core;

namespace LIOGO.Framework
{
	[LogoLibrary]
	public class MyLib
	{
		[LogoProcedure]
		static public ILogoValue hello()
		{
			Console.WriteLine("Hello World!");
			return null;
		}
	}
}

To be callable by Liogo, our method "hello" :

The file "hellow.lgo" just call our new method:


hello

MessageBox in Liogo

In a same way than a Logo procedure, a .NET method can receive and output any Logo datum. Here is a sample receiving words to call the famous MessageBox function of Windows:



using System;
using System.Windows.Forms;
using LIOGO.Core;

namespace LIOGO.Framework
{
	[LogoLibrary]
	public class MyLib
	{
		[LogoProcedure]
		static public ILogoValue confirm_q(ILogoValue message)
		{
			DialogResult result = MessageBox.Show(
					null, 
					message.Print(), 
					"Liogo Confirmation", 
					MessageBoxButtons.YesNo, 
					MessageBoxIcon.Question);

			if(result == DialogResult.Yes)
				return LogoWord.True;
			return LogoWord.False;
		}
	}
}

As you can see the interface ILogoValue is used for each parameter.

The new operation defined here is a new predicate called "confirm?". Because special characters are not allowed in .NET for method names the Logo name is encoded:

The "ILogoValue.Print()" method return the value as a printable string (as in print command).

LogoWord, LogoNumber, LogoList and LogoArray are the four .NET classes extending ILogoValue interface. Only LogoWord is used in this sample with constant Logo value true and false.

Following is the Logo code to call our new "confirm?" predicate:


(print [assertion is] confirm? [Liogo is pretty cool, isn't it?])

.NET Regular Expressions

Our next sample show the added value to use the .NET Framework. More precisely here we use System.Text.RegularExpressions. These APIs may validate, split and replace a pattern in a string. Why not use these features for a Logo Word ? Here how:


using System;
using System.Text.RegularExpressions;
using LIOGO.Core;

namespace LIOGO.Framework
{
	[LogoLibrary]
	public class MyLib
	{
		[LogoProcedure]
		static public ILogoValue match_q(ILogoValue pattern, ILogoValue valueToTest)
		{
			LogoContext.BeginProcedure("match?", pattern, valueToTest);
			
			Regex r = new Regex(pattern.Print());
			Match m = r.Match(valueToTest.Print());
			ILogoValue result = LogoWord.False;
			if (m.Success)
				result = LogoWord.True;

			return LogoContext.EndProcedure("match?", result);
		}
	}
}

Following is few Logo lines to test "match?" with a pattern for e-mail validator:


make "mailpat "|[\w\.\-]+@[\w\.\-]+\.\w{2,5}|

print match? :mailpat "llaske
print match? :mailpat "llaske@sourceforge.net 

Of course, .NET procedures are fully usable in Liogo:

Here a more complex use of our "match?" operation:



to message :isvalid :label
    ifelse not :isvalid [output (word :label "\ is "\ incorrect.)] [output "]
end

print [Type your firstname with first letter in uppercase]
make "firstname readword
print [Type your lastname with first letter in uppercase]
make "lastname readword
print [Type your email]
make "email readword

print (map "message (map "match? [|[A-Z][a-z]+| |[A-Z][a-z]+| |[\w\.\-]+@[\w\.\-]+\.\w{2,5}|] (list :firstname :lastname :email)) [Firstname Lastname email])

What's more ?

In a same way than Regular Expressions Liogo let you call Web Services, do a request on a SQL data base, display Windows Forms, call ActiveX components, ... On the other side, every Liogo context can be handle from a .NET DLL. In fact, all the Liogo Framework is written in C# using this same schema. With Liogo, you have just one limit to mix Logo and .NET: your imagination !