Re: @safe std.file.read

2020-01-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 6, 2020 8:52:01 AM MST Steven Schveighoffer via 
Digitalmars-d-learn wrote:
> On 1/6/20 5:07 AM, WebFreak001 wrote:
> > I was wondering, how are you supposed to use std.file : read in @safe
> > code when it returns a void[] but you want to get all bytes in the file?
> >
> > Is void[] really the correct type it should be returning instead of
> > ubyte[] when it just reads a (binary) file to memory? Or should void[]
> > actually be castable to ubyte[] in @safe code?
>
> I feel like this conversation has been had before. But I think it should
> be ubyte[]. Not sure why it's void[]. Perhaps for symmetry with write,
> which takes void[] (for good reason)?

I think that in previous discussions, it was decided that in general, when
you're dealing with something like reading from / write to a file or a
socket, writing should accept void[], because then you can write any binary
data to it without casting (including objects which are being serialized),
whereas reading should give you ubyte[] or const(ubyte)[], because what
you're getting from the OS is bytes of data, and it's up to the program to
figure out what to do with them.

- Jonathan M Davis





Re: Algebraic and implicit conversions

2020-01-06 Thread drug via Digitalmars-d-learn

06.01.2020 22:48, Steven Schveighoffer пишет:


I think his question is, why shouldn't this work? e.g., this works:



Ah, indeed. Sorry for noise.


Re: Algebraic and implicit conversions

2020-01-06 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/6/20 2:33 PM, drug wrote:

06.01.2020 20:08, Per Nordlöw пишет:

alias A = Algebraic!(long, string);
 A x;
 x = 42;


That's because you try to assign int, not long. This works:

alias A = Algebraic!(long, string);
A x;
x = 42L;


I think his question is, why shouldn't this work? e.g., this works:

long x;
x = 42;

FWIW, 3rd-party algebraic types (e.g. TaggedAlgebraic) will do a 
conversion for this.


-Steve


Re: Algebraic and implicit conversions

2020-01-06 Thread drug via Digitalmars-d-learn

06.01.2020 20:08, Per Nordlöw пишет:

alias A = Algebraic!(long, string);
     A x;
     x = 42;


That's because you try to assign int, not long. This works:

alias A = Algebraic!(long, string);
A x;
x = 42L;


Algebraic and implicit conversions

2020-01-06 Thread Per Nordlöw via Digitalmars-d-learn

Is there a reason why

alias A = Algebraic!(long, string);
A x;
x = 42;

doesn't implicitly convert `42` to `long` and stores it in `x`?


Re: @safe std.file.read

2020-01-06 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/6/20 5:07 AM, WebFreak001 wrote:
Or should void[] 
actually be castable to ubyte[] in @safe code?


No, because you can implicitly cast anything to void[], including 
pointer arrays.


Possibly const(ubyte[]).

-Steve


Re: @safe std.file.read

2020-01-06 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/6/20 5:07 AM, WebFreak001 wrote:
I was wondering, how are you supposed to use std.file : read in @safe 
code when it returns a void[] but you want to get all bytes in the file?


Is void[] really the correct type it should be returning instead of 
ubyte[] when it just reads a (binary) file to memory? Or should void[] 
actually be castable to ubyte[] in @safe code?


I feel like this conversation has been had before. But I think it should 
be ubyte[]. Not sure why it's void[]. Perhaps for symmetry with write, 
which takes void[] (for good reason)?


-Steve


Re: Unfold string array

2020-01-06 Thread Teo via Digitalmars-d-learn

On Monday, 6 January 2020 at 00:03:06 UTC, Temtaime wrote:


https://ideone.com/tvpreP


That's cool! Thank you very much!



Re: Mimicking a shell

2020-01-06 Thread Jan via Digitalmars-d-learn
I think the suggestion of angel would be most fitting for my 
case. As angel said, the using the C code for D would be a 
relatively small refactor.


if you want to send like a synthetic arrow keystroke, well, 
things get ugly again, it will need to send the right series of 
bytes based on what terminal the program thinks you are.


Using arrow key etc. would be very beneficial for my case. So I 
thank Adam for his solution, but I prefer angel's one.


Thanks guys :)



Re: How load icon from resource using LoadImage?

2020-01-06 Thread ShadoLight via Digitalmars-d-learn

On Sunday, 5 January 2020 at 13:52:27 UTC, JN wrote:

On Sunday, 5 January 2020 at 13:33:35 UTC, Marcone wrote:


[snip]


By the way, have you managed to add the res file into the 
binary? My understanding is that the res file should be added 
into the exe file by the rc command before it can be used.


Sort of correct... but not strictly correct. Typically the 
resource compiler (such as Microsoft's rc.exe) compiles 
xyzfile.rc into xyzfile.res.


xyzfile.res is then added into the exe by the linker during 
linking.




Re: What type does byGrapheme() return?

2020-01-06 Thread Alex via Digitalmars-d-learn

On Monday, 6 January 2020 at 08:39:19 UTC, Robert M. Münch wrote:

On 2020-01-05 04:18:34 +, H. S. Teoh said:

At a minimum, I think we should file a bug report to 
investigate whether
Grapheme.opSlice can be implemented differently, such that we 
avoid this
obscure referential behaviour that makes it hard to work with 
in complex
code. I'm not sure if this is possible, but IMO we should at 
least

investigate the possibilities.


Done... my first bug report :-) I copied togehter all the 
findings from this thread.


For the sake of completeness
https://issues.dlang.org/show_bug.cgi?id=20483


Re: @safe std.file.read

2020-01-06 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn

On Monday, 6 January 2020 at 10:07:37 UTC, WebFreak001 wrote:
I was wondering, how are you supposed to use std.file : read in 
@safe code when it returns a void[] but you want to get all 
bytes in the file?


Is void[] really the correct type it should be returning 
instead of ubyte[] when it just reads a (binary) file to 
memory? Or should void[] actually be castable to ubyte[] in 
@safe code?


I definitely think it should return ubyte[].
void[] is a very special abstraction that shouldn't be used at 
all if you don't know very well what you're doing.


Re: @safe std.file.read

2020-01-06 Thread Dennis via Digitalmars-d-learn

I would say it should return a ubyte[].

On Monday, 6 January 2020 at 10:07:37 UTC, WebFreak001 wrote:

Or should void[] actually be castable to ubyte[] in @safe code?


Definitely not with the current semantics, since a void[] can 
alias pointers in @safe code.

See: https://issues.dlang.org/show_bug.cgi?id=20345


linkererrors when reducion phobos with dustmite

2020-01-06 Thread berni44 via Digitalmars-d-learn
As mentioned on the dustmite website [1] I copied the folder std 
from Phobos in a separate folder and renamed it to mystd. The I 
changed all occurences of std by mystd in all files.


That works most of the time, but sometimes I get hundreds of 
linker errors I do not understand:


$> dmd -main -unittest -g -run mystd/variant.d

/usr/bin/ld: variant.o:(.data.rel.ro+0x68): undefined reference 
to `_D5mystd4meta12__ModuleInfoZ'
/usr/bin/ld: variant.o:(.data.rel.ro+0x70): undefined reference 
to `_D5mystd6traits12__ModuleInfoZ'
/usr/bin/ld: variant.o:(.data.rel.ro+0x78): undefined reference 
to `_D5mystd8typecons12__ModuleInfoZ'

...

Does anyone know, what's the problem here and how to get arround 
this?


[1] 
https://github.com/CyberShadow/DustMite/wiki#minimizing-the-standard-library


@safe std.file.read

2020-01-06 Thread WebFreak001 via Digitalmars-d-learn
I was wondering, how are you supposed to use std.file : read in 
@safe code when it returns a void[] but you want to get all bytes 
in the file?


Is void[] really the correct type it should be returning instead 
of ubyte[] when it just reads a (binary) file to memory? Or 
should void[] actually be castable to ubyte[] in @safe code?


Re: What type does byGrapheme() return?

2020-01-06 Thread Robert M. Münch via Digitalmars-d-learn

On 2020-01-05 04:18:34 +, H. S. Teoh said:


At a minimum, I think we should file a bug report to investigate whether
Grapheme.opSlice can be implemented differently, such that we avoid this
obscure referential behaviour that makes it hard to work with in complex
code. I'm not sure if this is possible, but IMO we should at least
investigate the possibilities.


Done... my first bug report :-) I copied togehter all the findings from 
this thread.


--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster