October 20, 2021

On Wednesday, 20 October 2021 at 19:41:52 UTC, Kagamin wrote:

>

Like many people here I tried to design my own language, but I noticed that I can't get (logically) puristic concepts into an adequate form. I grew suspicious it's because the problem domain itself is impure, so puristic concepts can't be adequate, and an adequate language should elegantly incorporate impurity instead of evading it at all wasteful costs. I also take this approach in program design, somehow a line is easy to see that the component shouldn't be more pure than this.

I've tried as well, but lack of experience and lack of attention span has made this hard to achieve.

I had a crazy plan at one point to make my own assembler, then make my own language on top of that assembler, for whatever dumb reason.

The main point of this post was to explore what D could've possibly looked like, based on the ideas of the forum dwellers.

Here's a very rough estimation of other people's proposals:

class A {}
class B : A {}

// @safe, @pure, @nothrow, etc all applied automatically by the compiler
// Very small executable because we don't import phobos
// Slightly big executable because we use the runtime (GC)

void func(const(A)* a) {} // Adam's proposal
void funcb(const(B)* b) { func(b); // I assume upcasting still works }

void intPromotion() {
    byte b;
    b = 2 + 3; // byte
    b = b << 1; // byte
}

int* pointers() {
    int^ managed = new int;
    // Explicit nullable
    int*? raw = cast(int*?)malloc(int.sizeof);

    // ! == "Definitely not null"
    // Using the proposed || == x ? x : y syntax
    return raw! || managed.ptr;
}

void nullChaining(SomeClass*? value) {
   value?.subvalue?.func();
}
October 20, 2021
On Wed, Oct 20, 2021 at 07:41:52PM +0000, Kagamin via Digitalmars-d wrote:
> Like many people here I tried to design my own language, but I noticed that I can't get (logically) puristic concepts into an adequate form. I grew suspicious it's because the problem domain itself is impure, so puristic concepts can't be adequate, and an adequate language should elegantly incorporate impurity instead of evading it at all wasteful costs. I also take this approach in program design, somehow a line is easy to see that the component shouldn't be more pure than this.

This is why I like D's approach to (functional) purity: it's defined in terms of its effect on the outside world, rather than internal purity (in the sense of a real functional language like Haskell).  As Andrei once put it, you can have all the imperative, impure, dirty laundry you want inside your function body, but as long as the outside world can't see it, you're effectively a pure function to them.

Also, one of D's stated goals is to be a systems programming language, in the sense of being able to implement the GC within the language itself instead of resorting to some other language required to perform the unsafe operations required to implement a GC. I.e., it's still D under the hood, not some other language.  For this, there must be escape hatches from things like @safe or immutable, since the GC must be able to manipulate untyped memory without running afoul of immutability (e.g., it must be able to cast mutable memory from its heap into an immutable object during allocation, and vice versa during collection). To user code, the memory is truly immutable, but the GC is actually performing low-level casts to create it under the hood.

IOW, things like purity, immutability, etc., apply to the outward-facing APIs, but the implementation need not be thus constrained as long as it continues to fulfill the promises of attributes of the API.


T

-- 
Too many people have open minds but closed eyes.
October 21, 2021

On Wednesday, 20 October 2021 at 15:58:49 UTC, Adam D Ruppe wrote:

>

On Wednesday, 20 October 2021 at 15:53:53 UTC, H. S. Teoh wrote:

>

Object* is the pointer. There's nothing going on behind the scenes.

well tho does obj++; move the pointer or call the operator on the class?

I don't think this syntax is ideal (I kinda prefer the old Object ref proposal), but just it is something interesting to think about.

Umm, do we have to do anything in this case?

It'll be the same as for structs:

import std;

struct S{
    void opUnary(string s : "++")(){
    	writeln(`called opUnary!("++")()`);
    }
    int a;
}

void func(S* param){
    writeln((*param).a);
    (*param)++;
}
void main()
{
 	S s;
    func(&s);
}

You use ref, you can't do pointer arithmetic anymore.

October 21, 2021

On Wednesday, 20 October 2021 at 18:45:42 UTC, kyle wrote:

>

On Wednesday, 20 October 2021 at 09:47:54 UTC, SealabJaster wrote:

>

If you could make any changes to D, what would they look like?

I want some non-ridiculous way to use +=, -=, *=, etc with property functions. Whether that's with @property or otherwise. And I want https://issues.dlang.org/show_bug.cgi?id=21321 (Class with unimplemented interface method compiles, links, then segfaults, if inherited through abstract base class) fixed.

I have a PR request that address this, if you want to check it out.

-Alex

October 21, 2021

On Thursday, 21 October 2021 at 14:33:02 UTC, 12345swordy wrote:

>

On Wednesday, 20 October 2021 at 18:45:42 UTC, kyle wrote:

>

On Wednesday, 20 October 2021 at 09:47:54 UTC, SealabJaster wrote:

>

If you could make any changes to D, what would they look like?

I want some non-ridiculous way to use +=, -=, *=, etc with property functions. Whether that's with @property or otherwise. And I want https://issues.dlang.org/show_bug.cgi?id=21321 (Class with unimplemented interface method compiles, links, then segfaults, if inherited through abstract base class) fixed.

I have a PR request that address this, if you want to check it out.

-Alex

Looks like it would be a great quality of life change along with Adam's "Implement shortened methods with => syntax" (#11833) PR. I'm curious exactly what is meant by "Disallow parameters for property functions". Does that mean the only allowed parameter is 1 in the setter? C# pays my bills and implementing properties with it is a rare thing that I find much nicer about C# than D, and these 2 PRs would bring D much closer there. Thanks for your work.

October 21, 2021
On Wednesday, 20 October 2021 at 21:05:44 UTC, Ali Çehreli wrote:
> Me neither because I was following convention in C++: "Pass inherited types by reference because there is slicing." That rule renders C++ classes (and structs) of inheritance hierarchies "reference types". I like D's (and Java's and C#'s) approach here.

That is the classical Simula model. Simula did however use ":-" for reference assigment and ":=" for value assignment, so it was always clear to the user that objects followed reference semantics.


October 21, 2021

On Wednesday, 20 October 2021 at 09:47:54 UTC, SealabJaster wrote:

>

Just for giggles, without pesky things like breaking changes; rational thinking, logical reasoning behind the changes, etc.

What interesting changes would you make to the language, and what could they possibly look like?

Unique/Isolated; A way to declare or require that an object (both struct and class) cannot have more than one reference.

For instance, it is perfectly fine to move an AA across thread boundaries if there is only one reference to it. But in the general you can't because you can't proof there is.

This touches on @live a bit, but @live is put on functions whereas I want it on objects (class+structs).

October 22, 2021
On Thursday, 21 October 2021 at 20:26:47 UTC, Sebastiaan Koppe wrote:
> Unique/Isolated; A way to declare or require that an object (both struct and class) cannot have more than one reference.
>
> For instance, it is perfectly fine to move an AA across thread boundaries if there is only one reference to it. But in the general you can't because you can't proof there is.
>
> This touches on @live a bit, but @live is put on functions whereas I want it on objects (class+structs).

It's the difference between linear types and uniqueness types.  'Linear' is part of the api contract of the callee: it promises not to change the number of references to an object.  While 'unique' is part of the api contract of the caller: it promises an object to which there is only one object.
October 24, 2021

On Wednesday, 20 October 2021 at 09:47:54 UTC, SealabJaster wrote:

>

I think the language is lovely -- my sole wish is that there was a bit more tooling integrated into the core of language.

Mostly a Language Server. I cannot use UFCS at all because Code-D for VS Code isn't able to properly resolve them using the community Serve-D lang server.

It's not the end of the world, I just nest the functions instead, but it sort of ruins the beauty of the language.

October 24, 2021

On Sunday, 24 October 2021 at 17:42:28 UTC, Gavin Ray wrote:

>

On Wednesday, 20 October 2021 at 09:47:54 UTC, SealabJaster wrote:

>

I think the language is lovely -- my sole wish is that there was a bit more tooling integrated into the core of language.

Mostly a Language Server. I cannot use UFCS at all because Code-D for VS Code isn't able to properly resolve them using the community Serve-D lang server.

It's not the end of the world, I just nest the functions instead, but it sort of ruins the beauty of the language.

Iirc there are some pr for this