Questions tagged [prolog-assert]

Prolog-assert globally affects stored information in Prolog, a general purpose logic programming language.

Source: http://alumni.cs.ucr.edu/~vladimir/cs171/prolog_2.pdf

Prolog assert(X) Adds a new fact or clause to the database. Term is asserted as the last fact or clause with the same key predicate.

47 questions
3
votes
2 answers

How to generate an assert that forces a false?

First of all thanks for your help. On to my problem: Let's say I have: some_fact:- true. and I want to asserta a rule on top of it that looks like this: some_fact:- fail, !. This is because I want to transform the "some_fact:- true." to force a…
Gaspa79
  • 5,488
  • 4
  • 40
  • 63
2
votes
1 answer

Prolog Dynamic Predicates Basic Usage

with this knowledge base using https://swish.swi-prolog.org :- dynamic happy/1. go:- assert(happy(mia)), write(happy(mia)). if I run go. I get happy(mia) true If I just have :- dynamic happy/1. assert(happy(mia)). and run happy(mia), I…
Robin Andrews
  • 3,514
  • 11
  • 43
  • 111
2
votes
1 answer

Prolog and "reverse" output in expert system

i am new to Prolog. I mabaged to understand how to do simple expert system, like go :- hypothesize(Vehicle), write('I guess that the Vehicle is: '), write(Vehicle), nl, undo. hypothesize(car) :- car, !. hypothesize(van) :-…
Senso Hakai
  • 141
  • 1
  • 2
  • 13
2
votes
1 answer

Reading in input using Prolog

Sorry if this is obvious, but I've been learning prolog recently and am attempting to read in a data to use in a recommender system. gifter :- write('how much money? '), read(money), nl, assert(will_spend(money)), write('Is the…
jalban
  • 23
  • 2
2
votes
1 answer

Modules with dynamic predicates

This is a follow up question to : Adapting csv reading for multiple tables If I have the following module defined: :- module(csv_load_mod,[prepare_db/3]). :- use_module(library(csv)). :- set_prolog_stack(global, limit(4*10**9)). prepare_db(File,…
2
votes
1 answer

Save asserted facts in Prolog

In prolog, if I assert some fact, for example: assert(boy(john4)). assert(boy(john3)). assert(boy(john2)). assert(boy(john1)). How can I save this fact in file?
user2254798
  • 553
  • 2
  • 6
  • 17
1
vote
2 answers

Calling facts from database in prolog

I've inserted the given context free grammar into the database using assert(....) If the grammar is something like S-->a,S,b S-->c This grammar is inserted into the database. I have to write a dcg to generate sentences for the cfg in the…
Anil
  • 2,405
  • 6
  • 25
  • 28
1
vote
1 answer

How to assert new rule from user input (PROLOG)

I want to accept users' input, i.e. [garfield, hates, blacky]. hates/2 doesn't exist currently. In my database, process:- read(Input_List), add_rule(Input_List). add_rule([X, Predicate, Y]):- assertz(Predicate(X, Y)). But this doesn't…
Js Lim
  • 3,625
  • 6
  • 42
  • 80
1
vote
1 answer

In Prolog why does this query return this particular result

?- assert(p(a)),assert(p(b)),p(X). X = a yes Whats the effect of this query and why does it return this particular result?
General_9
  • 2,249
  • 4
  • 28
  • 46
1
vote
0 answers

Unclear phrase in the definition of retract/1

There is something about retract/1 that doesn't make sense to me. According to ISO/IEC 13211-1:1995: 8.9.3 retract/1 8.9.3.1 Description retract(Clause) is true iff the database contains at least one dynamic procedure with a clause Clause …
repeat
  • 18,496
  • 4
  • 54
  • 166
1
vote
0 answers

Prolog rule assertion with variable name

I try to assert some rules automatically in SWI-Prolog: generate_rule_len(FG,SG):- length(FG,L),length(SG,L0), Head = input_len(FG,SG,FS,SS,X), Body = (length(FG,L1),L1 is L, length(SG,L2), L2 is L0, X = SS), % Rule = (Head :-…
74ck
  • 65
  • 2
  • 9
1
vote
1 answer

Prolog: a rule containing assert adds only first result to facts

I'm trying to precompute some stuff and save the results as facts at the beginning of my program: (simplified code) :- dynamic cost/2. %recipe(Id,Cost) recipe(1,20). recipe(2,40). assert_all :- recipe(Id,Cost), assert(cost(Id,Cost)). But only the…
Juraj
  • 99
  • 7
1
vote
1 answer

Best way to update/add fact in the db?

Say I have facts like this : fact(abc,2). I want something like this (pseudo code) : fact_update(Functor,Name,AddToValue) :- if Fact_exist then update_fact : NewVal is CurrentValue + AddToValue else create_new_fact :…
sten
  • 7,028
  • 9
  • 41
  • 63
1
vote
2 answers

In PROLOG, How can I use assert recursively without getting 'true' result?

I'm planning to make new facts based on existing facts, by using assert. However, the number of facts to be made will be more than 500, so that typing semicolon to go further steps become pretty tedious work. thus I want to ignore or pass the…
Cho Sinhee
  • 59
  • 1
  • 10
1
vote
1 answer

Prolog - Assert into a new database

:-dynamic listofQuestions/2. myrule:- write('P = '), write(Percent), write('-'),write(X), ( listofQuestions(Percent,X) -> true ; assert(listofQuestions(Percent,X)) ), The code snippet might not be required to answer my question. I want to…
HungryCoder
  • 1,029
  • 2
  • 10
  • 16