Hello I have a predicate that returns example equalisation for given list
equalisation([1,2,3,4,12],L).
L = (1=2-3* (4/12))
now I want to change this result into a list like this:
L = [1,=,2,-,3,*,4,/,12]
How can I do that?
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.
The simplest solution would be to traverse a term creating a list of small lists, and then to flatten everything. However, the simplest solution is not the most elegant one – quoting the SWI Prolog flatten/2 manual:
So here is an alternative solution using difference lists:
Clearly, the current solution works only for binary operations. If operations with an arbitrary number of arguments are allowed, then another traversal of the arguments will be required.