ulr...@mips.complang.tuwien.ac.at (Ulrich Neumerkel) schrieb:
> But if it is not declared an operator the Prolog text
> in question would be invalid.
That is your problem Ulrich. You are always thinking
in terms of syntax and not in terms of semantic.
If SWI-7 accepts a Prolog text, it doesn't mean
it does the right thing.
If SWI-7 accepts [H|T], but represents it internally
as '[|]'(H,T) then this doesn't conform to
6.3.5 Compound terms - list notation
List notation can be used for inputting or outputting a
compound term with principal functor '.'/2 (dot).
> But if it is not declared an operator the Prolog text
> in question would be invalid. So there is a chance
> to sneak in such behaviour as an extension.
You see above. Wrong thinking. You think if
something doesn't exist ob the syntax level
it doesn't exist on the semantic level.
> (Of course this is quite independent of the choice in SWI to
> use a new, incompatible, name for the list constructor.)
Well that is the main issue of this thread, and
not only the syntax. The main issue is syntax AND
semantic of the SWI-7 release.
Yes I read it. And I gave already the response:
Jan Burse wrote 27.02.2015 02:45:
> Wouldn't another syntax also do, for example a :> f to access
> a field? The :> would be defined via function expansion.
And I also gave reasons:
Jan Burse wrote 28.02.2015 12:52:
> I think dot-syntax would require rewriting Prolog parser/unparser
> and operator handling. And this is probably not viable, a lot of
> overhead for a small thing.
>
> The cheapest is just using another operator :> which doesn't
> have some special meaning already.
BTW: I don't have to read #adding_conforming_dot . I came
up with this idea myself in a old thread on comp.lang.prolog.
But I am regretting the idea now.
It is an expensive semantic idea, not worth considering,
since the problems of the dot itself on the syntax
surface are more severe.
As long as Prolog is a language where a dot with a layout
character, a new line or a percent acts as a line terminator
the dot should not be used inside a line.
In other Languages there is no such problem. For example
in Java one can write the dot how ever one wants to, the
following is all valid Java texts:
foo.bar; /* form 1 */
foo.
bar; /* form 2 */
foo
.bar; /* form 3 */
Interestingly form 2 is seldom seen. On the other hand
form 3 is often seen. And it would also Work in Prolog.
But nevertheless I wouldn't recommend using a dot
on the surface.
I must admit, the dot is very nice and readable, and
probably better than the :> . But if one wants the
dot I guess one has to invent a new language. This
is what Picat did. And we have also semantic rewriting
for the dot, but more elaborate:
Chapter 3
http://picat-lang.org/download/picat_guide.pdf
The dot operator (.) is used in OOP notations for
accessing attributes and for calling predicates
and functions. It is also used to qualify calls
with a module name. The notation A1.f(A2,...,Ak)
is the same as f(A1,A2,...,Ak), unless A1 is
an atom, in which case A1 must be a module qualifier
for f. If an atom needs to be passed as the first
argument to a function or a predicate, then this
notation cannot be used. The notation A:Attr,
where Attr does not have the form f(...),
is the same as the function call get(A; Attr).
For example, the expression S.name returns the
name, and the expression S.arity returns the
arity of S if S is a structure. Note that
the dot operator is left-associative. For
example, the expression X.f().g() is the same
as g(f(X)).
But I don't understand whether Picat has abandoned
the idea of having user defined operators. At least
I find in the doc no more op/3 directive. It could
be that Picat uses a custom parser. Since it also
details an extensive syntax in Appendix G.
My own proposal #adding_conforming_dot would be
suited for such things as Picat, since with this
proposal one wouldn't need a special syntax in
Appendix G and disallow op/3. One could just
rewrite $dot/2 in a function expansion. Namely
the Chapter 3 cases of Picat can possibly all dealt
with in a function expansion. No need for an
extensive syntax and a specialized parser.
But I guess Picat has a specialized parser,
since with Prolog operators we cannot model
"begin ... end" like syntaxes. See another post
of mine on comp.lang.prolog. We can also not
do mixfix with the ordinary Prolog operators,
or fxx which is for example found in Eclipse(*).
That it must have a specialized parser is seen
in the following syntax production:
enclosed_goal ->
"if" goal "then" goal
{"elseif" goal "then" goal} "else" goal "end"
"foreach" "(" iterator {","
(iterator | condition)} ")" goal "end"
"while" "(" goal ")" ["loop"] goal "end"
"loop" goal "while" "(" goal ")"
"try" goal catch_clause {catch_clause} ["finally" goal] "end"
expression {bin_rel_op expression}
But when there is a specialized parser,
possibly interleave with semantic processing,
there is again no need for $dot/2, there is
possibly anyway an AST that is a little remote
from the surface syntax.
So I think Picat does the right thing. It
offers the end-user:
- A dot operator, with a varied semantic
added value
- "begin ... end" like syntax in various
places
- Unfortunately Picat may also be subject
to the Problem of form 2: (**)
foo.
bar; /* form 2 */
But I don't see that the SWI-7 approach makes
any sense at all, except that it breaks the
ISO standard and tries to dictate a new Prolog
to the world, invalidating a rich stock of
Prolog history. Experiment failed!
Sorry, if there is too much bias against SWI-7
at the moment. Nobody could convince me yet
that it is a good thing to imitate as is.
Bye
(*)
I am currently going with an operator based
alternative to fxx. I am using a Curry lambda
expression with a prefix operator. So for example
the following is Prolog:
∀ x\(x ∈ a <=> x ∈ b)
Or with Church lambda expressions:
∀ y:u\(y ∈ {z} <=> z(y))
Very nice.
(**)
In other languages such as Java, the dot is usually
extremly ubiquitous. Such a thing always needs more
semantic processing, up to type systems etc..
In Jekejeke Prolog I am currently following the
approach of different syntactic operators for
different things. Mainly because of backward
compability and operator level reasons.
So the structured module name separator is
(/)/2 and not (.)/2. And the predicate qualification
separator is (:)/2 and not (.)/2. So what
reads in Jekejeke:
foo:bar/2
baz/foo:bar/2
foo:bar(x,y)
baz/foo:bar(x,y)
Reads in Java:
N/A (No predicate indicators in Java)
N/A (No predicate indicators in Java)
foo.bar(x,y)
baz.foo.bar(x,y)
Reads in Picat:
foo.bar/2
N/A (The picat baz.foo would be a getter,
and not a module path)
foo.bar(x,y)
N/A (The picat baz.foo would be a getter,
and not a module path)