[Ex. 1.1] Append Head element right sided via [Variable|Head]

Disclaimer: Dieser Thread wurde aus dem alten Forum importiert. Daher werden eventuell nicht alle Formatierungen richtig angezeigt. Der ursprüngliche Thread beginnt im zweiten Post dieses Threads.

[Ex. 1.1] Append Head element right sided via [Variable|Head]
Dear all,

I tried to implement the removeDuplicates function via checking whether current Head is a member of some bufferlist that contains the previously seen elements. If it is not a member, I intended to append it right-sided via [bufferList|Head].

Unfortunately this results in an encapsulated List of the shape [[[[1]2]3]4].
The other way round works well [Head|bufferList].

Intermediately I solved it via reverting the base case at the end to have the elements in the right order, but I think it is not very elegant.

Does somebody know which is the reason for the different behaviour of [Head|bufferList] vs. [bufferList|Head]? Is there another way to append right-sided without using the predefined append function?

Thank you and kind regards,
Matthias


In Prolog the Pattern Matching with List works like this:

if you use [m][Head|Tail][/m], then [m]Head[/m] is a single element, while [m]Tail[/m] is a List.

When you are writing [m][bufferList|Head][/m] in your code, Prolog has to match [m]bufferList[/m] with an element and [m]Head[/m] with a list.
That seems to be your problem here, at least from my perspective.(Also [m]bufferList[/m] is not capitalized => it is a constant!)

There is no simple pattern for this, but as it is quite easy, you should be able to build your own append method.