singleton variables in prolog

后端 未结 3 1299
甜味超标
甜味超标 2021-02-07 00:03

I was testing my new version of SWI prolog and keep coming across the error :singleton variable.

Example:

member(X,[X|T]).

member(X,[X|         


        
3条回答
  •  名媛妹妹
    2021-02-07 00:22

    You can read about it on the official page of SWI-Prolog FAQ

    The most common cases this warning appears are:

    1. Spelling mistakes in variables
    2. Forget to use/bind a variable

    SWI suggest some ways to ignore it:

    1. Use anonymous variable named _ for this purpose.
    2. Use your variable starting with _ (like _T, _X), to avoid warning and document what you ignore.
    3. If you are aware of what you are doing, you can use :- style_check(-singleton). and all warnings should go away.

提交回复
热议问题