Subject: [SWIPL] Problem with PL_get_name_arity

From: "Andris" <[email-masked]>
Date: Wed, 6 Feb 2002 17:40:02 +0200

Hi.
I want to pass a list to C procedure. List looks like this [opt1(arg1),
opt2(arg2)]. I can get arity and argument, but am unable name of functor.
I`m wondering if i have missed something.
Thanks.

This is how it looks like:

static foreign_t pl_show_list(term_t list) {

  term_t option,arg;
  term_t opts=PL_copy_term_ref(list);
  atom_t key;
  int arity;
  char buf[20];
  char *keyname;
  char *argvalue;

  arg=PL_new_term_ref();
  option=PL_new_term_ref();

  while (PL_get_list(opts, option, opts)) {
    PL_get_name_arity(option, &key, &arity);
    //PL_get_atom_chars(key, &keyname); // uncomented this produces an eror

    if (arity>0) {
      PL_get_arg(1, option, arg);
      PL_get_atom_chars(arg, &argvalue);
      sprintf(buf, "%s=%s", keyname, argvalue);
      MessageBox(NULL, buf, "Test", MB_OK|MB_TASKMODAL);
    }
  }
  PL_succeed;
}

Prolog part:

go:-
 load_foreign_library(foreign(test)),
 show_list([opt1(arg1), opt2(arg2)]),
 unload_foreign_library(foreign(test)).