On Thursday, 20 January 2022 at 04:38:39 UTC, forkit wrote:
all done ;-)
// ---
module test;
import std.stdio : writeln;
import std.range : iota, isForwardRange, hasSlicing, hasLength,
isInfinite;
import std.array : array, Appender;
import std.random : Random, unpredictableSeed, dice,
Hi,
It looks so delicious. Thank you.
On Wednesday, 19 January 2022 at 18:59:10 UTC, Ali Çehreli wrote:
And adding length() was easy as well.
Finally, I have provided property functions instead of allowing
direct access to members.
It doesn't matter as we can't use a 3rd parameter. But
On Thursday, 20 January 2022 at 04:00:59 UTC, forkit wrote:
void makeUniqueIDs(ref uint[] arr, size_t sz)
{
...
}
arrg!
what was i thinking! ;-)
// ---
void makeUniqueIDs(ref uint[] arr, size_t sz)
{
arr.reserve(sz);
// id needs to be 9 digits, and needs to start with 999
On Thursday, 20 January 2022 at 00:30:44 UTC, H. S. Teoh wrote:
Do the id's have to be unique?
yep...
I'm almost there ;-)
// ---
module test;
import std.stdio : writeln;
import std.range : iota, isForwardRange, hasSlicing, hasLength,
isInfinite;
import std.array : array, Appender;
On Thursday, 20 January 2022 at 01:14:51 UTC, Adam Ruppe wrote:
On Thursday, 20 January 2022 at 00:55:33 UTC, Jack Stouffer
wrote:
static foreach(member; __traits(allMembers,
Manager))
member here is a string, not the member. I prefer to call it
memberName.
Then you
On Thursday, 20 January 2022 at 00:55:33 UTC, Jack Stouffer wrote:
static foreach(member; __traits(allMembers,
Manager))
member here is a string, not the member. I prefer to call it
memberName.
Then you __traits(getMember, Manager, memberName) to actually get
the alias you can
On Wednesday, 19 January 2022 at 21:49:12 UTC, Adam D Ruppe wrote:
I never use most of std.traits, they just complicate things.
Bleh idk, I wouldn't bother with it and loop through the
__traits instead.
Unless I'm missing something obvious this has to be a DMD bug,
because this prints
On Thu, Jan 20, 2022 at 12:12:56AM +, forkit via Digitalmars-d-learn wrote:
[...]
> createBoolAssociativeMatrix(mArrBool,3, 2);
>
> [ [1000:[1, 0]], [1001:[1, 1]], [1001:[1, 0]]]
>
>
> where 1000 is some random id...
Do the id's have to be unique? If not, std.random.uniform() would do
the
On Wednesday, 19 January 2022 at 21:59:15 UTC, forkit wrote:
so at the moment i can get a set number of tuples, with a set
number of bool values contained within each tuple.
e.g.
createBoolMatrix(mArrBool,3, 2);
[[1, 0], [1, 1], [1, 0]]
my next challenge (more for myself, but happy for
On Wednesday, 19 January 2022 at 16:36:36 UTC, Ali Çehreli wrote:
On 1/19/22 06:06, michaelbi wrote:
On Wednesday, 19 January 2022 at 13:21:32 UTC, Stanislav
Blinov wrote:
On Wednesday, 19 January 2022 at 13:15:35 UTC, michaelbi
wrote:
[...]
[...]
...because there's an empty line at
On Wednesday, 19 January 2022 at 15:41:31 UTC, Brian Callahan
wrote:
On Wednesday, 19 January 2022 at 15:01:29 UTC, michaelbi wrote:
as captioned... thx.
```d
import std.stdio;
import std.conv;
void main()
{
writefln("0b%b", to!int("111000", 2));
}
```
Got it, thanks
On 1/19/22 15:21, H. S. Teoh wrote:
> On Wed, Jan 19, 2022 at 02:33:02PM -0800, Ali Çehreli via
Digitalmars-d-learn wrote:
> [...]
>> // Returning a dynamically allocated array looks expensive
>> // here. Why not use a struct or std.typecons.Tuple instead?
>
> Premature optimization. ;-)
Not
On Wednesday, 19 January 2022 at 22:35:58 UTC, Ali Çehreli wrote:
so I combined ideas from all responses:
// --
module test;
import std.stdio : writeln;
import std.range : iota, isForwardRange, hasSlicing, hasLength,
isInfinite, array;
import std.random : Random, unpredictableSeed, dice;
On Wednesday, 19 January 2022 at 23:22:17 UTC, forkit wrote:
oops
// e.g: create a matrix consisting of 5 tuples, with each tuple
containing 3 random bools (0 or 1)
createBoolMatrix(mArrBool,5, 3);
On Wed, Jan 19, 2022 at 02:33:02PM -0800, Ali Çehreli via Digitalmars-d-learn
wrote:
[...]
> // Returning a dynamically allocated array looks expensive
> // here. Why not use a struct or std.typecons.Tuple instead?
Premature optimization. ;-) There's nothing wrong with allocating an
array.
If
On 1/19/22 14:33, Ali Çehreli wrote:
> Random rnd;
>
> shared static this() {
>rnd = Random(unpredictableSeed);
> }
But that's a mistake: If rnd is thread-local like that, it should be
initialized in a 'static this' (not 'shared static this'). Otherwise,
only the main thread's 'rnd' would
On 1/19/22 13:59, forkit wrote:
> void createBoolMatrix(ref uint[][] m)
> {
> auto rnd = Random(unpredictableSeed);
That works but would be unnecessarily slow and be against the idea of
random number generators. The usual approach is, once you have a
randomized sequence, you just
On Wed, Jan 19, 2022 at 09:59:15PM +, forkit via Digitalmars-d-learn wrote:
> so I have this code below, that creates an array of tuples.
>
> but instead of hardcoding 5 tuples (or hardcoding any amount of
> tuples), what I really want to do is automate the creation of
> how-ever-many tuples
On Wednesday, 19 January 2022 at 21:59:15 UTC, forkit wrote:
oh. that randomShuffle was unnecessary ;-)
so I have this code below, that creates an array of tuples.
but instead of hardcoding 5 tuples (or hardcoding any amount of
tuples),
what I really want to do is automate the creation of
how-ever-many tuples I ask for:
i.e.
instead of calling this: createBoolMatrix(mArrBool);
I would call
On Wednesday, 19 January 2022 at 21:44:57 UTC, Jack Stouffer
wrote:
The error is actually coming from trying to use the result of
getSymbolsByUDA in the right part of the `static foreach`
huh..
I never use most of std.traits, they just complicate things. Bleh
idk, I wouldn't bother with
On Wednesday, 19 January 2022 at 20:53:29 UTC, Adam D Ruppe wrote:
So you want to `__traits(child, system, this).run()` and it
should work - the traits child will re-attach a this value.
The error is actually coming from trying to use the result of
getSymbolsByUDA in the right part of the
On Wednesday, 19 January 2022 at 20:46:17 UTC, Jack Stouffer
wrote:
static foreach(system; getSymbolsByUDA!(Manager,
Runnable))
{
system.run();
onlineapp.d(16): Error: value of `this` is not known at compile
time
The getSymbols returns aliases, meaning you hit
I'm trying to use getSymbolsByUDA in order to loop over all of
the members in a struct with a certain UDA, and then call a
function on the member. The plan is to use this to avoid looping
over an array of function pointers.
However, the compiler is giving a strange error and the
On 1/19/22 04:51, Salih Dincer wrote:
> Is it okay to swap places instead of throwing an error?
I would be happier if my potential mistake is caught instead of the
library doing something on its own.
> Let's also
> implement BidirectionalRange, if okay.
I had started experimenting with that
On 1/19/22 06:06, michaelbi wrote:
On Wednesday, 19 January 2022 at 13:21:32 UTC, Stanislav Blinov wrote:
On Wednesday, 19 January 2022 at 13:15:35 UTC, michaelbi wrote:
foreach(line; >
File("input.txt").byLine.map!(a=>a.idup).array.transposed)
so why there is a [] at the end of
On Wednesday, 19 January 2022 at 15:01:29 UTC, michaelbi wrote:
as captioned... thx.
```d
import std.stdio;
import std.conv;
void main()
{
writefln("0b%b", to!int("111000", 2));
}
```
On 1/19/22 3:47 AM, Enjoys Math wrote:
```
module expr;
import dots;
import operator;
import equation;
import var;
import var_expr;
import zz_const;
class Expr
{
public:
void opBinary(string op)(string s) const
{
static if (op == "+")
{
Expr right = null;
as captioned... thx.
On Wednesday, 19 January 2022 at 14:06:45 UTC, michaelbi wrote:
i got it, though i still don't know where the [] come from.
$ rdmd --eval 'writeln("".array.strip.sort.group.assocArray)'
[]
$ rdmd --eval
'writeln(typeid("".array.strip.sort.group.assocArray))'
uint[dchar]
It's what an empty
On Wednesday, 19 January 2022 at 13:21:32 UTC, Stanislav Blinov
wrote:
On Wednesday, 19 January 2022 at 13:15:35 UTC, michaelbi wrote:
foreach(line; >
File("input.txt").byLine.map!(a=>a.idup).array.transposed)
so why there is a [] at the end of assocArray printed? thanks.
...because
On Wednesday, 19 January 2022 at 13:15:35 UTC, michaelbi wrote:
foreach(line; >
File("input.txt").byLine.map!(a=>a.idup).array.transposed)
so why there is a [] at the end of assocArray printed? thanks.
...because there's an empty line at the end of input.txt?
input:
00100
0
10110
10111
10101
0
00111
11100
1
11001
00010
01010
code:
void main()
{
foreach(line;
File("input.txt").byLine.map!(a=>a.idup).array.transposed){
auto sortgroup = line.array.strip.sort.group.assocArray;
On Tuesday, 18 January 2022 at 23:13:14 UTC, Ali Çehreli wrote:
But I like the following one better because
it is fast and I think it works correctly.
Is it okay to swap places instead of throwing an error? Let's
also implement BidirectionalRange, if okay. This great struct
will now run 4x4
On Sunday, 16 January 2022 at 20:01:09 UTC, JN wrote:
On Saturday, 15 January 2022 at 23:15:16 UTC, JN wrote:
Is there some way I could improve this with some D features?
My main gripes with it are:
Managed to dramatically simplify it to 10 lines of code with
variadic templates.
```d
On Wednesday, 19 January 2022 at 02:31:31 UTC, Hipreme wrote:
I have separated my project in a bunch of modules to be
compiled separated. But it seems I have lost my debugging power
since then. I would like to know if there is any workaround
beside not using it as a lib.
I'm using it from
On Sunday, 16 January 2022 at 18:03:53 UTC, Paul Backus wrote:
On Sunday, 16 January 2022 at 15:15:07 UTC, Hipreme wrote:
Is there some way to throw a stack trace when killing the
program from the CTRL+C from the terminal?
It would help a lot into debugging occasional infinity loops
On
On Wednesday, 19 January 2022 at 08:47:27 UTC, Enjoys Math wrote:
```
module expr;
import dots;
import operator;
import equation;
import var;
import var_expr;
import zz_const;
class Expr
{
public:
void opBinary(string op)(string s) const
{
static if (op == "+")
{
On Wednesday, 19 January 2022 at 08:47:27 UTC, Enjoys Math wrote:
```
module expr;
import dots;
import operator;
import equation;
import var;
import var_expr;
import zz_const;
class Expr
{
public:
void opBinary(string op)(string s) const
{
static if (op == "+")
{
```
module expr;
import dots;
import operator;
import equation;
import var;
import var_expr;
import zz_const;
class Expr
{
public:
void opBinary(string op)(string s) const
{
static if (op == "+")
{
Expr right = null;
if (s == ".." || s == "..." || s ==
40 matches
Mail list logo