From emav@aegean.gr Wed Jul 25 09:39:53 2001
Received: from eupalinos.samos.aegean.gr (eupalinos.aegean.gr [195.251.160.12])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f6P7drJ03089
	for <prolog@swi.psy.uva.nl>; Wed, 25 Jul 2001 09:39:53 +0200 (MET DST)
Received: by eupalinos.aegean.gr with Internet Mail Service (5.5.2653.19)
	id <P25BC47X>; Wed, 25 Jul 2001 10:38:57 +0300
Message-ID: <81FBBA8C21B9D311A6E500508B6144AA02B1DB@eupalinos.aegean.gr>
From: Kourakos-Mavromichalis Evagelos <emav@aegean.gr>
To: "'prolog@swi.psy.uva.nl'" <prolog@swi.psy.uva.nl>
Date: Wed, 25 Jul 2001 10:38:55 +0300
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Content-Type: text/plain
Subject: [SWIPL] Please Help

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;
}

