[m-users.] Mercury to c# workflow?

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri Jan 14 17:47:37 AEDT 2022


2022-01-14 17:25 GMT+11:00 "David Epstein" <davideps at umich.edu>:
> I'm still trying to understand the relationship between Mercury and C#. For
> example, CSharpProlog <https://www.nuget.org/packages/CSProlog/> is a
> Prolog implementation written entirely in C#.

The Mercury implementation is written in Mercury, not C#. It can interoperate
with C# code by compiling Mercury code to C# code, that can then be linked
with other C# code.

> Then I can assert and retract clauses and query a live Prolog database
> after compilation, which can target any .NET platform including Android and
> iOS.

Mercury is a statically compiled language, and therefore views the definition
of a predicate as static. Even in most Prolog systems, you can use assert and
retract only on predicates that have been declared dynamic. In Mercury,
predicates CANNOT be declared to be dynamic.

> An old Mercury flyer
> <https://www.mercurylang.org/about/dotnet/objectworld_flyer.html> describes
> "the possibility to interoperate with code generated by any other compiler
> on the .NET platform."

Yes. This interoperation is done by linking C# code generated by Mercury
to C# code from other sources.

> But, based on your previous answers, this is not
> like having a C# Prolog library, correct?

I can't answer that, since I don't know in what sense you use
the word "like" above. It like it in some respects, but not others.

> There is no easy way to maintain
> a live (dynamic) Prolog database inside my application and target Android
> and iOS, right?

Yes, there is, and I pointed you to it last time: initialize a set, and then add to and/or
delete items from it. This differs from the assert/retract approach, but (a) it gets
the job done just as well, or even better (since e.g. undo is trivial to program), and
(b) the assert/retract approach is supported ONLY by Prolog.

You seem to want to use Mercury as a version of Prolog, one that includes
all the nonlogical operations that Prolog has (such as assert and retract).
But Mercury's main difference from Prolog is precisely the fact that
Mercury has ALL of Prolog's nonlogical operations DESIGNED OUT OF IT,
replaced by logical operations that can achieve the same objectives.
This yields huge benefits (such as having a useful semantics), but it does mean
that Mercury is NOT a simple, drop-in replacement for Prolog.

Zoltan.


More information about the users mailing list