Prolog - How to make a variable list out of a given list from input file?

后端 未结 1 556
挽巷
挽巷 2021-01-26 09:47

I have a input predicate will read the file as a list: input(Filename,List). The list then will be in the format of

[\"_\",\"_\",\"_\",9,\"_\",\"_\"]

相关标签:
1条回答
  • 2021-01-26 10:15
    to_var_list([],[]).
    to_var_list([A|R1],[B|R2]):-
         (A = '_' ->
          true;
          A = B),
        to_var_list(R1,R2).
    

    Exchange '_' with "_" if you actually have one character strings and not underscore atoms. Also, there is a read predicate that does something like you want to achieve, but it expects a . after your lists in the file.

    0 讨论(0)
提交回复
热议问题