contrib-swiplcs icon indicating copy to clipboard operation
contrib-swiplcs copied to clipboard

writeln/1 issue on monogame

Open SchroterQuentin opened this issue 8 years ago • 4 comments

It seems that when I use writeln/1 on my program, the predicate fail. This behavior appear only on monogame, I try the same example on console application and it works fine.

SchroterQuentin avatar Nov 29 '16 19:11 SchroterQuentin

Can you give a reproducible example? Can you explain what "monogame" is?

wouterbeek avatar Nov 29 '16 19:11 wouterbeek

After some research, the problem seems to be between execution mode and not monogame (which is a graphic framewok for game development). Here is a reproductible example

static void Main(string[] args)
{
    if (!PlEngine.IsInitialized)
    {
        String[] param = { "-q" };
        PlEngine.Initialize(param);
        PlQuery q = new PlQuery("write('Hi'), X is 1");
        foreach (PlQueryVariables v in q.SolutionVariables)
        {
            Console.WriteLine(v["X"].ToString());
        }
        PlEngine.PlCleanup();
        Console.ReadKey();
    }
}

On "execution with debug" mode, nothing appear on the console and on "execution without debug" 'Hi' and 1 appear.

Now if we execute the same code with write/1 instead of writeln/1 with debug : only 1 appear and without debug : 1 and 'Hi' appear.

SchroterQuentin avatar Dec 04 '16 12:12 SchroterQuentin

That looks like Java code to me. You're probably using the Java/Prolog API called JPL. There's a separate issue tracker for that over at: https://github.com/SWI-Prolog/packages-jpl/issues

wouterbeek avatar Dec 04 '16 14:12 wouterbeek

All I can say is that, unless someone redefined I/O, write/1 writes to user_output, which is initially bound to stdout. This is a line-buffered stream, so to see something you need a newline or call flush_output/0. I don't think this has to do much with the interface, more the OS and how it is embedded.

JanWielemaker avatar Dec 04 '16 15:12 JanWielemaker