Reputation: 67
I'm trying to write a rule to compare two atoms to see which one is better for example (memory_with_gb_2 is better than memory_with_gb_1) and what I've written and tried in SWI-prolog is the following:
better_attribute3_in(Attribute3_in,Attribute3):-
atom_codes(Attribute3,List_Attribute3),
startsWith(List_Attribute3,Attribute3_Start,Rest_Attribute3_List),
atom_to_term(Rest_Attribute3_List,Attribute3_Number,_),
number(Attribute3_Number),
atom_codes(Attribute3_in,List_Attribute3_in),
startsWith(List_Attribute3_in,Attribute3_in_Start,Rest_Attribute3_in_List),
atom_to_term(Rest_Attribute3_in_List,Attribute3_in_Number,_),
number(Attribute3_in_Number),
Attribute3_in_Number>=Attribute3.
which is working perfectly in SWI-Prolog but when I try it in SICStus Prolog it just does not seem to work, is there anyway to implement the upper code in SICStus.
Upvotes: 0
Views: 362
Reputation: 10487
I have trouble understanding what your code is intended to do and I do not think it works as it stands.
(To get something that mimics the original code you could probably replace startsWith(A,B,C) with append(B,C,A) and replace atom_to_term(A,B,C) with name(A,B)).
Upvotes: 1
Reputation: 67
I figured it it out thank you for your kind suggestion I changed my code to this:
better_attribute3_in(Attribute3_in,Attribute3):-
atom_codes(Attribute3,List_Attribute3),
startsWith(List_Attribute3,Attribute3_Start,
Rest_Attribute3_List),numeric(Rest_Attribute3_List),
number_codes(Attribute3_Number,Rest_Attribute3_List),
atom_codes(Attribute3_in,List_Attribute3_in),
startsWith(List_Attribute3_in,Attribute3_Start,Rest_Attribute3_in_List),
numeric(Rest_Attribute3_in_List),
number_codes(Attribute3_in_Number,Rest_Attribute3_in_List),
!,Attribute3_Number=<Attribute3_in_Number.
using ascii codes to see if the contents of a list represent a number or no:
numeric(List):-subset(List,[48,49,50,51,52,53,54,55,56,57]).
and using startsWith to see if they start with the same string or not (for example I can compare two memories together but not a memory and a hard disk):
startsWith(OldString,[],OldString):- true.
startsWith([H|TOldString],[H|T],Rest):-
startsWith(TOldString,T,Rest).
Upvotes: 0