Home Up Mail an Joachim Pimiskern Impressum

Inflisp - Lisp interpreter for Delphi

Inflisp is a Lisp interpreter written in Borland Pascal / Delphi. Its main purpose is to enhance Delphi applications with Artificial Intelligence, but you could also use it for scripting / automation. The name Inflisp was chosen because it's the successor of an OPS5-like inference engine Infmod. Inflisp is the AI motor of Augos 4, a Go playing program.

Status: Freeware; modify and use it at your own risk. I'd be glad if you left a comment in the source files about the original author, Joachim Pimiskern.

Download

Installation

Add expr_reg.pas to a new or an existing package. You will get a new VCL component TLispExpression in the new Inflisp panel. Compile the demo project demo.dpr and start it.

Demo application

The demo application treats a TMemo component as the input stream and another TMemo component as the output stream. A TLispExpression component evaluates the input when the button ButtonRun is pressed. See the method process(); it is the recommended way of interfacing between Delphi TStringList and Lisp.

Inflisp user interface

Communication between Inflisp and Delphi

With the demo application you have seen how to pass a Delphi stream or a TStringList to TLispExpression as input and get the Lisp result after an evaluation into the same data types.

However, there is another way to pass data to the Lisp system. You can use a constant Lisp text in TLispExpression.Expression, with additional parameters. A parameter in this context is a string with a preceding '?', e.g.
(+ ?a (* ?b ?c))
Delphi code to set these parameters would look this like:

LispExpression.Prepare; // Must be called once
...
LispExpression.SetIntegerParam('?A',5);
LispExpression.SetIntegerParam('?B',6);
LispExpression.SetIntegerParam('?C',7);
LispExpression.Execute;
ShowMessage(IntToStr(LispExpression.AsInteger));

You can see that after executing the Lisp expression, the result, which is hidden in an internal variable of TLispExpression, is retrieved by the function AsInteger. In the following table the complete list of Set... and As... functions is shown.


    procedure   SetIntegerParam(s: string; value: longint);
  
Set the parameter given by s to an integer value.

    procedure   SetFloatParam(s: string; value: double);
  
Set the parameter given by s to a float value.

    procedure   SetStringParam(s: string; value: string);
  
Set the parameter given by s to a string value.

    procedure   SetSymbolParam(s: string; value: string);
  
Set the parameter given by s to the lisp symbol given by a string.

    procedure   SetBooleanParam(s: string; value: boolean);
  
Set the parameter given by s to a Lisp boolean value, T or NIL.

    procedure   SetNodeParam(s: string; value: pNode);
  
Set the parameter given by s to a Lisp node, created before e.g. by LspNew().

    function    AsNode   : pNode;
  
Returns the result of TLispExpression in native Lisp format.

    function    AsInteger: longint;
  
Returns the result of TLispExpression as integer number.

    function    AsFloat  : double;
  
Returns the result of TLispExpression as float number.

    function    AsString : string;
  
Returns the result of TLispExpression as a string.

    function    AsSymbol : string;
  
Returns the result of TLispExpression as the name of a symbol.

    function    AsBoolean: boolean;
  
Returns the result of TLispExpression as a Delphi boolean.

Home Up Mail an Joachim Pimiskern Impressum