Re: Tips on TCP socket to postgresql middleware

2022-02-23 Thread eugene via Digitalmars-d-learn

On Thursday, 24 February 2022 at 06:54:07 UTC, eugene wrote:

Wagner F. et al
Modeling Software with Finite State Machines: A Practical 
Approach


I've adopted some ideas from this book to POSIX/Linux API.


Ah! I also have EDSM for bare metal (AVR8 to be exact)
There is [some 
description](http://zed.karelia.ru/go.to/for.all/software/avr8-edsm) (in Russian), but you can look to the [C-source](http://zed.karelia.ru/mmedia/bin/avr8-edsm-r0.tar.gz)






Re: Will it be possible to write a GCC frontend in D?

2022-02-23 Thread rempas via Digitalmars-d-learn
On Wednesday, 23 February 2022 at 21:33:00 UTC, Adam D Ruppe 
wrote:


There is no branch, it is just part of the upstream mainline. 
see:


https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=gcc/d/dmd;h=454baa71a0d270fb891acdda6fd0215a3d6cb588;hb=HEAD


Oh, this is what I mean by saying "branch" so my mistake. Thanks 
for the info!


and yeah it is extern(C++). importC isn't going to be helpful, 
but still, gdc proves you can make a gcc frontend in d.


Yeah, If you put it that way. Tbh, I already knew it was possible 
to do is this way because I know GDC's frontend was written in D. 
However, I was wondering if we can have C bindings but it seems 
that's not the case.


Re: Tips on TCP socket to postgresql middleware

2022-02-23 Thread eugene via Digitalmars-d-learn

On Thursday, 24 February 2022 at 06:30:51 UTC, Tejas wrote:

On Wednesday, 23 February 2022 at 09:34:56 UTC, eugene wrote:
On Tuesday, 22 February 2022 at 20:19:39 UTC, Chris Piker 
wrote:

[...]


As you might have been already noted,
the key idea is to implement SM explicitly,
i.e we have states, messages, actions, transitions
and extremely simple engine (reactTo() method)

[...]


I remember you once mentioned a book that you used to learn 
this particular software design technique

Could you please name it again? Thank you in advance


Wagner F. et al
Modeling Software with Finite State Machines: A Practical Approach

I've adopted some ideas from this book to POSIX/Linux API.
see also http://www.stateworks.com/



Re: Tips on TCP socket to postgresql middleware

2022-02-23 Thread Tejas via Digitalmars-d-learn

On Wednesday, 23 February 2022 at 09:34:56 UTC, eugene wrote:

On Tuesday, 22 February 2022 at 20:19:39 UTC, Chris Piker wrote:

[...]


As you might have been already noted,
the key idea is to implement SM explicitly,
i.e we have states, messages, actions, transitions
and extremely simple engine (reactTo() method)

[...]


I remember you once mentioned a book that you used to learn this 
particular software design technique


Could you please name it again? Thank you in advance


Re: how to return map(fn)

2022-02-23 Thread Steven Schveighoffer via Digitalmars-d-learn

On Wednesday, 23 February 2022 at 16:48:00 UTC, steve wrote:
Thank you both a lot for your help. I am new to D so all of 
this is incredibly helpful. This seems like an amazing 
community!


@Ali I will have a look at std.functional as I think this is 
really what I was looking for. Until then, I have solved the 
problem with a simple class (e.g. below). I'm sure its not a 
particularly good way of doing it but it will work for now :). 
Also thank you for your book, its amazing!



```d
class Mapper
{
float function(float) fn;

this(float function(float) func)  {this.fn = func;}

float[] opCall(float[] x){
auto arr = new float[x.length];
foreach (i,elem; x) { arr[i] = fn(elem);}
return arr;
}

}


float times_two(float x) {return 2*x;}


void main() {

import std.stdio;

Mapper map2x = new Mapper(_two);
writeln(map2x([1., 2., 3.]));
}
```


I'm not sure what programming languages you are used to, so let 
me just show you the idiomatic D way ;)


```d
float times_two(float x) {return 2*x;}

// if you would rather make sure the result is an array
float[] times_two_array(float[] arr) {
   import std.algorithm; // for map
   import std.array; // for array
   return arr
  .map!times_two // map your function
  .array; // convert to an array
}

void main() {
   import std.stdio;
   import std.algorithm; // for map
   alias map2x = map!times_two;
   writeln(map2x([1., 2., 3.]));
   float[] arr2 = times_two_array([1., 2., 3.]);
   writeln(arr2);
}
```

-Steve



Re: Will it be possible to write a GCC frontend in D?

2022-02-23 Thread Adam D Ruppe via Digitalmars-d-learn

On Wednesday, 23 February 2022 at 20:42:10 UTC, rempas wrote:

Do you know where is the updated GDC branch btw?


There is no branch, it is just part of the upstream mainline. see:

https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=gcc/d/dmd;h=454baa71a0d270fb891acdda6fd0215a3d6cb588;hb=HEAD

and yeah it is extern(C++). importC isn't going to be helpful, 
but still, gdc proves you can make a gcc frontend in d.


Re: Will it be possible to write a GCC frontend in D?

2022-02-23 Thread rempas via Digitalmars-d-learn
On Wednesday, 23 February 2022 at 20:19:04 UTC, Adam D Ruppe 
wrote:


I should hope so, otherwise gdc wouldn't exist, yet it does.


[extern 
(C++)](https://github.com/D-Programming-GDC/gdc/tree/master/gcc/d/dmd) and manually creating the decorations. At least that's my understanding of browsing the source and that was until 2018. Do you know where is the updated GDC branch btw?


Re: Will it be possible to write a GCC frontend in D?

2022-02-23 Thread rempas via Digitalmars-d-learn

On Wednesday, 23 February 2022 at 20:06:58 UTC, bachmeier wrote:


Not sure if this is the same thing (a link would have helped) 
but [this is done in 
C](https://www.cs.usfca.edu/~galles/compilerdesign/C/csupport.html)


Thank you! However, one things that I didn't mentioned is that 
GCC was once written in C but now it is written in C++ so the 
date this was created matters.


Re: Will it be possible to write a GCC frontend in D?

2022-02-23 Thread Adam D Ruppe via Digitalmars-d-learn

On Wednesday, 23 February 2022 at 19:58:45 UTC, rempas wrote:

Will it be possible to write a GCC frontend in D?


I should hope so, otherwise gdc wouldn't exist, yet it does.


Re: Will it be possible to write a GCC frontend in D?

2022-02-23 Thread bachmeier via Digitalmars-d-learn

On Wednesday, 23 February 2022 at 19:58:45 UTC, rempas wrote:
I'm using a book called "modern compiler design (version 2)" to 
learn how to create compiler and I thought about learning and 
applying this knowledge on writing a GCC frontend just for fun 
to see where this gets me. However, I've seen some tutorials 
and I've seen people doing it in C++. Now, I want to do it in D 
(of course!). My problem is that I don't if the headers are 
using C++ features because If this is possible then I won't be 
able to use ImportC to "automatically" get bindings to use in 
D. Any ideas?


Not sure if this is the same thing (a link would have helped) but 
[this is done in 
C](https://www.cs.usfca.edu/~galles/compilerdesign/C/csupport.html)


Will it be possible to write a GCC frontend in D?

2022-02-23 Thread rempas via Digitalmars-d-learn
I'm using a book called "modern compiler design (version 2)" to 
learn how to create compiler and I thought about learning and 
applying this knowledge on writing a GCC frontend just for fun to 
see where this gets me. However, I've seen some tutorials and 
I've seen people doing it in C++. Now, I want to do it in D (of 
course!). My problem is that I don't if the headers are using C++ 
features because If this is possible then I won't be able to use 
ImportC to "automatically" get bindings to use in D. Any ideas?


Re: how to return map(fn)

2022-02-23 Thread steve via Digitalmars-d-learn
Thank you both a lot for your help. I am new to D so all of this 
is incredibly helpful. This seems like an amazing community!


@Ali I will have a look at std.functional as I think this is 
really what I was looking for. Until then, I have solved the 
problem with a simple class (e.g. below). I'm sure its not a 
particularly good way of doing it but it will work for now :). 
Also thank you for your book, its amazing!



```
class Mapper
{
float function(float) fn;

this(float function(float) func)  {this.fn = func;}

float[] opCall(float[] x){
auto arr = new float[x.length];
foreach (i,elem; x) { arr[i] = fn(elem);}
return arr;
}

}


float times_two(float x) {return 2*x;}


void main() {

import std.stdio;

Mapper map2x = new Mapper(_two);
writeln(map2x([1., 2., 3.]));
}```


Re: Tips on TCP socket to postgresql middleware

2022-02-23 Thread eugene via Digitalmars-d-learn

On Tuesday, 22 February 2022 at 20:19:39 UTC, Chris Piker wrote:

credit you for the basic ideas


As you might have been already noted,
the key idea is to implement SM explicitly,
i.e we have states, messages, actions, transitions
and extremely simple engine (reactTo() method)

Switch-based implementation of SMs is probably normal
for text/token driven SMs (parsers),
but is not good for event/message driven SMs (i/o and alike).

Remember main OOP principle, as it is understood by Alan Key?
It is message exchanging, not class hierarchy.
In this sense this craft is OOP twice, both classes and
message exchanging.

Another important point is SM decomposition & hierarchy
(I mean master/slave (or customer/provider) relation here,
not 'A is B' relation) - instead of having one huge SM
I decompose the task into subtasks and construct various SMs.
See for example that echo-server - it has 3 level hierarchy
of states machines:

LISTENER <-> {WORKERS} <-> {RX,TX}

When I wrote the very first version of EDSM engine
(more than 5 years ago, may be 7 or so), I...
I was just stuck - how to design machines themselves?!?
Well, the engine is simple, but what next? How do I choose states?
After a while I came to a strong rule - as long as I
want to send/recv some "atomic" portion of data,
it is a state (called stage in D version)!
Then as a result of elimination of code duplcation
I "invented" kinda universal RX and TX machine and so on...

In general I've found SM very nice way of designing
(networking) software. Enjoy! :)




Re: Tips on TCP socket to postgresql middleware

2022-02-23 Thread eugene via Digitalmars-d-learn

On Tuesday, 22 February 2022 at 20:19:39 UTC, Chris Piker wrote:

On Monday, 21 February 2022 at 07:00:52 UTC, eugene wrote:

On Monday, 21 February 2022 at 04:46:53 UTC, Chris Piker wrote:

On Sunday, 20 February 2022 at 18:00:26 UTC, eugene wrote:
I'm adverse to reading it closely since there was no license 
file and don't want to accidentally violate copyright.


:) I think WTFPL will do :)

If you want to add this file (or similar) to your sources, 
http://www.wtfpl.net/txt/copying/, but with your name in the 
copyright line I'd be happy to put the D version through it's 
paces and credit you for the basic ideas.  I would not have 
thought of this formalism on my own (at least not right away) 
and want to give credit where it's due.


ok
http://zed.karelia.ru/0/e/edsm-2022-02-23.tar.gz
added 2 files, AUTHOR & LICENSE