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: > >> It seems like assertThrown works as ex

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 sa

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 glance, it l

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. [...]