[comp.lang.prolog] Bootstrapping precedence grammars.

markh@csd4.milw.wisc.edu (Mark William Hopkins) (08/01/89)

Simple question:

   Can Prolog's read(X) predicate be defined using only the character
predicates for I/O?  In other words, does Prolog have the capacity to
bootstrap its own precedence grammar, using the operator declarations
made by the op predicate?

   I believe the answer is no, because (and ONLY because)

                         op(Prec, Type, Rator)

cannot be used in the mode

			 op(OUTPUT, OUTPUT, INPUT),

to find the precedence and fixity of an operator, but only in the mode

		         op(INPUT, INPUT, INPUT).

to set it.

dave@quintus.UUCP (David Bowen) (08/02/89)

>	op(Prec, Type, Rator)
> 
> cannot be used in the mode
> 
>       op(OUTPUT, OUTPUT, INPUT),
> 
> to find the precedence and fixity of an operator, but only in the mode
> 
>       op(INPUT, INPUT, INPUT).


The predicate that you need is current_op/3.  This can be called
with any or all of its arguments unbound.

There is a reasonably well-accepted rule that predicates
which cause side-effects, like op/3, should be kept separate
from predicates which merely inspect the state of the system,
like current_op/3.  A benefit of this rule is that if you
accidentally call a predicate like op/3 with an unbound variable
as an argument, you should get an error, rather than having
the goal either fail quietly or fill in some value and continue.

jiyang@ecrcvax.UUCP (Jiyang Xu) (08/04/89)

In article <3635@csd4.milw.wisc.edu>, markh@csd4.milw.wisc.edu (Mark William Hopkins) writes:
>    Can Prolog's read(X) predicate be defined using only the character
> predicates for I/O?  In other words, does Prolog have the capacity to
> bootstrap its own precedence grammar, using the operator declarations
> made by the op predicate?

Certainly you can, as defined in the famous O'Keefe's reader, which
is also used in SB-Prolog and possibly many other Prologs.
                                                                      
>                          op(Prec, Type, Rator)
>
> cannot be used in the mode
> 
> 			 op(OUTPUT, OUTPUT, INPUT),
                                                                   
There is another predicate "current_op/3" for this purpose.
The predicate is implemented in most Prolog systems.