Appendo is a common function in logic programming, where you can pass in 3 variables, which you can use to not only compute the append of two linkedLists, but also the combination of all linkedLists that could have been used to produce the result
?- append(X,Y,[1,2,a,b]).
X = [], Y = [1, 2, a, b] ;
X = [1], Y = [2, a, b] ;
X = [1, 2], Y = [a, b] ;
X = [1, 2, a], Y = [b] ;
X = [1, 2, a, b], Y = [] ;
I was wondering if it is possible to write such a function in Verse?
Here is my attempt:
linkedList := class:
Value: string
Next: ?linkedList
appendo(xs, ys, zs: ?linkedList)<decides><transacts>: void :=
if (xs?) {
zs = ys
} else {
head: string;
xtail: ?linkedList;
ztail: ?linkedList;
xs = option{linkedList{Value := head, Next := xtail}};
zs = option{linkedList{Value := head, Next := ztail}};
appendo (xtail, ys, ztail)
}
Is this legal or what would be a better way?
Does this already work in Verse in UEFN?