Discussions related to Visual Prolog
Posts: 9
Joined: 9 May 2021 9:55

An Object 'pointer' - how to store references to objects

Unread post by sbishop61 »

I am sorry to ask such a basic question, but I have tied myself in knots over this.

I would like to have an object that has a reference (pointer) to another object, not an embedded copy of the object. In fact a list of pointers to objects something like tuple(classname, objectref)*

I probably haven't found the right part of the documentation - once gain apologies.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1253
Joined: 28 Feb 2000 0:01

Re: An Object 'pointer' - how to store references to objects

Unread post by Thomas Linder Puls »

Here are three ways to store a "set/list" of person objects in an object:

Code: Select all

implement myObject   facts     person_fact : (person Person) nondeterm.     % use assert(person_fact(P)) to insert one more person.   facts     personList : person* := [].     % set a new list using personList := PL   facts     personSet : setM{person} := setM_redBlack::new().     % insert a person using personSet:insert(P).
If you actually need to store the person's under a key you can use a map:

Code: Select all

facts     personMap : mapM{string Name, person Person} := mapM_redBlack::new().     % insert a person using personMap:set(N, P)
Regards Thomas Linder Puls
Post Reply