Skip to content

Reflection of defined predicates on un-instantiated classes? #182

Answered by pmoura
EllenOrange asked this question in Q&A
Discussion options

You must be logged in to vote

You also need to declare the foo/1 predicate dynamic:

:- object(superclass,
	instantiates(metaclass)).

	:- public(foo/1).
	:- dynamic(foo/1).
	foo(1).

:- end_object.

After that change and after adding the following directive to the beginning of the file containing your code:

:- set_logtalk_flag(dynamic_declarations, allow).

We get:

$ swilgt -q
?- {eo}.
*     Suspicious call: A::assertz(B) instead of ::assertz(B)
*       while compiling object metaclass
*       in file /Users/pmoura/Desktop/lgtemp/eo.lgt between lines 7-9
*     
true.

?- superclass::class_assert(foo(2)).
!     Permission error: create predicate_declaration foo/1
!       in goal: assertz(foo(2))
!       with execution co…

Replies: 4 comments 14 replies

Comment options

You must be logged in to vote
3 replies
@pmoura
Comment options

@pmoura
Comment options

@EllenOrange
Comment options

Comment options

You must be logged in to vote
10 replies
@pmoura
Comment options

@EllenOrange
Comment options

@pmoura
Comment options

@pmoura
Comment options

Answer selected by EllenOrange
@EllenOrange
Comment options

Comment options

You must be logged in to vote
1 reply
@EllenOrange
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants