Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ordering Strings in Prolog

I want to know how can I compare two strings that would tell me if one string is greater that the other one, or not.

I don't want equality/inequality. I want to have the good old alphanumeric ordering.

Example: 'aaaa' ,'aaad', 'aaab' the sorted should be: 'aaaa', 'aaab', 'aaad'

Also, what if I have atoms? How to order atoms? (again a=b or a\=b doesn't do the job, i need order.)

like image 504
Aaron Azhari Avatar asked Feb 21 '23 22:02

Aaron Azhari


1 Answers

Use the term-ordering predicates @< and friends.

?- aaaa @< aaab.
true.

?- aaad @>= aaab.
true.
like image 140
Fred Foo Avatar answered Feb 27 '23 19:02

Fred Foo