Re: Proposal: Class Templates

2019-01-16 Thread Claude Pache
From what I understand (that is, not much), class templates are useful in strongly typed languages, so that one can have a family of classes that share the same implementation but that derive from different types; e.g. Stack for stacks of ints and Stack for stacks of strings. In JS, you can have

Re: Proposal: Class Templates

2019-01-16 Thread Isiah Meadows
Reflection would be nice, but that's about the only use case I can think of. Being able to tell a typed number array from a typed object array would be useful for some array processing optimizations and maybe stream processing optimization, but that's about it AFAIK. On Wed, Jan 16, 2019 at 04:42 C

Re: Proposal: Class Templates

2019-01-16 Thread Isiah Meadows
Also, it's worth mentioning Julia exists as language precedent here: it's got generic runtime types in the form of both classes and type aliases, despite being a dynamically typed, JIT-compiled language. On Wed, Jan 16, 2019 at 04:54 Isiah Meadows wrote: > Reflection would be nice, but that's abo

Re: Proposal: Class Templates

2019-01-16 Thread Michał Wadas
Isn't it already solvable by: const SizedArray = (size) => class SizedArray extends Array { constructor(...args) { if(args.length > size) throw new SyntaxError('Argument size is too big.') super(...args) } push(i) { if(this.length + 1 > size) throw new SyntaxError('Cannot push

Re: Proposal: Class Templates

2019-01-16 Thread Claude Pache
> Le 16 janv. 2019 à 13:57, ViliusCreator a écrit > : > > “Strongly typed” Strongly typed is not Statically typed. Python is strongly > typed for example. Strongly typed language means that `”something” + 1` will > throw error, Weakly typed means that `”something” + 1` will turn `1` into >

Re: Proposal: Class Templates

2019-01-16 Thread Augusto Moura
In the proposal: > ``` js > class SizedArray extends Array { > > constructor(...args) { > if(args.length > size) throw new SyntaxError('Argument size is too big.') > super(...args) > } > push(i) { > if(this.length + 1 > size) throw new SyntaxError('Cannot push items > anymore, ar

Re: Re: Proposal: Class Templates

2019-01-16 Thread ViliusCreator
“Strongly typed” Strongly typed is not Statically typed. Python is strongly typed for example. Strongly typed language means that `”something” + 1` will throw error, Weakly typed means that `”something” + 1` will turn `1` into string and add it to `something`, which will result in `something1`.

Re: Re: Proposal: Class Templates

2019-01-16 Thread ViliusCreator
Yes, you can do that. But then doesn’t that look ugly? `new (Abc(1, 2, 3)(4, 5, 6)`, vs `new Abc<4, 5, 6>(1, 2, 3)`. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus ___ es-discuss mailing list es

Re: Re: Proposal: Class Templates

2019-01-16 Thread T.J. Crowder
On Wed, Jan 16, 2019 at 1:01 PM ViliusCreator wrote: > > Yes, you can do that. But then doesn’t that look ugly? > > `new (Abc(1, 2, 3)(4, 5, 6)`, vs `new Abc<4, 5, 6>(1, 2, 3)`. You meant `new (Abc(4, 5, 6))(1, 2, 3)` vs. `new Abc<4, 5, 6>(1, 2, 3)`, right? There's not a *lot* in it... :-) The p

Re: Re: Proposal: Class Templates

2019-01-16 Thread ViliusCreator
You could use ```js new Abc`abc`(‘abc’) ``` But you could only use strings. What about constructors? You would need to use ```js const thatConstructor = (new Function(‘return ’ + t))() ``` But it would only give what is defined in that constructor. --- This email has been checked for viruses by A

Re: Re: Proposal: Class Templates

2019-01-16 Thread ViliusCreator
Also, using `new (Abc(4, 5, 6))(1, 2, 3)` causes error ` Uncaught TypeError: Abc(...) is not a constructor`. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus ___ es-discuss mailing list es-discus

Re: Re: Proposal: Class Templates

2019-01-16 Thread Jordan Harband
https://github.com/michaelficarra/proposal-first-class-protocols may be a more palatable approach here. On Wed, Jan 16, 2019 at 9:41 AM ViliusCreator wrote: > Also, using `new (Abc(4, 5, 6))(1, 2, 3)` causes error ` Uncaught > TypeError: Abc(...) is not a constructor`. > > > > >

Re: Re: Proposal: Class Templates

2019-01-17 Thread T.J. Crowder
On Wed, Jan 16, 2019 at 5:29 PM ViliusCreator wrote: > You could use > > ```js > new Abc`abc`(‘abc’) > ``` I think you must have missed [my earlier reply]( https://esdiscuss.org/topic/proposal-class-templates#content-7), which covered that, and also the fact that the major problem with using `<>`

Re: Re: Proposal: Class Templates

2019-01-17 Thread ViliusCreator
But then `Abc(4, 5, 6) !== Abc(4, 5, 6)`. Using `Abc.constructor = class Abc$ {}` and then returning `Abc.constructor` won’t make it work. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus ___ es-d

Re: Re: Proposal: Class Templates

2019-01-17 Thread Ranando King
It can still be made to work... ```js const Abc = (function() { const cache = new Map; function readCache(c, arg, val=new Map) { if (!c.has(a)) c.set(a, val); return c.get(arg); } return (a, b, c) => { // ...optionally do something with a, b, an