5.3.3 Block operators
Introducing curly bracket and array subscripting.177Introducing
block operators was proposed by Jose Morales. It was discussed in the
Prolog standardization mailing list, but there were too many conflicts
with existing extensions (ECLiPSe and B-Prolog) and doubt about their
need to reach an agreement. Increasing need to get to some solution
resulted in what is documented in this section. These extensions are
also implemented in recent versions of YAP. The symbols []
and
{}
may be declared as an operator, which has the following
effect:
- [ ]
- This operator is typically declared as a low-priority
yf
postfix operator, which allows forarray[index]
notation. This syntax produces a term[]([index],array)
. - { }
- This operator is typically declared as a low-priority
xf
postfix operator, which allows forhead(arg) { body }
notation. This syntax produces a term{}({body},head(arg))
.
Below is an example that illustrates the representation of a typical‘curly bracket language’in Prolog.
?- op(100, xf, {}). ?- op(100, yf, []). ?- op(1100, yf, ;). ?- displayq(func(arg) { a[10] = 5; update(); }). {}({;(=([]([10],a),5),;(update()))},func(arg))