Scryer-prolog: library(dcgs): missing ('|')//2

Created on 21 Feb 2020  路  5Comments  路  Source: mthom/scryer-prolog

All 5 comments

?- use_module(library(dcgs)).
true.
?- op(1105,xfy,'|').
true.
?- phrase(("a"|"b"),L).
caught: error(existence_error(procedure,('|')/4),('|')/4)
?- phrase(("a";"b"),L).
L = [a] ;
L = [b].

Ideally, ('|')//2 describes an alternative, but rejects if-then-else during term-to-body conversion.

I don't know how to retain the usual meaning of ('|') as a head-tail separator in lists while overloading it as an operator (or if I should).

(So this is now a syntax question only) There is no ambiguity between head-separator and the infix bar operator, since the infix bar must have a priority of 1001 or higher. See http://www.complang.tuwien.ac.at/ulrich/iso-prolog/dtc2#Res_A78 The elements within a list have always been restricted to See in 6.3.5 the use of non-terminal arg defined in 6.3.3.1 reading:

           arg =  atom ;
Abstract:  a      a
Condition: a is an operator

           arg =  term ;
Abstract:  a      a
Priority:         999

Ambiguity would only arise with smaller priority.

In any case for library(dcgs), within the actual module, the bar must be written in functional notation.

Now its all wrong, one level too much:

?- phrase(("a"|"b"),L).
L = [[a]] ;
L = [[b]].
?- phrase("a",L).
L = [[a]].
?- L = "a".
L = [a].
?- phrase(("a";"b"),L).
L = [[a]] ;
L = [[b]].
Was this page helpful?
0 / 5 - 0 ratings

Related issues

UWN picture UWN  路  4Comments

notoria picture notoria  路  4Comments

Qqwy picture Qqwy  路  3Comments

XVilka picture XVilka  路  3Comments

dcnorris picture dcnorris  路  3Comments