Is there a way to write non-homogenous lists in prolog?
I want to create a list which contains symbols and integers. Something like:
[A 2 3 B C D E]
Thanks
P.S. I user Turbo Prolog 2.0
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Turbo Prolog requires that list elements be of a single type. But there is a way around this – you just need to define a single type which can represent both integers and symbols. You can do this by defining a compound domain, in which each different type is wrapped with a different functor. So, for example:
The downside is that you need a functor around every list element, which is a bit awkward: