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

Xiangrong Fang
I am sorry I didn't follow this thread although I am the "OP" :-).   If I understand correct, I would suggest NOT introduce the "absolute" keyword, instead, make it ALWAYS absolute. i.e.:

with a = SomeObject, b = SomeRecord do begin
  ... ...
end;

Both a and b are "reference" to the object or record, IMO there seems no need to do assignment in the with syntax. Thus, I suggest use = instead of :=


2013/3/18 Sven Barth <[hidden email]>
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


_______________________________________________
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
18.03.13, 9:27, Xiangrong Fang пишет:

> I am sorry I didn't follow this thread although I am the "OP" :-).   If
> I understand correct, I would suggest NOT introduce the "absolute"
> keyword, instead, make it ALWAYS absolute. i.e.:
>
> with a = SomeObject, b = SomeRecord do begin
>    ... ...
> end;
>
> Both a and b are "reference" to the object or record, IMO there seems no
> need to do assignment in the with syntax. Thus, I suggest use = instead
> of :=

'=' can't be used because it can be a part of expression. There is no
big difference between
with (a = SomeObject) do
and
with a = SomeObject do

After more thinking I see that ':=' as well as absolute keyword are also
bad because they will complicate the parser (although it is possible to
use them). Parser will need to read the first token and check if it is
an identifier, read second token and compare with ':=' (or 'absolute')
and if it is not ':=' (or 'absolute') return to expression parse.

At the same time we will not complicate the parser if we place alias
identifier after the with expression like:

with expression1, expression2 => alias2, expression3, expression4 =>
alias4 do

begin

end;

Where '=>' is some token which can't be used in expressions.

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

Xiangrong Fang
OK, I see. However I feel "=>" a very "un-pascal" thing, remind me of PHP.  :-)   I guess "as" would also complicate the parser?

2013/3/18 Paul Ishenin <[hidden email]>
18.03.13, 9:27, Xiangrong Fang пишет:

I am sorry I didn't follow this thread although I am the "OP" :-).   If
I understand correct, I would suggest NOT introduce the "absolute"
keyword, instead, make it ALWAYS absolute. i.e.:

with a = SomeObject, b = SomeRecord do begin
   ... ...
end;

Both a and b are "reference" to the object or record, IMO there seems no
need to do assignment in the with syntax. Thus, I suggest use = instead
of :=

'=' can't be used because it can be a part of expression. There is no big difference between
with (a = SomeObject) do
and
with a = SomeObject do

After more thinking I see that ':=' as well as absolute keyword are also bad because they will complicate the parser (although it is possible to use them). Parser will need to read the first token and check if it is an identifier, read second token and compare with ':=' (or 'absolute') and if it is not ':=' (or 'absolute') return to expression parse.

At the same time we will not complicate the parser if we place alias identifier after the with expression like:

with expression1, expression2 => alias2, expression3, expression4 => alias4 do

begin

end;

Where '=>' is some token which can't be used in expressions.

Best regards,
Paul Ishenin


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


_______________________________________________
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

Am 18.03.2013 04:17 schrieb "Xiangrong Fang" <[hidden email]>:
>
> OK, I see. However I feel "=>" a very "un-pascal" thing, remind me of PHP.  :-)   I guess "as" would also complicate the parser?

As already written by others: "as" is one of the worst tokens you can choose for this, as it is perfectly legal to do a typecast in an expression (which includes the expression for with).

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

Paul Ishenin
In reply to this post by Xiangrong Fang
18.03.13, 11:16, Xiangrong Fang пишет:
> OK, I see. However I feel "=>" a very "un-pascal" thing, remind me of
> PHP.  :-)   I guess "as" would also complicate the parser?

I did not suggest to use '=>' I wrote:

 > Where '=>' is some token which can't be used in expressions.

Which means replace '=>' in my example with some token (like ':' char or
'alias' word or anything else).

And since 'as' can be used in expressions (with List as TStringList do)
we should not use it.

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

Xiangrong Fang
In reply to this post by Sven Barth-2
Alternatively, how about just use SPACE to separate the token? i.e.:

with SomeObject o1, SomeOtherObject o2 do....

Because you need a COMMA for 2 or more expressions in with, and SPACE is not valid in token?


2013/3/18 Sven Barth <[hidden email]>

Am 18.03.2013 04:17 schrieb "Xiangrong Fang" <[hidden email]>:


>
> OK, I see. However I feel "=>" a very "un-pascal" thing, remind me of PHP.  :-)   I guess "as" would also complicate the parser?

As already written by others: "as" is one of the worst tokens you can choose for this, as it is perfectly legal to do a typecast in an expression (which includes the expression for with).

Regards,
Sven


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


_______________________________________________
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 our previous episode, Xiangrong Fang said:
> Alternatively, how about just use SPACE to separate the token? i.e.:
>
> with SomeObject o1, SomeOtherObject o2 do....

That's perfectly fine for C. But this isn't C.
_______________________________________________
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
2013/3/18 Marco van de Voort <[hidden email]>
In our previous episode, Xiangrong Fang said:
> Alternatively, how about just use SPACE to separate the token? i.e.:
>
> with SomeObject o1, SomeOtherObject o2 do....

That's perfectly fine for C. But this isn't C.

What's wrong here? In pascal, we also see space used in similar way:

property Item[Index: Integer]: Integer read GetItem write SetItem; default;

i.e. there is NO ; or anything before the "read" keyword, but you do need a ; before "default".  Anyway, this maybe related to how the parser is implemented, or just a decision by the language designer, but I don't really see why this has to do with C vs. Pascal??


_______________________________________________
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 our previous episode, Xiangrong Fang said:
> > In our previous episode, Xiangrong Fang said:
> > > Alternatively, how about just use SPACE to separate the token? i.e.:
> > >
> > > with SomeObject o1, SomeOtherObject o2 do....
> >
> > That's perfectly fine for C. But this isn't C.
>
> What's wrong here? In pascal, we also see space used in similar way:

Never between type and variable/alias name and never in the order
type[space]variable
 
_______________________________________________
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
2013/3/18 Marco van de Voort <[hidden email]>
In our previous episode, Xiangrong Fang said:
> > In our previous episode, Xiangrong Fang said:
> > > Alternatively, how about just use SPACE to separate the token? i.e.:
> > >
> > > with SomeObject o1, SomeOtherObject o2 do....
> >
> > That's perfectly fine for C. But this isn't C.
>
> What's wrong here? In pascal, we also see space used in similar way:

Never between type and variable/alias name and never in the order
type[space]variable

This is not the case, as the thing before space is NOT a type but a variable.   In my feeling things un-pascal is extensive use of "weird" symbols... :-)

I cannot recall if there is already a notion of "alias" in free pascal, if not then we just introduce this idea within the scope of "with" expression.

_______________________________________________
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 Xiangrong Fang
On Mon, 18 Mar 2013 15:36:13 +0800
Xiangrong Fang <[hidden email]> wrote:

> Alternatively, how about just use SPACE to separate the token? i.e.:
>
> with SomeObject o1, SomeOtherObject o2 do....

I think this is a bad idea.
One of the strengths of Pascal is its verbosity/redundancy which allows
unambiguous error messages and avoids many common mistakes.
For example when I forget a comma
  with A B do
the compiler points to B and writes "DO" expected but "identifier B"
found.
Using a space as separator compiles this without error.

 
> Because you need a COMMA for 2 or more expressions in with, and SPACE is
> not valid in token?

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

leledumbo
Administrator
In reply to this post by Xiangrong Fang
> I cannot recall if there is already a notion of "alias" in free pascal, if not then we just introduce this idea within the scope of "with" expression.

Let me give you one then:

procedure p; [public, alias: 'my_p'];
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Sven Barth-2
In reply to this post by Xiangrong Fang

Am 18.03.2013 10:36 schrieb "Xiangrong Fang" <[hidden email]>:
>
> 2013/3/18 Marco van de Voort <[hidden email]>
>>
>> In our previous episode, Xiangrong Fang said:
>> > > In our previous episode, Xiangrong Fang said:
>> > > > Alternatively, how about just use SPACE to separate the token? i.e.:
>> > > >
>> > > > with SomeObject o1, SomeOtherObject o2 do....
>> > >
>> > > That's perfectly fine for C. But this isn't C.
>> >
>> > What's wrong here? In pascal, we also see space used in similar way:
>>
>> Never between type and variable/alias name and never in the order
>> type[space]variable
>
>
> This is not the case, as the thing before space is NOT a type but a variable.   In my feeling things un-pascal is extensive use of "weird" symbols... :-)
>
> I cannot recall if there is already a notion of "alias" in free pascal, if not then we just introduce this idea within the scope of "with" expression.

Which is why I suggested "absolute" as this already carries the note of "a is the same as b".

Though considering that we already have an "alias" token that would also be an alternative...

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

Ludo Brands
In reply to this post by leledumbo
On 03/18/2013 02:30 PM, leledumbo wrote:
>> I cannot recall if there is already a notion of "alias" in free pascal, if
> not then we just introduce this idea within the scope of "with" expression.
>
> Let me give you one then:
>
> procedure p; [public, alias: 'my_p'];
>

And another one:

var
  a:integer;
  a_alias:integer absolute a;

:)

Ludo
_______________________________________________
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 Mon, Mar 18, 2013 at 10:42 AM, Sven Barth
<[hidden email]> wrote:

> Am 18.03.2013 10:36 schrieb "Xiangrong Fang" <[hidden email]>:
> (...)
>> I cannot recall if there is already a notion of "alias" in free pascal, if
>> not then we just introduce this idea within the scope of "with" expression.
>
> Which is why I suggested "absolute" as this already carries the note of "a
> is the same as b".
>
> Though considering that we already have an "alias" token that would also be
> an alternative...

Reading your comment, maybe "same" is a worth candidate ;-)

-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

Xiangrong Fang
In reply to this post by leledumbo
2013/3/18 leledumbo <[hidden email]>
> I cannot recall if there is already a notion of "alias" in free pascal, if
not then we just introduce this idea within the scope of "with" expression.

Let me give you one then:

procedure p; [public, alias: 'my_p'];

Is it related to COM or DLL stuff? Where is this kind of usage documented in the manual?

Thanks!
 

_______________________________________________
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

leledumbo
Administrator
> Is it related to COM or DLL stuff?

No, though might be if you want to export with your own symbol in DLL

> Where is this kind of usage documented in the manual?

http://www.freepascal.org/docs-html/ref/refsu64.html
Reply | Threaded
Open this post in threaded view
|

Re: a proposal about "with" syntax

Sven Barth-2
In reply to this post by etrusco
Am 18.03.2013 15:24, schrieb Flávio Etrusco:

> On Mon, Mar 18, 2013 at 10:42 AM, Sven Barth
> <[hidden email]> wrote:
>> Am 18.03.2013 10:36 schrieb "Xiangrong Fang" <[hidden email]>:
>> (...)
>>> I cannot recall if there is already a notion of "alias" in free pascal, if
>>> not then we just introduce this idea within the scope of "with" expression.
>> Which is why I suggested "absolute" as this already carries the note of "a
>> is the same as b".
>>
>> Though considering that we already have an "alias" token that would also be
>> an alternative...
> Reading your comment, maybe "same" is a worth candidate ;-)
I personally prefer to use tokens first that we already have and "same"
is not part of them.

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

Jürgen Hestermann
In reply to this post by Xiangrong Fang

Am 2013-03-16 07:13, schrieb Xiangrong Fang:
I would like to do this:

with MyClassInstance as mci
, SomethingElse do begin
  Caption := 'A new caption';
  for i := 0 to Count - 1 do
    mci[i] := UpperCase(mci[i]);
end;


That is, to add an optional "as" clause to the with statement so that access array element in a structure is made easier.

I fail to see how this would be helpful.
It's just more confusing.
Suddenly there are 2 (or more?) identifiers meaning the same thing.
If I want to avoid typing a long identifer name multiple times
I would simply select it and copy it to the clipboard.
If someone (I myself?) chose a long identifier name I think it was for some reason (readability?).
Foiling this by making the code more obscure is not a good idea IMO.
That's making the code a bit more C'ish (harder to read).
You won't cripple down all variables to one letter names A, B, C only because this is easier to type, won't you?

_______________________________________________
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

Ralf A. Quint
At 10:03 AM 3/18/2013, Jürgen Hestermann wrote:

>Am 2013-03-16 07:13, schrieb Xiangrong Fang:
>>I would like to do this:
>>
>>with MyClassInstance as mci, SomethingElse do begin
>>   Caption := 'A new caption';
>>   for i := 0 to Count - 1 do
>>     mci[i] := UpperCase(mci[i]);
>>end;
>>
>>That is, to add an optional "as" clause to the
>>with statement so that access array element in a structure is made easier.
>I fail to see how this would be helpful.
>It's just more confusing.
>Suddenly there are 2 (or more?) identifiers meaning the same thing.
>If I want to avoid typing a long identifer name multiple times
>I would simply select it and copy it to the clipboard.
>If someone (I myself?) chose a long identifier
>name I think it was for some reason (readability?).
>Foiling this by making the code more obscure is not a good idea IMO.
>That's making the code a bit more C'ish (harder to read).
>You won't cripple down all variables to one
>letter names A, B, C only because this is easier to type, won't you?

+1

I don't see either why a programming language
needs to be changed to support the laziness of some programmers.

But in recent months (years?) it seems more and
more folks in here don't wont' to program in
Pascal anymore and come up all the time with "new
and improved" features that render the advantages of Pascal useless...

Ralf

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