Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Syntax for user-defined infix operators
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dmitry A. Kazakov  
View profile  
 More options Aug 29 2009, 4:20 am
Newsgroups: comp.lang.misc
From: "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
Date: Sat, 29 Aug 2009 10:20:33 +0200
Local: Sat, Aug 29 2009 4:20 am
Subject: Re: Syntax for user-defined infix operators

On Fri, 28 Aug 2009 14:01:34 -0700 (PDT), tm wrote:
> On 28 Aug., 18:48, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>>>> To me user-defined scalar types are paramount.

>>> Seed7 supports user defined enumeration types and subtypes of scalar
>>> (and other) types (see below for a link to an example).

>> But no integers, reals etc.

> This is wrong. Seed7 supports subtypes of integers and floats also.

I wrote about types. If user-defined integer *types* are supported, do they
have literals? If they do, then there shall be contexts where 1 may mean
more than one type.

>>>>> The expression '20 times 0' creates the array value of 20 integer
>>>>> elements with the value 0.

>>>> But already this is ambiguous in a language like Ada.

>>> But not in Seed7. In the expression '20 times 0' the 'times'
>>> operator uses the index type 'integer' and the lower bound 1.

>> Why Integer and not Byte, Priority_Level, Identity_No etc?

> I did not say that the index must be 'integer'. I wrote:

>   Seed7 also supports arrays where the
>   index type is not 'integer'.

> which includes Byte, Priority_Level, Identity_No etc.

In that case 20 times 0 is "ambiguous" because 20 may refer to
Priority_Levels Idle, Very_Low, Low etc, or Bytes from 0 to 19, or
whatever.

>>>> Ada is a strongly typed language you
>>>> cannot get anything wrong because of overloading. Any ambiguity is treated
>>>> as an error.

>>> As I showed above a sub-expression like 1+2 can be ambiguous.

>> Ambiguous in Ada = illegal. You cannot compile an illegal program. No harm
>> can happen.

> You obviously don't try to follow my arguments.

No, "ambiguity" is a language term. You are using it is a psychological
context of some imaginary layman, who would consider some language
constructs "ambiguous" or not. This is fruitless, because in order to make
statements about psychology or sociology, one should conduct scientific
experiments. Otherwise it is all a matter of taste.

As an OO programmer I am accustomed to generic programming, that is
programming in terms of sets of types (AKA classes). So an expression like
1+2 renders to me to a class of additive types probably of the structure of
a ring or a group, with an operation + and elements 1 and 2. This is quite
enough to grasp the idea (semantics) of the program. The concrete types
involved are of no interests so long my strongly typed language has checked
them OK.

----------------
Anyway. The language design point is rather simple. In presence of
user-defined scalar types (=types that have literals), you have
semantically overloaded literals. Period.

>>>>>> This is
>>>>>> automatically more friendly, because the body of name clashes is smaller in
>>>>>> Ada than seems to be in Seed7.

>>>>> I have probably more knowledge about Ada than you about Seed7 :-)
>>>>> and I have a different view. "Do what I mean" concepts which are
>>>>> not understood by the programmer are a possible source of undetected
>>>>> errors.

>>>> I don't see how it applies here. If there are conflicting interpretations
>>>> of a construct, the program is rejected in Ada.

>>> When the programmer does not know how the overload resolution works
>>> he might think that 'a' has type Latin-1 instead of UCS-2. Here I am
>>> referring to your example

>>>   ('a' => 'a', 'b' => 'b')

>>> where you said:

>>>   "where 'a' on the left is not 'a' on the right"

>> The programmer can think anything he wants. What is the problem? So long
>> there is no ambiguity, everything is OK.

> You think that a program that compiles without errors is OK?

Certainly yes, if its semantics responds the programmer's intention. The
converse is wrong.

If the programmer's intention was to index UCS-2 string using Latin-1
index, why should the language forbid this? Consider it as a task:

The task: create a map of Latin-1 characters to the Unicode UCS-2 code
positions. Then create a To_Lower map.

In Ada this task can be accomplished in a way I used above:

   type Latin_to_UCS is array (Character) of Wide_Character;
   To_Lower_Case : Latin_to_UCS :=
       (  'a' | 'A' => 'a',  'b' | 'B' => 'b',  -- and so on
       );

It is natural, obvious and elegant to denote Latin-1 'a' and Unicode 'a'
using the same literal. Why should it be otherwise?

>>>>> People are instinctively aware that the bottom up overloading
>>>>> resolution determines the type of every expression and subexpresion
>>>>> unambiguously.

>>>> This is an unsupported claim.

>>> Proof: When I asked you for the type of 1+2 you answered:
>>> "Technically in Ada it is Universal_Integer"
>>> You probably used a bottom up approach.

>> No, I did not. Ada declares all integer literals of the type
>> Universal_Integer which is automatically converted to the particular
>> integer or modular type. The effect is as if types had literals of their
>> own. That does not change the semantics. You can treat 1+2 as
>> Unsigned_64'(1) + Unsigned_64'(2).

> When the + is overloaded with

>   function "+"(LEFT, RIGHT: INTEGER) return REAL;

> the expression 1+2 may return a 'REAL' result as well as an
> 'INTEGER' one.

And Unsigned_8, and Integer_16, and Long_Integer, and potentially infinite
number of types. Why should I care without a context?

>> There is a subtle but important difference, which can illustrate the
>> advantages of Ada's model. The standard requires all static numeric
>> expressions to be evaluated exact. Consider the following:

>>    type T is range 1..2;  -- Has only 1 and 2 values
>>    X : T := 1024 / 512;  -- This is OK!

>> Though neither 1024 nor 512 belong to T, the compiler is required to accept
>> this program because 1024 / 512 is statically 2 which is in T. Observe that
>> an attempt to qualify the types involved in, in a bottom-up manner would
>> produce an illegal program,

> There is a cast involved when the integer 1024 / 512 is assigned
> to T. Seed7 would just require that this cast is explicit instead
> of implicit.

So casting to a known type is supposed to be readable? I prefer a language
where I am not forced to cast obvious expressions.

>> 1+2 perfectly fits the concept. You want to add things at the higher
>> abstraction level (on the TOP). If the compiler grasps your idea,
>> everything is OK and you both are happy. If it complains, you descend one
>> level below (DOWN) and consider what are these types involved etc. It is
>> just a matter of productivity, comfort and SAFETY. Consider awful integer
>> literals in C. of different length. You have to specify 1L and if later the
>> type gets changed you will have to revise the program. That is error prone.

> A strong typed language would at least tell you where you need
> to change something.

Yes, and this argument equally refutes what you wrote about "ambiguities".

> Attribute parameters are a feature that can be used for different
> purposes.

Overloading is such a feature. Programmers are not advised to extensively
use it, but in certain cases they have to.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.