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 8958451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:12:59+00:00 2026-06-15T15:12:59+00:00

When I run a query after creating my Prolog listing, how does Prolog use

  • 0

When I run a query after creating my Prolog listing, how does Prolog use scoping to solve it? I understand that the cut operator ! can affect the results. Does it do this by affecting the scope?

  • 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-15T15:13:00+00:00Added an answer on June 15, 2026 at 3:13 pm

    First things first: does prolog uses dynamic scoping? No, it does not, and the reason why it doesn’t is because prolog needs to keep track of the variables defined, so that any new assignment would refer to the initial variable — and not to last value assigned to that variable name.

    Bash, on the other hand, uses dynamic scoping, and so, using a variable i in a for loop, and using a variable i in another function, which happens to be called during — or not — the loop execution, will affect each other’s i value.

    This may go not very straightforward, so, an example:

    #!/bin/bash
    function my_first_I() {
        I=10;
    }
    function my_second_I() {
        I=100;
    }
    
    I=1; echo $I;
    my_first_I; echo $I;
    my_second_I; echo $I;
    

    Output:

    $ ./script.sh
    1
    10
    100
    

    The trick here is that a variable is messing up with a thought-to-be different one.

    Now, as you may be aware of, you’re not able to this in prolog:

    #!/usr/bin/swipl
    my_first_I(I) :- I is 10.
    my_second_I(I) :- I is 100.
    
    test(I) :-
        I is 1,
        write(I), nl,
        my_first_I(_),
        write(I), nl,
        my_second_I(_),
        write(I), nl.
    

    Output:

    ?- test(I).
    1
    1
    1
    I = 1.
    

    This example does simply point out that, in prolog, the variable is defined in its own local scope, with no leakage into another function’s definition.

    Now, the second part: how does the ! work? The logic programming solutions generated by Prolog are derived after the application of an unification algorithm. During the process, a tree-like structure is built in a DFS fashion, performing evaluations on the statements according to the values variables may assume. After each leaf-level expansion, Prolog backtracks up to the next available expansion.

    If an ! is found, the breadth expansion is stopped, cutting off other possible values for the local solution, and only perfoming the deeper expansions in the tree. Here is a quite simple usage of the ! operator.

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

Sidebar

Related Questions

I'm creating a query that will be run twice a month: On the 5th
Can anyone help me write this query more efficiently? I have a table that
I am creating a small web based tool that allows users to query a
I have to run a query after every update and I want to know
I use ADO.net and run an update query by sqldataadapter. The update query updates
I want to run an alter database query on the Schema I am designing
private Cursor getContacts() { // Run query Uri uri = ContactsContract.Contacts.CONTENT_URI; String[] projection =
I run a query sometimes and it just hangs. I go look at processes
If I run this query in Toad: SELECT BANDID, BANDNAME FROM WOODSTOCK WHERE BANDNAME
If I run a query simialr to: SELECT * FROM user u LEFT JOIN

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.