In Erlang I can do something like this:
f(L = [_|_]) -> % code
This will match on any list that has at least one element and bind the whole list to L
.
Is there some similar construct available in prolog?
I tried the following on an online playground (I’m on mobile without proper prolog interpreter).
f(A = [_|_], A).
Hoping it would act like identity for any list of length greater than or equal to 1, but it just replied false
independent of how I called the predicate. Except for when I use it as a “generator” then it produces results to what I’d expect:
?- f(B, A).
B = (A=[_1514|_1516])
?- f([a], A).
false
?- f([a,b], A).
false
Using a list just for the example, the data that I do in fact expect will be a lot more complex compound terms.
Edit:
As this might also be specific to the online playground I used, it’s this one: