Hi, this is probably a stupid noobie question, but here goes...
In ordinary prolog, I can declare that something exists using a statement like
fred("jim").
And then I can use fred("jim") in a predicate to check that this object exists.
But if I create an object
Jim = fred::new("jim"),
how do I later check for the existence of Jim?
-
- VIP Member
- Posts: 452
- Joined: 5 Nov 2000 0:01
Re: How to check existence of an object
One way would be to create a class database in your base class and store the object identifier information you need in that database when you create each object, something like that below. You will need to manage removing personObj/2 facts when objects are destroyed and you also should remember that class facts persist as long as your application is active.
Code: Select all
implement person
open core
class facts
personObj : (string Name, person ObjID).
clauses
new(Name) :-
% ... do various things
assert(personObj(Name, This)),
nothing(This).
clauses % declare in person.cl to access object information
tryGetObject(Name) = PersonObject :-
personObj(Name, PersonObject),
!.
end implement person
Re: How to check existence of an object
Thanks.
But what does the nothing(This) line do?
But what does the nothing(This) line do?
-
- VIP Member
- Posts: 452
- Joined: 5 Nov 2000 0:01
Re: How to check existence of an object
nothing(...) does nothing. It's a way of making the IDE capture an unused variable so you can see it when running the debugger. Unused variables do not consistently display in the Variables window when debugging without making them appear as being used to the compiler.
It has no place in production code. I should have removed it before posting.
It has no place in production code. I should have removed it before posting.
- Thomas Linder Puls
- VIP Member
- Posts: 1424
- Joined: 28 Feb 2000 0:01
Re: How to check existence of an object
See also Debugging tips: nothing.
Regards Thomas Linder Puls
PDC
PDC
Re: How to check existence of an object
I learn something every day