Re: Asserting a fact when triggering a rule

Baltasar García Perez-Schofield <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Organization Personal
Message-ID <[email protected]>
	Hi, there,

	Thank you all for your answers. I was trying not to give you the gory details, but it seems you'll have to suffer it.

	My objective is to infer types from an AST. The rule of concern is of the form:

	% VBLE = EXPR2
	isType( EXPR1, TYPE ) :-
			node( EXPR1, asg, VBLE, EXPR2 ),
                        isType( EXPR2, TYPE ).

	The nodes of the AST are represented by the predicate node. The result of the inference is the predicate isType (chanining the inferred isType predicates will give you the type of the topmost node).

	The problem is that this rule gives you the type of the node, as expected, but not the type of the variable (VBLE). In order for that to be inferred, I could duplicate the rule, such as in:

	% VBLE = EXPR2
	isType( VBLE, TYPE ) :-
			node( EXPR1, asg, VBLE, EXPR2 ),
                        isType( EXPR2, TYPE ).

	isType( EXPR1, TYPE ) :-
			node( EXPR1, asg, VBLE, EXPR2 ),
                        isType( EXPR2, TYPE ).

	
	The problem is that this rule won't be fired if you don't ask for the type of the variable explicitely. This is maybe not a problem, as I probably can do that, but for example in Pyke I can execute python code if I put this code at the end of the rule:

	use
		isType( $EXPR1, $TYPE )
	when
		node( $EXPR1, asg, $VBLE, $EXPR2 )
                isType( $EXPR2, $TYPE )
		python enfine.assert_( $VBLE, $TYPE )

	The question is whether there is something like that existing in Prolog.

-- 
Baltasar ([email protected]  http://baltasarq.info/)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.