Recent

Poll

What missing 'modern' language feature would you like to see implemented first in Pas2JS ?

Interfaces
26 (32.1%)
Anonymous functions
11 (13.6%)
Attributes
2 (2.5%)
Generics
15 (18.5%)
Type helpers
11 (13.6%)
I do not care, start on any feature...
6 (7.4%)
First make the compiler more strict in what it allows now (stuff like range checking etc.)
10 (12.3%)

Total Members Voted: 40

Voting closed: February 28, 2018, 09:22:09 am

Author Topic: Pas2JS missing language features ?  (Read 33463 times)

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: Pas2JS missing language features ?
« Reply #15 on: January 17, 2018, 02:56:49 pm »
Same in pas2js. It supports external classes, functions and variables. See unit js for examples.
You can even descend a new Pascal class from an external JS class.

And you can use asm-blocks to insert JS directly. But the external classes are so powerful, that even the RTL hardly use asm blocks.
Wow, good to know! So it seems it is now time to have a deep look into PAS2JS :-) Thanks for the hint!

Edit: found the section in the wiki: http://wiki.freepascal.org/pas2js#Importing_Javascript_classes Sorry for not reading carefully enough!
« Last Edit: January 17, 2018, 03:00:18 pm by dubst3pp4 »
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Pas2JS missing language features ?
« Reply #16 on: January 17, 2018, 10:19:28 pm »
I also miss "Type alias" very much. Too bad it's not in the list. I use it a lot.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

BeniBela

  • Hero Member
  • *****
  • Posts: 905
    • homepage
Re: Pas2JS missing language features ?
« Reply #17 on: January 18, 2018, 12:20:27 am »
Pointers would be nice :)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Pas2JS missing language features ?
« Reply #18 on: January 20, 2018, 02:00:42 pm »
@mattias
Can I use this also in native Free Pascal code? I've tried your interesting closure example, but in my version the value of y is initialized to the same value as x at every call:

No, this doesn't work in Free Pascal (or at least only by chance), because the value of y is loaded from the stack or a register depending on the calling convention. For this to work closure support is needed (which is already a Work In Progress) as that stores the value of y at a temporary, hidden class instance that is destroyed once the procedure reference moves out of scope again.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Pas2JS missing language features ?
« Reply #19 on: January 20, 2018, 02:02:23 pm »
Note that pas2js supports closures, so for example instead of using an anymous function you can use a sub function:

Delphi:
Code: Pascal  [Select][+][-]
  1. function MakeAdder(y: Integer): TFuncOfInt;
  2. begin
  3.   Result := function(x: Integer)
  4.     begin
  5.       Result := x + y;
  6.     end;
  7. end;
  8.  

Pas2js:
Code: Pascal  [Select][+][-]
  1. function MakeAdder(y: Integer): TFuncOfInt;
  2.   function Adder(x: Integer): integer;
  3.   begin
  4.     Result := x + y;
  5.   end;
  6. begin
  7.   Result:=@Adder;
  8. end;
  9.  

Please note that once anonymous functions/closures are supported in FPC I plan to extend it so that local functions/procedures can also be passed to "reference to procedure/function" variables as well. This way those that don't want to use anonymous functions due to their syntax can still enjoy their capabilities.

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: Pas2JS missing language features ?
« Reply #20 on: January 22, 2018, 11:37:15 am »
Thanks @PascalDragon, as a developer who's handling closures in JavaScript every day, my expectations were misleaded here, but what you wrote makes sense to me! :-)
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

warleyalex

  • New Member
  • *
  • Posts: 24
Re: Pas2JS missing language features ?
« Reply #21 on: January 30, 2018, 10:24:27 pm »
I just can not just believe, anonymous functions is not at top of the list.
It's so boring writing sub functions :( to do simple things.

Sergionn

  • New member
  • *
  • Posts: 8
Re: Pas2JS missing language features ?
« Reply #22 on: February 10, 2018, 11:27:19 am »
I just can not just believe, anonymous functions is not at top of the list.
It's so boring writing sub functions :( to do simple things.
Can't add something better to say!

 

TinyPortal © 2005-2018