Re: Blog Post #69: TextView and TextBuffer Basics

2019-09-10 Thread Zekereth via Digitalmars-d-learn

On Tuesday, 10 September 2019 at 08:29:59 UTC, Ron Tarrant wrote:
This morning's discussion covers the basic workings and 
relationship between the TextView and TextBuffer widgets. 
Here's the link: 
https://gtkdcoding.com/2019/09/10/0069-textview-and-textbuffer.html


Yes, thank you very much. Your tutorials are a great help! Keep 
it up! Thanks again.


Re: Undefined reference - built from source DMD

2019-09-10 Thread Stefanos Baziotis via Digitalmars-d-learn
On Tuesday, 10 September 2019 at 15:01:11 UTC, Stefanos Baziotis 
wrote:
On Tuesday, 10 September 2019 at 14:47:00 UTC, Nicholas Wilson 
wrote:


Is this you have built your own DMD


Yes



I have branched to an old PR (4 months ago) and the problem 
doesn't exist.




Re: LDC asm for int128

2019-09-10 Thread Nicholas Wilson via Digitalmars-d-learn

On Tuesday, 10 September 2019 at 06:18:05 UTC, Newbie2019 wrote:
I want to translate this c code into d (build with ldc), so I 
can use -flto and inline with other code.


uint64_t _wymum(uint64_t A, uint64_t B){
__uint128_t r = A ;
r *= B;
return  (r>>64)^r;
}

Do i need ASM or is there a easy way to implement it ?


Easiest way is to use GFM's[1] 128bit integers.

[1]:http://code.dlang.org/packages/gfm


Re: Blog Post #69: TextView and TextBuffer Basics

2019-09-10 Thread Ron Tarrant via Digitalmars-d-learn

On Tuesday, 10 September 2019 at 09:14:13 UTC, Mike Parker wrote:

Seriously impressed that you're able to keep this up so 
consistently. Keep on trucking!


Thanks, Mike.



Re: Undefined reference - built from source DMD

2019-09-10 Thread Stefanos Baziotis via Digitalmars-d-learn
On Tuesday, 10 September 2019 at 14:47:00 UTC, Nicholas Wilson 
wrote:


Is this you have built your own DMD


Yes

and using it to compile a test program and you get that error, 
or you get that error trying to build DMD?


Both. I get that error trying to compile _any_ program.


Re: Undefined reference - built from source DMD

2019-09-10 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 10 September 2019 at 11:12:30 UTC, Stefanos Baziotis 
wrote:

I don't if this the right group to post this.

DMD built from source fails to link / find `main`. The error is:
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function 
`_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

Does anyone know how this could have happened?


Is this you have built your own DMD and using it to compile a 
test program and you get that error, or you get that error trying 
to build DMD?


Re: need this for name of type string

2019-09-10 Thread Andre Pany via Digitalmars-d-learn

On Tuesday, 10 September 2019 at 11:20:03 UTC, Ali Çehreli wrote:

On 09/10/2019 03:32 AM, Andre Pany wrote:

>  [...]

The UDA syntax allows both types and an objects. method0 uses 
Foo type and method1 uses a Foo object. So, if your API allows 
both, your code that deals with UDA must account for both.


[...]


Fantastic! Thanks a lot for the solution.

Kind regards
André


Re: need this for name of type string

2019-09-10 Thread Ali Çehreli via Digitalmars-d-learn

On 09/10/2019 03:32 AM, Andre Pany wrote:

>  @Foo void method0(){}
>
>  @Foo("abc") void method1(){}

The UDA syntax allows both types and an objects. method0 uses Foo type 
and method1 uses a Foo object. So, if your API allows both, your code 
that deals with UDA must account for both.


The simplest solution here is to have method0 take an object as well:

  @Foo() void method0(){}

If you want to allow for both, the UDA code must change similar to the 
following:


static foreach(fieldName; __traits(allMembers, T))
{
static if (hasUDA!(__traits(getMember, T, fieldName), Foo))
{
  static if (is (getUDAs!(__traits(getMember, T, fieldName), 
Foo)[0])) {

// The UDA is the type Foo
pragma(msg, "Default Foo string: ", Foo.init.name);

  } else {
// The UDA is a Foo object
pragma(msg, "Special Foo string: ", 
getUDAs!(__traits(getMember, T, fieldName), Foo)[0].name);

  }
}
}

Ali



Re: need this for name of type string

2019-09-10 Thread Alex via Digitalmars-d-learn

On Tuesday, 10 September 2019 at 10:32:29 UTC, Andre Pany wrote:

Hi,

following coding is throwing compiler error:
  need this for name of type string

The error disappears if I delete method0.
My gut feeling is, this is a compiler bug?

---
class C
{
static this()
{
getT!(typeof(this))();
}

@Foo void method0(){}

@Foo("abc") void method1(){}
}

struct Foo
{
string name;
}

void getT(T)()
{
import std.traits: hasUDA, getUDAs;

static foreach(fieldName; __traits(allMembers, T))
{
static if (hasUDA!(__traits(getMember, T, fieldName), 
Foo))

{
pragma(msg, getUDAs!(__traits(getMember, T, 
fieldName), Foo)[0].name);

}
}
}

void main(){}
---

Kind regards
André


Don't think so. In case of @Foo, you don't instantiate an object. 
Therefore, name cannot exist. So... in this case, the UDA is a 
type, not an object you can query for a name.
It's more the like the example with SimpleAttr on the help page 
[1], I think.


[1] https://dlang.org/library/std/traits/get_ud_as.html


Undefined reference - built from source DMD

2019-09-10 Thread Stefanos Baziotis via Digitalmars-d-learn

I don't if this the right group to post this.

DMD built from source fails to link / find `main`. The error is:
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function 
`_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

Does anyone know how this could have happened?


need this for name of type string

2019-09-10 Thread Andre Pany via Digitalmars-d-learn

Hi,

following coding is throwing compiler error:
  need this for name of type string

The error disappears if I delete method0.
My gut feeling is, this is a compiler bug?

---
class C
{
static this()
{
getT!(typeof(this))();
}

@Foo void method0(){}

@Foo("abc") void method1(){}
}

struct Foo
{
string name;
}

void getT(T)()
{
import std.traits: hasUDA, getUDAs;

static foreach(fieldName; __traits(allMembers, T))
{
static if (hasUDA!(__traits(getMember, T, fieldName), 
Foo))

{
pragma(msg, getUDAs!(__traits(getMember, T, 
fieldName), Foo)[0].name);

}
}
}

void main(){}
---

Kind regards
André


Re: Blog Post #69: TextView and TextBuffer Basics

2019-09-10 Thread Mike Parker via Digitalmars-d-learn

On Tuesday, 10 September 2019 at 08:29:59 UTC, Ron Tarrant wrote:
This morning's discussion covers the basic workings and 
relationship between the TextView and TextBuffer widgets. 
Here's the link: 
https://gtkdcoding.com/2019/09/10/0069-textview-and-textbuffer.html


Seriously impressed that you're able to keep this up so 
consistently. Keep on trucking!


Blog Post #69: TextView and TextBuffer Basics

2019-09-10 Thread Ron Tarrant via Digitalmars-d-learn
This morning's discussion covers the basic workings and 
relationship between the TextView and TextBuffer widgets. Here's 
the link: 
https://gtkdcoding.com/2019/09/10/0069-textview-and-textbuffer.html




Re: LDC asm for int128

2019-09-10 Thread a11e99z via Digitalmars-d-learn

On Tuesday, 10 September 2019 at 06:18:05 UTC, Newbie2019 wrote:
I want to translate this c code into d (build with ldc), so I 
can use -flto and inline with other code.


uint64_t _wymum(uint64_t A, uint64_t B){
__uint128_t r = A ;
r *= B;
return  (r>>64)^r;
}

Do i need ASM or is there a easy way to implement it ?


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


Re: Learning delegates

2019-09-10 Thread Bert via Digitalmars-d-learn

On Sunday, 8 September 2019 at 10:04:57 UTC, Joel wrote:
I'm trying to understand delegates. Is there any good ways I 
can get a better understanding of them?


Simple, don't make it harder than it is.

Delegates are basically functions... that is, function 
pointers(they point to some function somewhere in space)... BUT 
they include a "context". The context a scope.



{  // In some scope

   int x;
   d = () { writeln(x); };
}


() { writeln(x); };

is the function defined as a lambda(inline).

It accesses a variable outside of it, that is, in the scope... 
which is called the context.


d is the delegate, it is a function pointer that holds the 
function AND the context pointer.


We can then do

d();

which called/executes the function... the function is called, and 
x can be referenced because d stores the context.


If you do not understand functions, then function pointers, you 
can't understand delegates.






LDC asm for int128

2019-09-10 Thread Newbie2019 via Digitalmars-d-learn
I want to translate this c code into d (build with ldc), so I can 
use -flto and inline with other code.


uint64_t _wymum(uint64_t A, uint64_t B){
__uint128_t r = A ;
r *= B;
return  (r>>64)^r;
}

Do i need ASM or is there a easy way to implement it ?