Re: How can I implement conc with difference list?



alex <onghwan@xxxxxxxxx> wrote:
Thank you for your advice.
I know, but I just want to know 'how' to implement conc and concat with
each other,
I heard that implementing conc with concat(vice versa) is possible.
However, I did my best to find the way, but it was difficult because I
am a newbie.


I can't speak for others on this group, but I'm slightly unco-operative in
spelling out pret a comput'e answers.

But as I said before, your problame is the same problem as if you wanted to
do a linear search of a list-of-integers when you have a subroutine that
searched an array of integrs.
Viz: You have to convert from one type of data representation to the other
(and probably back again).

In your case you want to convert between the "X-Y" form of list -- called
a "difference list" by some -- and the regular [X|Y] type of list.

As a first step you'll need something like

convert_diff_to_regular(X-X,[]).

and

convert_regular_to_diff([],X-X).

as the base cases for each type of converter. Now just add the
clause(s) for the general case(s), and you'll have the type converters.

Then to use conc from concat or vice versa (but not both in the same program,
of course) requires a conversion from the input list type to the "inner" list
type, a call to the inner concat/conc predicate, and a re-conversion from the
inner list type to the output list type.
.



Relevant Pages