[Pas2js] Pas2js Digest, Vol 12, Issue 41

Stephen Wright stephenmichaelwright at yahoo.co.uk
Mon Dec 31 12:45:02 CET 2018


 For our area of interest which is making it easier for non specialists programmers to code simple apps that work "everywhere" the main attraction of FPC/Lazarus/Pas2JS is the very wide coverage of different platforms and the assumption that almost everything that works in Pas2JS will work in FPC.  Any new Pas2JS specific features will be a negative for this type of application.
Steve
    On Monday, 31 December 2018, 11:00:21 GMT, pas2js-request at lists.freepascal.org <pas2js-request at lists.freepascal.org> wrote:  
 
 Send Pas2js mailing list submissions to
    pas2js at lists.freepascal.org

To subscribe or unsubscribe via the World Wide Web, visit
    http://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js
or, via email, send a message with subject or body 'help' to
    pas2js-request at lists.freepascal.org

You can reach the person managing the list at
    pas2js-owner at lists.freepascal.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Pas2js digest..."


Today's Topics:

  1. The goal of pas2js (warleyalex)
  2. Re: The goal of pas2js (Michael Van Canneyt)
  3. Re: The goal of pas2js (Michael Van Canneyt)
  4. Re: The goal of pas2js (silvioprog)
  5. Re: Dataset improved (warleyalex)
  6. Re: The goal of pas2js (Ralf Quint)
  7. Re: Dataset improved (Michael Van Canneyt)


----------------------------------------------------------------------

Message: 1
Date: Sun, 30 Dec 2018 09:13:06 -0700 (MST)
From: warleyalex <warleyalex at yahoo.com.br>
To: pas2js at lists.freepascal.org
Subject: [Pas2js] The goal of pas2js
Message-ID: <1546186386337-0.post at n8.nabble.com>
Content-Type: text/plain; charset=us-ascii

Michael said: "I wish to repeat that the goal of pas2js is to make pascal
available in the browser. 
The goal is not to make pascal resemble Javascript." 

However, I wish the general purpose and were not limited to pascal available
in the browser.
Pas2js should be an full extented feature language; the language can support
several syntax and features/extensions introduced similar to Delphi Prism /
Oxygene / DWScript / FPC, as well as various language extensions, "make
pascal resemble Javascript".

a) variables can be declared in-line anywhere in the code, allowing code
like
for var i:=1 to 10 do begin
  var k : Integer;
  (...)
end;

b) variables can be initialized to custom values upon declaration
var obj : TMyObject = TMyObject.Create;

c) if then else alternative feature 
var
  msg: String;
begin
  msg := "There are " + IntToStr(n) + " user" + if (n>1) then "s" else "";
end;

d) has support the operator ?? 
var 
  x: JSValue; 
begin 
  console.log(x ?? 1);  // it translates to something like x || 1
end; 

e) anonymous classes syntax, to emit literal objects:

type 
  THandleArray = array of JSValue; 

function list: THandleArray; 
begin 
result := [ 
  CLASS 
    l  := 'fieldA1'; external name 'length'; 
    w := 'fieldB1'; external name 'width'; 
  END, 
  CLASS 
    l  := 'fieldA2'; external name 'length'; 
    w := 'fieldB2'; external name 'width'; 
  END, 
  CLASS 
    l  := 'fieldA3'; external name 'length'; 
    w := 'fieldB3'; external name 'width'; 
  END]; 

end; 

to emit literal objects

function list() { 
  var Result = []; 
  Result = [{ 
      "width" : "fieldB1" 
      ,"length" : "fieldA1" 
  }, { 
      "width" : "fieldB2" 
      ,"length" : "fieldA2" 
  }, { 
      "width" : "fieldB3" 
      ,"length" : "fieldA3" 
  }].slice(); 
  return Result 
}; 

f) nested records syntax:

  TTestCustomJSONArraySimpleArray = record
    F: String;
    G: array of String;
    H: record
      H1: Integer;
      H2: String;
      H3: record
        H3a: Boolean;
        H3b: TSQLRawBlob;
      end;
    end;
    I: TDateTime;
    J: array of record
      J1: Byte;
      J2: TGUID;
      J3: TRecordEnum;
    end;
  end;

f) Partial classes
TWebCustomControl = partial class(TWebMovableControl)

g) type helpers
  TIntegerHelper = helper for Integer
      function ToString2 : String;
  end;





--
Sent from: http://pas2js.38893.n8.nabble.com/


------------------------------

Message: 2
Date: Sun, 30 Dec 2018 17:59:44 +0100 (CET)
From: Michael Van Canneyt <michael at freepascal.org>
To: warleyalex via Pas2js <pas2js at lists.freepascal.org>
Subject: Re: [Pas2js] The goal of pas2js
Message-ID: <alpine.DEB.2.20.1812301753160.24541 at home.telenet.be>
Content-Type: text/plain; format=flowed; charset=US-ASCII



On Sun, 30 Dec 2018, warleyalex via Pas2js wrote:

> Michael said: "I wish to repeat that the goal of pas2js is to make pascal
> available in the browser. 
> The goal is not to make pascal resemble Javascript." 
>
> However, I wish the general purpose and were not limited to pascal available
> in the browser.
> Pas2js should be an full extented feature language; the language can support
> several syntax and features/extensions introduced similar to Delphi Prism /
> Oxygene / DWScript / FPC, as well as various language extensions, "make
> pascal resemble Javascript".

Well, it is open source. you are of course free to fork the project.

Some of the things you ask will definitely be done, but not all.

The features that exist in Delphi/FPC will be ported. But we will not enter the
"complete" Javascript syntax world.

But if you want all Javascript features, simply program Javascript. 
With Typescript, you'll have complete javascript and type safety on top.

Michael.


------------------------------

Message: 3
Date: Sun, 30 Dec 2018 19:59:46 +0100 (CET)
From: Michael Van Canneyt <michael at freepascal.org>
To: pas2js discussions <pas2js at lists.freepascal.org>
Subject: Re: [Pas2js] The goal of pas2js
Message-ID: <alpine.DEB.2.20.1812301935090.31815 at home.telenet.be>
Content-Type: text/plain; format=flowed; charset=US-ASCII



On Sun, 30 Dec 2018, Michael Van Canneyt wrote:

>> Pas2js should be an full extented feature language; the language can 
> support
>> several syntax and features/extensions introduced similar to Delphi Prism /
>> Oxygene / DWScript / FPC, as well as various language extensions, "make
>> pascal resemble Javascript".
>
> Well, it is open source. you are of course free to fork the project.
>
> Some of the things you ask will definitely be done, but not all.
>
> The features that exist in Delphi/FPC will be ported. But we will not enter 
> the
> "complete" Javascript syntax world.
>
> But if you want all Javascript features, simply program Javascript. 
> With Typescript, you'll have complete javascript and type safety on top.

I am not satisfied with the tone of my reply, it comes across as much harder
than I intended it, for which I apologize.

Let me rephrase and clarify:

The goal of pas2js is to enable to use pascal in the browser.
There is still a long way to go to make this possible. In the first place,
all features available in Delphi/FPC must be suported.

Secondly, the compiler needs optimizations to emit more efficient Javascript. 
We just posted a page on the wiki:
http://wiki.freepascal.org/Pas2js_optimizations

The above program is already quite heavy, and will take quite a long time to
complete. Delphi and FPC are also moving targets, no doubt the list will
grow.

I wish to stress the need to focus on (and restrict ourselves to) the above goals.

If we want to convince component developers to port their components to Pascal, 
we must first of all offer what Delphi has.

The same is true for Lazarus: the LCL uses generics. If we ever want a real
lazarus LCL widgetset, we must support that.

Adding Javascript-specific features can be cunterproductive:
I don't know if anyone has already tried to work with pas2JS in Delphi 
(using TMS Web core) but if you include a unit that is not in the list of stub
units provided by TMS Software, Delphi stops working: no more code
completion, no 'code intelligence' or whatever it is called.

This is simply because we use external classes. Something that Delphi does
not understand. Adding more 'strange' language features will only make this
problem worse.

One could say that Lazarus can be made to understand it, and this is
correct. But delphi does not (yet) and I consider it important that we 
keep Delphi people on board.
Adding more Javascripts-pecific features while neglecting Delphi/FPC 
compatibility does not fit this purpose.

Lastly, I think it is important that most if not all pascal code is also 
usable outside pas2js. This will not work if we start adding Javascript-specific 
features.
(yes, I know about modeswitches, but they do not solve this problem)

The motto of Lazarus is code once, compile everywhere. I want to keep this
true as long as possible, and so the goal is: make pascal available on the
browser.

if, in 5 or 10 years, the browser has replaced all other platforms, we'll adjust
out goals obviously, but for the moment, I don't think this is relevant.

Last but not least: I firmly believe that we need lots of libraries instead
of language feature: 
Therefor I would like to see a lot of external class definitions for existing
libraries: Bootstrap, Angular, react, underscore, backbone. 
Excellent libraries that we should not reinvent. 
We already have the language features that we need to make these libraries
available.

So my belief is that we should focus on this, and not lament the lack of
perceived advantages of Javascript language features.

Michael.


------------------------------

Message: 4
Date: Sun, 30 Dec 2018 16:34:34 -0300
From: silvioprog <silvioprog at gmail.com>
To: pas2js discussions <pas2js at lists.freepascal.org>
Subject: Re: [Pas2js] The goal of pas2js
Message-ID:
    <CAKq_V2K7wr-w3JmgUEZOx0ZYJFUd_aHp1ftp0PeO+WAyZOuY0A at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sun, Dec 30, 2018 at 3:59 PM Michael Van Canneyt <michael at freepascal.org>
wrote:
[...]

> Last but not least: I firmly believe that we need lots of libraries instead
> of language feature:
> Therefor I would like to see a lot of external class definitions for
> existing
> libraries: Bootstrap, Angular, react, underscore, backbone.

[...]

Complementing: plus jsPDF & plugins. 😀

[...]

> Excellent libraries that we should not reinvent.

Michael.


-- 
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20181230/bbe7b2c2/attachment-0001.html>

------------------------------

Message: 5
Date: Sun, 30 Dec 2018 13:55:38 -0700 (MST)
From: warleyalex <warleyalex at yahoo.com.br>
To: pas2js at lists.freepascal.org
Subject: Re: [Pas2js] Dataset improved
Message-ID: <1546203338317-0.post at n8.nabble.com>
Content-Type: text/plain; charset=us-ascii

In my 5-minute-experiment, using TMS Web Core with Lazarus component,
"locate" function does not work for me :(

I dropped into Lazarus designer, basically 8 visual widgets:
  WebDataSource1: TWebDataSource;
  WebClientConnection1: TWebClientConnection;
  WebClientDataSet1: TWebClientDataSet;
  WebClientDataSet1_Length__cm_: TLongintField;
  WebDBLabel1: TWebDBLabel;
  WebEdit1: TWebEdit;
  WebButton1: TWebButton;
  WebButton2: TWebButton;

i) When I hit button/WebButton1 (Connect), the label/WebDBLabel1 component
displays "50" as expected! 
ii) When I click at WebButton2, it shows False (the edit/WebEdit1 is set to
50)

procedure TWebForm1.WebButton2Click(Sender: TObject);
begin
  console.log( 
    WebClientDataSet1.Locate('_Length__cm_',
WebEdit1.Text,[loCaseInsensitive, loPartialKey])
  );
end;

the JSON file is:
{
"ROW": [
    {
        "_Species_No": "90020",
        "_Category": "Triggerfishy",
        "_Common_Name": "Clown Triggerfish",
        "_Species_Name": "Ballistoides conspicillum",
        "_Length__cm_": 50,
        "_Length_In": "19.6850393700787",
        "_Notes": "Also known as the big spotted triggerfish.  Inhabits outer reef
areas and feeds upon crustaceans and mollusks by crushing them with powerful
teeth.  They are voracious eaters, and divers report seeing the clown
triggerfish devour beds of pearl oysters.\r\n\r\nDo not eat this fish. 
According to an 1878 account, \"the poisonous flesh acts primarily upon the
nervous tissue of the stomach, occasioning violent spasms of that organ, and
shortly afterwards all the muscles of the body.  The frame becomes rocked
with spasms, the tongue thickened, the eye fixed, the breathing laborious,
and the patient expires in a paroxysm of extreme suffering.\"\r\n\r\nNot
edible.\r\n\r\nRange is Indo-Pacific and East Africa to Somoa.\r\n\r\n              
\r\n                \r\n                \r\n                \r\n              
"
    },
    {
        "_Species_No": "90030",
        "_Category": "Snapper",
        "_Common_Name": "Red Emperor",
        "_Species_Name": "Lutjanus sebae",
        "_Length__cm_": 60,
        "_Length_In": "23.6220472440945",
        "_Notes": "Called seaperch in Australia.  Inhabits the areas around lagoon
coral reefs and sandy bottoms.\r\n\r\nThe red emperor is a valuable food
fish and considered a great sporting fish that fights with fury when hooked. 
The flesh of an old fish is just as tender to eat as that of the very
young.\r\n\r\nRange is from the Indo-Pacific to East Africa.\r\n\r\n              
\r\n                \r\n                \r\n                "
    }
]}




--
Sent from: http://pas2js.38893.n8.nabble.com/


------------------------------

Message: 6
Date: Sun, 30 Dec 2018 14:25:48 -0800
From: Ralf Quint <freedos.la at gmail.com>
To: pas2js at lists.freepascal.org
Subject: Re: [Pas2js] The goal of pas2js
Message-ID: <6dcb5b0f-1f6c-f8fd-2ff6-8df74295a40b at gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed

On 12/30/2018 8:13 AM, warleyalex via Pas2js wrote:
> Michael said: "I wish to repeat that the goal of pas2js is to make pascal
> available in the browser.
> The goal is not to make pascal resemble Javascript."
>
> However, I wish the general purpose and were not limited to pascal available
> in the browser.
> Pas2js should be an full extented feature language; the language can support
> several syntax and features/extensions introduced similar to Delphi Prism /
> Oxygene / DWScript / FPC, as well as various language extensions, "make
> pascal resemble Javascript".

Sorry, but I rather would stick with Michael's statement.

I don't have a direct use case for pas2js myself yet, but I would see 
its use in being able to to reuse as much of my existing Pascal code 
that runs natively in an application that runs in a web browser.

There is no point in shoehorning pas2js into "resembling Javascript". If 
you want that, you can use Javascript directly, no need to transpile 
from Pascal into Javascript. This would be IMHO just a waste of 
everybody's time, energy and resources...

Ralf


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



------------------------------

Message: 7
Date: Mon, 31 Dec 2018 00:03:04 +0100 (CET)
From: Michael Van Canneyt <michael at freepascal.org>
To: warleyalex via Pas2js <pas2js at lists.freepascal.org>
Subject: Re: [Pas2js] Dataset improved
Message-ID: <alpine.DEB.2.20.1812310000130.16671 at home.telenet.be>
Content-Type: text/plain; charset=US-ASCII; format=flowed



On Sun, 30 Dec 2018, warleyalex via Pas2js wrote:

> In my 5-minute-experiment, using TMS Web Core with Lazarus component,
> "locate" function does not work for me :(

How does that work ? 
It's not yet in TMS Web core, so you must use TJSONDataset ?

>    WebClientDataSet1.Locate('_Length__cm_',
> WebEdit1.Text

No type conversion is done at this point.

_Length__cm_ is an integer so you must privide an integer, not a string.


Michael.


------------------------------

Subject: Digest Footer

_______________________________________________
Pas2js maillist  -  Pas2js at lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js

------------------------------

End of Pas2js Digest, Vol 12, Issue 41
**************************************
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20181231/a36a18a5/attachment-0001.html>


More information about the Pas2js mailing list