% Autor:
% Fecha: 02/02/2010
:- use_module( library(pce) ).
:- use_module( library(broadcast) ).
name_of(a,ah).
name_of(b,bh).
name_of(c,ch).
name_of(d,dh).
:- pce_begin_class(name_item, text_item).
variable(id, any, get, "Id visualised"). % name, type, access,
[comment]
initialise(NI, Id:any) :-> name_of(Id, Name),
send_super(NI, initialise, name, Name,
message(NI, set_name, @arg1)),
send(NI, slot, id, Id),
listen(NI, name_of(Id, Name), send(NI,
selection, Name)),
unlink(NI) :-> unlisten(NI), send_super(NI, unlink).
set_name(NI, Name:name) :-> get(NI, id, Id), retractall(name_of(Id,
_)), assert(name_of(Id, Name)), broadcast(name_of(Id, Name)).
:- pce_end_class.
When I compile and create an object from this class, and try to use
set_name method, I find an error:
% library(win_menu) compiled into win_menu 0.00 sec, 11,760 bytes
% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 2,024 bytes
% c:/users/ron/appdata/roaming/swi-prolog/pl.ini compiled 0.00 sec,
380 bytes
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.8.2)
Copyright (c) 1990-2009 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?- consult('C:/project/workflow prolog/modularity/name_item.pl').
% library(quintus) compiled into quintus 0.02 sec, 10,768 bytes
% library(pce) loaded into pce 0.03 sec, 197,788 bytes
% library(broadcast) compiled into broadcast 0.00 sec, 3,944 bytes
% C:/project/workflow prolog/modularity/name_item.pl compiled 0.05
sec, 206,752 bytes
true.
3 ?- new( NIA, name_item(a) ).
NIA = @8394732/name_item.
4 ?- send( NIA, set_name, newName ).
ERROR: Arguments are not sufficiently instantiated
what's the reason for this error (ERROR: Arguments are not
sufficiently instantiated)?
thanks in advance for your help.
Ron
This is Prolog: there are no global variables. NIA was instantiated
in the first query, but in the second query it is a new,
uninstantiated variable. If you wrote:
?- new( NIA, name_item( a ) ), send( NIA, set_name, newName ).
the results would be different.
Hope this helps,
-- Feliks
Thanks Feliks for your quick answer, I'm just learning this
interesting language. Unfortunately I found this error after I
modified the query:
ERROR: retractall/1: No permission to modify static_procedure `name_of/
2'
Is necessary to define the name_of/2 into a module to be accessed into
pce_class? I tried to define into pce_[begin|end]_class block but I
found the same error. Thanks
Add the following directive to your code:
:- dynamic(name_of/2).
Cheers,
Paulo
Thanks Paulo, it was very useful
Ron