[fpc-devel] new features and facilities

2015-10-08 Thread Mohsen

Hi!
I wanna add new features and facilities to pascal like while - else, for 
- else and inline if statement like python.


examples

ex1:

I:=5;
while(I>0) do
  begin
 Write(I);
 I:=I-1;
 end else Write(' While Else ');

ex1-output:54321 While Else

ex2:

I:=5;
  while(I>0) do
  begin
 Write(I);
 Break;
  end else Write(' While Else ');

ex2-output:5


so i want you to help me how to implement  it.

thanks a million.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread MohsenTi
I know this issue but with changing some of structures, I can implement it
and now I only want testing adding features to compiler and don't care
about backward compatibility,just testing.

I added some changes to compiler functions and classes like
pstatmnt.while_statement and nflw.twhilerepeatnode but need more
information about functions and units.

Mohsen Timar

On Thu, Oct 8, 2015 at 6:28 PM, Michael Van Canneyt 
wrote:

>
>
> On Thu, 8 Oct 2015, Mohsen wrote:
>
> Hi!
>> I wanna add new features and facilities to pascal like while - else, for
>> - else and inline if statement like python.
>>
>> examples
>>
>> ex1:
>>
>> I:=5;
>> while(I>0) do
>>  begin
>> Write(I);
>> I:=I-1;
>> end else Write(' While Else ');
>>
>
> This cannot be implemented without breaking the language.
>
> I:=5:
> If (I<5) then
>  while(I>0) do
>   begin
>  Write(I);
>  I:=I-1;
>  end else
>   Write(' While Else ');
>
> Will not work correctly any more if you want to implement your idea.
>
> So this extension is not possible without breaking backwards compatibility.
>
> Michael.
> ___
> fpc-devel maillist  -  fpc-devel@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Michael Van Canneyt



On Thu, 8 Oct 2015, Mohsen wrote:


Hi!
I wanna add new features and facilities to pascal like while - else, for - 
else and inline if statement like python.


examples

ex1:

I:=5;
while(I>0) do
 begin
Write(I);
I:=I-1;
end else Write(' While Else ');


This cannot be implemented without breaking the language.

I:=5:
If (I<5) then
 while(I>0) do
  begin
 Write(I);
 I:=I-1;
 end 
else

  Write(' While Else ');

Will not work correctly any more if you want to implement your idea.

So this extension is not possible without breaking backwards compatibility.

Michael.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Paul Michell

I'm in tomorrow, we can take a look then.

Kind regards,

Paul


On 08/10/15 14:33, Mohsen wrote:

Hi!
I wanna add new features and facilities to pascal like while - else, 
for - else and inline if statement like python.


examples

ex1:

I:=5;
while(I>0) do
  begin
 Write(I);
 I:=I-1;
 end else Write(' While Else ');

ex1-output:54321 While Else

ex2:

I:=5;
  while(I>0) do
  begin
 Write(I);
 Break;
  end else Write(' While Else ');

ex2-output:5


so i want you to help me how to implement  it.

thanks a million.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel



___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Ondrej Pokorny

On 08.10.2015 17:37, MohsenTi wrote:
I know this issue but with changing some of structures, I can 
implement it and now I only want testing adding features to compiler 
and don't care about backward compatibility,just testing.


I added some changes to compiler functions and classes like 
pstatmnt.while_statement and nflw.twhilerepeatnode but need more 
information about functions and units.


And what about the inline if? That should be backwards compatible at a 
first glance. And it would be a fun thing because the Delphi community 
has asked for it for many years and Embarcadero looks like they won't 
add it at all :)


Ondrej
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Mark Morgan Lloyd

Ondrej Pokorny wrote:

As Michael has said, adding an extra  else  or for that matter 
otherwise  would be a problem.


And what about the inline if? That should be backwards compatible at a 
first glance. And it would be a fun thing because the Delphi community 
has asked for it for many years and Embarcadero looks like they won't 
add it at all :)


Inline if is an ALGOL feature, and it's inexplicable why it's never been 
in Pascal.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Sven Barth
Am 08.10.2015 17:37 schrieb "MohsenTi" :
>
> I know this issue but with changing some of structures, I can implement
it and now I only want testing adding features to compiler and don't care
about backward compatibility,just testing.

I wouldn't integrate it in the compiler, but for playing around with the
language and learning the workings of the compiler it's okay. :)

> I added some changes to compiler functions and classes like
pstatmnt.while_statement and nflw.twhilerepeatnode but need more
information about functions and units.

At first glance those locations look correct. Anything specific you're
looking for now? Cause the compiler is quite large and I can't explain
everything to you just now ^^

Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread David W Noon
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Thu, 08 Oct 2015 16:12:56 +, Mark Morgan Lloyd
(markmll.fpc-de...@telemetry.co.uk) wrote about "Re: [fpc-devel] new
features and facilities" (in ):

> Ondrej Pokorny wrote:
> 
> As Michael has said, adding an extra  else  or for that matter 
> otherwise  would be a problem.
> 
>> And what about the inline if? That should be backwards compatible
>> at a first glance. And it would be a fun thing because the Delphi
>> community has asked for it for many years and Embarcadero looks
>> like they won't add it at all :)
> 
> Inline if is an ALGOL feature, and it's inexplicable why it's never
> been in Pascal.

Indeed, it is even more succinct in C/C++:

   x =  ?  : ;

This was taken directly from ALGOL 60 and remains a very elegant feature.

However, Jensen & Wirth excluded it from the original Pascal Report.
- -- 
Regards,

Dave  [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
david.w.n...@googlemail.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iEYEARECAAYFAlYWnHkACgkQogYgcI4W/5R5IwCgz5RvrROIZn26Pn1u1flRIBKH
mIUAn3gyUm9TdTglLkQdYjiI26lSg6ye
=HFIP
-END PGP SIGNATURE-
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Sven Barth
Am 08.10.2015 17:43 schrieb "Ondrej Pokorny" :
>
> On 08.10.2015 17:37, MohsenTi wrote:
>>
>> I know this issue but with changing some of structures, I can implement
it and now I only want testing adding features to compiler and don't care
about backward compatibility,just testing.
>>
>> I added some changes to compiler functions and classes like
pstatmnt.while_statement and nflw.twhilerepeatnode but need more
information about functions and units.
>
>
> And what about the inline if? That should be backwards compatible at a
first glance. And it would be a fun thing because the Delphi community has
asked for it for many years and Embarcadero looks like they won't add it at
all :)

I had the idea to implement inline-if as well. I think the syntax I
selected is derived from Oxygene, but it looks very Pascal and shouldn't
break anything:

left := if expr1 then expr2 else expr3;

Thereby expr1 returns Boolean and expr2 determines the type of the whole
inline-if, thus expr3 needs to be compatible to expr2.

Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Ondrej Pokorny

On 08.10.2015 18:54, Sven Barth wrote:
I had the idea to implement inline-if as well. I think the syntax I 
selected is derived from Oxygene, but it looks very Pascal and 
shouldn't break anything:


left := if expr1 then expr2 else expr3;

Thereby expr1 returns Boolean and expr2 determines the type of the 
whole inline-if, thus expr3 needs to be compatible to expr2.



Exactly. We discussed the same Oxygene-syntax in the Delphi community.

Ondrej
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Ralf Quint

On 10/8/2015 9:54 AM, Sven Barth wrote:


I had the idea to implement inline-if as well. I think the syntax I 
selected is derived from Oxygene, but it looks very Pascal and 
shouldn't break anything:


left := if expr1 then expr2 else expr3;

Thereby expr1 returns Boolean and expr2 determines the type of the 
whole inline-if, thus expr3 needs to be compatible to expr2.



Sorry, but that doesn't "look Pascal" at all, and is anything but easily 
understandable, specially given the possible complexity of expr[1,2,3]...


Ralf

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Ralf Quint

On 10/8/2015 10:35 AM, Mark Morgan Lloyd wrote:



Indeed, it is even more succinct in C/C++:

   x =  ?  : ;


At which point you'll have various members of the Pascal community 
decrying it as too C-like.


Well, the tenary operator as present in C(++) is a shortcut for a simple 
if-then-else, and can be pretty readable if used "in moderation". And it 
assigns a  value to x depending on two expressions not some murky 
boolean result out of three expressions like Bart supposed...


Ralf


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Carlo Kok



Op 2015-10-08 om 19:25 schreef Dmitry Boyarintsev:

On Thu, Oct 8, 2015 at 12:54 PM, Sven Barth > wrote:

I had the idea to implement inline-if as well. I think the syntax I
selected is derived from Oxygene, but it looks very Pascal and
shouldn't break anything:

left := if expr1 then expr2 else expr3;

Thereby expr1 returns Boolean and expr2 determines the type of the
whole inline-if, thus expr3 needs to be compatible to expr2.

Does Oxygene allow something like this?
left := if expr1 then begin exprN, left := exprK end else begin
left:=left+3; exp3 end

or is it only one expression at a time?
left := if expr1 then if expr2 then expr5 else expr6 else expr7;


Only one expression at a time, since the 'result' of the expression in 
oxygene is the combined type of the true value and false value, false 
being optional defaulting to nil.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Dmitry Boyarintsev
On Thu, Oct 8, 2015 at 12:54 PM, Sven Barth 
wrote:

> I had the idea to implement inline-if as well. I think the syntax I
> selected is derived from Oxygene, but it looks very Pascal and shouldn't
> break anything:
>
> left := if expr1 then expr2 else expr3;
>
> Thereby expr1 returns Boolean and expr2 determines the type of the whole
> inline-if, thus expr3 needs to be compatible to expr2.
>
Does Oxygene allow something like this?
left := if expr1 then begin exprN, left := exprK end else begin
left:=left+3; exp3 end

or is it only one expression at a time?
left := if expr1 then if expr2 then expr5 else expr6 else expr7;

thanks,
Dmitry
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Mark Morgan Lloyd

David W Noon wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Thu, 08 Oct 2015 16:12:56 +, Mark Morgan Lloyd
(markmll.fpc-de...@telemetry.co.uk) wrote about "Re: [fpc-devel] new
features and facilities" (in ):


Ondrej Pokorny wrote:

As Michael has said, adding an extra  else  or for that matter 
otherwise  would be a problem.



And what about the inline if? That should be backwards compatible
at a first glance. And it would be a fun thing because the Delphi
community has asked for it for many years and Embarcadero looks
like they won't add it at all :)

Inline if is an ALGOL feature, and it's inexplicable why it's never
been in Pascal.


Indeed, it is even more succinct in C/C++:

   x =  ?  : ;


At which point you'll have various members of the Pascal community 
decrying it as too C-like.



This was taken directly from ALGOL 60 and remains a very elegant feature.

However, Jensen & Wirth excluded it from the original Pascal Report.


More to the point, I don't believe it was in in Wirth's early Pascal 
compilers although it was in ALGOL-W. This is actually quite a messy 
area, since ALGOL 68 changed the syntax to add an explicit FI for 
compatibility with the statement-level IF THEN ELSE FI.


ALGOL also had inline CASE etc., and some implementations (e.g. 
Burroughs) extended this to accomodate jump tables etc. Curiously, 
Wirth's Stanford-era compilers use these liberally.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread MohsenTi
Thank you Sven,
is there any documentation about freepascal compiler parts ?

On Thu, Oct 8, 2015 at 8:27 PM, Sven Barth 
wrote:

> Am 08.10.2015 17:37 schrieb "MohsenTi" :
> >
> > I know this issue but with changing some of structures, I can implement
> it and now I only want testing adding features to compiler and don't care
> about backward compatibility,just testing.
>
> I wouldn't integrate it in the compiler, but for playing around with the
> language and learning the workings of the compiler it's okay. :)
>
> > I added some changes to compiler functions and classes like
> pstatmnt.while_statement and nflw.twhilerepeatnode but need more
> information about functions and units.
>
> At first glance those locations look correct. Anything specific you're
> looking for now? Cause the compiler is quite large and I can't explain
> everything to you just now ^^
>
> Regards,
> Sven
>
> ___
> fpc-devel maillist  -  fpc-devel@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
>
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Mark Morgan Lloyd

Ralf Quint wrote:

On 10/8/2015 9:54 AM, Sven Barth wrote:


I had the idea to implement inline-if as well. I think the syntax I 
selected is derived from Oxygene, but it looks very Pascal and 
shouldn't break anything:


left := if expr1 then expr2 else expr3;

Thereby expr1 returns Boolean and expr2 determines the type of the 
whole inline-if, thus expr3 needs to be compatible to expr2.



Sorry, but that doesn't "look Pascal" at all, and is anything but easily 
understandable, specially given the possible complexity of expr[1,2,3]...


But at least in this instance there's /always/ an ELSE, so there's no 
risk of apparent ambiguity due to "dangling else": a closing END or FI 
isn't needed.


It's more difficult to argue for inline CASE, particularly since that 
one might have optional ELSE or OTHERWISE.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] patch for rtl/linux/aarch64/cprt0.as

2015-10-08 Thread Jonas Maebe

On 06/10/15 20:50, Edmund Grimley Evans wrote:


But perhaps you'll want to consider fpc-x86_64-cprt0.patch (attached)
for the trunk. I can confirm that it doesn't break Debian's build.
Perhaps someone else can test it in some other way.


I've run the testsuite and didn't see any regressions on RHEL 5.5 either.


And here's an improved patch for AArch64: fpc-aarch64-cprt0.patch.
AArch64 seems to need a corresponding version of the change that was
needed for i386, so I've included both changes here.


Thanks, all committed.


(So if you've
already applied the patch from Debian bug #800811 there will be a
conflict.) Apart from the i386 part, this patch could perhaps go into
fixes_3_0_ios as it clearly (I hope) only affects AArch64-Linux so
can't break anything that used to work.


Yes, I'll do that.


Jonas

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Michael Van Canneyt



On Thu, 8 Oct 2015, Sven Barth wrote:


Am 08.10.2015 19:10 schrieb "Ralf Quint" :


On 10/8/2015 9:54 AM, Sven Barth wrote:



I had the idea to implement inline-if as well. I think the syntax I

selected is derived from Oxygene, but it looks very Pascal and shouldn't
break anything:


left := if expr1 then expr2 else expr3;

Thereby expr1 returns Boolean and expr2 determines the type of the whole

inline-if, thus expr3 needs to be compatible to expr2.




Sorry, but that doesn't "look Pascal" at all, and is anything but easily

understandable, specially given the possible complexity of expr[1,2,3]...

And you think C's ternary would be more Pascal? Also you need /some/
definition of what defines the type no whether what syntax you choose (in
addition expr1 is the same as in normal ifs, so it's only the "complexity"
of expr2 and expr3). And no, "the left side" is not the Pascal answer
either.


Actually, yes I think C's or Javascript's ternary is better suited.

Let me explain. If I see

If expr1 then expr2 else expr3

it says 'statement' to me. But

a ? b : c;

Says "expression" to me.

So

left := a ? b : c;

looks more 'right' than the 'if then else', because the right-hand side is 
clearly an expression.

The "if expr1 then expr2 else expr3" is equally counter-intuitive and confusing 
as anonymous functions.

Keyword "If" starts a statement. If you allow to use it in expressions, its meaning becomes context sensitive. 
That is a bad thing in my book.


So if this thing needs to be implemented, then I'd much prefer it in the 
ternary form.

Michael.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Mark Morgan Lloyd

Michael Van Canneyt wrote:

On Thu, 8 Oct 2015, Sven Barth wrote:


Am 08.10.2015 19:10 schrieb "Ralf Quint" :


On 10/8/2015 9:54 AM, Sven Barth wrote:



I had the idea to implement inline-if as well. I think the syntax I

selected is derived from Oxygene, but it looks very Pascal and shouldn't
break anything:


left := if expr1 then expr2 else expr3;

Thereby expr1 returns Boolean and expr2 determines the type of the 
whole

inline-if, thus expr3 needs to be compatible to expr2.




Sorry, but that doesn't "look Pascal" at all, and is anything but easily

understandable, specially given the possible complexity of expr[1,2,3]...

And you think C's ternary would be more Pascal? Also you need /some/
definition of what defines the type no whether what syntax you choose (in
addition expr1 is the same as in normal ifs, so it's only the 
"complexity"

of expr2 and expr3). And no, "the left side" is not the Pascal answer
either.


Actually, yes I think C's or Javascript's ternary is better suited.

Let me explain. If I see

If expr1 then expr2 else expr3

it says 'statement' to me. But

a ? b : c;

Says "expression" to me.

So

left := a ? b : c;


OK. So presumably, since false < true, b is executed if a is false and c 
is executed if it's true? >:-)


looks more 'right' than the 'if then else', because the right-hand side 
is clearly an expression.


The "if expr1 then expr2 else expr3" is equally counter-intuitive and 
confusing as anonymous functions.


Keyword "If" starts a statement. If you allow to use it in expressions, 
its meaning becomes context sensitive. That is a bad thing in my book.


So if this thing needs to be implemented, then I'd much prefer it in the 
ternary form.


The way I look at it is that it's restoring a feature that was (possibly 
accidentally) dropped during the ALGOL -> Pascal transition. As such I 
don't have any problem with ALGOL-style


left := if a then b else c;

After all, while concise C-style operators work well in expressions this 
is not a simple expression where all components are evaluated: it's 
directly equivalent to the statement-level  if  potentially including 
exactly the same short-circuiting rules in the boolean expression (a above).


The thing I do have problems with is the difficulty people had 
explaining nested inline ifs during the 1960s. However I think that was 
more because they simply hadn't worked out how to write language 
documentation rather than there being anything inherently tricky about 
it, and these days there's absolutely no reason why it shouldn't be 
spaced and indented in a thoroughly Pascal-like fashion :-)


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Sven Barth
Am 08.10.2015 19:10 schrieb "Ralf Quint" :
>
> On 10/8/2015 9:54 AM, Sven Barth wrote:
>>
>>
>> I had the idea to implement inline-if as well. I think the syntax I
selected is derived from Oxygene, but it looks very Pascal and shouldn't
break anything:
>>
>> left := if expr1 then expr2 else expr3;
>>
>> Thereby expr1 returns Boolean and expr2 determines the type of the whole
inline-if, thus expr3 needs to be compatible to expr2.
>>
>>
> Sorry, but that doesn't "look Pascal" at all, and is anything but easily
understandable, specially given the possible complexity of expr[1,2,3]...

And you think C's ternary would be more Pascal? Also you need /some/
definition of what defines the type no whether what syntax you choose (in
addition expr1 is the same as in normal ifs, so it's only the "complexity"
of expr2 and expr3). And no, "the left side" is not the Pascal answer
either.

Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Ralf Quint

On 10/8/2015 2:07 PM, Sven Barth wrote:
And you think C's ternary would be more Pascal? 

Well, no.

While I use the ternary operator quite a bit when using C, as it IMHO 
allows for a cleaner formatting of code there, in Pascal, I always use a 
cleanly formatted If-then-else.


Ralf

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Michael Van Canneyt



On Thu, 8 Oct 2015, Mark Morgan Lloyd wrote:


Michael Van Canneyt wrote:

On Thu, 8 Oct 2015, Sven Barth wrote:


Am 08.10.2015 19:10 schrieb "Ralf Quint" :


On 10/8/2015 9:54 AM, Sven Barth wrote:



I had the idea to implement inline-if as well. I think the syntax I

selected is derived from Oxygene, but it looks very Pascal and shouldn't
break anything:


left := if expr1 then expr2 else expr3;

Thereby expr1 returns Boolean and expr2 determines the type of the whole

inline-if, thus expr3 needs to be compatible to expr2.




Sorry, but that doesn't "look Pascal" at all, and is anything but easily

understandable, specially given the possible complexity of expr[1,2,3]...

And you think C's ternary would be more Pascal? Also you need /some/
definition of what defines the type no whether what syntax you choose (in
addition expr1 is the same as in normal ifs, so it's only the "complexity"
of expr2 and expr3). And no, "the left side" is not the Pascal answer
either.


Actually, yes I think C's or Javascript's ternary is better suited.

Let me explain. If I see

If expr1 then expr2 else expr3

it says 'statement' to me. But

a ? b : c;

Says "expression" to me.

So

left := a ? b : c;


OK. So presumably, since false < true, b is executed if a is false and c is 
executed if it's true? >:-)


Why would anyone in the world think that ?

Many pascal programmers do not even know that falseBy contrast, many people these days have encountered some C-ish language and 
do know ternary expressions.




After all, while concise C-style operators work well in expressions this is 
not a simple expression where all components are evaluated:


Of course it is the same. Boolean expressions by default are shortcut-evaluated. 
So the ternary is completely equivalent to that and should not present any difficulties whatsoever.


Michael.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] new features and facilities

2015-10-08 Thread Martin Frb

On 08/10/2015 23:18, Mark Morgan Lloyd wrote:

Michael Van Canneyt wrote:

Let me explain. If I see

If expr1 then expr2 else expr3

it says 'statement' to me. But

a ? b : c;

Says "expression" to me.


The way I look at it is that it's restoring a feature that was 
(possibly accidentally) dropped during the ALGOL -> Pascal transition. 
As such I don't have any problem with ALGOL-style


left := if a then b else c;


Well if it is merely a decision between syntax: FPC already as a command 
line option for c like operator += -+ ..., so the ? could be only if c 
like ops are enabled.


Besides this, if ?: is treated like any operator then you can also use 
it in values for default param, or const


const bar = 1;
const TVal = 2;
const TVal2 = 3;
procedure foo(a: integer = 7 = bar ? TVal : TVal2);
...
const foo: integer = 7 = bar ? TVal : TVal2;

Which is hard enough to read. The meaning of the colon in the 
declaration block changes, if preceded by a ?



Of course the if can be made misleading too, if you break lines in the 
wrong place

  foo := SomeBoolValOrExpression +
  if a= b then bar(1) else bar(2);

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel