Re: need help to work around float union non-zero init

2024-09-20 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 20 September 2024 at 09:38:54 UTC, Dakota wrote: I need my struct defined as `isZeroInit`, so can I can import them as `di` file. (this also reduce build size) But I find this problem with float inside union: ```d struct test_t { union { int i32; float f32;

Re: need help to work around float union non-zero init

2024-09-20 Thread monkyyy via Digitalmars-d-learn
On Friday, 20 September 2024 at 09:38:54 UTC, Dakota wrote: I need my struct defined as `isZeroInit`, so can I can import them as `di` file. (this also reduce build size) But I find this problem with float inside union: ```d struct test_t { union { int i32; float f32;

Re: How to escape control characters?

2024-09-20 Thread kdevel via Digitalmars-d-learn
On Thursday, 19 September 2024 at 14:30:08 UTC, Gerardo Cahn wrote: I am using the code listed here. It should be left to posterity that the code presented in this thread cannot properly escape ``` "A\xfeZ" ``` ``` BV's escape: cast(char) 0x41, cast(char) 0xFE, cast(char) 0x5A steve's: c

Re: need help to work around float union non-zero init

2024-09-20 Thread IchorDev via Digitalmars-d-learn
On Friday, 20 September 2024 at 09:38:54 UTC, Dakota wrote: I consider this is compiler bug (it may take years to get fixed) I've sent issues for compiler bugs and had them fixed within the next release—about month, not years. Also yes, this seems to be a compiler bug; unless there's some s

need help to work around float union non-zero init

2024-09-20 Thread Dakota via Digitalmars-d-learn
I need my struct defined as `isZeroInit`, so can I can import them as `di` file. (this also reduce build size) But I find this problem with float inside union: ```d struct test_t { union { int i32; float f32; } } static assert(__traits(isZeroInit, test_t) ); ``` ``

Re: How to escape control characters?

2024-09-19 Thread Gerardo Cahn via Digitalmars-d-learn
On Wednesday, 24 August 2022 at 08:12:33 UTC, Salih Dincer wrote: On Tuesday, 23 August 2022 at 23:17:21 UTC, Salih Dincer wrote: ... Actually, both structures could be combined: ```d struct EscapedString { string[1] str; this(string str) @nogc pure nothrow @safe { ...(rest clipped) `

Using C header libs with importC

2024-09-18 Thread Imperatorn via Digitalmars-d-learn
https://forum.dlang.org/post/qpmqvhipfyyyehvoe...@forum.dlang.org On Monday, 8 January 2024 at 23:00:02 UTC, Dennis wrote: On Monday, 8 January 2024 at 21:56:10 UTC, Renato wrote: but I tried exactly that! Which gives a seg fault. Looks like there's a bug with the -H switch: https://issues.dl

Re: vibe-d linker error: undefined reference to deimos openssl

2024-09-16 Thread Curtis Spencer via Digitalmars-d-learn
On Saturday, 14 September 2024 at 12:31:01 UTC, Steven Schveighoffer wrote: On Tuesday, 10 September 2024 at 20:41:12 UTC, Curtis Spencer wrote: I'm attempting to upgrade the vibe-d dependencies of a project. The project compiles fine using `dub`, but the linker fails with: … I'm at a loss

Re: vibe-d linker error: undefined reference to deimos openssl

2024-09-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On Tuesday, 10 September 2024 at 20:41:12 UTC, Curtis Spencer wrote: I'm attempting to upgrade the vibe-d dependencies of a project. The project compiles fine using `dub`, but the linker fails with: … I'm at a loss for how to fix this linker error. Any help would be appreciated. You may

Re: assert

2024-09-12 Thread Andy Valencia via Digitalmars-d-learn
On Thursday, 12 September 2024 at 22:34:04 UTC, user1234 wrote: On Wednesday, 11 September 2024 at 10:08:29 UTC, ryuukk_ wrote: On Wednesday, 11 September 2024 at 09:14:39 UTC, Nick Treleaven wrote: On Wednesday, 11 September 2024 at 08:08:45 UTC, ryuukk_ wrote: [...] I again apologies for bei

Re: assert

2024-09-12 Thread user1234 via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 10:08:29 UTC, ryuukk_ wrote: On Wednesday, 11 September 2024 at 09:14:39 UTC, Nick Treleaven wrote: On Wednesday, 11 September 2024 at 08:08:45 UTC, ryuukk_ wrote: [...] I again apologies for being wrong and i apologies again for trying to improve things, i d

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-12 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 22:06:54 UTC, WB wrote: Honestly, D, does not really need it, and most of solutions (like above) do have one or few limitations and drawbacks. Some will be acceptable in some projects, some not. There is plenty of stuff in language and library already, add

Re: assert

2024-09-12 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 04:01:53 UTC, f wrote: i mean , is this a bug? This is not a bug. The problem is due to a misunderstanding of the -release parameter. The following related topic opened by Steven and the answers given by Walter are really valuable: https://forum.dlang.org/t

Re: assert

2024-09-11 Thread Fox via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 16:40:05 UTC, Bradley Chatha wrote: On Wednesday, 11 September 2024 at 12:17:02 UTC, Fox wrote: I don't care about whether it's a bug or not, I just want to learn What illegal instructions did this "assert(false);" code create? Fortunately Godbolt supports

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-11 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 22:06:54 UTC, WB wrote: I feel there is too much already in D and standard library, and things are added to quickly and eagerly, and years later we end up in a mess that cannot be solved (because of compatibility). this isnt autodecoding, cant be, your oping

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-11 Thread WB via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 19:44:54 UTC, Salih Dincer wrote: It looks clean and understandable. What is not understandable is that it has not been included in std.stdio for over 10 years. I know, string interpolation has just been integrated, but why hasn't something like this been deve

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-11 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 18:29:39 UTC, WB wrote: This code is about 13 years old, but still works. (It is functional and works, but I never it used more than what is in this repo). But now that we have interpolation sequences in the language, it would be way easier, cleaner and more

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-11 Thread WB via Digitalmars-d-learn
On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: Specifically, I want a way to create a print command that behaves like `@show` from Julia lang or `dump` from (if my memory is correct) Nim. Yes. https://github.com/baryluk/echo/blob/master/echo.d#L205-L209 ```d mixin(echo("e

Re: assert

2024-09-11 Thread Bradley Chatha via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 12:17:02 UTC, Fox wrote: I don't care about whether it's a bug or not, I just want to learn What illegal instructions did this "assert(false);" code create? Fortunately Godbolt supports D, so it's easy to see that it generates `ud2` on x86(_64): https://god

Re: assert

2024-09-11 Thread Fox via Digitalmars-d-learn
I don't care about whether it's a bug or not, I just want to learn What illegal instructions did this "assert(false);" code create?

Re: assert

2024-09-11 Thread Kapendev via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 10:08:29 UTC, ryuukk_ wrote: On Wednesday, 11 September 2024 at 09:14:39 UTC, Nick Treleaven wrote: On Wednesday, 11 September 2024 at 08:08:45 UTC, ryuukk_ wrote: It is a bug, don't claim it is not, the compiler gives the wrong information, wich lead to a con

Re: assert

2024-09-11 Thread ryuukk_ via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 09:14:39 UTC, Nick Treleaven wrote: On Wednesday, 11 September 2024 at 08:08:45 UTC, ryuukk_ wrote: It is a bug, don't claim it is not, the compiler gives the wrong information, wich lead to a confused user You don't want confused users, you want compiler say

Re: assert

2024-09-11 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 11 September 2024 at 08:08:45 UTC, ryuukk_ wrote: It is a bug, don't claim it is not, the compiler gives the wrong information, wich lead to a confused user You don't want confused users, you want compiler say what's up, if i type assert, it should assert, end of the story The

Re: assert

2024-09-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, September 10, 2024 10:01:53 PM MDT f via Digitalmars-d-learn wrote: > i mean , is this a bug? No, it's not a bug. Assertions with an expression that is known to be false at compile time are treated as special. They are always left in the generated code so that they will k

Re: assert

2024-09-10 Thread f via Digitalmars-d-learn
i mean , is this a bug?

assert

2024-09-10 Thread f via Digitalmars-d-learn
void main() { assert(false); } dmd -release a.d dmd version 2.109.1 debian bookworm x64 illegal instruction thanks

vibe-d linker error: undefined reference to deimos openssl

2024-09-10 Thread Curtis Spencer via Digitalmars-d-learn
I'm attempting to upgrade the vibe-d dependencies of a project. The project compiles fine using `dub`, but the linker fails with: ``` /usr/bin/ld: ../../.dub/packages/vibe-d-0.9.8/vibe-d/tls/.dub/build/openssl-debug-linux.posix-x86_64-dmd_v2.101.2-BCC9E2A9CB402B67930FAFFBF7360088035232BADBED8A5

Re: Can the send function send an array?

2024-09-10 Thread Fox via Digitalmars-d-learn
OK, It works, thanks. // dlang tries to use the type system to make one be clear about what data is shared between potentially concurrent threads. // You need that data to be "shared" before you can send it between threads. // Andy import std.concurrency; import std.stdio; void main(){

Re: Can the send function send an array?

2024-09-10 Thread Andy Valencia via Digitalmars-d-learn
On Tuesday, 10 September 2024 at 13:14:05 UTC, Fox wrote: // I am learning how to send and receive data. The following is my intention, but it cannot be compiled. // aliases to mutable thread-local data not allowed, what does it mean? thank you. dlang tries to use the type system to make one b

Can the send function send an array?

2024-09-10 Thread Fox via Digitalmars-d-learn
// I am learning how to send and receive data. The following is my intention, but it cannot be compiled. // aliases to mutable thread-local data not allowed, what does it mean? thank you. I am learning how to send and receive. The following is my intention, but it cannot be compiled. Report i

Re: Problem with assertThrown

2024-09-09 Thread kookman via Digitalmars-d-learn
On Tuesday, 10 September 2024 at 01:04:15 UTC, Jonathan M Davis wrote: When I run it locally, assertThrown passes as expected for test case 5, and the same happens on run.dlang.io, so nothing in my specific setup is making it pass when it normally wouldn't. So, unless you verified that your

Re: Problem with assertThrown

2024-09-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, September 9, 2024 6:40:07 PM MDT kookman via Digitalmars-d-learn wrote: > On Tuesday, 10 September 2024 at 00:27:43 UTC, Jonathan M Davis > > wrote: > > On Monday, September 9, 2024 5:46:18 PM MDT kookman via > > > > Digitalmars-d-learn wrote: > >>

Re: Problem with assertThrown

2024-09-09 Thread kookman via Digitalmars-d-learn
On Tuesday, 10 September 2024 at 00:27:43 UTC, Jonathan M Davis wrote: On Monday, September 9, 2024 5:46:18 PM MDT kookman via Digitalmars-d-learn wrote: It seems like assertThrown works as expected for case 4, but mysteriously not working for case 5 - despite the code under test raising the

Re: Problem with assertThrown

2024-09-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, September 9, 2024 5:46:18 PM MDT kookman via Digitalmars-d-learn wrote: > It seems like assertThrown works as expected for case 4, but > mysteriously not working for case 5 - despite the code under test > raising the same exception. Am I missing something stupid here? At a g

Problem with assertThrown

2024-09-09 Thread kookman via Digitalmars-d-learn
I'm having trouble understanding why the assertThrown in unit test 5 is not behaving in the code below: ``` ubyte[] decodeBase32(string encoded) { import std.string: indexOf, stripRight; // Remove padding if present encoded = encoded.stripRight("="); ubyte[] result; size_t

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 9 September 2024 at 20:52:09 UTC, WraithGlade wrote: In any case, this version seems more brittle than the others at least After all, you will need it in 2 ways: 1. to learn, 2. to test. After testing, you can disable it with just the version parameter while compiling. It is even p

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread monkyyy via Digitalmars-d-learn
On Monday, 9 September 2024 at 20:52:09 UTC, WraithGlade wrote: This is not that surprising considering it uses hardcoded numbers and doesn't look right. I made it on dlang.io which does space tabs, if its not ovisous to a beginner, parse is ~~lazy~~ not correct, it need to do find substrin

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread WraithGlade via Digitalmars-d-learn
On Monday, 9 September 2024 at 17:56:04 UTC, monkyyy wrote: On Monday, 9 September 2024 at 17:39:46 UTC, WraithGlade wrote: import std; auto parse(char[] s)=>s[9..$-2]; void show(T,string file= __FILE__,int line=__LINE__)(T t){ writeln(File(file).byLine.drop(line-1).front.parse," == ",t)

Re: How to Humanize Numerical Input|Output

2024-09-09 Thread user1234 via Digitalmars-d-learn
On Monday, 9 September 2024 at 20:02:48 UTC, Jabari Zakiya wrote: I have this code to input integer values: ``` ulong[] x; foreach (_; 0 .. 2) { ulong a; readf!" %d"(a); x ~= a; } end_num = max(x[0], 3); start_num = max(x[1], 3); if (start_num > end_num) swap(start_num, end_num); sta

Re: How to Humanize Numerical Input|Output

2024-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 9 September 2024 at 20:02:48 UTC, Jabari Zakiya wrote: Also for output, I do this: ``` writeln("total twins = ", twinscnt, "; last twin = ", last_twin - 1, "+/-1"); ``` I'd also like to output data as: 123,987 or 123_987 You can use separators using writefln: ```d writefln("%,

Re: How to Humanize Numerical Input|Output

2024-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 9 September 2024 at 20:02:48 UTC, Jabari Zakiya wrote: I have this code to input integer values: ``` ulong[] x; foreach (_; 0 .. 2) { ulong a; readf!" %d"(a); x ~= a; } end_num = max(x[0], 3); start_num = max(x[1], 3); if (start_num > end_num) swap(start_num, end_num); sta

How to Humanize Numerical Input|Output

2024-09-09 Thread Jabari Zakiya via Digitalmars-d-learn
I have this code to input integer values: ``` ulong[] x; foreach (_; 0 .. 2) { ulong a; readf!" %d"(a); x ~= a; } end_num = max(x[0], 3); start_num = max(x[1], 3); if (start_num > end_num) swap(start_num, end_num); start_num = start_num | 1; // if start_num even add 1 e

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread monkyyy via Digitalmars-d-learn
On Monday, 9 September 2024 at 19:29:01 UTC, Salih Dincer wrote: My only concern is why i == 5 in the line below when i == 28? i isn't being modified by a `*=`. its only the two ++

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 9 September 2024 at 17:56:04 UTC, monkyyy wrote: auto parse(char[] s)=>s[9..$-2]; void show(T,string file= __FILE__,int line=__LINE__)(T t){ writeln(File(file).byLine.drop(line-1).front.parse," == ",t); } void main(){ int i=3; show(i++ + ++i * i); show(i); } This so

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread monkyyy via Digitalmars-d-learn
On Monday, 9 September 2024 at 17:39:46 UTC, WraithGlade wrote: import std; auto parse(char[] s)=>s[9..$-2]; void show(T,string file= __FILE__,int line=__LINE__)(T t){ writeln(File(file).byLine.drop(line-1).front.parse," == ",t); } void main(){ int i=3; show(i++ + ++i * i); sho

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread WraithGlade via Digitalmars-d-learn
Thank you all for your very helpful replies and for taking the time to make them! It is indeed heartening to see that D supports multiple different forms of this mechanism. This is certainly sufficient for the example I gave. I suggest that something like this should be added to the standar

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: Basically, I want there to be a way to print both an expression and its value but to only have to write the expression once (which also aids refactoring). Such a feature is extremely useful for faster print-based debugging. [...]

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread monkyyy via Digitalmars-d-learn
On Monday, 9 September 2024 at 00:34:03 UTC, Paul Backus wrote: The only way is that a challenge? void main() { import std.stdio; mixin(show!"1 + 2"); // 1 + 2 == 3 const int x = 1 + 2; mixin(show!"x"); // x == 3 } ``` idk why you calling it a macro, im pretty sure d isnt

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 8 September 2024 at 23:01:22 UTC, monkyyy wrote: On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: I want to just be able to write this: ``` show!(1 + 2) ``` ```d void show(string s)(){ auto res=mixin(s); writeln(s,"==",res); } show!"1+2"; ``` This works for `s

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread Paul Backus via Digitalmars-d-learn
On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: Basically, I want there to be a way to print both an expression and its value but to only have to write the expression once (which also aids refactoring). Such a feature is extremely useful for faster print-based debugging. Thus,

Re: Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread monkyyy via Digitalmars-d-learn
On Sunday, 8 September 2024 at 22:01:10 UTC, WraithGlade wrote: I want to just be able to write this: ``` show!(1 + 2) ``` ```d void show(string s)(){ auto res=mixin(s); writeln(s,"==",res); } show!"1+2"; ```

Is it possible to use templates to implement something like the `@show` macro from the Julia programming langauge in D?

2024-09-08 Thread WraithGlade via Digitalmars-d-learn
Hello everyone! This is my first post in these forums. D is an interesting language (basically a saner C++, which is a nice prospect because I've used C++ working in the game industry in the past) and I've been considering using it and may still do so. However, there is a very basic debuggin

Re: Pipeline issue

2024-09-07 Thread zzzSleep via Digitalmars-d-learn
Thanks go to Paul Backus, nside the foreach loop, this will cause your code to wait at the end of the current loop iteration, not at the end of the function.

Pipeline issue

2024-09-07 Thread zzzSleep via Digitalmars-d-learn
Could I ask some questions on the pipeline, the following code always stops at the second cmds, cmds[1]. I tested the command under shell and found it can quickly end and get output.bam ``` import std.process; import std.stdio; import std.conv; void executeCommandPipe(string[][] cmds) { //

Re: Tuple List

2024-09-05 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 4 September 2024 at 08:58:34 UTC, Sergey wrote: Something like: ```d l2.byPair.filter!"a.value > 0".map!(a => a.key).writeln; ``` Thank you for your answers, my forum friends. For tuples that are not fully integrated into the language yet, byPair() is a nice possibility. Becaus

Re: Tuple List

2024-09-04 Thread Sergey via Digitalmars-d-learn
On Wednesday, 4 September 2024 at 08:45:04 UTC, Salih Dincer wrote: On Wednesday, 4 September 2024 at 08:04:58 UTC, drug007 wrote: Thank you, it's my mistake. We confused HOF, which has the same first letter. So, if we turn the question towards the associative array, can a similar one be done w

Re: Tuple List

2024-09-04 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 4 September 2024 at 08:04:58 UTC, drug007 wrote: You should use filter instead of find. Find finds the first element and returns the range from that first element to the end of the original range. Thank you, it's my mistake. We confused HOF, which has the same first letter. So

Re: Tuple List

2024-09-04 Thread drug007 via Digitalmars-d-learn
On 04.09.2024 10:51, Salih Dincer wrote: import std.algorithm; import std.typecons; alias T = Tuple!(string, "key", int, "value"); auto t1 = [T("WC", 0), T("Atelye", 0), T("Mutfak", 41),     T("Salon", 42) ]; assert(t1.find!"a.value > 0"   .map!"a.key" .equal(["Mutfak", "Salon"]) ); au

Tuple List

2024-09-04 Thread Salih Dincer via Digitalmars-d-learn
Why doesn't t2 give the same result as t1? ```d import std.algorithm; import std.typecons; alias T = Tuple!(string, "key", int, "value"); auto t1 = [T("WC", 0), T("Atelye", 0),     T("Mutfak", 41),     T("Salon", 42) ]; assert(t1.find!"a.value > 0"       .map!"a.key" .equal(["Mu

Re: std.random.uniform failing

2024-09-03 Thread remontoir via Digitalmars-d-learn
On Tuesday, 3 September 2024 at 12:09:36 UTC, monkyyy wrote: I think your wrong about what remove does, `axes=axes.remove(axis.length.uniform)` Duh ! You're right, remove does take indices or ranges. Using filter, now ;) `axes.filter!(a => a != axis).array` thanks.

Re: std.random.uniform failing

2024-09-03 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 3 September 2024 at 11:57:42 UTC, remontoir wrote: Not really sure what is happening here. This works is "None" is removed, but displays a silly answer or fails with "range is smaller than amount of items to pop" otherwise. I guess it is related to enum being also integers ? ```d

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-09-02 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 2 September 2024 at 11:56:10 UTC, Nick Treleaven wrote: test.update("hello", () => noreturn.init, (ref int x) { x++; }); Sorry, that aborts if the key isn't present. `update` requires the first callback to provide a value for the key, and it can't return void.

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-09-02 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 2 September 2024 at 11:56:10 UTC, Nick Treleaven wrote: Annoyingly, the `int` is required, though maybe just an IFTI bug. https://issues.dlang.org/show_bug.cgi?id=24255

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-09-02 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 31 August 2024 at 15:38:49 UTC, ryuukk_ wrote: Let's see how other languages do it: ```zig map.put("hello", 42); // get pointer if (map.get("hello")) |*it| { std.log.debug("{}", .{it}); } // get value if (map.get("hello")) |it| { std.log.deb

Re: Adding a partial specialization of std.conv.to for Typedef!string

2024-09-01 Thread monkyyy via Digitalmars-d-learn
On Sunday, 1 September 2024 at 11:01:13 UTC, kdevel wrote: In order to make this work ```d import std.typecons; alias vstring = Typedef!string; void main () { import std.stdio; import std.conv; auto v = 3.to!vstring; // ain't work out of the box writeln (v); auto w = 3.to!stri

Adding a partial specialization of std.conv.to for Typedef!string

2024-09-01 Thread kdevel via Digitalmars-d-learn
In order to make this work ```d import std.typecons; alias vstring = Typedef!string; void main () { import std.stdio; import std.conv; auto v = 3.to!vstring; // ain't work out of the box writeln (v); auto w = 3.to!string; writeln (w); long l = 3.to!long; writeln (l);

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-09-01 Thread evilrat via Digitalmars-d-learn
On Sunday, 1 September 2024 at 08:50:53 UTC, ryuukk_ wrote: if checking for/getting a value from a hashmap requires all that crap, then perhaps something is wrong with the language, and it perhaps isn't the one i should have picked for the task my mistake perhaps, not yours besides, i do u

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-09-01 Thread kdevel via Digitalmars-d-learn
On Saturday, 31 August 2024 at 13:48:52 UTC, ryuukk_ wrote: On Saturday, 31 August 2024 at 13:00:42 UTC, Steven Schveighoffer wrote: On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: ```D void main() { int[string] test; test["hello"] = 42; if (auto it = "hello" in test)

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-09-01 Thread ryuukk_ via Digitalmars-d-learn
On Sunday, 1 September 2024 at 03:06:53 UTC, Paul Backus wrote: On Saturday, 31 August 2024 at 22:06:26 UTC, kdevel wrote: Is that functionally different from ``` void main() { import std.stdio; int[string] test = ["hello": 42]; if (auto p = "hello" in test) { writeln(

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 31 August 2024 at 22:06:26 UTC, kdevel wrote: Is that functionally different from ``` void main() { import std.stdio; int[string] test = ["hello": 42]; if (auto p = "hello" in test) { writeln("hello => ", *p); } } ``` It's essentially the same. I only

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 01/09/2024 4:34 AM, Lance Bachmeier wrote: On Saturday, 31 August 2024 at 15:38:49 UTC, ryuukk_ wrote: Let's see how other languages do it: ```zig     map.put("hello", 42);     // get pointer     if (map.get("hello")) |*it| {     std.log.debug("{}", .{it});     }     // get value    

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread kdevel via Digitalmars-d-learn
On Saturday, 31 August 2024 at 14:25:29 UTC, Paul Backus wrote: [...] Once the next release of Phobos comes out, with [PR 9039][1] merged, you'll be able to do it like this: ```d import std.typecons; Nullable!V maybeGet(K, V)(V[K] aa, K key) { if (auto ptr = key in aa) return null

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread ryuukk_ via Digitalmars-d-learn
On Saturday, 31 August 2024 at 16:34:00 UTC, Lance Bachmeier wrote: On Saturday, 31 August 2024 at 15:38:49 UTC, ryuukk_ wrote: Let's see how other languages do it: ```zig map.put("hello", 42); // get pointer if (map.get("hello")) |*it| { std.log.debug("{}", .{it}); }

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread Lance Bachmeier via Digitalmars-d-learn
On Saturday, 31 August 2024 at 15:38:49 UTC, ryuukk_ wrote: Let's see how other languages do it: ```zig map.put("hello", 42); // get pointer if (map.get("hello")) |*it| { std.log.debug("{}", .{it}); } // get value if (map.get("hello")) |it| { std.log.deb

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread ryuukk_ via Digitalmars-d-learn
Let's see how other languages do it: ```zig map.put("hello", 42); // get pointer if (map.get("hello")) |*it| { std.log.debug("{}", .{it}); } // get value if (map.get("hello")) |it| { std.log.debug("{}", .{it}); } ``` No imports, no templates, ONE LIN

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread ryuukk_ via Digitalmars-d-learn
On Saturday, 31 August 2024 at 14:25:29 UTC, Paul Backus wrote: On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: ```D void main() { int[string] test; test["hello"] = 42; if (auto it = "hello" in test) { } } ``` Is there a way to get the value instead of a point

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: ```D void main() { int[string] test; test["hello"] = 42; if (auto it = "hello" in test) { } } ``` Is there a way to get the value instead of a pointer? while keeping the conciseness (one line) Once the next rel

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread ryuukk_ via Digitalmars-d-learn
On Saturday, 31 August 2024 at 13:00:42 UTC, Steven Schveighoffer wrote: On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: ```D void main() { int[string] test; test["hello"] = 42; if (auto it = "hello" in test) { } } ``` Is there a way to get the value instead o

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: ```D void main() { int[string] test; test["hello"] = 42; if (auto it = "hello" in test) { } } ``` Is there a way to get the value instead of a pointer? while keeping the conciseness (one line) Maybe if(auto it

Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread ryuukk_ via Digitalmars-d-learn
```D void main() { int[string] test; test["hello"] = 42; if (auto it = "hello" in test) { } } ``` Is there a way to get the value instead of a pointer? while keeping the conciseness (one line)

Re: importC error: _Builtin_stddef

2024-08-30 Thread Tim via Digitalmars-d-learn
On Friday, 30 August 2024 at 04:49:48 UTC, Dakota wrote: get this error: ```sh In file included from /llvm/lib/clang/18/include/stddef.h:77, from /usr/include/time.h:29, from /llvm/include/clang-c/CXFile.h:17, from /llvm/include/clang-c/CXSour

Re: importC error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/vm_types.h(168): Error: variable `lib_test.mach_vm_range_recipe_v1_

2024-08-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 8 August 2024 at 06:34:43 UTC, Dakota wrote: ```sh /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/vm_types.h(168): Error: variable `lib_test.mach_vm_range_recipe_v1_t.range` - no definition of struct `mach_vm_range` /

Re: importC error: _Builtin_stddef

2024-08-30 Thread Lance Bachmeier via Digitalmars-d-learn
On Friday, 30 August 2024 at 04:49:48 UTC, Dakota wrote: get this error: ```sh In file included from /llvm/lib/clang/18/include/stddef.h:77, from /usr/include/time.h:29, from /llvm/include/clang-c/CXFile.h:17, from /llvm/include/clang-c/CXSour

Re: How do I compile D code for WASM? Any alternative runtime recommendations?

2024-08-29 Thread solidstate1991 via Digitalmars-d-learn
On Wednesday, 28 August 2024 at 19:43:53 UTC, Sergey wrote: No, many of them on the Discord.. Your game with raylib + wasm example also in the list of links :) Regardless, I will add them to the wiki, which is easier to search and access than a service primarily designed for chat.

Re: Understanding the Behavior of i + ++i in D Language

2024-08-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, August 28, 2024 3:44:59 PM MDT Johann Lermer via Digitalmars-d- learn wrote: > On Friday, 23 August 2024 at 08:58:16 UTC, Me'vâ wrote: > > writeln("Result: ", i + ++i); > > I would definitely expect 11 as result (but I still have K&R on >

Re: Understanding the Behavior of i + ++i in D Language

2024-08-28 Thread Johann Lermer via Digitalmars-d-learn
On Friday, 23 August 2024 at 08:58:16 UTC, Me'vâ wrote: writeln("Result: ", i + ++i); I would definitely expect 11 as result (but I still have K&R on my book shelf, maybe I'm a bit biased). So, when you get 12 with C, I would consider that an error.

Re: How do I compile D code for WASM? Any alternative runtime recommendations?

2024-08-28 Thread Sergey via Digitalmars-d-learn
On Wednesday, 28 August 2024 at 19:29:39 UTC, monkyyy wrote: On Wednesday, 28 August 2024 at 19:08:58 UTC, Sergey wrote: In Discord we are collecting all links about different topics. We already have D & Wasm topic with most of the relevant links. airnt all the wasm projects by people not on

Re: How do I compile D code for WASM? Any alternative runtime recommendations?

2024-08-28 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 28 August 2024 at 19:08:58 UTC, Sergey wrote: In Discord we are collecting all links about different topics. We already have D & Wasm topic with most of the relevant links. airnt all the wasm projects by people not on the discord?

Re: How do I compile D code for WASM? Any alternative runtime recommendations?

2024-08-28 Thread Sergey via Digitalmars-d-learn
On Wednesday, 28 August 2024 at 18:26:21 UTC, solidstate1991 wrote: I don't really see any readily available tutorials for it quickly, but I'm willing to add one to the official Wiki. Official Wiki is busted :P In Discord we are collecting all links about different topics. We already have D &

Re: core dumped when run this simple D program.

2024-08-26 Thread Fox via Digitalmars-d-learn
On Monday, 26 August 2024 at 07:17:58 UTC, Richard (Rikki) Andrew Cattermole wrote: Classes in D are heap objects, you have to allocate them. ``myClas_1 c1 = new myClas_1;`` The default is null. thank you very much!

Re: core dumped when run this simple D program.

2024-08-26 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Classes in D are heap objects, you have to allocate them. ``myClas_1 c1 = new myClas_1;`` The default is null.

MMOEXP : Beneath the radiant sun of Throne and Liberty

2024-08-26 Thread Ludwighench via Digitalmars-d-learn
Beneath the radiant sun of Throne and Liberty, a hidden melody whispers of riches the song of the Sollant Fields. In this fertile oasis, nestled between towering mountains and whispering forests, lies the potential for a fortune beyond imagination. For those skilled enough to dance with darknes

MMOEXP : That aren't rated as highly within Madden 25

2024-08-26 Thread Ludwighench via Digitalmars-d-learn
Every roster is broken down into five levels. Top/near elite, top starters, low-level starters backups and backups of low-level. This results in a wide gap between top players and the ones at the bottom. This is among the many things Madden was unable to accomplish over the years. Players shoul

core dumped when run this simple D program.

2024-08-25 Thread Fox via Digitalmars-d-learn
import std.stdio; class myClas_1 { int a; } void main() { myClas_1 c1; writeln(c1.a); } === what's wrong? dmd and gdc both can compile these code, but can't run either. DMD64 D Compiler v2.109.1 gcc 14.2.1 20240824 (GCC) fedora 41 thanks!

Re: Using D libraries with SDL. Error: "Cannot find module protobuf'

2024-08-25 Thread Serg Gini via Digitalmars-d-learn
On Saturday, 24 August 2024 at 00:24:12 UTC, Nicol Farran Terra wrote: wanted to use protobuf for data serialization between the two. Maybe consider to use msgpack instead of protobuf This version of protobuf is broken for modern versions of D compilers

Re: Using D libraries with SDL. Error: "Cannot find module protobuf'

2024-08-24 Thread IchorDev via Digitalmars-d-learn
On Saturday, 24 August 2024 at 12:35:03 UTC, Nicol Farran Terra wrote: On Saturday, 24 August 2024 at 12:29:41 UTC, IchorDev wrote: On Saturday, 24 August 2024 at 12:24:04 UTC, Nicol Farran Terra wrote: On Saturday, 24 August 2024 at 12:11:03 UTC, IchorDev wrote: snip snip2 That isvery

Re: Using D libraries with SDL. Error: "Cannot find module protobuf'

2024-08-24 Thread Nicol Farran Terra via Digitalmars-d-learn
On Saturday, 24 August 2024 at 12:29:41 UTC, IchorDev wrote: On Saturday, 24 August 2024 at 12:24:04 UTC, Nicol Farran Terra wrote: On Saturday, 24 August 2024 at 12:11:03 UTC, IchorDev wrote: snip snip2 That isvery helpful. So sort of like Swift, running the 'build' command will just

Re: Using D libraries with SDL. Error: "Cannot find module protobuf'

2024-08-24 Thread IchorDev via Digitalmars-d-learn
On Saturday, 24 August 2024 at 12:24:04 UTC, Nicol Farran Terra wrote: On Saturday, 24 August 2024 at 12:11:03 UTC, IchorDev wrote: snip Okay, yeah now I see my problem sort of. So now it at least builds, but it wont compile with dmd app.d. Says basically the same thing before where it canno

Re: Using D libraries with SDL. Error: "Cannot find module protobuf'

2024-08-24 Thread Nicol Farran Terra via Digitalmars-d-learn
On Saturday, 24 August 2024 at 12:11:03 UTC, IchorDev wrote: snip Okay, yeah now I see my problem sort of. So now it at least builds, but it wont compile with dmd app.d. Says basically the same thing before where it cannot find the module. Maybe I am supposed to link it? I am so used to doin

Re: Using D libraries with SDL. Error: "Cannot find module protobuf'

2024-08-24 Thread IchorDev via Digitalmars-d-learn
On Saturday, 24 August 2024 at 11:34:18 UTC, Nicol Farran Terra wrote: You are importing `google.protobuf`, right? Providing the app.d would be helpful, or at least a snippet of it with the import that’s giving you the ‘error’—presumably a compiler error? No, I am just importing 'protobuf'.

  1   2   3   4   5   6   7   8   9   10   >