Not logged in. · Lost password · Register

oh01ahyz
Member since Oct 2018
18 posts
Subject: [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
tyr
ModKrypt Tutor WS19/20
Avatar
Member since Oct 2014
100 posts
In Prolog the Pattern Matching with List works like this:

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

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

Is there another way to append right-sided without using the predefined append function?

There is no simple pattern for this, but as it is quite easy, you should be able to build your own append method.
"Debugging is like doing surgery by randomly squeezing stuff in a patient's body and going like 'lmao tell me when this guy stops breathing'." -- Orteil, Creator of Cookie-Clicker
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Datenschutz | Kontakt
Powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2011 by Yves Goergen