Re: template/mixin magic for to! auto inferring type from variable

2024-02-02 Thread Chris Katko via Digitalmars-d-learn
On Friday, 2 February 2024 at 21:01:53 UTC, Paul Backus wrote: No, D only does bottom-up type inference, not top down. If you want to avoid repeating the type, use `auto` on the left side: ```d auto time = to!uint(data[1]); auto priority = to!int(data[2]); ``` Okay thanks. It finally

template/mixin magic for to! auto inferring type from variable

2024-02-01 Thread Chris Katko via Digitalmars-d-learn
Is there some way to do: ```D string[3] data; //strings from some file input, some are ints, uints, etc. auto into!(T)(T value){return to!???(value); } // ??? uint time = into!(data[1]); // We already know this is uint int priority = into!(data[2]); ``` instead of: ```D uint time =

How to write an interface but with different signatures

2023-11-19 Thread Chris Katko via Digitalmars-d-learn
I know that sounds stupid on the face of it. An interface shouldn't change. But consider this: A frame timer and a clock timer(seconds) that re-use functionality from a parent class/interface. ``` class timerType { void start() = 0; void stop() = 0; void

Re: Print debug data

2023-07-16 Thread Chris Katko via Digitalmars-d-learn
On Monday, 17 July 2023 at 03:43:04 UTC, Alain De Vos wrote: Is it possible to print runtime memory usage of: -The stack -The heap -The garbage collector ? there's gc.stats for part of it: https://dlang.org/library/core/memory/gc.stats.html

Re: Advice on debugging possible exception or crash

2023-07-06 Thread Chris Katko via Digitalmars-d-learn
On Thursday, 6 July 2023 at 06:00:04 UTC, Cecil Ward wrote: My program is instrumented with a load of writeflns. At one point it looks as though it suddenly quits prematurely because the expected writeflns are not seen in the output. It could be that I am just reading the flow of control wrong

Re: Options for Cross-Platform 3D Game Development

2023-07-06 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 5 July 2023 at 22:27:46 UTC, Andrew wrote: So, I've gotten the itch to have a go at game development in D, after doing a bit of it in Java last year. I've previously used LWJGL, which is a java wrapper for OpenGL, OpenAL, GLFW, and some other useful libs. The problem is,

official activate script is super confusing

2023-07-01 Thread Chris Katko via Digitalmars-d-learn
https://dlang.org/install.html#activate I ran the two curl liners for grabbing DMD and LDC newest. So now I have ~/dlang/ldc-1.32.2 and ~/dlang/dmd-2.104.0 How am I supposed to have both "activated"? Why does LDC have to override DMD, and DMD have to override LDC in the PATH? I have both

Re: Debugging by old fashioned trace log printfs / writefln

2023-06-29 Thread Chris Katko via Digitalmars-d-learn
On Thursday, 29 June 2023 at 18:27:22 UTC, Cecil Ward wrote: I’m trying to debug my D program with old-fashioned printfs stuck in various strategic places, actually using writefln(). My problem is that the addition of printf fights with the existing declarations for pure nothrow @nogc @safe

Re: pragma msg field name?

2023-06-27 Thread Chris Katko via Digitalmars-d-learn
On Tuesday, 27 June 2023 at 22:34:17 UTC, Adam D Ruppe wrote: On Tuesday, 27 June 2023 at 22:20:22 UTC, Chris Katko wrote: pragma(msg, t.stringof); // does not see any new fields! D's declarations are all order-independent, in theory those foreaches are done simultaneously,

Re: pragma msg field name?

2023-06-27 Thread Chris Katko via Digitalmars-d-learn
Does anyone know why the new variables don't show up after the static foreach? I have a struct, it has some marked fields. I want to note those fields at compile time and make some similarly named fields like myField becomes myField__replicated. The code doesn't _have_ to be inside the

Re: pragma msg field name?

2023-06-26 Thread Chris Katko via Digitalmars-d-learn
On Tuesday, 27 June 2023 at 04:56:19 UTC, Ali Çehreli wrote: On 6/26/23 21:25, Chris Katko wrote: > How do I get just the field name? I know .tupleof, which you can typeof() as well: class myObject{ int field1, field2, field3; static foreach(field; typeof(this).tupleof) {

pragma msg field name?

2023-06-26 Thread Chris Katko via Digitalmars-d-learn
inside a static foreach I can do ``` enum rep; class myObject{ int field1, field2, field3; static foreach(field; getSymbolsByUDA!(typeof(this), rep)) { pragma(msg, field); // fails pragma(msg, fullyQualifiedName!field); // works } } ``` error for pragma(msg, field) ```

Returning a reference to be manipulated

2023-04-13 Thread Chris Katko via Digitalmars-d-learn
I'm trying to figure out how to return a reference to something that may not be a reference type. ```D struct stats { float[string] data=0; float ref opIndex(string key) { return data[key]; // want a ref to a specific element } } void test() { stats foo; auto x = foo.bar(); // returns

Assocative array lookup for object

2023-04-11 Thread Chris Katko via Digitalmars-d-learn
```D class bitmapHandler { bitmap*[string] bmps; void get(string name){return bmps[name]; /* plus other code */} } void usage() { bitmapHandler bh; bitmap foo = bh.get("bar"); // works bitmap foo2 = bh["bar"]; // desired } ``` Should I be using opEquals? Or something different? The problem

Virtual method call from constructor

2023-04-04 Thread Chris Katko via Digitalmars-d-learn
dscanner reports this as a warning: ```D struct foo{ this() { /* some initial setup */ refresh(); } void refresh() { /* setup some more stuff */} // [warn] a virtual call inside a constructor may lead to unexpected results in the derived classes } ``` Firstly, are all calls virtual

Re: templates and traits

2023-03-18 Thread Chris Katko via Digitalmars-d-learn
On Saturday, 18 March 2023 at 20:42:50 UTC, Nick Treleaven wrote: On Saturday, 18 March 2023 at 19:22:07 UTC, Chris Katko wrote: ... So there's multiple sub-problems to solve. I asked this years ago, and got 90% of the way done and then lost the code and cannot find the original forum post.

templates and traits

2023-03-18 Thread Chris Katko via Digitalmars-d-learn
Given: ```D struct pos {float x, y;} draw(myBitmap, pos(320, 240), centered); draw(pos(320, 240), myBitmap); draw("text", myFont, pos(320, 240)); ``` I'm writing a general "draw" template function that through compile-time, calls an associated DAllegro/Allegro 5 function: ``` draw(myBitmap,

Convert array of simple structs, to C array of values

2022-10-03 Thread Chris Katko via Digitalmars-d-learn
```D struct pair { float x; float y; } pair[10] values; import std.conv; auto valuesInCStyle = to!(const float*)(values); ``` Now that's not going to work because (I would imagine) to! doesn't understand x, and y, can be placed in order to give an array of: valuesInCStyle =

Re: dlang bug - accessing module variable from method segfaults only when using module reference directly

2022-07-01 Thread Chris Katko via Digitalmars-d-learn
On Friday, 1 July 2022 at 13:28:26 UTC, Chris Katko wrote: ...wait, does "world" not 'exist' until after the constructor finishes? Is that's what's going on? But then why does it 'exist' when I send it directly? Is it only "registered" with the module once this() finishes or something like

Re: dlang bug - accessing module variable from method segfaults only when using module reference directly

2022-07-01 Thread Chris Katko via Digitalmars-d-learn
On Friday, 1 July 2022 at 13:12:05 UTC, Adam D Ruppe wrote: On Friday, 1 July 2022 at 12:57:01 UTC, Chris Katko wrote: Cannot access memory at address 0x10 Looks like an ordinary null pointer. How did you create the variable? D bool initialize() //called from main {

Re: dlang bug - accessing module variable from method segfaults only when using module reference directly

2022-07-01 Thread Chris Katko via Digitalmars-d-learn
Forgot the last line. That's important because world MUST exist by time elf is called... because world... created and called elf. So it's not a memory issue, but some sort of linkage issue.

Re: dlang bug - accessing module variable from method segfaults only when using module reference directly

2022-07-01 Thread Chris Katko via Digitalmars-d-learn
To add, I cannot even access g.world from inside elf's constructor. ... which is the function that called it. D Thread 1 "main" received signal SIGSEGV, Segmentation fault. objects.elf.this(g.pair, objects.atlasHandler) (this=, atlas=, _pos=...) at ./src/objects.d:320 (gdb) bt #0

dlang bug - accessing module variable from method segfaults only when using module reference directly

2022-07-01 Thread Chris Katko via Digitalmars-d-learn
dmd (but I think LDC also is affected) this bug has bit me multiple times now, to the point I can recognize it. Accessing module variables, from inside a method, causes a segfault. Even if the variable should be available by then through the call order. Proving that its a bug, you can

Re: nested function overloading

2022-06-23 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 22 June 2022 at 12:42:48 UTC, Steven Schveighoffer wrote: On 6/22/22 2:05 AM, monkyyy wrote: On Monday, 20 June 2022 at 13:20:51 UTC, Steven Schveighoffer wrote: And you can also use an inner struct to define overloaded functions. I believe templates make a better bandaid ```d

Re: can you initialize a array of POD structs?

2022-06-18 Thread Chris Katko via Digitalmars-d-learn
On Saturday, 18 June 2022 at 17:52:16 UTC, Adam D Ruppe wrote: On Saturday, 18 June 2022 at 17:37:44 UTC, Chris Katko wrote: D struct pair { float x, y;} pair p[] = [[0, 0], [255, 255], [25,-25]]; //nope An array of pair is `pair[]`, keep the brackets with the type. Then a struct

can you initialize a array of POD structs?

2022-06-18 Thread Chris Katko via Digitalmars-d-learn
D struct pair { float x, y;} pair p[] = [[0, 0], [255, 255], [25,-25]]; //nope

multidim array with enum

2022-06-18 Thread Chris Katko via Digitalmars-d-learn
I'm having difficulty figuring out exactly what signature D is expecting. D enum DIR { UP = 0, DOWN, LEFT, RIGHT, UPLEFT, UPRIGHT, DOWNRIGHT, DOWNLEFT,

Re: nested function overloading

2022-06-17 Thread Chris Katko via Digitalmars-d-learn
On Friday, 17 June 2022 at 12:19:33 UTC, bauss wrote: On Friday, 17 June 2022 at 12:09:33 UTC, Chris Katko wrote: I don't need this functionality, but I wanted to be sure. Does function overloading not work with nested functions? I got a compiler error (something like "function already

nested function overloading

2022-06-17 Thread Chris Katko via Digitalmars-d-learn
I don't need this functionality, but I wanted to be sure. Does function overloading not work with nested functions? I got a compiler error (something like "function already defined") when I tried it.

Re: a struct as an multidimensional array index

2022-06-10 Thread Chris Katko via Digitalmars-d-learn
On Friday, 10 June 2022 at 17:26:48 UTC, Ali Çehreli wrote: On 6/10/22 08:13, z wrote: > arrays of arrays has different order for declaration and addressing, > and declaring array of arrays has different order depending on how you > declare it and wether it's static or dynamic array, *oof*) > >

Re: Run a command-line process with data sent, and retrieve the data.

2022-06-10 Thread Chris Katko via Digitalmars-d-learn
On Friday, 10 June 2022 at 17:37:30 UTC, Chris Katko wrote: I want to pipe in string data to a shell/commandline program, then retrieve the output. But the documentation I read appears to only show usage for 'Files' for stdin/stdout/stderr. ala something like this: D string input =

Run a command-line process with data sent, and retrieve the data.

2022-06-10 Thread Chris Katko via Digitalmars-d-learn
I want to pipe in string data to a shell/commandline program, then retrieve the output. But the documentation I read appears to only show usage for 'Files' for stdin/stdout/stderr. ala something like this: D string input = "hello\nworld"; string output; runProcess("grep hello", input,

a struct as an multidimensional array index

2022-06-10 Thread Chris Katko via Digitalmars-d-learn
Is it somehow possible to use a struct as a [multidimensional] array index: D struct indexedPair { size_t x, y; } bool isMapPassable[100][100]; auto p = indexedPair(50, 50); if(isMapPassable[p]) return true; Probably not, but I'm curious.

Odd construct idea. Splitting arguments inside a parameter list.

2022-05-23 Thread Chris Katko via Digitalmars-d-learn
D struct pair { float x,y; } myFunction(float taco, float x, float y, float burrito) { // stuff } myfunction(_taco, _x, _y, _burrito); // call function // But can we do this? pair p; myfunction(_taco, p; _burrito); // p becomes (x,y) and satisfies the two floats in the signature

Re: template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Chris Katko via Digitalmars-d-learn
On Thursday, 19 May 2022 at 10:35:30 UTC, ag0aep6g wrote: On 19.05.22 12:15, Chris Katko wrote: given ```D struct COLOR { float r, g, b, a; // a is alpha (opposite of transparency) } auto red   = COLOR(1,0,0,1); auto green = COLOR(0,1,0,1); auto blue  = COLOR(0,0,1,1); auto white =

template? mixin? template mixins? for modifying a struct setup

2022-05-19 Thread Chris Katko via Digitalmars-d-learn
given ```D struct COLOR { float r, g, b, a; // a is alpha (opposite of transparency) } auto red = COLOR(1,0,0,1); auto green = COLOR(0,1,0,1); auto blue = COLOR(0,0,1,1); auto white = COLOR(1,1,1,1); //etc ``` is there a way to do: ```D auto myColor = GREY!(0.5); // where GREY!(0.5) becomes

Re: Template shenannigans with multiple datatypes

2022-05-13 Thread Chris Katko via Digitalmars-d-learn
On Friday, 13 May 2022 at 07:05:36 UTC, vit wrote: On Friday, 13 May 2022 at 06:43:39 UTC, Chris Katko wrote: I have an intrinsicGraph(T) class that is given a pointer to a T dataSource and automatically polls that variable every frame to add it to the graph, whether it's a float, double,

Template shenannigans with multiple datatypes

2022-05-13 Thread Chris Katko via Digitalmars-d-learn
I have an intrinsicGraph(T) class that is given a pointer to a T dataSource and automatically polls that variable every frame to add it to the graph, whether it's a float, double, integer, and maybe bool. This all works fine if you have a single template type. But what if I want ... multiple

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Chris Katko via Digitalmars-d-learn
On Thursday, 12 May 2022 at 16:04:09 UTC, Ali Çehreli wrote: My view on private has changed over the years. I need to be convinced that there is usage that needs to be protected. :) I don't see people using types freely especially the ones that are in the same module. The only argument for

A template construct like using()

2022-04-26 Thread Chris Katko via Digitalmars-d-learn
I swear I asked something like this before years ago but it doesn't show up in my previous forum posts. I'm looking for a construct that mimics using(var)/with(var) D bitmap* b; draw_with(b) { draw_pixel(red, 16, 16); //draw red pixel to bitmap b (b is implied above) } But

Re: std.typecons Typedef initializers?

2022-04-25 Thread Chris Katko via Digitalmars-d-learn
On Monday, 25 April 2022 at 12:53:14 UTC, Mike Parker wrote: On Monday, 25 April 2022 at 08:54:52 UTC, Chris Katko wrote: D struct pair { float x,y; } alias sPair = Typedef!pair; // pair of xy in screen space coordinates alias vPair = Typedef!pair; // pair of xy in viewport space

std.typecons Typedef initializers?

2022-04-25 Thread Chris Katko via Digitalmars-d-learn
D struct pair { float x,y; } alias sPair = Typedef!pair; // pair of xy in screen space coordinates alias vPair = Typedef!pair; // pair of xy in viewport space coordinates //etc void test() { pair v0 = pair(1f, 2f); // works fine, but what about the typedefs? vPair v1 = vPair(1f, 2f);

save and load a 2d array to a file

2022-04-18 Thread Chris Katko via Digitalmars-d-learn
D struct map_t{ int data[50][50]; } map; //save std.file.write("save.map", map.data); // compiles //load map.data = std.file.read("save.map", map.data.sizeof); // error main.d(536): Error: cannot implicitly convert expression `read("save.map", 2500LU)` of type `void[]` to `ubyte[50][]`

Nested function requires forward declaration?

2022-04-14 Thread Chris Katko via Digitalmars-d-learn
Using DMD. v2.098-beta-2 Not sure if right terminology. But I just wrote a nested function that uses a variable outside its body. The capture (right term?) is obvious where the invocation is. However, I have to move the declaration of the variable to above the nested function for it to

unit test broken [DUB bug?]

2021-12-11 Thread Chris Katko via Digitalmars-d-learn
Running 64-bit Linux ``` dmd --version DMD64 D Compiler v2.098.0-beta.2 dub --version DUB version 1.27.0-beta.2, built on Sep 7 2021 ``` the following code 'compiles' in one project. ```d unittest { gasdindgaslkdgansklnasgdlknaglkgansklsdg; } void main(){} // compiles, links, and 'runs unit

Re: d strings are the bane of my existance

2021-12-05 Thread Chris Katko via Digitalmars-d-learn
On Sunday, 5 December 2021 at 16:32:16 UTC, rikki cattermole wrote: The string is not the problem. ```d string ip_address = "192.168.1.1"; auto x = new InternetAddress(ip_address, 8008); ``` That works. A string in D is an alias for immutable(char)[]. This is defined in druntime (object.d).

d strings are the bane of my existance

2021-12-05 Thread Chris Katko via Digitalmars-d-learn
All I want: ```d string ip_address = "192.168.1.1"; auto x = new InternetAddress( ip_string, "8008"); ``` ```d source/app.d(161,16): Error: none of the overloads of `this` are callable using argument types `(string, int)` /usr/include/dmd/phobos/std/socket.d(1472,5):Candidates are:

sleeping vs sched_yield

2021-12-02 Thread Chris Katko via Digitalmars-d-learn
there's: ```d import core.thread; Thread.sleep( dur!("msecs")(10) ); ``` but what if you want to simply yield all remaining time back to the time scheduler? Is there a D std.library accessible version of POSIX sched_yield: https://man7.org/linux/man-pages/man2/sched_yield.2.html It

automatic NaN propogation detection?

2021-09-25 Thread Chris Katko via Digitalmars-d-learn
Is there any automatic compiler-based or library methods for detecting NaNs? I mean, if the compiler is outputting code that it knows is going to be set in memory to NaN, why isn't it giving me at least a compiler warning? Is that some sort of "NP complete" can't-fix issue or something? I

Re: Is this a compiler aliasing bug?

2021-09-22 Thread Chris Katko via Digitalmars-d-learn
On Friday, 17 September 2021 at 10:29:12 UTC, bauss wrote: On Friday, 17 September 2021 at 09:44:53 UTC, Chris Katko wrote: [...] It's not a bug because "obj.x" referes to the same symbol that is "this.x" Alias will create an alias for a symbol, not an expression or the like. So obj.x

Is this a compiler aliasing bug?

2021-09-17 Thread Chris Katko via Digitalmars-d-learn
I'm debugging some code I wrote back in 2017 and a bounding box collision detection kept giving spurious answers till I resorted to assuming nothing and dumped every variable and alias. I kept getting results like it was checking against itself, and of course, that would result in finding a

Re: sort a string

2020-05-01 Thread Chris Katko via Digitalmars-d-learn
On Friday, 1 May 2020 at 08:17:33 UTC, norm wrote: On Friday, 1 May 2020 at 07:38:53 UTC, Chris Katko wrote: [...] You need to convert the sort output to dchar[], e.g. --- dchar[] line3 = sort(line2.to!(dchar[])).to!(dchar[]); --- Cheers, Norm That works, thanks!

sort a string

2020-05-01 Thread Chris Katko via Digitalmars-d-learn
I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string. ... and the google results on the dlang forums from 2017 don't work.

Re: Get memory used by current process at specific point in time

2020-01-15 Thread Chris Katko via Digitalmars-d-learn
On Sunday, 12 January 2020 at 13:58:18 UTC, Per Nordlöw wrote: Is there a druntime/phobos function for getting the amount of memory (both, stack, malloc, and GC) being used by the current process? Valgrind will tell you the exact usage (except no delineation for GC) per here:

Re: Practical parallelization of D compilation

2020-01-08 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 8 January 2020 at 06:51:57 UTC, H. S. Teoh wrote: On Wed, Jan 08, 2020 at 04:40:02AM +, Guillaume Lathoud via Digitalmars-d-learn wrote: [...] [...] Generally, the recommendation is to separately compile each package. E.g., if you have a source tree of the form:

Re: Using tasks without GC?

2020-01-05 Thread Chris Katko via Digitalmars-d-learn
Thanks everyone, looks like i'll have to benchmark myself (which is fine) but I'm always afraid because I know "proper benchmarking is hard. (TM)" Feel free to throw any other side advice in. I'm looking to get a broad perspective on this. Straight up shutting off the garbage collector in

Using tasks without GC?

2020-01-03 Thread Chris Katko via Digitalmars-d-learn
When I program, it's usually videogame ideas. That implies a soft, real-time requirement. In general, that requires the mantra "allocations are evil, use object pools whenever possible." [storing data in static arrays and 'deleting' is usually just marking an entry as is_deleted=true and

Why is this allowed? Inheritance variable shadowing

2019-08-12 Thread Chris Katko via Digitalmars-d-learn
You can drop this straight into run.dlang.io: import std.stdio; class base{ float x=1;} class child : base {float x=2;} //shadows base variable! void main() { base []array; child c = new child; array ~= c; writeln(c.x); //=2 writeln(array[0].x); //=1 //uses BASE's

Easiest way to use Linux system C files / tiny C libraries

2019-03-29 Thread Chris Katko via Digitalmars-d-learn
What's the easiest way to use POSIX and Linux-specific C include files? I know you can write a wrapper but it seems like half the time these files include 20 files which include 20 files which use strange enums, arrays, etc that don't clearly have answers on how to wrap them. Is there

Re: D is supposed to compile fast.

2018-11-25 Thread Chris Katko via Digitalmars-d-learn
On Saturday, 24 November 2018 at 20:44:57 UTC, welkam wrote: On Friday, 23 November 2018 at 08:57:57 UTC, Chris Katko wrote: D is supposed to compile fast. You didnt read the fine print. It compiles simple code fast. Also compilation is separate step from linking and your program might

Re: D is supposed to compile fast.

2018-11-24 Thread Chris Katko via Digitalmars-d-learn
On Friday, 23 November 2018 at 10:00:17 UTC, Nicholas Wilson wrote: If you pass all the files on the command line then they all get (re)compiled. How are you supposed include files if not passing them to the compiler? I'm only using std.regex in one file, IIRC, so whatever the "proper"

D is supposed to compile fast.

2018-11-23 Thread Chris Katko via Digitalmars-d-learn
Any time I see people mention the benefits of D, I see "compile times" "compile times" "compile times" over and over. I'm using very modest amounts of templates, for a fairly small sized program (very early work toward a game), and I'm hitting ~15 seconds compile time in LDC and ~7 seconds in

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-11-20 Thread Chris Katko via Digitalmars-d-learn
Try to learn D. Put writeln in deconstructor to prove it works as expected Make random changes, program never runs again. Takes 30+ minutes to realize that writeln("my string") is fine, but writeln("my string " ~ value) is an allocation / garbage collection which crashes the program without a

Re: Why is stdio ... stdio?

2018-11-10 Thread Chris Katko via Digitalmars-d-learn
On Saturday, 10 November 2018 at 13:53:14 UTC, Kagamin wrote: On Friday, 9 November 2018 at 09:11:37 UTC, Jonathan M Davis wrote: No, I didn't. I just used underscores, which has been used with plain text for emphasis for decades. Supporting markdown, would involve stuff like backticks for

Re: Why is stdio ... stdio?

2018-11-09 Thread Chris Katko via Digitalmars-d-learn
On Friday, 9 November 2018 at 09:11:37 UTC, Jonathan M Davis wrote: On Friday, November 9, 2018 1:27:44 AM MST Kagamin via Digitalmars-d-learn wrote: On Friday, 9 November 2018 at 06:42:37 UTC, Jonathan M Davis wrote: > [...] You used markdown three times in your message. No, I didn't. I

Why is stdio ... stdio?

2018-11-08 Thread Chris Katko via Digitalmars-d-learn
Simple curious question. Why isn't : import std.stdio; instead: import std.io; (Also, while we're at it. Why doesn't this form have code highlighting? It would much improve readibility. Doesn't that seem almost essential for a programming forum?) I mean, I get it. stdio is the c header

Re: lazy variables

2018-10-17 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 07:32:37 UTC, aliak wrote: Hi, Is there any notion of lazy vars in D (i see that there're parameters)? i.e: struct S { //... int y; //... } lazy S x = () { // do some heavy stuff }(); if (condition) { func(x.y); // heavy stuff evaluated here }

Why doesn't foreach support iterating?

2018-10-16 Thread Chris Katko via Digitalmars-d-learn
int [50]data; foreach(i, datum; data){} // works File file("gasdgasd"); foreach(i, line; file.byLine){} //NOPE. foreach(line; file.byLine){} //works. I finally noticed in the docs it says "for arrays only." The question is, why? Every language that I used previously (as far as I can

Re: std.regex is fat

2018-10-14 Thread Chris Katko via Digitalmars-d-learn
On Sunday, 14 October 2018 at 03:26:33 UTC, Adam D. Ruppe wrote: On Sunday, 14 October 2018 at 03:07:59 UTC, Chris Katko wrote: For comparison, I just tested and grep uses about 4 MB of RAM to run. Running and compiling are two entirely different things. Running the D regex code should be

Re: std.regex is fat

2018-10-13 Thread Chris Katko via Digitalmars-d-learn
On Sunday, 14 October 2018 at 02:44:55 UTC, Chris Katko wrote: On Friday, 12 October 2018 at 13:42:34 UTC, Alex wrote: [...] So wait, if their solution was to simply REMOVE std.regex from isEmail. That doesn't solve the regex problem at all. And from what I read in that thread, this penalty

Re: std.regex is fat

2018-10-13 Thread Chris Katko via Digitalmars-d-learn
On Friday, 12 October 2018 at 13:42:34 UTC, Alex wrote: On Friday, 12 October 2018 at 13:25:33 UTC, Chris Katko wrote: Like, insanely fat. All I wanted was a simple regex. The second include a regex function, my program would no longer compile "out of memory for fork". /usr/bin/time -v

std.regex is fat

2018-10-12 Thread Chris Katko via Digitalmars-d-learn
Like, insanely fat. All I wanted was a simple regex. The second include a regex function, my program would no longer compile "out of memory for fork". /usr/bin/time -v reports it went from 150MB of RAM for D, DAllegro, and Allegro5. To over 650MB of RAM, and from 1.5 seconds to >5.5

Re: Why are 2-D arrays reversed?

2018-10-10 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 10 October 2018 at 16:00:42 UTC, Steven Schveighoffer wrote: On 10/10/18 9:22 AM, Chris Katko wrote: int[][] data = [     [1, 0, 1, 0, 0],     [1, 0, 1, 0, 0],     [1, 0, 1, 1, 1],     [1, 0, 0, 1, 0],     [5, 1, 1, 1, 0] ]; when drawn with

Why are 2-D arrays reversed?

2018-10-10 Thread Chris Katko via Digitalmars-d-learn
int[][] data = [ [1, 0, 1, 0, 0], [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 0, 0, 1, 0], [5, 1, 1, 1, 0] ]; when drawn with data[i][j], prints the transpose of "data": [1, 1, 1, 1, 5] [0, 0, 0, 0, 1] [1,

Re: How do you iterate "vertically" over a 2-D array?

2018-10-09 Thread Chris Katko via Digitalmars-d-learn
On Tuesday, 9 October 2018 at 10:52:47 UTC, Chris Katko wrote: I have a 2-D array: int[5][5] data = [ [1, 0, 1, 0, 0], [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 0, 0, 1, 0], [1, 1, 1, 1, 0] ]; 1 - Is

How do you iterate "vertically" over a 2-D array?

2018-10-09 Thread Chris Katko via Digitalmars-d-learn
I have a 2-D array: int[5][5] data = [ [1, 0, 1, 0, 0], [1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 0, 0, 1, 0], [1, 1, 1, 1, 0] ]; 1 - Is there a way to foreach vertically through that? (that is,

Re: std.socket tutorials? examples?

2018-10-04 Thread Chris Katko via Digitalmars-d-learn
On Thursday, 4 October 2018 at 08:52:28 UTC, Andrea Fontana wrote: On Thursday, 4 October 2018 at 08:32:13 UTC, Chris Katko wrote: I've been Google'ing and there's like... nothing out there. One of the top results for "std.socket dlang examples"... is for TANGO. That's how old it is. Socket

std.socket tutorials? examples?

2018-10-04 Thread Chris Katko via Digitalmars-d-learn
I've been Google'ing and there's like... nothing out there. One of the top results for "std.socket dlang examples"... is for TANGO. That's how old it is.

Re: Template/mixin ideas?

2018-10-03 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 3 October 2018 at 11:51:01 UTC, Sebastiaan Koppe wrote: On Wednesday, 3 October 2018 at 11:01:53 UTC, Chris Katko wrote: [...] A combination of static introspection with string mixins does the trick: --- enum colors { reset = "\033[0m", red = "\033[31m" } auto

Template/mixin ideas?

2018-10-03 Thread Chris Katko via Digitalmars-d-learn
I've got this simple task but I'm trying to perfect it as best I can to learn something in the process. I have Linux terminal ASCII codes for coloring terminal output. string red(string) { /* ... */ } "Hello world".red => "\033[31mHello World\033[0m" which translates to "[red]Hello

Re: Dynamic Minimum width with Format / writefln

2018-10-02 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 3 October 2018 at 00:34:33 UTC, Adam D. Ruppe wrote: On Wednesday, 3 October 2018 at 00:14:03 UTC, Chris Katko wrote: Except it doesn't work and tries to decode col.width-1 into a hexadecimal number and only prints that. ("4D6EF6") That number certainly isn't col.width (unless

Dynamic Minimum width with Format / writefln

2018-10-02 Thread Chris Katko via Digitalmars-d-learn
- First, I'm confused. The docs say 's' is "whatever it needs to be". ("he corresponding argument is formatted in a manner consistent with its type:") But what if I specifically want a STRING. Because I only see floats, ints, etc. No forced string types. - Second, This works fine in D:

Re: Sending Tid in a struct

2018-09-28 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 23 November 2016 at 08:47:56 UTC, Christian Köstlin wrote: On 03/03/2012 18:35, Timon Gehr wrote: On 03/03/2012 12:09 PM, Nicolas Silva wrote: [...] Yes, this seems to be a bug. Workaround: struct Foo{ string s; Tid id; } void foo(){ Foo foo;

Re: Simple parallel foreach and summation/reduction

2018-09-24 Thread Chris Katko via Digitalmars-d-learn
On Monday, 24 September 2018 at 07:13:24 UTC, Chris Katko wrote: On Monday, 24 September 2018 at 05:59:20 UTC, Chris Katko wrote: [...] Actually, I just realized/remembered that the error occurs inside parallelism itself, and MANY times at that: [...] This JUST occurred to me.

Re: Simple parallel foreach and summation/reduction

2018-09-24 Thread Chris Katko via Digitalmars-d-learn
On Monday, 24 September 2018 at 05:59:20 UTC, Chris Katko wrote: On Saturday, 22 September 2018 at 02:26:41 UTC, Chris Katko wrote: On Saturday, 22 September 2018 at 02:13:58 UTC, Chris Katko wrote: On Friday, 21 September 2018 at 12:15:59 UTC, Ali Çehreli wrote: On 09/21/2018 12:25 AM, Chris

Re: Simple parallel foreach and summation/reduction

2018-09-24 Thread Chris Katko via Digitalmars-d-learn
On Saturday, 22 September 2018 at 02:26:41 UTC, Chris Katko wrote: On Saturday, 22 September 2018 at 02:13:58 UTC, Chris Katko wrote: On Friday, 21 September 2018 at 12:15:59 UTC, Ali Çehreli wrote: On 09/21/2018 12:25 AM, Chris Katko wrote: [...] You can use a free-standing function as a

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Chris Katko via Digitalmars-d-learn
On Saturday, 22 September 2018 at 02:13:58 UTC, Chris Katko wrote: On Friday, 21 September 2018 at 12:15:59 UTC, Ali Çehreli wrote: On 09/21/2018 12:25 AM, Chris Katko wrote: [...] You can use a free-standing function as a workaround, which is included in the following chapter that explains

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Chris Katko via Digitalmars-d-learn
On Friday, 21 September 2018 at 12:15:59 UTC, Ali Çehreli wrote: On 09/21/2018 12:25 AM, Chris Katko wrote: On Thursday, 20 September 2018 at 05:51:17 UTC, Neia Neutuladh wrote: On Thursday, 20 September 2018 at 05:34:42 UTC, Chris Katko wrote: All I want to do is loop from 0 to [constant]

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Chris Katko via Digitalmars-d-learn
On Thursday, 20 September 2018 at 05:51:17 UTC, Neia Neutuladh wrote: On Thursday, 20 September 2018 at 05:34:42 UTC, Chris Katko wrote: All I want to do is loop from 0 to [constant] with a for or foreach, and have it split up across however many cores I have. You're looking at

Simple parallel foreach and summation/reduction

2018-09-19 Thread Chris Katko via Digitalmars-d-learn
All I want to do is loop from 0 to [constant] with a for or foreach, and have it split up across however many cores I have. ulong sum; foreach(i; [0 to 1 trillion]) { //flip some dice using float die_value = uniform(0F,12F); if(die_value > [constant]) sum++;

Re: Load entire file, as a char array.

2018-09-03 Thread Chris Katko via Digitalmars-d-learn
On Monday, 3 September 2018 at 07:38:51 UTC, Chris Katko wrote: On Monday, 3 September 2018 at 06:28:38 UTC, bauss wrote: On Monday, 3 September 2018 at 06:25:23 UTC, bauss wrote: On Monday, 3 September 2018 at 03:19:39 UTC, Neia Neutuladh wrote: On Monday, 3 September 2018 at 03:04:57 UTC,

Re: Load entire file, as a char array.

2018-09-03 Thread Chris Katko via Digitalmars-d-learn
On Monday, 3 September 2018 at 06:28:38 UTC, bauss wrote: On Monday, 3 September 2018 at 06:25:23 UTC, bauss wrote: On Monday, 3 September 2018 at 03:19:39 UTC, Neia Neutuladh wrote: On Monday, 3 September 2018 at 03:04:57 UTC, Chris Katko wrote: This should be simple? All I want to do is load

Re: Load entire file, as a char array.

2018-09-02 Thread Chris Katko via Digitalmars-d-learn
On Monday, 3 September 2018 at 03:19:39 UTC, Neia Neutuladh wrote: On Monday, 3 September 2018 at 03:04:57 UTC, Chris Katko wrote: This should be simple? All I want to do is load an entire file, and access individual bytes. The entire thing. I don't want to have know the file size before hand,

Load entire file, as a char array.

2018-09-02 Thread Chris Katko via Digitalmars-d-learn
This should be simple? All I want to do is load an entire file, and access individual bytes. The entire thing. I don't want to have know the file size before hand, or "guess" and have a "maximum size" buffer. So far, all google searches for "dlang binary file read" end up not working for me.

Re: Doxygen newbie

2018-04-23 Thread Chris Katko via Digitalmars-d-learn
Oh goodness. I thought D was using Doxygen! Thanks.

Doxygen newbie

2018-04-23 Thread Chris Katko via Digitalmars-d-learn
I'm a complete doxygen newbie. But my first thought when writing comments is... why not use Markdown? (Which has become almost universal online these days.) So I google it and Moxygen comes up. Which seems pretty good.

Re: Rotate array in writefln?

2018-04-19 Thread Chris Katko via Digitalmars-d-learn
On Wednesday, 18 April 2018 at 07:15:47 UTC, Simen Kjærås wrote: On Wednesday, 18 April 2018 at 06:54:29 UTC, Chris Katko wrote: I need to rotate an array by 90 degrees, or have writefln figure that out. I need, say: 0 4 5 6 0 0 0 0 0 0 0 0 0 0 0 0 But it's outputting: 0 0 0 0 4 0 0 0 5 0

Rotate array in writefln?

2018-04-18 Thread Chris Katko via Digitalmars-d-learn
I need to rotate an array by 90 degrees, or have writefln figure that out. I need, say: 0 4 5 6 0 0 0 0 0 0 0 0 0 0 0 0 But it's outputting: 0 0 0 0 4 0 0 0 5 0 0 0 6 0 0 0 int [4][4] data; file.writeln(format("%(%-(%d %)\n%)", data));

Re: Delegates and classes for custom code.

2018-04-17 Thread Chris Katko via Digitalmars-d-learn
That was all pseudo-code typed by hand. I got my code to work today. I don't know if it's the prettiest it can be, but it works: // TESTING ACCESS TO the OWNING function //--- class test_window { float x; float y;

Re: Delegates and classes for custom code.

2018-04-16 Thread Chris Katko via Digitalmars-d-learn
I'm having trouble conceptualizing this issue at the moment. But it seems if I pass to the delegate my object, then I can ONLY use one class type. Say, the delegate takes a "this" from... some class that wants to have a dialog. A window. Now the delegate NEEDS a this from a window, and only

  1   2   >