arsd errors on windows

2019-10-16 Thread Greatsam4sure via Digitalmars-d-learn

from my project root directory


dub add arsd-official

This is added to dub.json

"arsd-official": "~>4.0.3"

just run the project gives


Fetching arsd-official 4.0.3 (getting selected version)...
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86_64.
arsd-official:cgi 4.0.3: building configuration 
"embedded_httpd"...

..\..\AppData\Local\dub\packages\arsd-official-4.0.3\arsd-official\cgi.d(5828,3):
 Warning: statement is not reachable
C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.



import arsd.simpledisplay : SimpleWindow;

run the project gives



Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe for 
x86_64.
arsd-official:cgi 4.0.3: building configuration 
"embedded_httpd"...

..\..\AppData\Local\dub\packages\arsd-official-4.0.3\arsd-official\cgi.d(5828,3):
 Warning: statement is not reachable
C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.

Enter the following code get the same error

SimpleWindow window = new SimpleWindow;
window.eventLoop(0);

what is the way out. I am in need of a gui in D for Window.Gtkd 
and dlangui are not options for me. it should be easily 
customization









Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 16 October 2019 at 21:34:35 UTC, Dennis wrote:
Except that e.g. -2 - int.max underflows to int.max suggesting 
that int.max < -2.


Eh yeah, it would be something you should check in opCmp.

But this is how it is actually implemented on the processor 
itself, just the cpu happens to also check the overflow for you 
automatically...


Re: std.algorithm.cmp doesn't seem to support numeric types?

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

On 10/16/2019 02:34 PM, Dennis wrote:

> Except that e.g. -2 - int.max underflows to int.max suggesting that
> int.max < -2.

Timon had corrected me on that point a while back, so I had added the 
following warning at



http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opCmp

"Warning: Using subtraction for the implementation of opCmp is a bug if 
valid values of a member can cause overflow."


However, note how I say "overflow" instead of "underflow". The reason 
is, underflow is a different concept that applies only to floating point 
values[1]. Apparently, "integer underflow" has become common usage as 
well[2].


Ali

[1] https://en.wikipedia.org/wiki/Arithmetic_underflow

[2] https://en.wikipedia.org/wiki/Integer_overflow



Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 October 2019 at 20:07:10 UTC, Adam D. Ruppe 
wrote:
Notice that the docs say "a negative value" rather than -1 
specifically. That's because the implementation for integers an 
be as simple as


return a - b; // if b > a, you get a negative value


Except that e.g. -2 - int.max underflows to int.max suggesting 
that int.max < -2.


Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 16 October 2019 at 19:25:18 UTC, DNoob wrote:
I'm just learning D, so it's very possible that I'm missing a 
more appropriate function that exists elsewhere, but basically 
I found today that while I could easily write a cmp function 
that worked for everything, the one in std.algorithm doesn't 
seem to:


Yeah, it is primarily for strings, to be used as a sorting 
predicate.


For numbers, simple less than (for bool comparisons) or 
subtraction operators (for the integer ones) will do it.


Notice that the docs say "a negative value" rather than -1 
specifically. That's because the implementation for integers an 
be as simple as


return a - b; // if b > a, you get a negative value

and thus doesn't really need a specific function.


Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Paul Backus via Digitalmars-d-learn

On Wednesday, 16 October 2019 at 19:25:18 UTC, DNoob wrote:
I'm just learning D, so it's very possible that I'm missing a 
more appropriate function that exists elsewhere, but basically 
I found today that while I could easily write a cmp function 
that worked for everything, the one in std.algorithm doesn't 
seem to:


std.algorithm.cmp compares two ranges, not two values. From the 
documentation:


Performs a lexicographical comparison on two input ranges. 
Iterating r1 and
r2 in lockstep, cmp compares each element e1 of r1 with the 
corresponding
element e2 in r2. If one of the ranges has been finished, cmp 
returns a
negative value if r1 has fewer elements than r2, a positive 
value if r1 has
more elements than r2, and 0 if the ranges have the same number 
of elements.


Source: 
https://dlang.org/phobos/std_algorithm_comparison.html#.cmp


std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread DNoob via Digitalmars-d-learn
I'm just learning D, so it's very possible that I'm missing a 
more appropriate function that exists elsewhere, but basically I 
found today that while I could easily write a cmp function that 
worked for everything, the one in std.algorithm doesn't seem to:


import std.stdio, std.algorithm;

pure nothrow @nogc @system byte my_cmp(T1, T2)(T1 a, T2 b)
{
if (a < b)
{
return -1;
}
else if (a == b)
{
return 0;
}
else
{
return 1;
}
}

void main()
{
  //template error on the next line if uncommented
  //writeln(cmp(1, 2));

  writeln(my_cmp(1, 2));
}

Any advice would be much appreciated!


Re: Uninstalling DMG file

2019-10-16 Thread Jacob Carlborg via Digitalmars-d-learn

On 2019-10-16 05:30, Joel wrote:


Everything seems to be working again - yay!


Great. If you see a lot of warnings when linking, I have a PR for that [1].

[1] https://github.com/dlang/dmd/pull/10476

--
/Jacob Carlborg


Re: A proper WAT moment

2019-10-16 Thread Jacob Carlborg via Digitalmars-d-learn

On 2019-10-15 09:06, John Colvin wrote:

And all the other ones in my example that access members without an 
instance that also compile?


There's something pretty strange about the rules here.


The thing is that it should be possible to access a non-static member 
without an instance because it's possible to manually construct a delegate:


class S
{
int a;
int e() @property { return a; }
}

void foo()
{
int function() f = &S.e; // this compiles
int delegate() dg;
S s;
dg.ptr = &s;
dg.funcptr = f;
}

struct C
{
void bar()
{
int function() f = &S.e; // this fails for some reason but 
should compile

}
}

So the expression `S.e` should compile, because it can be part of a 
large expression, i.e. `&S.e`, which should compile.


The strange thing is that it fails to compile inside `C`. But if `bar` 
is changed to a static method it compiles again.


--
/Jacob Carlborg


Re: struct Foo may not define both a rvalue constructor and a copy constructor

2019-10-16 Thread drug via Digitalmars-d-learn

On 10/16/19 6:40 PM, rikki cattermole wrote:

On 17/10/2019 4:29 AM, drug wrote:

struct Foo
{
 this(ref const(Foo) other) {}
 this(const(Foo) other) {}
}

I'm trying to update dmd version and starting from 2.086 my code 
doesn't compile due to the error above. What is the reason of that?


Copy constructors were added (sort of like postblit).

https://dlang.org/spec/struct.html#struct-copy-constructor


Is it temporarily situation?


No.


My question is why the struct may not define both a rvalue ctor and a 
copy ctor?


Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-16 Thread nazriel via Digitalmars-d-learn

On Friday, 11 October 2019 at 11:38:27 UTC, Jacob Carlborg wrote:

On 2019-10-10 20:12, Robert M. Münch wrote:
I have two project I want to compile and both times get this 
error:


Undefined symbols for architecture x86_64:
  "_dyld_enumerate_tlv_storage", referenced from:
  __d_dyld_getTLSRange in libphobos2.a(osx_tls.o)

I'm wondering where this comes from as I didn't see it in the 
past. Any idea?




Any D application needs to be compiled with DMD 2.087.1 or 
later or the corresponding version of LDC to be able to run on 
macOS Catalina. That includes DMD itself. The oldest version of 
DMD that runs on Catalina is 2.088.0, since any given version 
of DMD is compiled with the previous version.


That means that all D applications out there for macOS needs to 
be recompiled.


When I tried to build DMD from source (via updated brew tap) it 
failed due to fact that DMD_HOST is stuck on dmd.2.079.1 which 
seems to still use old symbols.


Should we bump 
https://github.com/dlang/dmd/blob/master/src/posix.mak#L143 ?


BR,
Damian


Re: struct Foo may not define both a rvalue constructor and a copy constructor

2019-10-16 Thread rikki cattermole via Digitalmars-d-learn

On 17/10/2019 4:29 AM, drug wrote:

struct Foo
{
     this(ref const(Foo) other) {}
     this(const(Foo) other) {}
}

I'm trying to update dmd version and starting from 2.086 my code doesn't 
compile due to the error above. What is the reason of that?


Copy constructors were added (sort of like postblit).

https://dlang.org/spec/struct.html#struct-copy-constructor


Is it temporarily situation?


No.


struct Foo may not define both a rvalue constructor and a copy constructor

2019-10-16 Thread drug via Digitalmars-d-learn

struct Foo
{
this(ref const(Foo) other) {}
this(const(Foo) other) {}
}

I'm trying to update dmd version and starting from 2.086 my code doesn't 
compile due to the error above. What is the reason of that? Is it 
temporarily situation?


Re: Blog Post #79: Notebook, Part III - Customized Tabs, Part I

2019-10-16 Thread Ron Tarrant via Digitalmars-d-learn
On Wednesday, 16 October 2019 at 07:46:42 UTC, Antonio Corbi 
wrote:



Hope this helps.


Thanks, Antonio. I'll check this out.

I'll work up a demo based on this stuff and put it in the 
gtkdcoding queue.


How to write correct multi-threaded code?

2019-10-16 Thread Andrey Zherikov via Digitalmars-d-learn
I'm trying to write multi-threaded code that uses mutexes, 
condition variables and atomics but I've got confused how to do 
this correctly. Everything I found so far include a lot of 
casting to/from shared even for the objects that are supposed to 
be shared (like mutex and condition variable).


Is there any good explanation or guide with examples of how to 
write correct multi-threaded code in D using shared, 
synchronized, core.sync.* etc things?


Re: Mixin and introspection ordering

2019-10-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 October 2019 at 10:09:51 UTC, Sebastiaan Koppe 
wrote:
Do we want to be able to catch things in their 'before' state? 
Or is it a bug?


The 'before' and 'after' are implementation details showing up as 
a result of underspecification.


Module level declarations are supposed to be order invariant. I 
weirdly can't find that directly in the spec, but it is implied 
in the world 'unlike' in this sentence:


"Unlike module level declarations, declarations within function 
scope are processed in order."

https://dlang.org/spec/function.html#nested

Now look at the specification of __traits(compiles):

"Returns a bool true if all of the arguments compile (are 
semantically correct)."

https://dlang.org/spec/traits.html#compiles

That isn't very clear; compile in what context? What is 
"semantically correct" at that point?

For example:
```
static if (__traits(compiles, sqrt(3))) {
import std.math: sqrt;
}
```
The reference implementation does not import sqrt here because in 
the context without the import it doesn't compile, but arguably 
importing sqrt is a valid resolution of the constraints here.


Another problem arises when evaluating the equivalent of "this 
statement is false":

if x doesn't compile, make x compile. Let's have two of them:
```
static if (!__traits(compiles, a)) {
   string a;
}
static if (!__traits(compiles, a)) {
   int a;
}
pragma(msg, typeof(a)); // int or string?
```

Either this is a contradiction, or __traits(compiles) should 
evaluate it in a "compilation state" before everything that 
depends on it. That implies there actually is an order of module 
level declarations.


Ideally, the D language formally specifies constraints for the 
validity of programs and any D compiler contains a correct 
constraint resolution algorithm for it. In practice DMD  has 3 
semantic passes for symbols and kind of recursively calls it on 
symbols on an as-needed basis without much rigor. Walter stated 
in his "Spelunking D compiler internals" talk [1] that the 3 
semantic passes were a mistake and an endless source of bugs. 
Small bugs with it are resolved  occasionally (for example [2]), 
but there are always more (for example [3] and [4]) and we need a 
good specification of semantic analysis before DMD can stop 
leaking its order of semantic analysis on symbols.


[1] https://www.youtube.com/watch?v=l_96Crl998E
[2] https://github.com/dlang/dmd/pull/9069
[3] https://issues.dlang.org/show_bug.cgi?id=9125
[4] https://issues.dlang.org/show_bug.cgi?id=19458


Re: Mixin and introspection ordering

2019-10-16 Thread Sebastiaan Koppe via Digitalmars-d-learn

On Tuesday, 15 October 2019 at 19:50:33 UTC, Paul Backus wrote:
On Tuesday, 15 October 2019 at 19:19:58 UTC, Sebastiaan Koppe 
wrote:
You would expect 2 to print `tuple(a)` as well, but it 
doesn't. Don't know if it is a bug.


Any time you use a construct that mutates the AST (template 
mixin, string mixin, static if, static foreach), it's possible 
to catch it in both "before" and "after" states. For example:


This can cause some "interesting" things to happen when using 
templates like the ones in std.traits to do reflection, since 
the result of template instantiation is cached:


Wth the simple examples in this thread it can even be excused. 
However, when the mixin and the introspection are part of 
something larger it is no longer easily apparent.


I myself spend 30min wondering why it didn't work. And I wrote it 
myself.


Do we want to be able to catch things in their 'before' state? Or 
is it a bug?


Re: Blog Post #79: Notebook, Part III - Customized Tabs, Part I

2019-10-16 Thread Antonio Corbi via Digitalmars-d-learn

On Tuesday, 15 October 2019 at 22:02:35 UTC, WebFreak001 wrote:

On Tuesday, 15 October 2019 at 20:03:00 UTC, Ron Tarrant wrote:

...

Do you have links for these?


thanks! :p

both the packages can simply be found on dub: 
https://code.dlang.org/search?q=glade


Not sure if there are other ways like directly loading an XML 
in GTK, haven't looked into it too much yet because I am not so 
often building GTK GUI applications, but with the new Linux 
Phones on the market (Librem 5, PinePhone) running GTK Apps 
natively and really needing some Apps those will be great 
platforms to start app development on.


Hi WebFreak001, Ron:

There's no need to generate code from glade files.
You can load at runtime the XML file that glade generates.

You have to create an instance of the Gtk.Builder class[1], and 
supply it
the XML file, i.e. from the file that you saved from glade[2] and 
after that you 'load' your UI controls into your program 
variables using getObject[3], a small snippet of this pattern:


---
   
   auto builder = new Builder();
   
if(!builder.addFromFile(buildPath(pkgdatadir,"ui/MainWindow.ui")))

   {
  writeln("Window ui-file cannot be found");
  return;
   }

   HeaderBar headerBar = cast(HeaderBar) 
builder.getObject("headerBar");
   Box windowContent = cast(Box) 
builder.getObject("windowContent");

   ...
---

Once I wrote this extremely simple class to simplify Builder 
usage:


---
module gtagui.uibuilder;

private import gobject.ObjectG;
import gtk.Builder;

class UiBuilder : Builder {
  this (string uif) {
if (!addFromFile (uif))
  throw new Exception ("File not found: " ~ uif);
  }

  public T getObject(T) (string name) {
return (cast(T) super.getObject (name));
  }
}
---

So you can now write things like this:

---
  public void loadUiFrom (string uifile) {
uib = new UiBuilder (uifile);

topbox = uib.getObject!Box ("box1");

theCanvas = uib.getObject!DrawingArea("imgwindow");
assert (theCanvas !is null);
---

Hope this helps.
Antonio

[1] https://api.gtkd.org/gtk.Builder.Builder.html
[2] https://api.gtkd.org/gtk.Builder.Builder.addFromFile.html
[3] https://api.gtkd.org/gtk.Builder.Builder.getObject.html