Yaswi with modules
[email protected] (Steffen Schwigon) Mon, 09 Jan 2006 16:30:03 +0100
| Newsgroups | perl.ai |
|---|---|
| Organization | webit! Gesellschaft fuer neue Medien mbH |
| Message-ID | <[email protected]> |
--=-=-=
Hi!
I'm using Language::Prolog::Yaswi.
Everything works ok with 'consult'ing prolog files.
When I write all my prolog in modules (without public/export
declaration) I have problems to use them in L::P::Yaswi.
My mini example (see attachments) has a predicate give_me_sth/2, that
can be used this way in pure swi prolog:
$ pl
?- use_module('a.swipl').
?- use_module('b.swipl').
?- module(a).
a: ?- give_me_sth(2, Answer).
Answer = 222 ;
a: ?- module(b).
b: ?- give_me_sth(2, Answer).
Answer = 2 ;
However I'm not able to call it from Perl with L::P::Yaswi. I always
get: error(existence_error(procedure, '/'(give_me_sth, 2)), _100).
I thought it should basically used this way:
swi_use_modules ( "./a.swipl", "./b.swipl" );
local $swi_module = 'a'; ### or 'b'
swi_set_query( give_me_sth(2, Answer) );
swi_var(Answer);
Please see attachment for full mini example.
If someoene please could give me a hint what I'm doing wrong ...
I'm no prolog wizard anyway, so it's also possible I'm doing
something wrong there.
(Greeti+Tha)nX
Steffen
--
Steffen Schwigon <[email protected]>
Dresden Perl Mongers <http://dresden-pm.org/>
--=-=-=
Content-Type: text/x-perl
Content-Disposition: inline; filename=use_swi.pl
#! /usr/bin/perl
use strict;
use warnings;
use Language::Prolog::Types::overload;
use Language::Prolog::Yaswi qw(:query :load :context);
use Language::Prolog::Sugar
functors => { give_me_sth => 'give_me_sth' },
vars => [qw( Answer )] ;
swi_use_modules ( "./a.swipl", "./b.swipl" );
sub yaswi_give_me_sth {
local $swi_module = 'a'; ### or 'b'
# Variante 1
swi_set_query( give_me_sth(2, Answer) );
my $answer = swi_var(Answer) if swi_next;
swi_cut if swi_next;
print "Answer: $answer \n";
}
yaswi_give_me_sth();
--=-=-=
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=a.swipl
%a.swipl
:- module(a, [ ]). %% explicitly empty, no give_me_sth/2
give_me_sth(1, Y) :- Y is 111.
give_me_sth(2, Y) :- Y is 222.
give_me_sth(3, Y) :- Y is 333.
--=-=-=
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=b.swipl
%b.swipl
:- module(b, [ ]). %% explicitly empty, no give_me_sth/2
give_me_sth(1, Y) :- Y is 1.
give_me_sth(2, Y) :- Y is 2.
give_me_sth(3, Y) :- Y is 3.
--=-=-=--