Logtalk's asserta and ic library

Tips and tricks when running Logtalk using ECLiPSe as the back-end compiler

Moderator: Paulo Moura

Post Reply
WitJakuczun
Posts: 9
Joined: Thu Feb 14, 2008 3:08 pm
Location: Warsaw, Poland
Contact:

Logtalk's asserta and ic library

Post by WitJakuczun » Thu May 08, 2008 7:41 am

Hi,
I have a question. Assume I have an object:

Code: Select all

:- object(clp_object).
   :- private(var1/1).
   :- dynamic(var1/1).

   :- private(var2/2).
   :- dynamic(var2/2).

   :- public(add_var1/0).
   :- public(add_var2/0).

   add_var1(Id) :-
        ic:(V :: 0..1),
        asserta(var1([Id, V]))
        .

   add_var2(Id) :-
        ic:(V :: 0..1),
        asserta(var2(Id, V))
        .
:- end_object.   
Now, calling

Code: Select all

clp_object::add_var1(1)
works but

Code: Select all

clp_object::add_var2(1)
is not working (it returns: syntax error: illegal head in rating(3, V{suspend : _1359, ic : ic(integer, 0.0, 1.0, undefined, [], [], [], [])})

What is wrong with 2-ary dynamic predicates?

Best regards,
Wit Jakuczun
--
[ Wit Jakuczun <W.Jakuczun [at] wlogsolutions.com> ]
[ WLOG Solutions http://www.wlogsolutions.com ]

WitJakuczun
Posts: 9
Joined: Thu Feb 14, 2008 3:08 pm
Location: Warsaw, Poland
Contact:

Re: Logtalk's asserta and ic library

Post by WitJakuczun » Thu May 08, 2008 9:38 am

Ok, I have checked this in pure ECLiPSe's prolog code. It
is also not working...
This is offtopic but maybe someone could explain me
why it is not working?

Best regards,
Wit Jakuczun
--
[ Wit Jakuczun <W.Jakuczun [at] wlogsolutions.com> ]
[ WLOG Solutions http://www.wlogsolutions.com ]

Paulo Moura
Logtalk developer
Posts: 474
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Logtalk's asserta and ic library

Post by Paulo Moura » Thu May 08, 2008 11:57 am

WitJakuczun wrote:Ok, I have checked this in pure ECLiPSe's prolog code. It
is also not working...
This is offtopic but maybe someone could explain me
why it is not working?
Maybe some conflicting operator definitions? Try:

Code: Select all

pmmbp:Desktop pmoura$ eclipse
ECLiPSe Constraint Logic Programming System [kernel]
Kernel and basic libraries copyright Cisco Systems, Inc.
and subject to the Cisco-style Mozilla Public Licence 1.1
(see legal/cmpl.txt or www.eclipse-clp.org/licence)
Source available at www.sourceforge.org/projects/eclipse-clp
GMP library copyright Free Software Foundation, see legal/lgpl.txt
For other libraries see their individual copyright notices
Version 5.10 #103 (i386_macosx), Mon Nov 26 15:44 2007
[eclipse 1]: ic:(V :: 0..1), writeq(V), asserta(v(V)).
WARNING: module 'ic' does not exist, loading library...
ic_kernel.eco loaded traceable 0 bytes in 0.01 seconds
linearize.eco loaded traceable 0 bytes in 0.01 seconds
ordset.eco loaded traceable 0 bytes in 0.00 seconds
ic_constraints.eco loaded traceable 0 bytes in 0.03 seconds
ic.eco     loaded traceable 0 bytes in 0.00 seconds
ic_generic_interface.eco loaded traceable 0 bytes in 0.01 seconds
ic_search.eco loaded traceable 0 bytes in 0.01 seconds
ic.eco     loaded traceable 0 bytes in 0.06 seconds
syntax error: illegal head in v(V{suspend : _1686, ic : ic(integer, 0.0, 1.0, undefined, [], [], [], [])})
_1683{suspend : _1686, ic : ic(integer, 0.0, 1.0, undefined, [], [], [], [])}Abort
I suggest you post the goal above to the ECLiPSE mailing list. Joachim or Kish should be able to clarify this issue.

Cheers,

Paulo
Paulo Moura
Logtalk developer

WitJakuczun
Posts: 9
Joined: Thu Feb 14, 2008 3:08 pm
Location: Warsaw, Poland
Contact:

Re: Logtalk's asserta and ic library

Post by WitJakuczun » Thu May 08, 2008 2:43 pm

Thanks. I will post this on ECLiPSe's lists.

Best regards
--
[ Wit Jakuczun <W.Jakuczun [at] wlogsolutions.com> ]
[ WLOG Solutions http://www.wlogsolutions.com ]
--
[ Wit Jakuczun <W.Jakuczun [at] wlogsolutions.com> ]
[ WLOG Solutions http://www.wlogsolutions.com ]

WitJakuczun
Posts: 9
Joined: Thu Feb 14, 2008 3:08 pm
Location: Warsaw, Poland
Contact:

Re: Logtalk's asserta and ic library

Post by WitJakuczun » Thu May 08, 2008 3:58 pm

Ok, I have found in SICStus documentation that assert does not work
well with attributed variables (ic variables are attributed).
To do this in sicsctus one could use copy_term. It is well explained
in SICStus documentation.
To do this in ECLiPSe one can use a following trick:

Code: Select all

ic:(V :: 0..1), writeq(V), asserta(v([V])).
I do not know whether it is portable!

Best Regards
--
[ Wit Jakuczun <W.Jakuczun [at] wlogsolutions.com> ]
[ WLOG Solutions http://www.wlogsolutions.com ]

Paulo Moura
Logtalk developer
Posts: 474
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Logtalk's asserta and ic library

Post by Paulo Moura » Thu May 08, 2008 4:06 pm

WitJakuczun wrote:Ok, I have found in SICStus documentation that assert does not work
well with attributed variables (ic variables are attributed).
To do this in sicsctus one could use copy_term. It is well explained
in SICStus documentation.
To do this in ECLiPSe one can use a following trick:

Code: Select all

ic:(V :: 0..1), writeq(V), asserta(v([V])).
I do not know whether it is portable!
That explains something that was puzzling me: why add_var1/1 works while add_var2/ throws an exception. No idea about portability, however; I never used attributed variables (mostly because they are available only in a few Prolog compilers).

Best regards,

Paulo
Paulo Moura
Logtalk developer

WitJakuczun
Posts: 9
Joined: Thu Feb 14, 2008 3:08 pm
Location: Warsaw, Poland
Contact:

Re: Logtalk's asserta and ic library

Post by WitJakuczun » Thu May 08, 2008 4:12 pm

I use attributed variables as I use mostly CLP for solving optimisation problems.

I have posted to comp.lang.prolog. Have the wiser speak ;).

Best regards
--
[ Wit Jakuczun <W.Jakuczun [at] wlogsolutions.com> ]
[ WLOG Solutions http://www.wlogsolutions.com ]

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest