다음을 통해 공유


P# - first glimpse

According to the PSharp manual:

"P# is a Prolog implementation designed for use with Microsoft’s .NET Framework. Specifically it translates Prolog to C# source code, allowing interoperation with C# and hence with other .NET languages. This allows the development of software which combines Prolog back-ends with C# front-ends."

and as such I wanted to try it out, although I really did not stress it a bit (future).

Installation, if we want to call it that way, is quite simple; just extract the ZIP-archive, maybe place the PSharp.dll into the GAC, and you are ready to go. PSharp comes with a mini-GUI interpreter and just like many Prolog implementations with a command-line based Prolog interpreter. The GUI itself is merely a thin wrapper to the Prolog interpreter but it does allow for writing, calling, compilation, ... of programs. Unfortunately, it does not feature syntax highlighting in the editor window but ain't we all notepad fans anyway?!

Now, I tested PSharp with the infamous factorial sample:

fac(0, 1) :- !.

fac(1, 1) :- !.

fac(X, Y) :-

fac_t(X, 1, Y), !.

fac_t(1, X, X).

fac_t(X, Int, Y) :-

X1 is X - 1,

NewInt is Int * X,

fac_t(X1, NewInt, Y).

Upon hopefully correct implementation (from my part) and entry into the editor it we are ready to get started. Entering the enquiry fac(2, X), and fac(5, X) into the "question" textbox - what is used to be the ?- part of a Prolog interpreter, PSharp computes the factorial of 2 to be 2 and of 5 to be 120 - correct it seems. Unfortunately it does not provide the neat big number support that SWI-Prolog does and as such computing the factorial of 100 results in a failure. However, to be fair this is something BProlog could not do out of the box as well.

Now, things to explore next, clearly include the side-by-side operation of .NET and Prolog features - maybe a little C# GUI to some Prolog code :) - let's see and read (you/me) soon.