From sd80041@lanet.lv Wed Feb  6 16:40:58 2002
Received: from dino.di.lv (dino.di.lv [159.148.146.129])
	by swi.psy.uva.nl (8.11.6/8.11.2) with ESMTP id g16Fewp20754
	for <prolog@swi.psy.uva.nl>; Wed, 6 Feb 2002 16:40:58 +0100 (MET)
Received: from gints ([159.148.146.171])
          by dino.di.lv (Lotus Domino Release 5.0.5)
          with SMTP id 2002020617400268:17322 ;
          Wed, 6 Feb 2002 17:40:02 +0200 
Message-ID: <006201c1af24$8add7fe0$ab92949f@ad.di.lv>
From: "Andris" <sd80041@lanet.lv>
To: <prolog@swi.psy.uva.nl>
Subject: [SWIPL] Problem with PL_get_name_arity
Date: Wed, 6 Feb 2002 17:40:02 +0200
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2462.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2462.0000
X-MIMETrack: Itemize by SMTP Server on dino/Datorikas Instituts/LV(Release 5.0.5 |September
 22, 2000) at 2002.02.06 17:40:02,
	Serialize by Router on dino/Datorikas Instituts/LV(Release 5.0.5 |September
 22, 2000) at 2002.02.06 17:40:04,
	Serialize complete at 2002.02.06 17:40:04
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset="iso-8859-4"

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)).

