A problem??

From: desert_bise (shazadi.gul_at_gmail.com)
Date: 03/05/05

  • Next message: Bart Demoen: "Re: A problem??"
    Date: 4 Mar 2005 23:25:10 -0800
    
    

    HI All, i am new to prolog and have tried to solve the problem using
    my own code.the prooblem has a list as follows:-
         ['first','second','third','first','second']
    I use the following code to get the number of each elements in the
    list and display them
    get_items([], Length, ElemList).
    get_items(List, Length, ElemList):-
                               length(List, Length),
                               last(List, Elem),
                               delete(List, Elem, List1),
                               length(List1, Length1),
                               N is Length - Length1,
                               item_to_remove(N,Elem,ElemList,ElemList1),
                               write(Elem), tab(2), write(N), tab(2),
                               get_items(List1, Length1, ElemList1).

    item_to_remove(N,Elem,ElemList,ElemList1):-
                               N > 1,
                               append(ElemList,Elem,ElemList1);
                               ElemList1 = ElemList.

    I run as this code to try and get a seperate list of items that occur
    in the list more than once.
    second 2 first 2 third 1

    Length = 5
    ElemList = []

    It correctly displays the number of times an item appears in the list
    but the list of items appearing more than once is empty? I dont know
    why?.


  • Next message: Bart Demoen: "Re: A problem??"

    Relevant Pages

    • Re: HTML and XHTML
      ... Harrie wrote: ... So, the prolog is required and is, therefore, always present, but as David said, doesn't have to contain *anything*. ... it's not represented an empty line. ...
      (comp.infosystems.www.authoring.html)
    • Re: Lists in Learn Prolog Now
      ... listA) (empty? ... listB)) false). ... You can use it in ways that are awkward to express in Scheme, even with totally unknown arguments, and still expect Prolog to give meaningfull answers. ...
      (comp.lang.prolog)
    • Re: Getting status of a free variable.
      ... I dont know if I understood exactly, but it seems to me that you have just ... to invert clauses, that is: ... I'm sorry for my english and my prolog dictionary... ... I'll try to be clearer if you don't understand my problem. ...
      (comp.lang.prolog)
    • Re: compare element in a list prolog
      ... kimos wrote: ... Now in Prolog this becomes: ... empty or a singleton should be treated in a special way, ...
      (comp.lang.prolog)
    • interfacing Prolog and C code
      ... I would like to call Prolog from my C code, but as a newbie I really ... Should I use SWI or Sicstus? ...
      (comp.lang.prolog)