Recent

Author Topic: The future of Free Pascal  (Read 228508 times)

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: The future of Free Pascal
« Reply #330 on: June 22, 2017, 04:49:24 pm »
The difference is only in the place of initialization, the rest of the goodies are already realized in the library
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}
  2. program Project1;
  3.  
  4. uses SysUtils;
  5.  
  6. function Test1: string;
  7. const
  8.   CStr = 'adc';
  9. begin
  10.   Result := CStr.Replace('d','b');
  11. end;
  12.  
  13. function Test2: string;
  14. const
  15.   CStr =
  16.     'Hello World'#0 +
  17.     '2. String'#0 +
  18.     'Last String';
  19. var
  20.   X: TStringArray;
  21. begin
  22.   X := CStr.Split(#0);
  23.   Result := X[High(X)];
  24. end;
  25.  
  26. begin
  27.   Writeln(Test1);
  28.   Writeln(Test2);
  29.   Readln;
  30. end.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: The future of Free Pascal
« Reply #331 on: June 22, 2017, 04:58:49 pm »
Complicated, just write (3.0.2+) :

Code: Pascal  [Select][+][-]
  1. {$mode delphi}
  2.  
  3. uses sysutils;
  4. function bla : string;
  5.  
  6. begin
  7.   result:='adc'.replace('d','b');
  8. end;
  9.  
  10. begin
  11.   writeln(bla);
  12. end.
  13.  

For a list of such functions see here. Note that some (like compare) have several overloads
« Last Edit: June 22, 2017, 05:02:20 pm by marcov »

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: The future of Free Pascal
« Reply #332 on: June 22, 2017, 05:09:36 pm »
Complicated, just write (3.0.2+) :
[/code]
Only for demonstration purposes, with an attempt to preserve the original construction.
Also can be
Code: Pascal  [Select][+][-]
  1. function Test2: string;
  2. var
  3.   X: TStringArray;
  4. begin
  5.   X := ''.Join(#0, ['Hello World', '2. String', 'Last String']).Split(#0);
  6.   Result := X[High(X)];
  7. end;

hengky

  • New Member
  • *
  • Posts: 11
Re: The future of Free Pascal
« Reply #333 on: June 22, 2017, 05:27:29 pm »
I mean Like C# below

CS2HX converts your C# 4.0 code into haXe code. haXe is a multi-target language, so the resulting haXe code can be converted to many other languages.

This means CS2HX can be a:
- C# to ActionScript converter
- C# to JavaScript converter
- C# to Java converter
- C# to PHP converter
- C# to C++ converter

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: The future of Free Pascal
« Reply #334 on: June 22, 2017, 06:06:51 pm »
I mean Like C# below

CS2HX converts your C# 4.0 code into haXe code. haXe is a multi-target language, so the resulting haXe code can be converted to many other languages.

This means CS2HX can be a:
- C# to ActionScript converter
- C# to JavaScript converter
- C# to Java converter
- C# to PHP converter
- C# to C++ converter

Actionscript is dead since flash is as good as dead, Javascript (pas2js) and Java jvm  are already supported or worked on.

Leaves PHP and C++. But then I rather have a direct translator pas2xxx then via yet another external tool. Nearly every converter limits the dialect, so two conversions doubly so.  a pas2haxe converter is too much work if it supports only trivial subsets and programs.

And subsets it always will be. Even C++ doesn't support enough to be an backend for the whole language. FPC/object pascal is massive.
« Last Edit: June 22, 2017, 06:09:28 pm by marcov »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: The future of Free Pascal
« Reply #335 on: June 22, 2017, 06:18:43 pm »
Pas2haxe may sound good, but if I can choose please put more efforts on pas2android.

Paul_

  • Full Member
  • ***
  • Posts: 143
Re: The future of Free Pascal
« Reply #336 on: June 22, 2017, 06:34:08 pm »
Is there something like this for variable values?
Code: Pascal  [Select][+][-]
  1. TPoint = record
  2.   x, y  : Single;
  3.   color : TColor;
  4. end;
  5.  
  6. Var
  7.    Point : TPoint;

And assigning values in code:
Code: Pascal  [Select][+][-]
  1. Point( 100, 200, clWhite );

Instead of:
Code: Pascal  [Select][+][-]
  1. With Point do begin
  2.   x := 100;
  3.   y := 200;
  4.   Color := clWhite;
  5. end;

or making function SetPointValue( x, y : Single; Color : TColor) : TPoint;

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: The future of Free Pascal
« Reply #337 on: June 22, 2017, 06:41:17 pm »
Is there something like this for variable values?
Code: Pascal  [Select][+][-]
  1. TPoint = record
  2.   x, y  : Single;
  3.   color : TColor;
  4. end;
  5.  

You can define a constant record of course, e.g.:

Code: Pascal  [Select][+][-]
  1. const mypoint : TMyPoint = (x:1;y:2;color:clwhite);

I used TMyPoint because TPoint is already predefined and used a lot.
« Last Edit: June 22, 2017, 06:45:35 pm by marcov »

bytebites

  • Hero Member
  • *****
  • Posts: 633
Re: The future of Free Pascal
« Reply #338 on: June 22, 2017, 07:41:15 pm »
Code: Pascal  [Select][+][-]
  1. TMyPoint = record
  2.   x, y  : Single;
  3.   color : TColor;
  4.   Create(x,y:integer, color:TColor):TMyPoint;
  5. end;
  6.  
  7.  
  8.  TMyPoint.Create(x,y:integer, color:TColor):TMyPoint;
  9. begin
  10.   self.x:=x;
  11.   self.y:=y;
  12.   self.color:=color;
  13. end;
  14. Var
  15.    MyPoint : TMyPoint;
  16.  
  17. begin
  18.   MyPoint.Create(100, 200, clWhite);

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: The future of Free Pascal
« Reply #339 on: June 22, 2017, 08:21:55 pm »
Pas2haxe may sound good, but if I can choose please put more efforts on pas2android.
Huh? We have pas2Android: FPC compiles to Android-arm (and Android-Intel? never tried that).
Android is an OS, not a language.
And we have an extremely capable jvm target too.
Problem is that the toolchain is rather long and object pascal programmers are not used to that...
The programmers that I know to complain about the build environment for FPC-Android have the same problems with configuring and using, say, Eclipse.
Especially when it is packaging time or even make a release build.
In that sense tools like Delphi and Lazarus make you lazy.
« Last Edit: June 22, 2017, 08:26:17 pm by Thaddy »
Specialize a type, not a var.

Paul_

  • Full Member
  • ***
  • Posts: 143
Re: The future of Free Pascal
« Reply #340 on: June 22, 2017, 08:23:59 pm »
Thanks for ideas. But constants are predefined and I can't compile bytebites code, It should be?
Code: Pascal  [Select][+][-]
  1. {$mode delphi}
  2. Type
  3.   TMyPoint = record
  4.     x, y  : Single;
  5.     color : TColor;
  6.     function Create(x,y:integer; color:TColor):TMyPoint;
  7.   end

I can declare function out of record, so I doesn't help much. The idea was in smaller and cleaner code.

And maybe define values in procedures or function in this style would be fine:
Code: Pascal  [Select][+][-]
  1. Type
  2. TMyPoint = record
  3.   x, y  : Single;
  4. end;
  5.  
  6. Procedure DrawText( Point : TMyPoint, Text : String );
  7. begin
  8.   // I will not use DrawText( x, y : Single; Text : String );
  9.   // Point is local "variable"
  10.   // some drawing code
  11. end;
  12.  
  13. begin
  14.   DrawText( (1, 2), 'Text 1');
  15.   DrawText( (3, 4), 'Text 2');
  16. end;

or:

Code: Pascal  [Select][+][-]
  1. begin
  2.   DrawText( TMyPoint(1, 2), 'Text 1');
  3.   DrawText( TMyPoint(3, 4), 'Text 2');
  4. end;
« Last Edit: June 22, 2017, 08:27:42 pm by PaulG »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: The future of Free Pascal
« Reply #341 on: June 22, 2017, 08:44:54 pm »
But more unsafe, specially if your reorder or insert new fields. If we get some tuple feature I hope it is as in the constant definition case, that you have to name the fields.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: The future of Free Pascal
« Reply #342 on: June 22, 2017, 08:51:47 pm »
Code: Pascal  [Select][+][-]
  1. function Test2: string;
  2. var
  3.   X: TStringArray;
  4. begin
  5.   X := ''.Join(#0, ['Hello World', '2. String', 'Last String']).Split(#0);
  6.   Result := X[High(X)];
  7. end;
I Really like that one My Include-File already look's like
Code: Pascal  [Select][+][-]
  1. 'First line',
  2. 'Second Line',
  3. [... another 230 Lines]
  4. 'Last Line'
  5.  
I'd do it like
Code: Pascal  [Select][+][-]
  1. function Test2: TStringArray;
  2. var
  3.   X: string;
  4. begin
  5.   X.Join(#0, [{$I TextFile.txt}]);
  6.   Result := X.Split(#0);
  7. end;
That replace my
Code: Pascal  [Select][+][-]
  1. const st:array[0..232] of string =({$I TextFile.txt});
  2.  
Whenever i change the Textfile I had to Change the number of the Array too, and I Sooooooooo didn't liked that !!!!!

@PaulG:
Solution: declare a Function:
Code: Pascal  [Select][+][-]
  1. function Mypoint(x,y:single):TMypoint;
  2. begin
  3.    result.x := x;
  4.    result.y := y;
  5. end;
  6.  
  7. // then This is valid
  8.  
  9.     begin
  10.       DrawText( MyPoint(1, 2), 'Text 1');
  11.       DrawText( MyPoint(3, 4), 'Text 2');
  12.     end;
  13.  

OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: The future of Free Pascal
« Reply #343 on: June 22, 2017, 09:04:33 pm »
Or the second Code: you only have to write a vararray to TmyPoint-conversion and overload the assignment operator then 
Code: Pascal  [Select][+][-]
  1. begin
  2.   DrawText( [1, 2], 'Text 1');
  3.   DrawText( [3, 4], 'Text 2');
  4. end;
  5.  
is Valid;
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: The future of Free Pascal
« Reply #344 on: June 22, 2017, 09:06:17 pm »
Maybe you want something like this. Only possible with trunk!
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$mode objfpc}
  3. type
  4.   TMyPoint =Array of single;
  5.  
  6. Procedure DrawText( Point : TMyPoint; Text : String );
  7. begin
  8. // whatever...
  9. end;
  10.  
  11. begin
  12.   DrawText( [1, 2], 'Text 1');
  13.   DrawText( [3, 4], 'Text 2');
  14. end.
  15.  

That compiles and works!
« Last Edit: June 22, 2017, 09:10:49 pm by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018