Re: is type checking in D undecidable?

2020-10-23 Thread Kagamin via Digitalmars-d-learn

On Thursday, 22 October 2020 at 18:24:47 UTC, Bruce Carneal wrote:
Per the wiki on termination analysis some languages with 
dependent types (Agda, Coq) have built-in termination checkers.


What they do with code that does, say, a hash preimage attack?


Re: It is possible to substract 5 from 3 unsigned integer

2020-10-08 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 6 October 2020 at 18:24:14 UTC, Alaindevos wrote:

A logical one. For the last one higher classes might be needed.


Also assert(5/3==1);


Re: How to spawn a thread within a GtkD button event handler

2020-10-08 Thread Kagamin via Digitalmars-d-learn
See 
https://forum.dlang.org/post/kqvpjwbkpravywald...@forum.dlang.org


Re: Cannot call @system funciton (stdout)

2020-09-19 Thread Kagamin via Digitalmars-d-learn

if(GetFileType(GetStdHandle(STD_OUTPUT_HANDLE))==FILE_TYPE_PIPE)setvbuf()


Re: Cannot call @system funciton (stdout)

2020-09-19 Thread Kagamin via Digitalmars-d-learn
That said, full buffering for pipes may be not all that 
profitable, so it makes sense to always set line buffering for 
pipes and leave full buffering only for file.


Re: Since DMD 2.089.0 and later, compiled .exe showing SFX zip and opening with winRar when use resource.

2020-08-19 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 18 August 2020 at 19:01:17 UTC, Marcone wrote:

SFX zip in it is properties: https://i.imgur.com/dH7jl5n.png
Opening with winRar: https://i.imgur.com/s7C9mZn.png


Probably winrar messing with your file manager. Try to uninstall 
ungerister winrar from your file manager or try a different file 
manager.


Re: Cannot call @system funciton (stdout)

2020-08-18 Thread Kagamin via Digitalmars-d-learn

On Sunday, 16 August 2020 at 18:13:07 UTC, Anonymouse wrote:
Just as a drive-by comment, the main stdio thing I came across 
that I couldn't do from within @safe was stdout.flush(), which 
I need to call manually for Cygwin terminals and some terminals 
embedded in editors (vscode). If someone knows why, please tell 
me.


Cygwin terminals are not recognized as terminals, you should set 
line buffered mode, then it will flush every line.


Re: Why is time_t defined as a 32-bit type on Windows?

2020-08-07 Thread Kagamin via Digitalmars-d-learn
Because it's used with C `time` function 
https://github.com/dlang/druntime/blob/master/src/core/stdc/time.d#L37 which is provided by msvcrt as 32-bit function. 64-bit variant has a different name.


Re: Good way to send/receive UDP packets?

2020-07-28 Thread Kagamin via Digitalmars-d-learn

On Monday, 27 July 2020 at 09:41:44 UTC, wjoe wrote:
But it's possible when bound with the socket option 
SO_REUSEPORT (at least that's the name of the flag on linux 
since 3.9).


The docs say it can't be used to hijack an address.
This option must be set on each socket (including the first 
socket) prior to calling bind(2) on the socket.


Re: Good way to send/receive UDP packets?

2020-07-23 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 22 July 2020 at 16:14:24 UTC, wjoe wrote:
If you send a UDP datagram to a single address, however, it 
will still be delivered to every program on that PC which 
receives UDP datagrams from that port.


Normally binding two sockets to the same port is not allowed.


Re: how to assign to shared obj.systime?

2020-07-14 Thread Kagamin via Digitalmars-d-learn
Yes, all the synchronization and casting pretty much mandates 
that shared data must be behind some kind of abstraction for 
better ergonomics and better correctness too.


Re: how to assign to shared obj.systime?

2020-07-14 Thread Kagamin via Digitalmars-d-learn

---
import std;

shared class TimeCount {
synchronized void startClock() {
auto me = cast()this;
me.startTime = Clock.currTime;
}
synchronized void endClock() {
auto me = cast()this;
me.endTime = Clock.currTime;
}
synchronized void calculateDuration() {
auto me = cast()this;
me.elapsed = me.endTime - me.startTime;
}

private:
SysTime startTime;
SysTime endTime;
Duration elapsed;
}
---
forgot synchronized attribute


Re: how to assign to shared obj.systime?

2020-07-14 Thread Kagamin via Digitalmars-d-learn

---
import std;

shared class TimeCount {
void startClock() {
auto me = cast()this;
me.startTime = Clock.currTime;
}
void endClock() {
auto me = cast()this;
me.endTime = Clock.currTime;
}
void calculateDuration() {
auto me = cast()this;
me.elapsed = me.endTime - me.startTime;
}

private:
SysTime startTime;
SysTime endTime;
Duration elapsed;
}
---
And this is shorter than your unshared member specification.


Re: how to assign to shared obj.systime?

2020-07-14 Thread Kagamin via Digitalmars-d-learn

On Monday, 13 July 2020 at 07:26:06 UTC, Arafel wrote:
That's exactly why what I propose is a way to *explicitly* tell 
the compiler about it, like @system does for safety.


With __gshared you can opt out from sharing safety, then you're 
back to old good C-style multithreading.


Re: How can I make executeShell ask for Admin Elevation?

2020-07-12 Thread Kagamin via Digitalmars-d-learn

I mean runas your own program.


Re: How can I make executeShell ask for Admin Elevation?

2020-07-12 Thread Kagamin via Digitalmars-d-learn
Well, you can elevate your own program and tell it to run that 
command, collect the result and send it back through e.g. shared 
memory.


Re: How can I make executeShell ask for Admin Elevation?

2020-07-12 Thread Kagamin via Digitalmars-d-learn
You call ShellExecute with "runas" verb: 
https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea


Re: how to assign to shared obj.systime?

2020-07-10 Thread Kagamin via Digitalmars-d-learn

On Friday, 10 July 2020 at 17:18:25 UTC, mw wrote:

On Friday, 10 July 2020 at 08:48:38 UTC, Kagamin wrote:

On Friday, 10 July 2020 at 05:12:06 UTC, mw wrote:

looks like we still have to cast:
as of 2020, sigh.


Why not?


Because cast is ugly.


Implicitly escaping thread local data into shared context is much 
uglier than a cast. D disallows such implicit sharing, and thus 
ensures existence of thread local data on the language level. 
SysTime wasn't designed to be shared and due to this is 
incompatible with sharing by default, which enforces the promise 
that SysTime must be thread local, because it wasn't designed to 
be shared.


synchronized setTime(ref SysTime t) shared {
(cast()this).time = t;
}
Steven's solution isn't good in the general case, because it 
still puts thread local data in shared context, which itself is a 
problem, because it makes thread local data implicitly shared, 
and when you work with such implicitly shared thread local data, 
you can't assume it's thread local, because it might be escaped 
into shared context. In this case the language prevented implicit 
sharing of thread local data (this is what shared does and does 
it well contrary to the popular myth that shared is broken).


Re: how to assign to shared obj.systime?

2020-07-10 Thread Kagamin via Digitalmars-d-learn

On Friday, 10 July 2020 at 05:12:06 UTC, mw wrote:

looks like we still have to cast:
as of 2020, sigh.


Why not?


Re: App/lib config system

2020-07-10 Thread Kagamin via Digitalmars-d-learn

Without contradictions the solution is trivial:

module config;

version(LogEnabled) enum isEnabled=true;
else enum isEnabled=false;

shared int level;


Re: App/lib config system

2020-07-10 Thread Kagamin via Digitalmars-d-learn

Contradictions that don't let you glue it all together.


Re: App/lib config system

2020-07-09 Thread Kagamin via Digitalmars-d-learn
If you suspect there's a contradiction in requirements, you need 
to specify them with better precision.


Re: Catching OS Exceptions in Windows using LDC

2020-07-04 Thread Kagamin via Digitalmars-d-learn
try 
https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-setunhandledexceptionfilter


Re: Delegates and C++ FFI lifetimes

2020-07-03 Thread Kagamin via Digitalmars-d-learn

You can store the delegate in an array and invoke it by index.


Re: Program exited with code -11 when calling

2020-06-30 Thread Kagamin via Digitalmars-d-learn
bson_t* bson_new_from_json(in char* data, long len, bson_error_t* 
error);


string str_utf8 = "{\"a\":1}";
bson_error_t error;

auto bson = bson_new_from_json(str_utf8.ptr, str_utf8.length, 
);


You have a wrong declaration for bson_error_t too.


Re: Calling C functions

2020-06-30 Thread Kagamin via Digitalmars-d-learn
On Monday, 29 June 2020 at 19:55:59 UTC, Steven Schveighoffer 
wrote:
Yep, for sure. I'll file an issue. Anyone know why the calling 
convention would differ?


It's easier to enforce left to right evaluation order this way: 
arguments are pushed to stack as they are evaluated, which is 
pascal calling convention.


Re: Garbage collection

2020-06-30 Thread Kagamin via Digitalmars-d-learn

On Saturday, 27 June 2020 at 14:49:34 UTC, James Gray wrote:
I have produced something which essentially reproduces my 
problem.


What is the problem? Do you have a leak or you want to know how 
GC works?


Re: Light-weight runtime

2020-06-29 Thread Kagamin via Digitalmars-d-learn

On Sunday, 28 June 2020 at 07:09:53 UTC, Виталий Фадеев wrote:

I want light-weight runtime !

How to ?


Runtime provides language features that rely on extra code. 
Removing that code from runtime means to give up on corresponding 
language features. This way you can implement only features you 
want or even reduce runtime to almost zero. You can start by not 
linking your code with druntime and see what's missing and see if 
you can evade or implement the feature.


Re: How to send ownerTid into a parallel foreach loop?

2020-06-27 Thread Kagamin via Digitalmars-d-learn

On Saturday, 27 June 2020 at 07:51:21 UTC, adnan338 wrote:

On Saturday, 27 June 2020 at 07:31:56 UTC, Kagamin wrote:
std.concurrency is for noninteractive appications, the 
approach with gui timer was the correct one.


Thank you. That works but my progress bar is sometimes getting 
stuck because of a possible data race.
See 
https://forum.dlang.org/post/gacweulvbyorkseti...@forum.dlang.org


Sometimes? In that code you write the progress variable only 
once, so it doesn't change after that. Nothing else can possibly 
happen there with or without multithreading.


Re: How to send ownerTid into a parallel foreach loop?

2020-06-27 Thread Kagamin via Digitalmars-d-learn
std.concurrency is for noninteractive appications, the approach 
with gui timer was the correct one.


Re: Downloading files over TLS

2020-06-26 Thread Kagamin via Digitalmars-d-learn

On Friday, 26 June 2020 at 10:12:09 UTC, Jacob Carlborg wrote:
Downloading files over TLS. This seems that it's something that 
should be quite simple to do. My high level goals are 
cross-platform and easy distribution. I don't need anything 
fancy just a simple API like this:


download("https://url.com;, "/local/file");


Maybe just start wget or something like that?

* Network [6]. This is an Apple specific library provided by 
the platform. This is the recommend alternative to 
SecureTransport. The problem is that this is not just an 
alternative TLS implementation, it's a completely different 
alternative to BSD sockets. The API is completely different and 
will require some extra layers to to provide a cross-platform 
API. This means that I cannot use any of the existing library 
to just add TLS, it will be a completely different 
implementation, which might be ok. Another big problem is that 
it only available on macOS 10.14 and later. I have not decided 
yet if this is acceptable or not


Since you want the latest certificate storage, you intend to 
support only the latest system. Many root certificates will 
timeout now.


* Are there any high level APIs, like NSURLSession, on Windows 
that can be used to download files?


https://docs.microsoft.com/en-us/windows/win32/winhttp/about-winhttp


Re: How to correctly integrate D library to Swift/Obj-C mobile project?

2020-06-22 Thread Kagamin via Digitalmars-d-learn
If you want to use them from D, you need those classes and 
methods declared in the D language, in text.


Re: GtkD code review - How to update a progressbar using data sharing concurrency

2020-06-21 Thread Kagamin via Digitalmars-d-learn

Not sure how much synchronization do you want to do.

import gio.Application : GioApplication = Application;
import gtk.Application : Application;
import gtk.ApplicationWindow : ApplicationWindow;
import gtk.ProgressBar : ProgressBar;
import glib.Timeout : Timeout;
import gtkc.gtktypes : GApplicationFlags, GPriority;

shared class Downloader
{
import core.atomic;
string[] links = [`link1`, `link2`, `link3`, `link4`];
private size_t completed = 0;

size_t count()
{
return atomicLoad(completed);
}

void increment()
{
atomicOp!"+="(completed, 1);
}

static void start(shared Downloader downloader)
{
import std.parallelism : parallel;
import core.thread : Thread, seconds;

{
// emulate HTTP response overhead;
Thread.sleep(seconds(2));
}
{
// emulate random Download time
import std.random : Random, uniform;

auto rnd = Random(4361);

foreach (ref link; downloader.links.parallel())
{
Thread.sleep(uniform(0, 6, rnd).seconds());
downloader.increment();
}
}
}
}

class ProgressIndicatorBar : ProgressBar
{
this()
{
super.setShowText(true);
super.setPulseStep(0.2);
}
}

class PrimaryWindow : ApplicationWindow
{
const int width = 320, height = 100;
ProgressIndicatorBar pib;
this(Application app)
{
super(app);
super.setSizeRequest(width, height);
scope (success)
super.showAll();

pib = new ProgressIndicatorBar();
scope (success)
add(pib);

shared downloader = new shared Downloader();

import std.parallelism : task;

auto downloadTask = task!(Downloader.start)(downloader);
downloadTask.executeInNewThread();

auto timeout = new Timeout(100, delegate bool() {
			const long completed=downloader.count, 
total=downloader.links.length;

if (completed < total)
{
if (completed == 0)
{
pib.setText(`Awaiting response...`);
pib.pulse();
}
else
{
pib.setText(`Downloading...`);
double fraction=completed; 
fraction/=total;
pib.setFraction(fraction);
}
return true;
}
else
{
super.setTitle(`Downloading complete`);
// pib.setShowText(false);
pib.setVisible(false);
return false;
}
}, GPriority.HIGH);
}
}

int main(string[] args)
{
	auto application = new 
Application(`org.gitlab.helloprogressbar`, 
GApplicationFlags.FLAGS_NONE);

application.addOnActivate(delegate void(GioApplication app) {
auto appWindow = new PrimaryWindow(application);
});
return application.run(args);
}



Re: Initializing an associative array of struct

2020-06-14 Thread Kagamin via Digitalmars-d-learn

string param="aa";
parameters[param]=Parameter();
in id=parameters[param].id;


Re: Initializing an associative array of struct

2020-06-14 Thread Kagamin via Digitalmars-d-learn

that's
int id=parameters[param].id;


Re: DIP1000 spec?

2020-06-14 Thread Kagamin via Digitalmars-d-learn

Logic is apparently still in flux, too early to document.


Re: How to allocate/free memory under @nogc

2020-05-22 Thread Kagamin via Digitalmars-d-learn

On Thursday, 21 May 2020 at 17:19:10 UTC, Konstantin wrote:
Hi all! I will try to ask again(previous two posts still have 
no answers) : are there any site/page/docs somewhere to track 
actual info about @nogc support in language itself and in 
phobos library? Or, at least plans to extend such support?


https://dlang.org/spec/function.html#nogc-functions - here's 
language support. Phobos tends to infer attributes like @nogc, so 
it's context dependent, the actual info is provided by the 
compiler.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Kagamin via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote:
It would be great if we could change/customise the icon of the 
Command line application that run the HelloWorld application. 
But I have a bad feeling that it is probably not possible 
without a GUI library.


I think the window icon is just the first icon pulled from the 
executable file.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Kagamin via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:02:02 UTC, BoQsc wrote:
The important question is: how can we change the name/title of 
this Command Line application.


As the simplest solution, you can set the window title in 
shortcut properties.


Re: GtkD - how to list 0..100K strings [solved]

2020-04-28 Thread Kagamin via Digitalmars-d-learn

On Monday, 27 April 2020 at 10:28:04 UTC, mark wrote:
I renamed the class shown in my previous post from View to 
InnerView, then created a new View class:


class View : ScrolledWindow {
import qtrac.debfind.modelutil: NameAndDescription;

InnerView innerView;

this() {
super();
innerView = new InnerView;
addWithViewport(innerView);
}

void clear() {
innerView.viewData.clear;
}

void populate(NameAndDescription[] namesAndDescriptions) {
innerView.viewData.populate(namesAndDescriptions);
}
}


Try this:

void populate(NameAndDescription[] namesAndDescriptions) {

if(namesAndDescriptions.length>100)namesAndDescriptions=namesAndDescriptions[0..100];

innerView.viewData.populate(namesAndDescriptions);
}


Re: Can I get the compiler to warn or fail on uninitialized variables/class members?

2020-03-21 Thread Kagamin via Digitalmars-d-learn

Maybe if you teach dparse to do this check.


Re: Best way to learn 2d games with D?

2020-03-19 Thread Kagamin via Digitalmars-d-learn
On Thursday, 19 March 2020 at 13:10:29 UTC, Steven Schveighoffer 
wrote:

Similar for me but not GameMaker but RPG Maker.


I've seen all your work on the language, and this is a pretty 
good endorsement.


Not sure if I'm ready to pay for it though, I want to make sure 
his motivation/drive is not going to fizzle out ;)


IME RPG Maker has bad support for animations and shines in mostly 
static turn based RPG battles. Some games try to do nontrivial 
animations, but they become very slow slideshows with many 
seconds between slides. Not sure which game he would prefer to 
make.


Re: OR in version conditional compilation

2020-03-19 Thread Kagamin via Digitalmars-d-learn

https://issues.dlang.org/show_bug.cgi?id=19495#c1


Re: Parsing with dxml

2019-11-19 Thread Kagamin via Digitalmars-d-learn

On Monday, 18 November 2019 at 06:44:43 UTC, Joel wrote:

```


http://www.w3.org/2001/XMLSchema-instance;>
  

```


You're missing a closing tag.


Re: Why same pointer type for GC and manual memory?

2019-11-14 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 13 November 2019 at 16:43:27 UTC, IGotD- wrote:

On Wednesday, 13 November 2019 at 15:30:33 UTC, Dukc wrote:


I'm not 100% sure what managed pointers mean -Are they so that 
you can't pass them to unregistered memory? A library solution 
would likely do -wrap the pointer in a struct and make it 
@system to extract it's pointer as "raw". So you cannot put it 
to C-allocated arrays without type casting, which you probably 
don't do accidently.




Best example is probably managed C++, an MS extension to C++ 
which is now deprecated. However, it server as an interesting 
example where MS extended C++ with a ^gc type.


AFAIK those managed pointers are not general purpose, but 
specifically for managed .net objects, you can't allocate 
unmanaged object on managed heap, and managed object on unmanaged 
heap. In case of D you would have raw pointers for unmanaged 
objects allocated in C heap and D GC heap, and additional .net 
pointers for .net objects.


Re: Eliding of slice range checking

2019-10-31 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote:
Does DMD/LDC avoid range-checking in slice-expressions such as 
the one in my array-overload of `startsWith` defined as


bool startsWith(T)(scope const(T)[] haystack,
   scope const(T)[] needle)
{
if (haystack.length >= needle.length)
{
return haystack[0 .. needle.length] == needle; // is 
slice range checking avoid here?

}
return false;
}


LDC is good at optimizing simple patterns, the only pitfall I 
know is 
https://forum.dlang.org/post/eoftnwkannqmubhjo...@forum.dlang.org


Re: Eliding of slice range checking

2019-10-29 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote:
Does DMD/LDC avoid range-checking in slice-expressions such as 
the one in my array-overload of `startsWith` defined as


bool startsWith(T)(scope const(T)[] haystack,
   scope const(T)[] needle)
{
if (haystack.length >= needle.length)
{
return haystack[0 .. needle.length] == needle; // is 
slice range checking avoid here?

}
return false;
}


LDC is good at optimizing simple patterns, the only pitfall I 
know is 
https://forum.dlang.org/post/eoftnwkannqmubhjo...@forum.dlang.org


Re: How to use Dbus to detect application uniqueness in D?

2019-09-30 Thread Kagamin via Digitalmars-d-learn

On Sunday, 29 September 2019 at 02:09:56 UTC, Hossain Adnan wrote:

On Saturday, 28 September 2019 at 13:37:12 UTC, Kagamin wrote:

https://ddbus.dpldocs.info/ddbus.bus.requestName.html


It requires a Connection type which I cannot find in the API.


It's in ddbus.thin, missing documentation comment, see unittest: 
https://ddbus.dpldocs.info/source/ddbus.bus.d.html#L46 and usage 
example at http://code.dlang.org/packages/ddbus


Re: How to use Dbus to detect application uniqueness in D?

2019-09-30 Thread Kagamin via Digitalmars-d-learn

On Sunday, 29 September 2019 at 02:09:56 UTC, Hossain Adnan wrote:

On Saturday, 28 September 2019 at 13:37:12 UTC, Kagamin wrote:

https://ddbus.dpldocs.info/ddbus.bus.requestName.html


It requires a Connection type which I cannot find in the API.


It's in ddbus.thin, missing documentation comment, see unittest: 
https://ddbus.dpldocs.info/source/ddbus.bus.d.html#L46


Re: How to use Dbus to detect application uniqueness in D?

2019-09-28 Thread Kagamin via Digitalmars-d-learn

https://ddbus.dpldocs.info/ddbus.bus.requestName.html


Re: Name change weird

2019-09-13 Thread Kagamin via Digitalmars-d-learn

Maybe you upgraded SFML and now binding doesn't match?


Re: getting rid of immutable (or const)

2019-09-06 Thread Kagamin via Digitalmars-d-learn

On Thursday, 5 September 2019 at 12:46:06 UTC, berni wrote:
OK. This are two solutions and although I'll probably not going 
to use any of those (due to other reasons), I still don't 
understand, why the original approach does not work. If I've 
got a book an put it in a box and later I'll get it out again, 
it's still the same book. So why has a struct changed when I 
put it into an AA and get it out again? It's not supposed to 
change...


Physical objects work like reference types. A place on bookshelf 
is at one coordinate and a book is at another coordinate, you 
don't copy the book, you fill a place on bookshelf with a 
reference to the book.


Re: D1: How to declare an Associative array with data

2019-09-05 Thread Kagamin via Digitalmars-d-learn
Maybe something like this 
https://forum.dlang.org/post/hloitwqnisvtgfoug...@forum.dlang.org


Re: Pro programmer

2019-08-26 Thread Kagamin via Digitalmars-d-learn

On Monday, 26 August 2019 at 12:02:12 UTC, GreatSam4sure wrote:
I want customizable GUI toolkit like JavaFX and adobe spark 
framework in D.


DWT was translated from java SWT, you can do the same for JavaFX, 
D is heavily based on java and there's an automatic translation 
tool from java to D.


There's no silver bullet to become a pro, you just work and gain 
experience and this experience allows you to reflect on coding 
practices on increasing scale.


Re: Is it possible to target all platforms that Qt Quick can target?

2019-08-12 Thread Kagamin via Digitalmars-d-learn

You're probably interested in readiness, not possibility?


Re: Help me decide D or C

2019-08-01 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 31 July 2019 at 22:30:52 UTC, Alexandre wrote:

1) Improve as a programmer
2) Have fun doing programs

Thats it basically. I am planning to study all "free" time I 
have. I am doing basically this since last year.


Try Basic. It has builtin graphics, seeing you program draw is 
quite fascinating.


Re: Calling / running / executing .d script from another .d script

2019-07-29 Thread Kagamin via Digitalmars-d-learn

On Sunday, 28 July 2019 at 12:56:12 UTC, BoQsc wrote:
Right now, I'm thinking what is correct way to run another .d 
script from a .d script. Do you have any suggestions?


You mean something like execute(["rdmd", "another.d"]); ?


Re: Is betterC affect to compile time?

2019-07-26 Thread Kagamin via Digitalmars-d-learn

On Thursday, 25 July 2019 at 12:46:48 UTC, Oleg B wrote:
What reason for such restrictions? It's fundamental idea or 
temporary implementation?


I think it's a dmd limitation. Currently it has a bug that it can 
still generate code for ctfe templated functions, and they will 
fail to link if they use runtime. So yeah, currently betterC 
really means betterC all the way down. The alternative is to 
compile without -betterC switch and just use a minimal runtime if 
you use runtime features, then you have full language in ctfe.


Re: Wrong vtable for COM interfaces that don't inherit IUnknown

2019-07-21 Thread Kagamin via Digitalmars-d-learn

On Sunday, 21 July 2019 at 07:04:00 UTC, rikki cattermole wrote:
COM is used heavily in WinAPI since about Vista. Pretty much 
all new functionality has been exposed by it and NOT 
extern(Windows) functions which was the standard during up to 
about XP (for example notification icons would today be COM 
based but isn't).


E.g. jump lists 
https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-icustomdestinationlist


Shell object library? It shipped with Internet Explorer 4 and was 
installable on windows 95. Shell (explorer) is not really winapi, 
it's more or less a normal userland application that provides 
integration, like an RPC server, in this way it can be similar to 
d-bus, but it's difficult to say, because the library abstracts 
whether it works in process or out of process, most (older) shell 
objects work in process and simply provide shell logic like 
moving files to trash bin and creating shortcuts.


Re: Wrong vtable for COM interfaces that don't inherit IUnknown

2019-07-20 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 16 July 2019 at 01:38:49 UTC, evilrat wrote:
Also from what I see MS done this intentionally, means they 
either no longer loves COM or there was some other good reason.


Primary consumer of COM interfaces is Visual Basic. It was really 
only Bill Gates who loved Basic, he wrote a Basic interpreter in 
1975 and created Microsoft as a business that sold Basic 
interpreters. As gamedev was locked in C++, there was no real use 
case for COM there, so MS probably does the expected thing and 
goes with straight C++.


Re: OT: in economic terms Moore's Law is already dead

2019-07-20 Thread Kagamin via Digitalmars-d-learn
TBH modern computers are obscenely powerful, I just spent weeks 
on celeron 1.8GHz 2mb L2 cache 2gb ram computer and didn't see 
any slowness on it despite some bloated software in python and a 
strange text editor pluma that ate 150mb ram just editing a plain 
text file, I swear it's not based on electron, most operations 
were seemingly io-bound. On my notebook I downclocked i7 to 50% 
to reduce it to a decent TDP, there was a reduction in 
performance... probably, because I don't see it without 
reference, i7 was a mistake, honestly.


Re: There is a computer languages benchmark compare site, but no Dlang benchmark. I think they should support D.

2019-06-22 Thread Kagamin via Digitalmars-d-learn

On Saturday, 22 June 2019 at 01:27:31 UTC, lili wrote:
A nick site, has a lot of languages, unfortunately no dlang in 
there. 
https://benchmarksgame-team.pages.debian.net/benchmarksgame/


See https://github.com/kostya/benchmarks


Re: Not able to use this C++ library in D

2019-06-06 Thread Kagamin via Digitalmars-d-learn
You should declare methods too, see example 
https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d


Re: Stack-based @nogc dynamic array

2019-05-17 Thread Kagamin via Digitalmars-d-learn

On Friday, 17 May 2019 at 06:58:54 UTC, Marco de Wild wrote:
Thank you. I've looked into it, and it appears to be quite a 
big library. I've looked into mach.collect and mach.range, but 
I didn't manage to find what I was looking for (a simple array 
data structure). Do you recommend to look into any specific 
module?


You use your array with math.range, but without alias this, it 
uses explicit accessor `asrange` for iteration.


Re: Stack-based @nogc dynamic array

2019-05-16 Thread Kagamin via Digitalmars-d-learn
Try mach.d https://github.com/pineapplemachine/mach.d it uses 
explicit range accessors for iteration.


Re: Windows / redirect STDERR to see assert messages

2019-05-14 Thread Kagamin via Digitalmars-d-learn
Assert failure uses system IO API, try 
https://docs.microsoft.com/en-us/windows/console/setstdhandle


Re: Framework design, initialization and framework usage

2019-05-07 Thread Kagamin via Digitalmars-d-learn

struct myFramework {
myFrameworkAccessor myFWApp;
}

interface myFrameworkApp {
void init();
}

main(){
myFramework mf = new myFramework;

mf.myFWApp.init(); // this bombs because myFWApp is NULL
}

struct myFrameworkAccessor {
myFrameworkApp instance()
{
if(_instance==null)_instance=new myAppCode();
return _instance;
}
myFrameworkApp _instance;
alias instance this;
}

class myAppCode : myFrameworkApp {
void init() {...}
}


Re: Erasing passwords from ram?

2019-04-30 Thread Kagamin via Digitalmars-d-learn

You better obfuscate the password on client side.


Re: DLL creation fails with undefined symbol error

2019-04-29 Thread Kagamin via Digitalmars-d-learn

fwrite, fputc - that's missing C library.


Re: How to debug long-lived D program memory usage?

2019-04-18 Thread Kagamin via Digitalmars-d-learn
If you have a slow memory leak, you can speed it up by a stress 
test. Also the debug built application can run in a separate 
environment.


Re: D threading and shared variables

2019-04-11 Thread Kagamin via Digitalmars-d-learn
Well, if the code is too complex to debug, the usual solution is 
to try simpler code and see if it works.


Re: Pass template parameter into q{} string

2019-04-08 Thread Kagamin via Digitalmars-d-learn

Maybe just use mixin template?

mixin template f(alias values)
{
static foreach(v;values)
mixin("bool " ~ v ~ " = false;");
}
int main()
{
enum string[] a=["a","b"];
mixin f!a;
return 0;
}


Re: What Does @ Mean?

2019-04-08 Thread Kagamin via Digitalmars-d-learn

https://dlang.org/spec/function.html#property-functions


Re: D threading and shared variables

2019-04-08 Thread Kagamin via Digitalmars-d-learn

On Sunday, 7 April 2019 at 14:49:20 UTC, Archie Allison wrote:
The codebase is a reasonable size so too big (and proprietary) 
to share.


You can reduce it to a minimal example that doesn't work. Static 
variables are thread local by default in D unless they are marked 
as shared or __gshared.


Re: Emulating DLL

2019-03-19 Thread Kagamin via Digitalmars-d-learn

There was this old project: http://dsource.org/projects/ddl/


Re: Can't make inout work.

2019-03-17 Thread Kagamin via Digitalmars-d-learn

On Saturday, 16 March 2019 at 14:57:35 UTC, Paul Backus wrote:
This code fails to compile if you change `auto s2` to `const 
s2`--in other words, it has the same problem as the original 
example.


Maybe there's not much need for qualifiers anyway.

struct S(T) {
T value;
}

auto make(T)(ref T value) {
return S!T(value);
}

auto f(T)(ref T s) {
return make(s.value);
}

void f() {
class C {}
C c;
auto s1 = S!C(c);
const s2 = make!C(c);
auto s3 = f(s2);
}


Re: Can't make inout work.

2019-03-17 Thread Kagamin via Digitalmars-d-learn

struct S(T) {
T value;
bool opEquals(U:S!V,V)(in U r) const
{ return value==r.value; }
}


Re: Why does D language do not support BigDecimal type?

2019-03-12 Thread Kagamin via Digitalmars-d-learn

On Monday, 11 March 2019 at 15:23:34 UTC, BoQsc wrote:
If it is unavoidable to use Floating point, how can I quickly 
and simply understand the rules of using float to make the 
least error, or should I just find a third party package for 
that as well?


It's taught in a computational mathematics course. In short, you 
estimate how errors accumulate over operations in your algorithm, 
e.g. for a sum operation `x+y` of values with errors you have 
(x±dx)+(y±dy)±r, for which you calculate the range of values: 
minimum is x-dx+y-dy-r, maximum is x+dx+y+dy+r, so the error is 
dx+dy+r, where r is a rounding error, this error gets carried 
over to subsequent calculations. Similar for other operations. 
See for example 
https://en.wikipedia.org/wiki/Round-off_error#Accumulation_of_roundoff_error


Re: std.zlib odd behavior

2019-03-05 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 5 March 2019 at 01:43:42 UTC, solidstate1991 wrote:

https://github.com/ZILtoid1991/dimage/blob/master/source/dimage/png.d

It seems that after a certain point, it doesn't add more data 
to the compression stream, flushing doesn't help.


What do you mean by "doesn't add"?

ubyte[] slice = pos < imageData.length ? imageData[pos..(pos + 
pitch)] : imageData[pos..$];

This can't possibly work. You slice past the end of array.


Re: how to pass a malloc'd C string over to be managed by the GC

2019-02-28 Thread Kagamin via Digitalmars-d-learn

byte[] snappyCompress(in byte[] plaintext) {
import deimos.snappy.snappy;
	size_t output_length = 
snappy_max_compressed_length(plaintext.length);

byte[] output = new byte[output_length];
	if(snappy_compress(cast(char*)plaintext.ptr, plaintext.length, 
cast(char*)output.ptr, _length) == SNAPPY_OK) {

byte[] compressed = output[0..output_length];
// < do something magical here
return compressed;
}
assert(0);
}

Snappy works on bytes, not text, char is a wrong type there.


Re: Best practices of using const

2019-02-20 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 19 February 2019 at 16:38:17 UTC, drug wrote:
The same I can say about properties - for example I use them in 
meta programming to detect what to serialize/process - I skip 
methods but serialize properties and for me this is a nice 
language feature.


Serialization of arbitrary stuff is a bad practice anyway, it was 
the cause of vulnerabilities in serialization libraries. DTO is 
the way to go.


Re: Best practices of using const

2019-02-19 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 19 February 2019 at 15:30:22 UTC, Atila Neves wrote:
I keep hearing how const is nigh unusable in D, and except for 
ranges I litter my code with const everywhere, pretty much just 
as often as I used in C++.


I once spent a good amount of effort to annotate my code with 
pure and inout only to find a compiler bug, then I realized that 
annotations aren't really needed, because the collection is 
inherently mutable anyway (appender).


Re: How does Rebindable suppress the compiler's optimizations for immutable?

2019-02-15 Thread Kagamin via Digitalmars-d-learn
Union is just a pretty cast, type system guarantees don't hold 
for it.


Re: Best practices of using const

2019-02-13 Thread Kagamin via Digitalmars-d-learn
D has immutable data, const allows to consume both mutable and 
immutable data.


Re: DMD: can't get extern __gshared to work right (vs. LDC)

2019-02-07 Thread Kagamin via Digitalmars-d-learn

On Friday, 8 February 2019 at 05:28:30 UTC, DanielG wrote:

Is this correct behavior?


It's correct for Windows: address of imported data is not known 
at link time and must use dynamic linkage. AFAIK, export 
attribute doesn't do much on posix platforms.


Re: Singleton in Action?

2019-02-04 Thread Kagamin via Digitalmars-d-learn

On Sunday, 3 February 2019 at 14:42:13 UTC, Ron Tarrant wrote:
This morning I was Googling "singleton replacement" and someone 
on another forum said Factory would do the job. Anyone have 
thoughts on that?


It's usually replaced with inversion of control: the service 
instance is passed as an argument to object constructors, a 
related pattern is service provider when you need to access many 
services. Though it needs a more involved code organization 
compared to singleton. As for testing, singletons can be tested 
if you provide a setter method that allows to set a custom 
singleton instance.


Re: Purpose of template DECLARE_HANDLE in druntime

2019-01-31 Thread Kagamin via Digitalmars-d-learn

It's a strong typed handle, in C it's declared as

#ifdef STRICT
typedef void *HANDLE;
#if 0 && (_MSC_VER > 1000)
#define DECLARE_HANDLE(name) struct name##__; typedef struct 
name##__ *name

#else
#define DECLARE_HANDLE(name) struct name##__{int unused;}; 
typedef struct name##__ *name

#endif
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif


Re: What is the alternative to the setlocale function of c in D? Thank you.

2019-01-25 Thread Kagamin via Digitalmars-d-learn
also 
http://blogs.microsoft.co.il/pavely/2009/07/23/changing-console-fonts/


Re: What is the alternative to the setlocale function of c in D? Thank you.

2019-01-25 Thread Kagamin via Digitalmars-d-learn
Create a shortcut to cmd.exe and edit its properties. The console 
window itself has a system menu for this too.


Re: What is the alternative to the setlocale function of c in D? Thank you.

2019-01-24 Thread Kagamin via Digitalmars-d-learn

Try workarounds here:
https://issues.dlang.org/show_bug.cgi?id=1448
https://issues.dlang.org/show_bug.cgi?id=2742


Re: How to use core.atomic.cas with (function) pointers?

2019-01-22 Thread Kagamin via Digitalmars-d-learn
I believe this is historical. It will fail because atomics are 
combinatorially parameterized because the compiler couldn't 
properly infer template arguments until recently (this also 
resulted in memory corruption in ldc fork of druntime). Now that 
the compiler was fixed, atomics can be fixed too and have single 
template parameter.


Re: Alternative to Interfaces

2019-01-19 Thread Kagamin via Digitalmars-d-learn
On Friday, 18 January 2019 at 18:48:46 UTC, Jonathan M Davis 
wrote:

Yes, but some D features will use the GC


They would like to allocate, but they don't know nor care where 
it's allocated from, if the developer uses custom memory 
management, he will know how it's allocated and will be able to 
manage it.



The list of such features is short, but delegates are on it.


Closures are, but not delegates. Delegate is just a pair of 
pointers, you don't need to allocate at all to keep them around, 
similar to slices. They even work in betterC.


get around the allocations in some cases, but in general, if 
you use delegates, you're going to allocate with the GC.


Custom memory management is obviously not the general case.

but the allocations that happen for delegates and lambdas is 
one of the biggest reasons that some folks avoid std.algorithm 
and complain that it allocates. That's what happens when you 
pass stuff that the compiler decides has to have closures 
allocated for it.


Is it really blocked? I got this to work with dip1000:

@safe @nogc:
alias int delegate(int) @safe @nogc dg;
struct Map(T)
{
private T a;
}
Map!dg map(return dg b)
{
Map!dg m;
m.a=b;
return m;
}
void f()
{
int a;
auto b=map(i=>a);
a=b.a(0);
}

Templated function can't infer closure type for some reason.


Re: Runtime heterogeneous collections?

2019-01-18 Thread Kagamin via Digitalmars-d-learn

On Thursday, 17 January 2019 at 02:21:21 UTC, Steven O wrote:

void main()
{
alias Rec_type = Tuple!(int, "x", int, "y", int, "z");
RedBlackTree!Rec_type[1] test;
}


alias Rec_type1 = Tuple!(int, "x", int, "y", int, "z");
alias Rec_type2 = Tuple!(int, "x", int, "y", string, "z");
Tuple!(RedBlackTree!Rec_type1, "x", RedBlackTree!Rec_type2, "z") 
test;


Similar questions were asked before, usually such heterogeneous 
collections are not the best solution to the problem at hand.


Re: Alternative to Interfaces

2019-01-18 Thread Kagamin via Digitalmars-d-learn

On Friday, 18 January 2019 at 00:08:00 UTC, 1001Days wrote:
It works, but I have two questions regarding its efficacy: is 
it viable in the long run, and is it now possible to use 
delegates without the GC?


GC is just a handy memory management approach, it even works for 
C and C++, (example: gcc), nothing in D needs GC if you manage 
memory in a different way. In fact there are D libraries that 
rely solely on manual memory management.


Re: Is there a nice syntax to achieve optional named parameters?

2019-01-18 Thread Kagamin via Digitalmars-d-learn

On Friday, 18 January 2019 at 09:39:31 UTC, John Burton wrote:
It likely is a bad idea for a small struct like this but if it 
was much bigger would it makes sense to write this as :-


this(const ref Config config)

Which is what you might do in C++ or does D handle this 
differently?


For big Config struct it probably doesn't matter, but ref 
parameters don't accept rvalues.


Re: Is there a nice syntax to achieve optional named parameters?

2019-01-16 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 15 January 2019 at 11:14:54 UTC, John Burton wrote:
auto window = Window(title = "My Window", width = 1000, 
fullscreen = true);


In this particular case I would make the constructor take 3 
parameters - title, width and height. Full screen is a rare 
functionality and shouldn't clutter the constructor, can it be 
set after the window is created?


one path skips constructor

2019-01-13 Thread Kagamin via Digitalmars-d-learn

---
struct A
{
int a;
this(int)
{
if(__ctfe)this(0,0); //Error: one path skips constructor
else a=0;
}
this(int,int){ a=1; }
}
---
Is this supposed to not compile?


Re: Temporary @trusted scope

2018-12-19 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 06:11:48 UTC, Jonathan M Davis 
wrote:
Really? I would have thought that that would be a pretty 
obvious optimization (especially if inlining is enabled). I 
suppose that it doesn't entirely surprise me if dmd does a poor 
job of it, but I would have expected ldc to do better than 
that. I would think that such an improvement would be pretty 
low-hanging fruit for adding to dmd's optimizer though.


AFAIK, it was added.


Re: Temporary @trusted scope

2018-12-19 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:42:12 UTC, rikki cattermole 
wrote:

Yes except for ldc with -O3.


ldc with -O2 generates the same code.


Re: Why do ints defined in template mixins have garbage values?

2018-12-12 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 11 December 2018 at 21:19:59 UTC, Steven 
Schveighoffer wrote:
If I add an int using a regular declaration or a straight 
mixin("int i0 = 5;"); then the variable shows up.


mixin template genInts()
{
enum arr = [0];
static foreach (t; arr)
{
mixin("int i0 = 5;");
}
}

Still prints garbage.


  1   2   3   4   5   6   7   8   9   >