0

Does anybody know a library (preferably not SWI-prolog) for using Prolog in Xcode? If not, do you know a library for a more recent language that does a similar job?

Thanks

ERIC
  • 184
  • 1
  • 9
  • Xcode is an IDE. If you mean, use Prolog from Objective-C, there isn't anything specific for it, you'll have to use an implementation with a friendly C binding (like SWI). – Daniel Lyons Aug 27 '13 at 22:08

1 Answers1

0

I have been using GNU Prolog (gprolog) a lot lately and it has a beautifully simple interface to C which allows you to produce custom executables made of standard code plus your own.

Being a Cocoa programmer too I am not sure how you would integrate the code but section "10.6 Calling Prolog from C" might give you some ideas on hoe to use it as part of an Xcode application.

The next section, 10.7 Defining a new C main() function might help on how you could translate that code (shown here for clarity) into something more ObjC like:

static int
Main_Wrapper(int argc, char *argv[])
{
  int nb_user_directive;
  PlBool top_level;

  nb_user_directive = Pl_Start_Prolog(argc, argv);

  top_level = Pl_Try_Execute_Top_Level();

  Pl_Stop_Prolog();

  if (top_level || nb_user_directive)
    return 0;

  fprintf(stderr,
          "Warning: no initial goal executed\n"
          "   use a directive :- initialization(Goal)\n"
          "   or remove the link option --no-top-level"
          " (or --min-bips or --min-size)\n");

  return 1;
}

int
main(int argc, char *argv[])
{
  return Main_Wrapper(argc, argv);
}

Kludging all that into NSApplicationMain is going to be fun and interesting!

The only other way I could think of doing it is to make the above code start your Cocoa application maybe by using objc_msgSend as described in this answer, "Calling Cocoa APIs from C".

Best of luck with it. Sean.

Community
  • 1
  • 1
  • Just found this SO question too, related and might also help... http://stackoverflow.com/questions/13583039/interface-from-c-programm-in-xcode-to-swi-prolog – Emacs The Viking Sep 01 '13 at 08:31