Nikita Vasin
Nikita Vasin

Reputation: 125

Get extract value from fact

Im pretty new to prolog, and got stuck. I need to store a variable with some string during calculations, I decided to do this by adding a "single fact" to the class I'm working with. Everything works well, the string is being stored, but when I try to add the code to access it later on, compiler returns an error "The expression has type 'dataBL::dataBL@objectDB', which is incompatible with the type '::symbol'".
I dont think it is the valid way to store a variable, so, can anyone help me with that? I tried searching online for the answers, and found nothing.

I'm trying to access the fact like this:

    getString(U) :-
    U = stringStorage(_).

Upvotes: 3

Views: 1636

Answers (1)

Anton Danilov
Anton Danilov

Reputation: 1276

If I get you right you need to store a value associated with some variable ID (key) as a fact. The (abstract) solution for your task canas the storing your values as a facts:

bind( Key, Value ).

Example of implementation (SWI Prolog)

Storing

recordz('var1', "String value1"),

recordz('var2', "String value2")

Querying value of var2

current_key(-Key), 

Key = 'var2'

recorded(Key, Value)

Upvotes: 1

Related Questions