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

  • SEARCH
  • Home
  • 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 8679705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:02:32+00:00 2026-06-12T21:02:32+00:00

*Hi, i am trying to replace an element from a list with another list

  • 0

*Hi, i am trying to replace an element from a list with another list and im stuck when turbo prolog gives me syntax error at the case where if C=A-> put in result list(L1) the list that replace the element.

domains
    list=integer*
    element=i(integer);l(list)
    lista=element*
predicates
    repl(list,integer,list,lista)
clauses
    repl([],A,B,[]):-!.
    repl([C|L],A,B,**[l(|L1])**:- C=A,repl(L,A,B,L1),!.
    repl([C|L],A,B,[i(C)|L1]):- repl(L,A,B,L1),!.

Thanks for help, problem solved (using dasblinkenlight code)

  • 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-12T21:02:34+00:00Added an answer on June 12, 2026 at 9:02 pm

    Try this:

    concat([],L,L).
    concat([H|T],L,[H|Res]) :- concat(T,L,Res).
    
    repl([],_,_,[]).
    repl([Val|T],Val,Repl,Res) :- repl(T,Val,Repl,Temp), concat(Repl,Temp,Res).
    repl([H|T],Val,Repl,[H|Res]) :- repl(T,Val,Repl,Res).
    

    I do not know if it is going to work in Turbo Prolog, but it works fine in SWI, and it does not use any built-in predicates.

    concat/3 pair of rules concatenates lists in positions 1 and 2 into a resultant list in position 3.

    • The first repl deals with the empty list coming in; it is identical to yours, except it replaces singleton variables with underscores (a highly recommended practice)
    • The second rule deals with the situation where the value Val being replaced is at the head of the list; it replaces the values in the tail, and concatenates the replacement list Repl with the result of the replacement Res.
    • The last rule deals with the situation when the head value does not match the Val. It recurses down one level, and prepends the head of the initial list to the head of the result of the replacement.

    As a side note, the cut operator ! is rarely necessary. In case of this problem, you can definitely do without it.

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

Sidebar

Related Questions

I am trying to remove an span element from HTML then replace that element
I am trying to replace specific highlighted(marked) text from element. This is how I
I'm trying to replace a div with created elements, going from: <div id='links'></div> to
I am trying to select a certain value from a multi-element background-image property such
I am trying to animate the background of an element from it's current position
I'm trying to parse a int from a String array element. Here is my
I'm trying use jquery to remove a class from an element (not knowing ahead
I'm trying to remove all of the spaces from elements in a list of
I'm trying to get an object element from my webpage using getElementById (ultimately so
I'm trying to remove/replace the title attribute on the category elements used by WordPress.

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.