Compiler or Interpreter or Hybrid

2020-11-22 Thread evanchitger via Digitalmars-d-learn

https://forum.dlang.org/post/qatjshmizzgvsfilk...@forum.dlang.org

On Thursday, 21 April 2016 at 02:06:00 UTC, newB wrote:
How is D  implemented? (Compiler, Interpreter and Hybrid). Can 
you please explain why?


A computer program is usually written in high level language 
described as a source code. The difference between an interpreter 
and compiler is the point at which a source code is actually 
executed. This means that when convert source code into machine 
code , we use either a compiler or an interpreter. So generally 
categorizing computer languages by "compiled" or "interpreted" 
doesn't make much sense. Now a days, interpreting Vs. compiling 
is a trade-off, with time spent compiling often being rewarded by 
better runtime performance , but an interpretative environment 
giving more opportunities for interaction .


http://net-informations.com/q/diff/cvsi.html


Re: How to construct a tree data structure with differently static nodes types

2020-11-22 Thread data pulverizer via Digitalmars-d-learn

On Monday, 23 November 2020 at 01:24:54 UTC, Max Haughton wrote:


If you want to keep things simple, use OOP (classes).

If you need to use structs, the "sumtype" may be just what you 
need (it's a bit more lightweight than std.algebraic in the 
standard library). If you want to implement this yourself then 
you need to write something called a tagged union.


I'm looking for a data structure that is fully specified at 
compile time and statically dispatched rather than dynamically 
dispatched like OOP and so forth.


Re: How to construct a tree data structure with differently static nodes types

2020-11-22 Thread data pulverizer via Digitalmars-d-learn
On Monday, 23 November 2020 at 01:20:04 UTC, data pulverizer 
wrote:

Hi all,

I am trying to construct a tree data structure composed of 
differently (statically) typed nodes. The basic case is a 
binary tree. So you have a node like:


```
struct Node(T)
{
  T value;
  Node* next;
  Node* prev;
}

void main()
{
  auto x = Node!(int)(2);
  auto y = Node!(double)(3.2);
  x.next = &y; //gives error
}
```
Error: cannot implicitly convert expression & y of type 
Node!double* to Node!int*


So implicity Node!(T) will produce an object with prev, and 
next type Node!(T)*. But once I give them different types:


```
struct Node(T, P, N)
{
  T value;
  Node!(P...)* prev;
  Node!(N...)* next;
}
```

I can no longer specify the types at all, they become 
circularly referenced. Would appreciate the solution to this.


Many thanks.


p.s. Something equivalent can be built using tuples but it's less 
convenient to write code for.


Re: How to construct a tree data structure with differently static nodes types

2020-11-22 Thread Max Haughton via Digitalmars-d-learn
On Monday, 23 November 2020 at 01:20:04 UTC, data pulverizer 
wrote:

Hi all,

I am trying to construct a tree data structure composed of 
differently (statically) typed nodes. The basic case is a 
binary tree. So you have a node like:


```
struct Node(T)
{
  T value;
  Node* next;
  Node* prev;
}

void main()
{
  auto x = Node!(int)(2);
  auto y = Node!(double)(3.2);
  x.next = &y; //gives error
}
```
Error: cannot implicitly convert expression & y of type 
Node!double* to Node!int*


So implicity Node!(T) will produce an object with prev, and 
next type Node!(T)*. But once I give them different types:


```
struct Node(T, P, N)
{
  T value;
  Node!(P...)* prev;
  Node!(N...)* next;
}
```

I can no longer specify the types at all, they become 
circularly referenced. Would appreciate the solution to this.


Many thanks.


If you want to keep things simple, use OOP (classes).

If you need to use structs, the "sumtype" may be just what you 
need (it's a bit more lightweight than std.algebraic in the 
standard library). If you want to implement this yourself then 
you need to write something called a tagged union.


How to construct a tree data structure with differently static nodes types

2020-11-22 Thread data pulverizer via Digitalmars-d-learn

Hi all,

I am trying to construct a tree data structure composed of 
differently (statically) typed nodes. The basic case is a binary 
tree. So you have a node like:


```
struct Node(T)
{
  T value;
  Node* next;
  Node* prev;
}

void main()
{
  auto x = Node!(int)(2);
  auto y = Node!(double)(3.2);
  x.next = &y; //gives error
}
```
Error: cannot implicitly convert expression & y of type 
Node!double* to Node!int*


So implicity Node!(T) will produce an object with prev, and next 
type Node!(T)*. But once I give them different types:


```
struct Node(T, P, N)
{
  T value;
  Node!(P...)* prev;
  Node!(N...)* next;
}
```

I can no longer specify the types at all, they become circularly 
referenced. Would appreciate the solution to this.


Many thanks.


Re: d++: Error: Could not execute `dmd c.o .\foo.d -offoo.exe`:

2020-11-22 Thread Jack via Digitalmars-d-learn

On Sunday, 22 November 2020 at 03:05:45 UTC, kinke wrote:

On Saturday, 21 November 2020 at 17:25:46 UTC, Jack wrote:

I got the error:


Error: Could not execute `dmd c.o .\foo.d -offoo.exe`:
Error: unrecognized file extension o


dmd version:

DMD32 D Compiler v2.094.1-dirty


gcc version:

gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)


DMD expects .obj for Windows. So you'll probably have to use 
the MS compiler or clang to emit an MSVC-compatible object 
file, and then use either -m32mscoff or -m64 for DMD.


that worked, thanks! i used MS C compiler to get the object file

cl /arch:IA32 /c c.c

then:

d++ -m32mscoff foo.dpp c.obj

worked fine


Re: Git-repo-root relative path

2020-11-22 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 18 November 2020 at 23:43:15 UTC, Petar Kirov 
[ZombineDev] wrote:

https://gist.github.com/PetarKirov/b4c8b64e7fc9bb7391901bcb541ddf3a


Thanks a lot!