tags:

views:

46

answers:

1

This is some of the code I am writing

assert(bar(foo)),
assert(foo(bar-5)),

I'm not sure if it works though. I'm trying to get it to reduce foo by 5. I need a way to write the value of foo, but haven't found a way too. write('foo is' + foo) would be the logical way to me, but doesn't seem to work.

+1  A: 

To be able to use a fact's value you have to unify it first. Unification is done passing unbound variable as an argument to a predicate, — bar(Moo) in our case:

facts
    bar(integer)
    foo(integer)

goal
    assert(bar(42)),
    bar(Moo),
    Baz = Moo - 5,
    assert(foo(Baz)),
    write(Baz).
Yasir Arsanukaev
I thought that `retract/1` is for removing facts from database/table. `bar(Moo)` should try to unify, but leaving dynamic facts untouched, I guess.
ony
@ony: Sure, I just implied that fact `foo` should be retracted before we can put it (un)changed to the facts base, otherwise we'd end up with 2 facts, update.
Yasir Arsanukaev
Which Prolog is this?
Kaarel
@Kaarel: This is Visual Prolog 5.2, didn't have any other at the moment of writing.
Yasir Arsanukaev