Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7772167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:49:36+00:00 2026-06-01T16:49:36+00:00

Another problem, I have a good working function for deleting: remove([],X,[]) :- !. remove([X|T],X,L1)

  • 0

Another problem, I have a good working “function” for deleting:

remove([],X,[]) :- !. 
remove([X|T],X,L1) :- !, remove(T,X,L1).         
remove([H|T],X,[H|L1]) :- remove(T,X,L1). 

But it doesn’t work like I want it to work.
It removes element or even list…

…but doesn’t remove all appearances. This is goal:

remove([A,B,[C],[A,[B]],[[A,[B]]]],[A,[B]],X).
X=[A,B,[C],[]]

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:49:37+00:00Added an answer on June 1, 2026 at 4:49 pm

    If you would like to remove all appearances e.g., to let remove([1,2,3,1],1,X) calculate X=[2,3] just replace the second clause with

     remove([X|T],X,L1) :- remove(T,X,L1), !.  
    

    However, it seems that you would like a) to work with variables that should be kept as variables and b) to remove lists from sublists.

    We will start with solving the b) issue first.

    remove([],_,[]) :- !. 
    remove(A,_,A) :- \+ (A = [_|_]), !.
    remove([X|T],X,L1) :- remove(T,X,L1), !.        
    remove([H|T],X,[G|L1]) :- remove(H,X,G), remove(T,X,L1).
    

    As you see we add a second recursive call to the last clause to take care of the internal list. Moreover, we had to add a special case (the second clause) since the first argument is not necessarily a list.

    Finally, to solve a) you need to use the “freeze” / “melt” predicates of Sterling and Shapiro. freeze replaces variables with expressions #VAR(0), #VAR(1), … and melt does the opposite. Melt is traditionally known as melt_new

    numvars('#VAR'(N),N,N1) :- N1 is N+1.
    numvars(Term,N1,N2) :- nonvar(Term), functor(Term,_,N),
                              numvars(0,N,Term,N1,N2).
    
    numvars(N,N,_,N1,N1).
    numvars(I,N,Term,N1,N3) :- I<N, I1 is I+1,
              arg(I1,Term,Arg), numvars(Arg,N1,N2),
              numvars(I1,N,Term,N2,N3).
    
    frz(A,B) :- frz(A,B,0).
    frz(A,B,Min) :- copy_term(A,B), numvars(B,Min,_),!.
    
    
    melt_new(A,B) :-
       melt(A,B,Dictionary), !.
    
    melt('$VAR'(N),X,Dictionary) :-
        lookup(N,Dictionary,X).
    melt(X,X,Dictionary) :-
        constant(X).
    melt(X,Y,Dictionary) :-
        compound(X),
        functor(X,F,N),
        functor(Y,F,N),
        melt(N,X,Y,Dictionary).
    
    melt(N,X,Y,Dictionary) :-
        N > 0, 
        arg(N,X,ArgX), 
        melt(ArgX,ArgY,Dictionary),
        arg(N,Y,ArgY), 
        N1 is N-1, 
        melt(N1,X,Y,Dictionary).
    melt(0,X,Y,Dictionary).
    
    /*  
        lookup(Key,Dictionary,Value) :-
        Dictionary contains the value indexed under Key.
        Dictionary is represented as an ordered binary tree.
    
    */
    
        lookup(Key,dict(Key,X,Left,Right),Value) :-
            !, X = Value.
        lookup(Key,dict(Key1,X,Left,Right),Value) :-
            Key < Key1 , lookup(Key,Left,Value).
        lookup(Key,dict(Key1,X,Left,Right),Value) :-
            Key > Key1, lookup(Key,Right,Value).
    

    By the way, I really recommend the book of Sterling and Shapiro “The Art of Prolog”.
    Melting and freezing are discussed in Chapter 15.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from a question I posted yesterday about GUIs, I have another problem
I've been struggling with Zend_Navigation all weekend, and now I have another problem, which
After getting a helpful answer here , I have run into yet another problem:
And another TreeView problem , should've used qt ;) I have a TreeView in
another ordered delivery problem. We have an orchestration which is bound to a send
I have a problem with .NET assembly redirection. 3rd party assembly A references another
here is the problem. I have one PC using VS2008 (SP1 ) and another
Okay, so I have another question on a prolog homework problem I am struggling
Having dealt with yet another stupid eclipse problem, I want to try to get
I'm not very good at mathematics, so I got a problem. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.