Re: More Elegant Settable Methods?

2023-01-29 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 21 January 2023 at 23:07:45 UTC, jwatson-CO-edu 
wrote:
I am trying to create a struct with a settable method that has 
access to the struct scope.

Is this the only way?
Is there a way to give access without explicitly passing `this`?


Why not use the delegate? What exactly do you want to do?  Set 
after constructor or assign delegate?


```d
struct S {
float /*--*/ a;
float /*--*/ b;

    void delegate(float x, float y) set;
    auto sum() { return a + b; }
}

void main() {
    S s;
    s.set = (x, y) {
        s.a = x;
        s.b = y;
    };
    s.set(10, 20);
    assert(s.sum == 30);
}
```

SDB@79


Which TOML package, or SDLang?

2023-01-29 Thread Daren Scot Wilson via Digitalmars-d-learn

So, which package do I use for TOML?

I find these three:

* toml-foolery  (Andrej Petrović)
* toml-d, or toml.d (oglu on github) at ver 0.3.0
* toml, (dlang community on github) at ver 2.0.1

I'm guessing from version numbers that the third one, toml, is 
officially good for real world use. But I wonder if there are 
good reasons to use the others.


Also, a low-effort search for TOML in the D world turned up 
SDLang, where the substring "DLang" has nothing to do with dlang, 
the common short name for D Language. SDLang looks nice. Should I 
ditch TOML for it?


I just realized - it's been ages since I've dealt with config 
files, beyond editing them as an end user. I work on existing 
software where someone else made the choiced and wrote the code, 
or it's a small specialized project not needing config. I'm a 
config caveman!


This is for a small fun personal project with potential show-off 
value, available on github but too primitive for now to mention. 
Controlling hardware, needing to store device info to recall for 
later runs. There are zero compatibility or standards issues to 
consider.  Whatever is simplest to implement and tinker with is 
the winner.


Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-29 Thread RTM via Digitalmars-d-learn
On Saturday, 28 January 2023 at 23:19:35 UTC, ProtectAndHide 
wrote:



That is, you can do OOP without classes


How so? Every OOP definition includes classes (encapsulation + 
inheritance).


Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-29 Thread thebluepandabear via Digitalmars-d-learn
I hate a world with the classes. I can do almost anything I 
want without the classes. The software world soared above C 
without classes.


SDB@79


As I said in my email to you -- each to their own.

There's no point in arguing about whether OOP is the best method 
of doing things or procedural is, it's up to the person's 
personal preferences.


Personally, I like interfaces, I like abstract classes, I like 
inheritance, I like polymorphism. A lot of things can be done 
with pure structs, but sometimes that extra OOP stuff is needed 
too.


Re: How to get the body of a function/asm statement in hexadecimal

2023-01-29 Thread Ali Çehreli via Digitalmars-d-learn

On 1/29/23 14:19, max haughton wrote:

> it is not trivial to find where the *end* of a
> function is

I suspected as much and did run ...

> objdump

... to fool myself into thinking that 0xc3 was . Well, arguments 
e.g. pointer values can have 0xc3 bytes in them. So, yes, I am fooled! :)


Ali



Re: How to get the body of a function/asm statement in hexadecimal

2023-01-29 Thread max haughton via Digitalmars-d-learn
On Sunday, 29 January 2023 at 21:45:11 UTC, Ruby the Roobster 
wrote:

I'm trying to do something like

```d
void main()
{
auto d = 
*d.writeln;
}

void c()
{
}
```

In an attempt to get the hexadecimal representation of the 
machine code of a function.  Of course, function pointers 
cannot be dereferenced.  What do?


Furthermore, I would like to be able to do the same for an 
`asm` statement.


The function pointer can be casted to a pointer type. It is worth 
saying, however, that it is not trivial to find where the *end* 
of a function is. In X86 it's not even trivial to find the end of 
an instruction!


If you'd just like the bytes for inspection, you could use a tool 
like objdump. For more complicated situations you will need to 
use a hack to tell you where the end of a function is.


Re: How to get the body of a function/asm statement in hexadecimal

2023-01-29 Thread Ali Çehreli via Digitalmars-d-learn

On 1/29/23 13:45, Ruby the Roobster wrote:

> Of course, function pointers cannot be dereferenced.

Since you want to see the bytes, just cast it to ubyte*. The following 
function dumps its own bytes:


import std;

void main() {
enum end = 0xc3;
for (auto p = cast(ubyte*)&_Dmain; true; ++p) {
writefln!" %02x"(*p);
if (*p == end) {
break;
}
}
}

(It can be written more elegantly as a range expression.)

> Furthermore, I would like to be able to do the same for an `asm` 
statement.


I don't know how to get the address of asm blocks.

Ali



How to get the body of a function/asm statement in hexadecimal

2023-01-29 Thread Ruby the Roobster via Digitalmars-d-learn

I'm trying to do something like

```d
void main()
{
auto d = 
*d.writeln;
}

void c()
{
}
```

In an attempt to get the hexadecimal representation of the 
machine code of a function.  Of course, function pointers cannot 
be dereferenced.  What do?


Furthermore, I would like to be able to do the same for an `asm` 
statement.


Re: Non-ugly ways to implement a 'static' class or namespace?

2023-01-29 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 28 January 2023 at 23:19:35 UTC, ProtectAndHide 
wrote:

On Wednesday, 25 January 2023 at 15:43:46 UTC, ryuukk_ wrote:


using static class and static function is not "OOP way" of 
doing things, it's a hack to mimic procedural style because 
Java doesn't have proper modules / scoping


mimicking the shortcomings of Java is a bad idea imo

D empowers you to write simple yet effective code, you should 
give it a try and embrace it


Classes (and this includes static classes) are 'one' means of 
encapsulation.


I hate a world with the classes. I can do almost anything I want 
without the classes. The software world soared above C without 
classes.


SDB@79