From jan@swi.psy.uva.nl  Thu Feb  3 13:12:49 2000
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id NAA10124;
	Thu, 3 Feb 2000 13:12:48 +0100 (MET)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id NAA21044;
	Thu, 3 Feb 2000 13:12:58 +0100
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: "Eelco J. Sommer" <e.j.sommer@kpn.com>,
        "Eelco J. Sommer" <e.j.sommer@kpn.com>, <prolog@swi.psy.uva.nl>
Subject: Re: foreign_library implementation question
Date: Thu, 3 Feb 2000 12:44:38 +0100
X-Mailer: KMail [version 1.0.28]
Content-Type: text/plain
References: <000201bf6dc6$8f0fe900$0115a8c0@thebe>
In-Reply-To: <000201bf6dc6$8f0fe900$0115a8c0@thebe>
MIME-Version: 1.0
Message-Id: <00020313125801.20536@gollem>
Content-Transfer-Encoding: 8bit

On Wed, 02 Feb 2000, Eelco J. Sommer wrote:
>A burning question:
>
>>From my foreign_library C file, I want to register/map several prolog
>predicates to the same C function. Within this C function I want to
>determine the (name of the) actual calling predicate. Can this be done?
>
>Background: I want to be able to generate predicates dynamically, and handle
>them using a generic handler.

Odd plan :-)  Basically you can do it using a call-back to Prolog, get
a reference to the current stack and walk up until you find the
call-back.  The predicates are prolog_frame_attribute/3 and friends.

This however is not really what you want, I guess.

An alternative is to generate your calls with an additional argument
telling what you want the foreign function to do.  This seems the
most portable and logical solution to me.

Alternative, the foreign interface has to be augmented.  This very
easy, but in principle their might be a day where optimisation makes
it hard to extract this information.

Of course you can do yourself whatever you like with the source, but
I will only add it to the interface if you can explain why passing
an extra argument doesn't solve your problem.

	Regards --- Jan

