I have a predicate that decomposes an expression and I am having results that I dont understand when I trace through it.
My predicate is as below
calc(R,Expr) :- Expr =..[Op,H,T].
So when I have an expression like [1,1], the Op is actually a period. Any idea why?
It’s because the form
[Head|Tail]is just syntactic sugar for'.'(Head, Tail)(everything is a term and lists are no exception). Normally, for the list made of1,2,3and4, you’d have to writeAs you can see, that’s not very practical and instead we use the shortcut:
And this shortcut has a shortcut:
And you can mix those as you wish:
That is handy when you want to specify some elements and then let the tail free:
BTW, you can see that for yourself by using
write_canonical/1:Hope it helped