0

I am going to split list into two list - by positions (odd or even), for example (of course it is not exact example, given way of working prolog).

[1,2,3,4,5]
[1,3,5]
[2,4]



div([H1|[]], [H1], []).
div([H1,H12|T1], [H2|T2], [H3|T3]) :- div(T1, T2, T3). 

Warning:

Singleton variables: [H1,H12,H2,H3]

I have no idea how to implement it to avoid this warning - have you some idea ?

  • 2
    (1) `[H1|[]]` can simply be written `[H1]`, (2) *singleton* means the variable shows up once and so doesn't serve a purpose. So in your second `div/3` clause, where do you use `H1` and `H12` besides the first argument? Where do `H2` and `H3` come from? – lurker May 13 '16 at 10:30
  • thanks, now I understood. –  May 13 '16 at 10:41
  • Possible duplicate of [Prolog "singleton variable" warning](http://stackoverflow.com/questions/27369740/prolog-singleton-variable-warning) – Patrick J. S. May 13 '16 at 10:53
  • 2
    (This comment is *not* about getting rid of the singleton variable warning.) Follow the links to the picture-perfect answers (+1) by salva http://stackoverflow.com/questions/8089849/shuffle-in-prolog/8091652 and NicholasCarey http://stackoverflow.com/a/26661926/4609915 ! – repeat May 13 '16 at 11:12

0 Answers0