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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:48:44+00:00 2026-05-13T00:48:44+00:00

I am new to Prolog and I have so far learned how to define

  • 0

I am new to Prolog and I have so far learned how to define a predicate in a file and the run the interpreter to use it. But I would like to know if there is a way to define the predicate at the ?- prompt so that I don’t have to switch back and forth.

the way I am doing it now is like this

file defs.pl:

adjacent(1,2).
adjacent(1,3).

in the prolog interpreter:

?- consult('defs.pl').
% defs.pl compiled 0.00 sec, 122 bytes
true.
?- adjacent(1,2).
true.

EDIT
maybe I meant how to define ‘facts’ I’m not sure.

  • 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-05-13T00:48:44+00:00Added an answer on May 13, 2026 at 12:48 am

    You can use the assert/1 predicate:

    ?- assert(adjacent(1,4)).
    true
    

    EDIT:
    By the way, this will not work if you try to combine it with predicates defined in a file.
    So either define all adjacent/2 predicates in your file, are define them all with assert in the command line.

    If you do want to define some of the predicates in the file, and others with assert, then declare in your file that the predicate is dynamic:

    % file contents
    :- dynamic(adjacent/2).
    adjacent(1,2).
    adjacent(1,3).
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all sorry for my English. I would like to use a backtracking
I'm trying to implement a findall predicate in Prolog (yes I know it's built
New to Objective-C and iOS development, would love a hand here! I have written
I am new in Prolog and I am stucked in a problem. I have
I have a prolog homework, which should work like this: singles([1,2,3,2,2,4,1], [3,4]). true Now
(Pardon if my terminology is wrong... I'm new to Prolog.) Suppose you have a
I'm new to SWI-Prolog and am trying some tutorials. Every file I try to
I would like to represent a mutable graph in Prolog in an efficient manner.
I'm new to Prolog. Using this basic 'database' structure, I thought I would be
I am new to Prolog and was tasked with a Fibonnaci predicate fib( N,

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.