Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

yfx Lists

30 views
Skip to first unread message

j4n bur53

unread,
May 17, 2015, 5:36:04 AM5/17/15
to
Dear All,

Any Prolog system around for a notation
of xfy Lists. First a little motivation
for such lists. In Logic, often the head
is put on the right hand side, instead of
the left hand side of a list.

Take for example the following logic
inference rule:


G, A |- B
----------- (->Right)
G |- A -> B

G,A and G are basically lists of premisses.
And in Prolog we would write [A|G] and G
for them.

What if I would like to have a notation that
reflects that the head is put on the right
side and not on the left side. Here is my
thinking the left side lists are just an
effect of an xfy operator.

Assume I would build lists with ','/2 instead
of '.'/2. I have the ','/2 operator already:

?- current_op(X,Y,',').
X = 1000,
Y = xfy.

And I would build a list [a,b,c] as follows:

?- write_canonical((a,b,c,[])).
','(a,','(b,','(c,[]))).

But I can also build lists with operators that
have the opposite associativity. Take the
'+'/2 operator:

?- current_op(X,Y,+).
X = 500,
Y = yfx.

I could build a list [a,b,c] as follows:

?- write_canonical([]+c+b+a).
+(+(+([],c),b),a)

Question: Does any Prolog system support a
list notation that is yfx. So that for
example I would write:

<c,b,a>

I would also write:

<G|a>

Or also:

<G|b,a>

Above "<" and ">" are some new parenthesis,
and the result would be an yfx list, as shown
with the '+'/2 operator?

Bye

j4n bur53

unread,
May 17, 2015, 5:41:26 AM5/17/15
to
j4n bur53 schrieb:
> example I would write:
>
> <c,b,a>

Maybe use this syntax, He He:

]c,b,a[

But I guess this is not a good
idea to overload [ and ] this way.

We couldn't write:

[ ]c,b,a[ ]

With the meaning of:

[ <c,b,a> ]

Since the first [ ] and second [ ]
would be interpreted as the empty
list.

Except if we would restrict the syntax
rule for empty lists a little bit, and
would not anymore accept [ ] as an
empty list. Only [].

Bye




Ulrich Neumerkel

unread,
May 17, 2015, 5:52:57 PM5/17/15
to
The very first Prolog program used left-associative lists to
represent lists of characters. These lists were called
peigne (comb).

Also boum/2 was provided somewhat similar to atom_chars/2
but also acting as a constraint.


To paraphrase into current syntax (p.32)

t(nil-c-h-a-c-a-l, nil-c-h-a-c-a-l-s).
...
t(X-a-l, X-a-u-x).

See more in

A.Colmauerauer, H.Kanoui, Ph.Roussel, R. Pasero.
Un systeme de communication homme-machine en Francais.
Rapport de recherche sur le contrat CRI no 72-18,
fevrier 72 a juin 73

http://www.prolog-heritage.org

Robert Virding

unread,
May 17, 2015, 6:09:05 PM5/17/15
to
On Sunday, May 17, 2015 at 11:36:04 AM UTC+2, j4n bur53 wrote:
> Dear All,
>
> Any Prolog system around for a notation
> of xfy Lists. First a little motivation
> for such lists. In Logic, often the head
> is put on the right hand side, instead of
> the left hand side of a list.

The really interesting question is why you want this?

Robert

j4n bur53

unread,
May 18, 2015, 5:13:40 AM5/18/15
to
Robert Virding schrieb:
>> Any Prolog system around for a notation
>> >of xfy Lists. First a little motivation
>> >for such lists. In Logic, often the head
>> >is put on the right hand side, instead of
>> >the left hand side of a list.

> The really interesting question is why you want this?

To make the notation more iconic to what is
used in math. Its not a hard business case,
its more a soft business case of human computer
interaction.

But I see drawbacks besides the advantage at the
same time:

1) Advantage: Lets say I would have tupple
syntax in Prolog which uses yfx Lists,
with empty list as '<>' and yfx cons as
''''. Then for example I would have

<<x1,..,xn>|xn+1> = <x1,..,xn,xn+1>

Could be more comfy for some applications
than the ordinary Prolog lists. The
initial example I gave was from Logic,
where sequents can be seen as having
yfx cons.

2) Disadvantage I: One more grammar Rule
in the Prolog syntax. Violates KISS
Principle. More code to write for the
parser. More documentation needed.

3) Disadvantage II: Some predicates that
do some generatic stuff on lists, wouldn't
be able to do that on tupples.

Unless tupples only exist on the surface, and
wouldn't use '<>'/0 and ''''/2, but instead
'[]'/0 and '.'/2. But then unparsing
wouldn't reconstruct the tupple.

Or otherwise Prolog would know object orientation,
so that one could write single rules that work
both for lists and tupples and who knows what.

Many object oriented languages can do that.
Besides generic rules that would work for
all list like structures, one could also
specify specific rules. For example to keep
some structures sorted and others not.

Currently the bulk of Prolog libraries is
not object oriented. Just xxxpredictaes, for
example a module lists and a module ordsets,
but they don't have anything in common.

Bye


j4n bur53

unread,
May 18, 2015, 5:16:27 AM5/18/15
to
Ravissant!

ulr...@mips.complang.tuwien.ac.at (Ulrich Neumerkel) schrieb:
0 new messages