a proposal about "with" syntax

classic Classic list List threaded Threaded
64 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Paul Ishenin
17.03.13, 18:25, Sven Barth пишет:
>> With a=VeryLongNameForARecord, b=AnotherRecordWithAVeryLongName do ...
>
> Now THAT is really unpascalish... either ":=" or the already suggested
> "as"...

Why? Constants and Types are also use '=' instead of ':=' for assignments.

Best regards,
Paul Ishenin
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Mattias Gaertner
In reply to this post by Sven Barth-2
On Sun, 17 Mar 2013 11:25:05 +0100
Sven Barth <[hidden email]> wrote:

>[...]
> Now THAT is really unpascalish... either ":=" or the already suggested
> "as"...

The AS syntax bites already existing syntax.

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Xiangrong Fang
> The AS syntax bites already existing syntax.

May I know what's the existing syntax?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Mattias Gaertner
On Sun, 17 Mar 2013 19:05:05 +0800
Xiangrong Fang <[hidden email]> wrote:

> > The AS syntax bites already existing syntax.
>
> May I know what's the existing syntax?

with A as T do

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Sven Barth-2
In reply to this post by Mattias Gaertner
On 17.03.2013 11:53, Mattias Gaertner wrote:
> On Sun, 17 Mar 2013 11:25:05 +0100
> Sven Barth <[hidden email]> wrote:
>
>> [...]
>> Now THAT is really unpascalish... either ":=" or the already suggested
>> "as"...
>
> The AS syntax bites already existing syntax.

Right. Then better ":=".

Regards,
Sven

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Sven Barth-2
In reply to this post by Paul Ishenin
On 17.03.2013 11:42, Paul Ishenin wrote:
> 17.03.13, 18:25, Sven Barth пишет:
>>> With a=VeryLongNameForARecord, b=AnotherRecordWithAVeryLongName do ...
>>
>> Now THAT is really unpascalish... either ":=" or the already suggested
>> "as"...
>
> Why? Constants and Types are also use '=' instead of ':=' for assignments.

But we aren't in a constant or type section here. Also one uses ":=" in
the for-loop header.

Regards,
Sven

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Marco van de Voort
In reply to this post by Sven Barth-2
In our previous episode, Sven Barth said:
> > I think having functions/procedures with no arguments callable with procedurename() is un-pascal-like as well, but it hardly bothers me that FPK allows it.  Just because I don't love it doesn't mean others don't.  (There is a lot of C like syntax that has creeped into FPK, but I assume that'S either because it was easy to implement and a few people wanted it, or because it made porting C stuff to Pascal easier).
>
> The reason that FPC allows to call parameterless functions and
> procedures with "()" is because Delphi (and maybe TP) allows it as well.
> For procedure/function variables (in non-Delphi modes) it is required
> however, because this way the compiler can know for sure that a procvar
> is called instead of just being used as a normal variable.

>From what I remember TP doesn't, and it was to introduced first to FPC to
disambiguate using the returnvalue of a function as function result, or
calling that function recursively. IIRC TP couldn't use function result as
rvalue.

Later it turned out that Delphi also allowed it.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Marco van de Voort
In reply to this post by Sven Barth-2
In our previous episode, Sven Barth said:
> >
> > Texas Instruments' Pascal had an extension of the with statement, IIRC
> > it used = instead of AS
> >
> > With a=VeryLongNameForARecord, b=AnotherRecordWithAVeryLongName do ...
>
> Now THAT is really unpascalish... either ":=" or the already suggested
> "as"...

Since it is a pseudo variable declaration, I would assume VAR syntax and
just use ":" ?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Martin Frb
On 17/03/2013 12:54, Marco van de Voort wrote:
> In our previous episode, Sven Barth said:
>>> Now THAT is really unpascalish... either ":=" or the already suggested
>>> "as"...
> Since it is a pseudo variable declaration, I would assume VAR syntax and
> just use ":" ?
>

Or maybe it should require a "variable" declaration (or otherwise
declared identifier with fixed type).

Otherwise it goes into an undesirable direction:

Function Foo;
begin
   with a: SomeInteger do Work(a);
   with a: SomeBoolean do Work(a);
end;

a is first integer, then boolean within the same scope. *Very* confusing.

And very close to the next step (which of course can be rejected by the
compiler)

Function Foo;
begin
   with a: SomeInteger do begin
      Work(a);
      with a: SomeBoolean do Work(a); // masking a
   end;
end;

But if the inner a was Integer too, then maybe it should work? Unless it
gets a similar special status like a loop variable?

-------------------
IIRC in other threads on this topic, some people explicitly stated they
wanted this feature so the would not need to declare "a" first (I may
remember this wrong).
IMHO starting with the first loop hole of allowing an undeclared
identifier to be used, is just opening the door to more and more
weakening of the language requirement.
Besides, it does not hurt, if "a" needs to be declared.



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Luca Olivetti-2
In reply to this post by Sven Barth-2
Al 17/03/13 13:16, En/na Sven Barth ha escrit:

> On 17.03.2013 11:42, Paul Ishenin wrote:
>> 17.03.13, 18:25, Sven Barth пишет:
>>>> With a=VeryLongNameForARecord, b=AnotherRecordWithAVeryLongName do ...
>>>
>>> Now THAT is really unpascalish... either ":=" or the already suggested
>>> "as"...
>>
>> Why? Constants and Types are also use '=' instead of ':=' for
>> assignments.
>
> But we aren't in a constant or type section here. Also one uses ":=" in
> the for-loop header.

But, differently than a for-loop, it's not an assignment, it's just an
alias definition.
Note that I can live without the option (after all I've not been using
the TI compiler for more than 20 years), but I liked the syntax at the
time and I still think it could be useful.

Bye
--
Luca

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Luca Olivetti-2
In reply to this post by Marco van de Voort
Al 17/03/13 13:54, En/na Marco van de Voort ha escrit:

> In our previous episode, Sven Barth said:
>>>
>>> Texas Instruments' Pascal had an extension of the with statement, IIRC
>>> it used = instead of AS
>>>
>>> With a=VeryLongNameForARecord, b=AnotherRecordWithAVeryLongName do ...
>>
>> Now THAT is really unpascalish... either ":=" or the already suggested
>> "as"...
>
> Since it is a pseudo variable declaration, I would assume VAR syntax and
> just use ":" ?

That would be consistent with "On E:Exception do writeln(E.message)".

Bye
--
Luca

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Paul Ishenin
In reply to this post by Sven Barth-2
17.03.13, 20:16, Sven Barth пишет:

> But we aren't in a constant or type section here. Also one uses ":=" in
> the for-loop header.

I agree that ':=' should be used but I would not say that '=' is not
pascalish :)

Let's look look at possibilities:

1. 'as' can't be used because we can use expressions in with and we can
'as' typecasting.
2. '=' can't be used because we can use expressions and '=' can be a
part of expression. For example 'with DoSomething(a = b) do'.
3. ':=' can be used since we can't use assignments in with expressions.
4. ':' (Marco suggesion) can be used - it is not used in expressions.
':' is used in pascal to:
   - separate variable and type,
   - in write intristic
   - in record constants to separate field and value
5. We can use some new keyword or reuse some keyword which is not used
in expressions.

If I need to choose from 3, 4 and 5 I would use ':=' syntax because it
more like to assignment:

with a := TStringList.Create do
begin
   Text := 'bla';
   DoSomething(a);
   Free;
end;

Best regards,
Paul Ishenin
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

etrusco
In reply to this post by Martin Frb
> On 17/03/2013 12:54, Marco van de Voort wrote:
>>
>> Since it is a pseudo variable declaration, I would assume VAR syntax and
>> just use ":" ?

This is indeed better.


On Sun, Mar 17, 2013 at 10:51 AM, Martin <[hidden email]> wrote:

> Or maybe it should require a "variable" declaration (or otherwise declared
> identifier with fixed type).
>
> Otherwise it goes into an undesirable direction:
>
> Function Foo;
> begin
>   with a: SomeInteger do Work(a);
>   with a: SomeBoolean do Work(a);
> end;
>
> a is first integer, then boolean within the same scope. *Very* confusing.

This is what already happens between the members of "aliased"
variables, and that's IMO reason for the proposal.
So I don't see a problem, on the contrary, it's progress since it
needs a more direct/clearer user "error" to be bitten by it.


> And very close to the next step (which of course can be rejected by the
> compiler)

It would be better.


> Function Foo;
> begin
>   with a: SomeInteger do begin
>      Work(a);
>      with a: SomeBoolean do Work(a); // masking a
>   end;
> end;
>
> But if the inner a was Integer too, then maybe it should work? Unless it
> gets a similar special status like a loop variable?

I don't think so.

> -------------------
> IIRC in other threads on this topic, some people explicitly stated they
> wanted this feature so the would not need to declare "a" first (I may
> remember this wrong).
> IMHO starting with the first loop hole of allowing an undeclared identifier
> to be used, is just opening the door to more and more weakening of the
> language requirement.
> Besides, it does not hurt, if "a" needs to be declared.

My POV is "with" already implies an undeclared variable.

Regards,
Flávio
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Jonas Maebe-2
In reply to this post by Luca Olivetti-2

On 17 Mar 2013, at 15:02, Luca Olivetti wrote:

Al 17/03/13 13:54, En/na Marco van de Voort ha escrit:
In our previous episode, Sven Barth said:

Texas Instruments' Pascal had an extension of the with statement, IIRC
it used = instead of AS

With a=VeryLongNameForARecord, b=AnotherRecordWithAVeryLongName do ...

Now THAT is really unpascalish... either ":=" or the already suggested 
"as"...

Since it is a pseudo variable declaration, I would assume VAR syntax and
just use ":" ?

That would be consistent with "On E:Exception do writeln(E.message)".

No, because "On E: Exception" says that "E" is of the type "Exception", just like in a variable declaration the expression after the colon also identifies the type. Here it's not about defining the type, but about making a symbol equivalent to repeating a non-type expression. So "=" from symbolic constant declarations would probably be closest. I think ":=" is less good, because ":=" implies that a copy or an assignment is made rather than an equivalence is defined, and hence changes to that copy could be assumed lost afterwards in case of records or objects, which would not be the case.


Jonas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

etrusco
In reply to this post by Sven Barth-2
On Sun, Mar 17, 2013 at 6:59 AM, Sven Barth <[hidden email]> wrote:
> On 17.03.2013 06:00, Flávio Etrusco wrote:
>>
>>    type generic TAlias1<T: TObject> = class(TObject)
>>      function Alias1: T;
>>    end;
>
> This already works.

In 2.7 I assume, because it doesn't work in 2.6.2. Great anyway :)

>>   function<T: TObject> Alias1(Source: T): TAlias1<T>;
>
> I don't really get what you want to express with that...

This is a Java a construction, I don't know whether it exists in other
languages.
In Java you specify it before the result type. It means the
parameterized result is be based on the parameter it receives. You can
also "bind" several parameters:

static <T extends Comparable> int IndexOf(List<T> p_list, T p_item);

-Flávio
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Mark Morgan Lloyd-5
In reply to this post by Marco van de Voort
Marco van de Voort wrote:

> In our previous episode, Sven Barth said:
>>> Texas Instruments' Pascal had an extension of the with statement, IIRC
>>> it used = instead of AS
>>>
>>> With a=VeryLongNameForARecord, b=AnotherRecordWithAVeryLongName do ...
>> Now THAT is really unpascalish... either ":=" or the already suggested
>> "as"...
>
> Since it is a pseudo variable declaration, I would assume VAR syntax and
> just use ":" ?

Are there any reputable cases where both type and value need to be
specified separately?

with foo: TSomeType= TSomeType(list.objects[i]) do

-- MarkMLl




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Sven Barth-2
In reply to this post by etrusco
On 17.03.2013 15:33, Flávio Etrusco wrote:

> On Sun, Mar 17, 2013 at 6:59 AM, Sven Barth <[hidden email]> wrote:
>> On 17.03.2013 06:00, Flávio Etrusco wrote:
>>>
>>>     type generic TAlias1<T: TObject> = class(TObject)
>>>       function Alias1: T;
>>>     end;
>>
>> This already works.
>
> In 2.7 I assume, because it doesn't work in 2.6.2. Great anyway :)

Of course only 2.7.1 :P

>>>    function<T: TObject> Alias1(Source: T): TAlias1<T>;
>>
>> I don't really get what you want to express with that...
>
> This is a Java a construction, I don't know whether it exists in other
> languages.
> In Java you specify it before the result type. It means the
> parameterized result is be based on the parameter it receives. You can
> also "bind" several parameters:
>
> static <T extends Comparable> int IndexOf(List<T> p_list, T p_item);

So you're basically just talking about generic methods here? The Delphi
compatible syntax for your two examples are:

=== code begin ===

function Alias1<T: TObject>(Source: T): TAlias1<T>;

function IndexOf<T: Comparable>(p_list: List<T>; p_item: T): LongInt;

=== code end ===

Support for generic methods (and global functions/procedures) is already
planned. They will of course support generic constraints as well (it
would be inconsistent if they wouldn't).

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Sven Barth-2
In reply to this post by Paul Ishenin
On 17.03.2013 15:07, Paul Ishenin wrote:
> If I need to choose from 3, 4 and 5 I would use ':=' syntax because it
> more like to assignment:
>
> with a := TStringList.Create do
> begin
>    Text := 'bla';
>    DoSomething(a);
>    Free;
> end;

Yes, I would prefer the ":=" as well because it's basically an
assignment. OR (now it's getting crazy, especially with the example you
gave ;) ):

=== code begin ===

with a absolute TStringList.Create do begin
   ...
end;

=== code end ===

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Sven Barth-2
In reply to this post by Jonas Maebe-2
On 17.03.2013 15:29, Jonas Maebe wrote:

>
> On 17 Mar 2013, at 15:02, Luca Olivetti wrote:
>
>> Al 17/03/13 13:54, En/na Marco van de Voort ha escrit:
>>> In our previous episode, Sven Barth said:
>>>>>
>>>>> Texas Instruments' Pascal had an extension of the with statement, IIRC
>>>>> it used = instead of AS
>>>>>
>>>>> With a=VeryLongNameForARecord, b=AnotherRecordWithAVeryLongName do ...
>>>>
>>>> Now THAT is really unpascalish... either ":=" or the already suggested
>>>> "as"...
>>>
>>> Since it is a pseudo variable declaration, I would assume VAR syntax and
>>> just use ":" ?
>>
>> That would be consistent with "On E:Exception do writeln(E.message)".
>
> No, because "On E: Exception" says that "E" is of the type "Exception",
> just like in a variable declaration the expression after the colon also
> identifies the type. Here it's not about defining the type, but about
> making a symbol equivalent to repeating a non-type expression. So "="
> from symbolic constant declarations would probably be closest. I think
> ":=" is less good, because ":=" implies that a copy or an assignment is
> made rather than an equivalence is defined, and hence changes to that
> copy could be assumed lost afterwards in case of records or objects,
> which would not be the case.

As I just wrote in another mail: what about "absolute". It might read
strange at first with a more complicated expression on the right hand
side, but it would express the concept of "this refers to the same".

Regards,
Sven

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

etrusco
In reply to this post by Sven Barth-2
On Sun, Mar 17, 2013 at 2:10 PM, Sven Barth <[hidden email]> wrote:
> On 17.03.2013 15:33, Flávio Etrusco wrote:
>>
>> (...)
>> static <T extends Comparable> int IndexOf(List<T> p_list, T p_item);
>
>
> So you're basically just talking about generic methods here?

Yes. Or actually not, it also involves allowing
non-specialized/not-completely-defined variables.


> The Delphi
> compatible syntax for your two examples are:
>
> === code begin ===
>
> function Alias1<T: TObject>(Source: T): TAlias1<T>;
>
> === code end ===

This time I tried with 2.7.1 :)
But it also gives "Error: Generics without specialization cannot be
used as a type for a variable".
Is something planned regarding this case?

Thanks a lot.

-Flávio
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
1234