Re: std.math module

2017-08-06 Thread Nicholas Wilson via Digitalmars-d-learn

On Sunday, 6 August 2017 at 23:33:26 UTC, greatsam4sure wrote:

import std.math;
import std.stdio;

cos(90*PI/180) = -2.7e-20 instead of zero. I will appreciate 
any help. thanks in advance.


tan(90*PI/180) = -3.689e+19 instead of infinity. What is the 
best way to use this module


in addition to what sarn said, tan(3pi/4) is a pole, not 
infinity. the mean of the left and right hand limits is 0


Re: Getting enum from value

2017-08-06 Thread Kreikey via Digitalmars-d-learn

On Saturday, 5 August 2017 at 20:11:27 UTC, Matthew Remmel wrote:

On Saturday, 5 August 2017 at 18:26:10 UTC, Kreikey wrote:
On Saturday, 5 August 2017 at 15:33:57 UTC, Matthew Remmel 
wrote:
I feel like I'm missing something, but there has to be an 
easier way to convert a value into an enum than switching 
over every possible value: i.e


[...]


Capitals c = cast(Capitals)"Chicago";
writeln(c);// Illinois


I'm annoyed that I didn't think of trying to cast it. That 
works great if the value exists in the enum. It does something 
weird if the value doesn't though. This is my test.d file:


import std.stdio;

enum Foo {
A = "AV",
B = "BV"
}

void main() {
Foo k = cast(Foo)"BV"; // Works and prints correctly

k = cast(Foo)"CV";
writeln("Type: ", typeid(k));  // Type: test.Foo
writeln("Value: ", k);   // Value: cast(Foo)CV
}

The output shows the type being the Foo enum but the value is 
'cast(Foo)CV'. I would of expected an error or exception to be 
thrown if it wasn't able to cast into an actual enum member. Is 
this something with how the enums are implemented under the 
hood?


So I've come up with a concise way to do this. Given:

Capitals strToEnum(string myString) {
  Capitals instance = cast(Capitals)myString;
  if (![EnumMembers!Capitals].canFind(instance))
throw new Exception("can't convert that string to that enum");
  return instance;
}

do:

Capitals c = strToEnum("Chicagoo");

Not quite a one-liner, but pretty close. Turning it into a 
template is left to the user as an exercise ;)


Re: std.math module

2017-08-06 Thread sarn via Digitalmars-d-learn

On Sunday, 6 August 2017 at 23:33:26 UTC, greatsam4sure wrote:

import std.math;
import std.stdio;

cos(90*PI/180) = -2.7e-20 instead of zero. I will appreciate 
any help. thanks in advance.


tan(90*PI/180) = -3.689e+19 instead of infinity. What is the 
best way to use this module


That's just floating point maths for you.  You're not putting 
exactly pi/2 into cos, just a good floating point approximation.  
What you're getting out isn't exactly 0, either, just a good 
floating point approximation.  (-2.7e-20 is really, really small.)


Here's a good talk from DConf 2016: 
https://www.youtube.com/watch?v=97bxjeP3LzY


If you need exact maths, you'll need a symbolic manipulation 
library (never used one in D, but there was a discussion recently 
https://forum.dlang.org/thread/ghihookwgzxculshi...@forum.dlang.org).  You don't need this for most practical applications, though.


Re: rename file, execute os, etc at compile time

2017-08-06 Thread Johnson Jones via Digitalmars-d-learn

On Sunday, 6 August 2017 at 23:11:56 UTC, Nicholas Wilson wrote:

On Sunday, 6 August 2017 at 19:56:06 UTC, Johnson Jones wrote:
is it possible to do? I would like to pre-configure some stuff 
at "pre-compilation"(in ctfe but before the rest of the 
program actually gets compiled).


I know it's not safe and all that but in my specific case it 
would help.  I'll probably use pre-build events, which is 
probably the best, but just curious about it in general... 
I've been wanting to write a ctfe virus in D for a while now! 
j/k.


It is deliberately not possible. reproducible builds security 
ect.

have a look at dubs preBuildCommand(?)


So it is intensionally preventing me from doing something I 
should be able to do if I want without issue because it thinks I 
will harm myself?


Why not a compiler switch that enables it? It's blocking 
something that might be an issue but is almost surely not and 
prevents the vast capabilities that it would otherwise be able to 
accomplish.


I guess one can always patch the compiler...

But Dmd does give an error about security, it usually says that 
the there are not source code available for compile time or 
something like that.


Re: returning D string from C++?

2017-08-06 Thread Mike Parker via Digitalmars-d-learn

On Sunday, 6 August 2017 at 17:16:05 UTC, bitwise wrote:



I was referring specifically to storing gc_malloc'ed pointers 
on the stack, meaning that I'm calling a C++ function on a D 
call stack, and storing the pointer as a local var in the C++ 
function before returning it to D.


The more I think about it, the more I think it has to be ok to 
do. Unless D stores [ESP] to some variable at each extern(*) 
function call, then the GC would have no choice but 
indifference as to what side of the language boundary it was 
scanning on. If it did, I imagine it would say so here:


https://dlang.org/spec/cpp_interface.html#memory-allocation


Yes, as long as you can guarantee it stays on the stack you 
should be good to go.


ldc D compiler installation on windows 10

2017-08-06 Thread greatsam4sure via Digitalmars-d-learn
Good day. I will appreciate it if anybody here can help me with 
the step by step way of installing ldc D compiler on windows. I 
have read online info but i just don't get it. let the process be 
in steps for easy comprehension.thanks in advance


std.math module

2017-08-06 Thread greatsam4sure via Digitalmars-d-learn

import std.math;
import std.stdio;

cos(90*PI/180) = -2.7e-20 instead of zero. I will appreciate any 
help. thanks in advance.


tan(90*PI/180) = -3.689e+19 instead of infinity. What is the best 
way to use this module


ldc instation on windows 10

2017-08-06 Thread greatsam4sure via Digitalmars-d-learn
Good day. I will appreciate it if anybody here can help me with 
the step by step way of installing ldc D compiler on windows. I 
have read online info but i just don't get it. let the process be 
in steps for easy comprehension.thanks in advance


Re: rename file, execute os, etc at compile time

2017-08-06 Thread Nicholas Wilson via Digitalmars-d-learn

On Sunday, 6 August 2017 at 19:56:06 UTC, Johnson Jones wrote:
is it possible to do? I would like to pre-configure some stuff 
at "pre-compilation"(in ctfe but before the rest of the program 
actually gets compiled).


I know it's not safe and all that but in my specific case it 
would help.  I'll probably use pre-build events, which is 
probably the best, but just curious about it in general... I've 
been wanting to write a ctfe virus in D for a while now! j/k.


It is deliberately not possible. reproducible builds security ect.
have a look at dubs preBuildCommand(?)


Re: lambda function with "capture by value"

2017-08-06 Thread bitwise via Digitalmars-d-learn

On Saturday, 5 August 2017 at 18:17:49 UTC, Simon Bürger wrote:
If a lambda function uses a local variable, that variable is 
captured using a hidden this-pointer. But this capturing is 
always by reference. Example:


int i = 1;
auto dg = (){ writefln("%s", i); };
i = 2;
dg(); // prints '2'

Is there a way to make the delegate "capture by value" so that 
the call prints '1'?


Note that in C++, both variants are available using
   [&]() { printf("%d", i); }
and
   [=]() { printf("%d", i); }
respectively.


I asked about this a couple of day ago:
http://forum.dlang.org/thread/ckkswkkvhfojbcczi...@forum.dlang.org

The problem is that the lambda captures the entire enclosing 
stack frame. This is actually a bug because the lambda should 
only capture the enclosing *scope*, not the entire stack frame of 
the function. So even if you were to copy `i` into a temporary in 
some nested scope where a lambda was declared (this works in C# 
for example), that temporary would still reside in the same stack 
frame as the outer `i`, which means there would still be only one 
copy of it.


There is a workaround in Timon's post here:
http://forum.dlang.org/post/om2aqp$2e9t$1...@digitalmars.com

Basically, that workaround wraps the nested scope in another 
lambda to force the creation of a separate stack frame.






Re: lambda function with "capture by value"

2017-08-06 Thread Simon Bürger via Digitalmars-d-learn

On Sunday, 6 August 2017 at 12:50:22 UTC, Adam D. Ruppe wrote:

On Saturday, 5 August 2017 at 19:58:08 UTC, Temtaime wrote:

(k){ dgs[k] = {writefln("%s", k); }; }(i);


Yeah, that's how I'd do it - make a function taking arguments 
by value that return the delegate you actually want to store. 
(Also use this pattern in Javascript btw for its `var`, though 
JS now has `let` which works without this trick... and D is 
supposed to work like JS `let` it is just buggy).


You could also define a struct with members for the values you 
want, populate it, and pass one of its methods as your 
delegate. It is syntactically the heaviest but does give the 
most precise control (and you can pass the struct itself by 
value to avoid the memory allocation entirely if you want).


But for the loop, the pattern Temtaime wrote is how I'd prolly 
do it.


I like the (kinda cryptic IMO) look of this '(k){...}(i)' 
construction. But for my actual code I went with struct+opCall 
without any delegate at all.


Anyway, thanks for all your suggestions.


rename file, execute os, etc at compile time

2017-08-06 Thread Johnson Jones via Digitalmars-d-learn
is it possible to do? I would like to pre-configure some stuff at 
"pre-compilation"(in ctfe but before the rest of the program 
actually gets compiled).


I know it's not safe and all that but in my specific case it 
would help.  I'll probably use pre-build events, which is 
probably the best, but just curious about it in general... I've 
been wanting to write a ctfe virus in D for a while now! j/k.


Re: gtkD: events being triggered twice

2017-08-06 Thread FoxyBrown via Digitalmars-d-learn

On Sunday, 6 August 2017 at 18:26:20 UTC, Mike Wey wrote:

On 06-08-17 16:58, FoxyBrown wrote:
I don't really(my code is a bit more complex) but basically 
all it boils down to is a UI with some nested widgets (an 
overlay, an box, and a box and one contains the eventbox which 
I added those callbacks on.


I think that something like

https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/TestWindow/TestWindow.d


should probably work by just adding an eventbox somewhere and 
adding that code above.


If it doesn't exhibit the same behavior then it has something 
to do with my project and I could try to reduce it to a 
minimal example.


To test i put the label that is on the label page in an event 
box but that doesn't reproduce the issue. I get just a single 
event on enter and a single event on leave.


Ok, I will try to work on figuring out what is going and and 
potentially reduce to a test case. It might be on my end. I'm 
pretty sure I'm not adding


You might try a separator though in the event box and might try 
to add it handling various events(maybe even other events for the 
event box)... things related to the mouse.


Here's the glade code for the event box I'm using

  
5
True
False
True

  
5
True
False
False

name="orientation">vertical

  

  


Try that when you get some time and see if that changes anything. 
If it doesn't then it's surely in my code or in the gtk version 
I'm using(still using msys, I'll update to what you released to 
see if that fixes it). At least we can narrow it down a little...




Re: gtkD: events being triggered twice

2017-08-06 Thread Mike Wey via Digitalmars-d-learn

On 06-08-17 16:58, FoxyBrown wrote:
I don't really(my code is a bit more complex) but basically all it boils 
down to is a UI with some nested widgets (an overlay, an box, and a box 
and one contains the eventbox which I added those callbacks on.


I think that something like

https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/TestWindow/TestWindow.d 



should probably work by just adding an eventbox somewhere and adding 
that code above.


If it doesn't exhibit the same behavior then it has something to do with 
my project and I could try to reduce it to a minimal example.


To test i put the label that is on the label page in an event box but 
that doesn't reproduce the issue. I get just a single event on enter and 
a single event on leave.


--
Mike Wey


Re: returning D string from C++?

2017-08-06 Thread bitwise via Digitalmars-d-learn

On Sunday, 6 August 2017 at 16:46:40 UTC, Mike Parker wrote:

On Sunday, 6 August 2017 at 16:23:01 UTC, bitwise wrote:

So I guess you're saying I'm covered then? I guess there's no 
reason I can think of for the GC to stop scanning at the 
language boundary, let alone any way to actually do that 
efficiently.


It's not something you can rely on. If the pointer is stored in 
memory allocated from the C heap, then the GC will never see it 
and can pull the rug out from under you. Best to make sure it's 
never collected. If you don't want to keep a reference to it on 
the D side, then call GC.addRoot on the pointer. That way, no 
matter where you hand it off, the GC will consider it as being 
live. When you're done with it, call GC.removeRoot.


I was referring specifically to storing gc_malloc'ed pointers on 
the stack, meaning that I'm calling a C++ function on a D call 
stack, and storing the pointer as a local var in the C++ function 
before returning it to D.


The more I think about it, the more I think it has to be ok to 
do. Unless D stores [ESP] to some variable at each extern(*) 
function call, then the GC would have no choice but indifference 
as to what side of the language boundary it was scanning on. If 
it did, I imagine it would say so here:


https://dlang.org/spec/cpp_interface.html#memory-allocation


Re: lambda function with "capture by value"

2017-08-06 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2017-08-06 at 12:50 +, Adam D. Ruppe via Digitalmars-d-learn
wrote:
> On Saturday, 5 August 2017 at 19:58:08 UTC, Temtaime wrote:
> >     (k){ dgs[k] = {writefln("%s", k); }; }(i);
> 
> Yeah, that's how I'd do it - make a function taking arguments by 
> value that return the delegate you actually want to store. (Also 
> use this pattern in Javascript btw for its `var`, though JS now 
> has `let` which works without this trick... and D is supposed to 
> work like JS `let` it is just buggy).
> 

Assuming I have understood the problem, this is the solution necessary in
Python: you have to use an enclosing function around the function so as to
capture the value using a parameter. I think Java requires the same.

-- 
Russel.
=
Dr Russel Winder  t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Roadm: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

signature.asc
Description: This is a digitally signed message part


VibeD - REST API and vibed.web.auth framework

2017-08-06 Thread holo via Digitalmars-d-learn

Hello

I'm trying to use auth framework with REST api ( 
http://vibed.org/api/vibe.web.auth/ ).


Is it possible to use it with registerRestInterface? According to 
description under: 
http://vibed.org/api/vibe.web.auth/requiresAuth it should be 
available on both Web and REST.


Here is my example code and compilation errors bellow:

import vibe.d;
import vibe.web.auth;
import vibe.http.session;
import vibe.web.rest : registerRestInterface;
import vibe.web.web : noRoute;
import std.algorithm, std.array;


struct AuthInfo {
string userName;
bool premium;
bool admin;

@safe:
bool isAdmin() { return this.admin; }
bool isPremiumUser() { return this.premium; }
}


interface IfOAuthAPI
{
void postLogin(ValidUsername login, ValidPassword password);
//bool postTokenValidation(string token, string userName);
}

@path("/api")
@requiresAuth
class OAuthAPI : IfOAuthAPI
{


  @noRoute
  AuthInfo authenticate(scope HTTPServerRequest req, scope 
HTTPServerResponse res) @safe

{
if (!req.session || !req.session.isKeySet("auth"))
			throw new HTTPStatusException(HTTPStatus.forbidden, "Not 
authorized to perform this action!");


return req.session.get!AuthInfo("auth");
  }

  this(MongoCollection coll)
  {
collection = coll;
  }

  private:
MongoCollection collection;

  public:
@noAuth
string postLogin(ValidUsername login, ValidPassword password)
{
  logInfo("Recived data for" ~ login ~ "and" ~ password);

  Bson query = Bson(["username" : Bson(login)]);
  auto result = collection.find(query);

  foreach (i, doc; result)
logInfo("Item %d: %s", i, doc.toJson().toString());

  logInfo("Sending respond");
  return "OK";

}
}

And im getting such errors:

ms-frontpage ~master: building configuration "application"...
../../.dub/packages/vibe-d-0.7.31/vibe-d/source/vibe/http/server.d(286,33): 
Deprecation: alias diet.traits.FilterCallback is deprecated - Use 
SafeFilterCallback instead.
source/app.d(14,31): Error: cannot create instance of interface 
IfOAuthAPI
source/service/oauth.d(35,8): Error: @safe function 
'oauth.OAuthAPI.authenticate' cannot call @system function 
'vibe.http.session.Session.opCast'
source/service/oauth.d(35,44): Error: @safe function 
'oauth.OAuthAPI.authenticate' cannot call @system function 
'vibe.http.session.Session.isKeySet'
source/service/oauth.d(36,10): Error: @safe function 
'oauth.OAuthAPI.authenticate' cannot call @system constructor 
'vibe.http.common.HTTPStatusException.this'
source/service/oauth.d(38,34): Error: @safe function 
'oauth.OAuthAPI.authenticate' cannot call @system function 
'vibe.http.session.Session.get!(AuthInfo).get'

dmd failed with exit code 1.

Regards
holo


Re: returning D string from C++?

2017-08-06 Thread Mike Parker via Digitalmars-d-learn

On Sunday, 6 August 2017 at 16:23:01 UTC, bitwise wrote:

So I guess you're saying I'm covered then? I guess there's no 
reason I can think of for the GC to stop scanning at the 
language boundary, let alone any way to actually do that 
efficiently.


It's not something you can rely on. If the pointer is stored in 
memory allocated from the C heap, then the GC will never see it 
and can pull the rug out from under you. Best to make sure it's 
never collected. If you don't want to keep a reference to it on 
the D side, then call GC.addRoot on the pointer. That way, no 
matter where you hand it off, the GC will consider it as being 
live. When you're done with it, call GC.removeRoot.


Re: returning D string from C++?

2017-08-06 Thread bitwise via Digitalmars-d-learn

On Sunday, 6 August 2017 at 05:31:51 UTC, Marco Leise wrote:

Am Sat, 05 Aug 2017 20:17:23 +
schrieb bitwise :

[...]

In due diligence, you are casting an ANSI string into a UTF-8
string which will result in broken Unicode for non-ASCII window
titles. In any case it is better to use the wide-character
versions of Windows-API functions nowadays.
[...]


Good point. (pun not originally intended ;)

All serious projects I have done for Windows thus far have 
actually been in C# (default UTF-16), so I guess I've been 
spoiled.


Second I'd like to mention that you should have set ret.length 
= GetWindowText(_hwnd, (char*)ret.ptr, ret.length); Currently 
your length is anything from 1 to N bytes longer than the 
actual string[2], which is not obvious because any debug 
printing or display of the string stops at the embedded \0 
terminator.

[...]


Totally right! I looked right at this info in the docs..not sure 
how I still got it wrong ;)


 Thanks


Re: returning D string from C++?

2017-08-06 Thread bitwise via Digitalmars-d-learn

On Saturday, 5 August 2017 at 21:18:29 UTC, Jeremy DeHaan wrote:

On Saturday, 5 August 2017 at 20:17:23 UTC, bitwise wrote:
I have a Windows native window class in C++, and I need a 
function to return the window title.


[...]


As long as you have a reachable reference to the GC memory 
SOMEWHERE, the GC won't reclaim it. It doesn't have to be on 
the stack as long as it is reachable through the stack.


I'm basically worried about this happening:

virtual DString getTitle() const {
DString ret;
ret.length = GetWindowTextLength(_hwnd) + 1;
ret.ptr = (const char*)gc_malloc(ret.length, 0xA, NULL);

gc collection on another thread

GetWindowText(_hwnd, (char*)ret.ptr, ret.length); // BOOM
return ret;
}

So I guess you're saying I'm covered then? I guess there's no 
reason I can think of for the GC to stop scanning at the language 
boundary, let alone any way to actually do that efficiently.


  Thanks



Re: Create class on stack

2017-08-06 Thread Moritz Maxeiner via Digitalmars-d-learn

On Sunday, 6 August 2017 at 15:24:55 UTC, Jacob Carlborg wrote:

On 2017-08-05 19:08, Johnson Jones wrote:
using gtk, it has a type called value. One has to use it to 
get the
value of stuff but it is a class. Once it is used, one doesn't 
need it.


Ideally I'd like to treat it as a struct since I'm using it in 
a
delegate I would like to minimize unnecessary allocations. Is 
there any
way to get D to allocate a class on the stack like a local 
struct?


Prefix the variable declaration with "scope":

scope foo = new Object;


If you use this option, do be aware that this feature has been 
scheduled for future deprecation [1].
It's likely going to continue working for quite a while (years), 
though.


[1] 
https://dlang.org/deprecate.html#scope%20for%20allocating%20classes%20on%20the%20stack


Re: Create class on stack

2017-08-06 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-08-05 19:08, Johnson Jones wrote:

using gtk, it has a type called value. One has to use it to get the
value of stuff but it is a class. Once it is used, one doesn't need it.

Ideally I'd like to treat it as a struct since I'm using it in a
delegate I would like to minimize unnecessary allocations. Is there any
way to get D to allocate a class on the stack like a local struct?


Prefix the variable declaration with "scope":

scope foo = new Object;

--
/Jacob Carlborg


Re: gtkD window centering message up and no app on taskbar

2017-08-06 Thread Johnson Jones via Digitalmars-d-learn

On Saturday, 5 August 2017 at 20:56:10 UTC, Mike Wey wrote:

On 05-08-17 20:14, Johnson Jones wrote:
When trying to center the window. If one uses ALWAYS_CENTERED 
any resizing of the window is totally busted. CENTER also does 
not work. move(0,0) seems to not be relative to the main 
display. I'd basically like to center the window on the main 
display or at least be able to set coordinates properly. 
Windows sets (0,0) to be the lower left corner of the main 
display I believe. What happens is that the gtk window, when 
using 0,0 actually is like -1000,0 or something in windows 
coordinates and ends up on my secondary monitor.


When the app starts there's no taskbar icon. Luckily I still 
have the console shown but Eventually I'll need the taskbar. 
I'm not setting skipTaskBarHint, but I have tried both true 
and false without any difference.




gtk.Widget.translateCoordinates or gtk.Fixed could be useful 
for positioning the widgets.


Windows will only show the taskbar icon if you are not running 
the application from the console.


Is there a way to get it to show up or have it correlate with the 
console's taskbar? What I'm finding is that if the window has no 
title bar(maximized) and/or behind other windows I have to do 
some window juggling to find it. I need the console for debugging.


I could probably set the project as win32 and then create a 
console manually if necessary but seems to be overkill for 
something relatively basic.




Re: gtkD: events being triggered twice

2017-08-06 Thread FoxyBrown via Digitalmars-d-learn

On Sunday, 6 August 2017 at 09:42:03 UTC, Mike Wey wrote:

On 06-08-17 03:25, Johnson Jones wrote:

GtkEventBox - Enter
GtkEventBox - Enter
Down
GtkEventBox - Leave
Up
GtkEventBox - Leave
GtkEventBox - Leave

That is when I move the mouse over the event box then click 
then move out out then release.


I would expect

Enter Down Leave Up

The fact that enter and leave are not paired equally is a 
problem. Can be worked around but seems like it would be a bug.


the code is simply


ebox.addOnEnterNotify(delegate(Event e, Widget w)
{
writeln(w.getName(), " - ", "Enter");
return true;});

ebox.addOnLeaveNotify((Event e, Widget w)
{writeln(w.getName(), " - 
", "Leave");

return true;
});


Do you have an more complete example that i could test.


I don't really(my code is a bit more complex) but basically all 
it boils down to is a UI with some nested widgets (an overlay, an 
box, and a box and one contains the eventbox which I added those 
callbacks on.


I think that something like

https://github.com/gtkd-developers/GtkD/blob/master/demos/gtkD/TestWindow/TestWindow.d

should probably work by just adding an eventbox somewhere and 
adding that code above.


If it doesn't exhibit the same behavior then it has something to 
do with my project and I could try to reduce it to a minimal 
example.




Re: lambda function with "capture by value"

2017-08-06 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 5 August 2017 at 19:58:08 UTC, Temtaime wrote:

(k){ dgs[k] = {writefln("%s", k); }; }(i);


Yeah, that's how I'd do it - make a function taking arguments by 
value that return the delegate you actually want to store. (Also 
use this pattern in Javascript btw for its `var`, though JS now 
has `let` which works without this trick... and D is supposed to 
work like JS `let` it is just buggy).


You could also define a struct with members for the values you 
want, populate it, and pass one of its methods as your delegate. 
It is syntactically the heaviest but does give the most precise 
control (and you can pass the struct itself by value to avoid the 
memory allocation entirely if you want).


But for the loop, the pattern Temtaime wrote is how I'd prolly do 
it.


Re: lambda function with "capture by value"

2017-08-06 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 5 August 2017 at 18:37:31 UTC, Johnson Jones wrote:
1. I'm pretty sure that D creates the delegate "lazily" in the 
sense that the first call is what captures the variable.


It actually does it at function entry, allocating the memory for 
the locals in the closure, so it never actually copies them.


Re: Create class on stack

2017-08-06 Thread Moritz Maxeiner via Digitalmars-d-learn

On Sunday, 6 August 2017 at 02:19:19 UTC, FoxyBrown wrote:

[...]

I don't think you understand what I'm saying.

If I use this method to create a "reference" type on the stack 
rather than the heap, is the only issue worrying about not 
having that variable be used outside that scope(i.e., have it 
"escape")?


It's the only one I'm aware of OTTOMH. If you encounter others, a 
bug report would be appreciated.


Re: gtkD: events being triggered twice

2017-08-06 Thread Mike Wey via Digitalmars-d-learn

On 06-08-17 03:25, Johnson Jones wrote:

GtkEventBox - Enter
GtkEventBox - Enter
Down
GtkEventBox - Leave
Up
GtkEventBox - Leave
GtkEventBox - Leave

That is when I move the mouse over the event box then click then move 
out out then release.


I would expect

Enter Down Leave Up

The fact that enter and leave are not paired equally is a problem. Can 
be worked around but seems like it would be a bug.


the code is simply


ebox.addOnEnterNotify(delegate(Event e, Widget w)
{
writeln(w.getName(), " - ", "Enter");
return true;});

ebox.addOnLeaveNotify((Event e, Widget w)
{writeln(w.getName(), " - ", "Leave");
return true;
});


Do you have an more complete example that i could test.

--
Mike Wey


Re: gtkD load images

2017-08-06 Thread Mike Wey via Digitalmars-d-learn

On 05-08-17 22:59, ag0aep6g wrote:

On 08/05/2017 10:30 PM, Mike Wey wrote:

On 05-08-17 15:23, Johnson Jones wrote:

On Saturday, 5 August 2017 at 12:51:13 UTC, Mike Wey wrote:

[...]
There are two issues here, you need to properly escape the slash: 
"C:a.jpg".

[...]

```
Pixbuf p = new Pixbuf(r"C:\\a.jpg");
```


Thanks. Why do I need 4 slashes? Is that standard with gtk because 
strings are interpreted twice or something? Seemed to work though.





Nothing specific to GTK but in D and other programing languages the \ 
is used as an escape character, so you can use special characters in 
your sting like `\n` for a newline. But this means you will need to 
use \\ to get an literal back slash.


I think you missed the point of the question.

In the end, the path should contain only one backslash. But with 
`"C:a.jpg"` and `r"C:\\a.jpg"` you get two. Why do you need two? 
Does the library do another round of escape sequence handling?


That's me not being a Windows user shining trough, i somehow got it in 
my head that you needed two backslashes after the C:.


But indeed just "C:\\a.jpg" or r"C:\a.jpg" will work as expected.

--
Mike Wey


Re: D on AArch64 CPU

2017-08-06 Thread Joakim via Digitalmars-d-learn
On Sunday, 6 August 2017 at 06:26:57 UTC, David J Kordsmeier 
wrote:
Also, why I don't look at LDC further, I think RAM on the 
embedded devices is still pretty skimpy, Raspi3 only has 1GB 
ram.
 It's not great for compiling with the LLVM-based things and 
probably run OOM.  Other devices I have only have 512MB ram.  
So gcc is usually fine in these circumstances.


Don't know about gdc, but ldc is close (most of the listed 
upstream PRs are merged):


https://github.com/ldc-developers/ldc/issues/2153

As for memory, ldc can be used to cross-compile from a more 
capable machine, the official builds all ship with the AArch64 
backend enabled now:


https://github.com/ldc-developers/ldc/releases/tag/v1.3.0

The next ldc beta will ship with a build tool that lets you 
easily compile or cross-compile the stdlib yourself, so you can 
generate the stdlib for AArch64 even if it isn't provided:


https://github.com/ldc-developers/ldc/pull/2253


Re: D on AArch64 CPU

2017-08-06 Thread David J Kordsmeier via Digitalmars-d-learn

On Sunday, 14 May 2017 at 15:05:08 UTC, Richard Delorme wrote:
I recently bought the infamous Raspberry pi 3, which has got a 
cortex-a53 4 cores 1.2 Ghz CPU (Broadcom). After installing on 
it a 64 bit OS (a non official fedora 25), I was wondering if 
it was possible to install a D compiler on it.




Richard, I would be interested in working through the GDC issues 
further with you if you haven't completely given up on this.  I 
am surprised the response is that there is still no official 
support.  I am struggling on nearly every project I have on 
aarch64 with really lagging support for a wide variety of 
software, mainly platform support in more complex builds that 
does not include aarch64, and clearly the compilers all need more 
core level work to bring up a language and programming toolchains 
in a new environment.  I think Go, for example, isn't fully 
supported on aarch64, and Rust has the same issue.


If you are still available, I would like to share notes on the 
GDC 6.3 work that you started, and see if we can work through the 
issues with the core team.  I realize there is probably some lack 
of visibility into the interest that exists in the ARM-embedded 
area for D, but I've been using gdc on ARM since 2014.  It has 
been reasonably good for me, however, with the migration of many 
device manufacturers to AARCH64, most notably the Raspi3 and all 
of the hordes of Android devices hitting the market, there is a 
substantial installed base.


I can commit some hardware to builds also, and have some contacts 
in the industry around arm stuff, so it shouldn't be hard to find 
more dedicated gear if this helps teams like the GDC team who may 
not have access to gear to even run nightly builds.


Honestly, I stopped using D when I ran into this issue, was 
hoping, as you, that "someone should fix this".  However, that's 
not how good OSS works, and I'm willing to put some cycles on it 
if there is a way forward.  At the time, I had to make some fast 
decisions and opted to rewrite my code base in C.  I look forward 
to hearing from you and anyone else interested in working 
on/contributing to this topic.


Also, why I don't look at LDC further, I think RAM on the 
embedded devices is still pretty skimpy, Raspi3 only has 1GB ram. 
 It's not great for compiling with the LLVM-based things and 
probably run OOM.  Other devices I have only have 512MB ram.  So 
gcc is usually fine in these circumstances.