Self-test 3 Solutions

Introductory list processing
 
   
 

    | ?- dissect_list([a,b,c]). a b c [] yes
    | ?- dissect_list([]).
    []
    
    yes
  1. | ?- dissect_list([Head|b , c]).

  2. This gives a syntax error in most Prologs because anything to the right of the list constructor ("|") should be within a single list. The goal dissect_list([Head, b , c]). would not have given an error.

    | ?- dissect_list([Head|[b, c]]).
    _70
    b
    c
    []
    
    true ? ;
    
    no
    | ?- dissect_list([1, car(metro, green)]).
    1
    car(metro,green)
    []
    
    yes
    | ?- dissect_list([[a,l,p,h,a], [b,e,t,a]]).
    [a,l,p,h,a]
    [b,e,t,a]
    []
    
    yes
    Note that the argument here is a list of two elements, both of which are lists.
    | ?- dissect_list([Tl|Hd]).
    _66
    []
    
    Hd = [] ? ;              {This is the variable instantiation}
    _180                   {This is the next alternative}
    []
    
    Hd = [_A] ? ;              {This is the variable instantiation}
    _196                   {This is the next alternative}
    []
    
    Hd = [_A,_B] ? ;              {This is the variable instantiation}
    _212                   {This is the next alternative}
    []
    
    Hd = [_A,_B,_C] ?                {This is the variable instantiation}
    yes