From 1b2c914d8552f4af1676f6b63203513d949c7817 Mon Sep 17 00:00:00 2001
From: Aleksander Sadikov I take the last element from the given list and add it back at the start of the list's remainder.
+You probably still remember how we took the last element of the list? And adding an element at the start
+is quite simple, isn't it? A list of length one is represented as a pattern If the given list The operator Of course, you can also solve the exercise without explicit use of either of these two operators, just
+remember that unification is implicitly performed with the predicate's arguments (head of clause). Perhaps the operator for unification (=) would be better? It seems your predicate is If the name is correct, check whether something else is misspelled, perhaps there is a full stop instead of
+a comma or vice versa, or maybe you typed a variable name in lowercase? It is, of course, also possible that your conditions are too restrictive, or even impossible to satisfy
+(as would be, for example, the condition that Is there an infinite recursion at work here? How will it ever stop? Or perhaps is there a missing, faulty, or simply incompatible (with the general recursive case) base case? Do you remember how the "pattern" representing a list with exactly one element looks like? Not like
+the second argument you gave to predicate Did you connect (use) all the variables? It seems as if you're returning an arbitrary result
+(a variable without an assigned value). It's usually not a good idea to ignore the warning about
+"singleton variables". The tail of the list is always another list and never just an element. How did you get the last
+element? This will not work... By using predicate Predicates Operator [X]
. This might come in handy, as well
+as the predicate conc/3
.L
is composed of last element E
and the remainder L1
,
+and if we put E
at the start of L1
, then we get list L
+shifted right.==
is "stricter" than operator =
in the sense that
+for the latter it is enough to be able to make the two operands equal (unification). Perhaps by using =
+you can make the predicate shiftleft/2
more general (e.g. able to work with output arguments becoming inputs).N
is equal to N + 1
,
+or something similarly impossible).conc/3
. ;)last/2
it will be difficult to solve this exercise as it leaves the last
+element in the original list. Rather try using predicate conc/3
instead.shiftleft/2
and shiftright/2
perform exactly the opposite function.
+If you simply swap the order of their arguments, you get the other predicate. In this way you could
+program shiftright/2
just by calling shiftleft/2
. You know that in prolog inputs
+and outputs can often be interchanged.==
je strožji od operatorja =
v smislu, da je za slednjega dovolj,
da elementa lahko naredi enaka (unifikacija). Morda z uporabo =
narediš predikat
-memb/2
delujoč tudi v kakšni drugi smeri.shiftright/2
delujoč tudi v kakšni drugi smeri.
Seveda pa lahko nalogo rešiš brez obeh omenjenih operatorjev, spomni se, da lahko unifikacijo narediš implicitno že kar v argumentih predikata (glavi stavka).
''', -- cgit v1.2.1