Subject: [SWIPL] Please Help

From: Kourakos-Mavromichalis Evagelos <[email-masked]>
Date: Wed, 25 Jul 2001 10:38:55 +0300

I am trying to embed the following SWI-Prolog file (is from SWI manual) in
the following C-program but when I try to execute it I get the following
result: 

---------------------------------------------------------
Welcome to SWI-Prolog (Version 4.0.0)
Copyright (c) 1990-2000 University of Amsterdam.
Copy policy: GPL-2 (see www.gnu.org)

For help, use ?- help(Topic). or ?- apropos(Word).

ERROR: Undefined procedure: calc/1
ERROR:     However, there are definitions for:
ERROR:         call/1
ERROR:         call/2
ERROR:         call/3
ERROR:         call/4
ERROR:         call/5
ERROR:         call/6
   Exception: (1) calc('2+3') ?
----------------------------------------------------------

What goes wrong ?

Thanks for your help,
Vangelis

---------------------- calc.pl ---------------------------
  calc(Atom) :-
          term_to_atom(Expr, Atom),
          A is Expr,
          write(A),
          nl.

------------------ MS C++ Program ------------------
#include <stdio.h>
#include <string.h>
#include <SWI-Prolog.h>

int
main()
{   char *program = "calc.pl";
	char *plav[2];

  plav[0] = program;
  plav[1] = NULL;

  if ( !PL_initialise(1, plav) )
    PL_halt(1);
else
  /* Lookup calc/1 and make the arguments and call */

  { predicate_t pred = PL_predicate("calc", 1, "user");
    term_t h0 = PL_new_term_refs(1);
    int rval;

    PL_put_atom_chars(h0, "2+3");
    rval = PL_call_predicate(NULL, PL_Q_NORMAL, pred, h0);

    printf("result:", rval);

    PL_halt(rval ? 0 : 1);
  }

  return 0;
}