| |
| Posted by Nick Treleaven in reply to Timon Gehr | PermalinkReply |
|
Nick Treleaven
Posted in reply to Timon Gehr
| On Sunday, 14 November 2021 at 23:05:03 UTC, Timon Gehr wrote:
...
>> nullable,
>
> Maybe:
>
> int*? x=null;
> writeln(*x); // error
>
> if(x) writeln(*x); // ok
Yes please.
>>> - type classes / some standard way to add UFCS methods to a type from another module that are then visible in an instantiated template from a third module
>
> import a: S;
> import b: rangeFun;
>
> auto ref front(ref S s){ ... }
> bool empty(ref S s){ ... }
> void popFront(){ ... }
>
> void main(){
> S s;
> rangeFun(s with(front, empty, popFront));
> alias T=S with (front,empty,popFront);
> T t=s;
> rangeFun(t);
> }
Does the `s with...` expression have to keep the same source type? If not we could make a type constructor template `methodize!(S,.)` which wraps the source type but has methods which wrap all public functions in the given module that have a first parameter of the source type.
>>> - `let Statement in Expression` expression
>
> void main(){
> auto z = {
> int x=1;
> int y=2;
> } in x+y;
> assert(z==3);
> }
>
>>> - `Expression where Statement` expression
>> ...
>
> void main(){
> auto z = x+y where{
> int x=1;
> int y=2;
> };
> assert(z==3);
> }
Isn't this sufficient?:
auto z = {
int x=1;
int y=2;
return x+y;
}();
> See above. Unfortunately I only had time to give some contrived examples.
>
>>> - mixin identifiers
>> example?
>
> static foreach((name, value);[("x",1),("y",2),("z",3)]){
> int mixin(name) = value;
> }
>
> writeln(x," ",y," ",z); // 1 2 3
Yes please.
>>> - template literals
>> example?
>
> enum sizes = staticMap!((B)!=>B.sizeof,Types);
I like 'alias template literal' syntax: `alias(B) => B.sizeof`
The only problem is currently `alias e = 5;` doesn't compile (at least on run.dlang.org). That is inconsistent as non-literal value expressions work.
>>> - consistent treatment of operators for built-in types, e.g. 1.opBinary!"+"(2) should work.
Seems we could add a few UFCS functions to object.d for that.
>>> - range literals
>> what's that?
>
> auto b = (fun(x) for x in iota(100) if bar(x));
>
> // equivalent to:
> // auto b = iota(100).filter!(x=>bar(x)).map!(x=>fun(x));
Maybe a template would make the current code a bit nicer:
auto b = iota(100).mapFilter!(x => bar(x) ? fun(x) : none);
>>> - strong variable updates (probably not happening)
>> what's that?
>
> int x=2;
> x="123";
> static assert(is(typeof(x)==string));
Seems bug prone unless it used special syntax to take a value of another type.
> auto f=File(x,"r");
> static assert(is(typeof(f)==File));
> f.close();
> static assert(is(typeof(f)==ClosedFile));
If we had affine typing, it would be simpler to just design `f.close` to invalidate any use of `f`, like your example calling `move` or `destroy`. (I suppose e.g. `f.closeForNow` would not invalidate `f` if needed).
|