how to pass a list in a predicate in prolog

前端 未结 2 637
眼角桃花
眼角桃花 2021-01-23 11:03

I want to store a paragram as a list in a variable and then call that list for counting how many times a particular word appears in that paragraph.

However, when I do th

2条回答
  •  误落风尘
    2021-01-23 11:50

    You do

    ?- X = [hello,how,are,you,hello,hello], counthowmany(hello, X, N).
    X = [hello, how, are, you, hello, hello],
    N = 3.
    

    First you first bind X ans then you ask for this specific X.

    Example 2.

    ?- counthowmany(hello, X, N).
    X = [],
    N = 0.
    

提交回复
热议问题