在序言中转换为点表示法 [英] Converting to dot notation in prolog
问题描述
我必须在Prolog中以点表示法表示[[fruits],[ ] ]
,以下是我的操作方法,但是有些东西告诉我这是错误的,因为我也扩展了[[ ]]
,这不正确吗?
I have to represent [[fruits],[ ] ]
in dot notation form in Prolog, and below is how I did it ,but something tells me this is wrong because I have expanded [[ ]]
too, is this incorrect ?
.([fruits],[[ ]] )
.(.(fruits, []),.([],[])
推荐答案
除了Willem所写的内容外,您始终可以使用write_canonical/1
来获取任何名词的规范表示形式.
In addition to what Willem wrote, you can always use write_canonical/1
to obtain the canonical representation of any term.
例如,在您的情况下:
| ?- write_canonical([[fruits],[ ] ]).
'.'('.'(fruits,[]),'.'([],[]))
这可以解决任务,并显示您已正确扩展列表[[]]
.
This solves the task, and shows that you have expanded the list [[]]
correctly.
特别是,我们有:
| ?- write_canonical([[]]).
'.'([],[])
是的:这是一个具有单个元素的列表,该元素是[]
,如'.'/2
项的第一个参数所示.由于它是 only 元素,因此第二个参数也是 []
.
That's right: This is a list with a single element, which is []
as indicated by the first argument of the '.'/2
term. Since it is the only element, the second argument is also []
.
这篇关于在序言中转换为点表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!