DateTime resetting
I've been working on a diary program (ChronoLog). but lately my date and time variable keeps resetting. I've spent hours trying to fix it. I'm wondering if there's a known issue.
Re: DateTime resetting
On Tuesday, 11 October 2022 at 22:21:35 UTC, Adam D Ruppe wrote: On Tuesday, 11 October 2022 at 22:09:34 UTC, Joel wrote: I've been working on a diary program (ChronoLog). but lately my date and time variable keeps resetting. I've spent hours trying to fix it. I'm wondering if there's a known issue. An ordinary DateTime variable? Those are pretty simple and won't reset unless something else is wrong around it. Do you have the code online? Or can at least show some of the context around its use? I programmed the date and time stuff past midnight, then I think I had trouble onwards. Here's code, I've included other code (maybe it can be compiled and run): https://www.icloud.com/iclouddrive/08fL87THzs2BrI7-lEwXFF0Mw#ChronoLog_etc
Re: DateTime resetting
On Tuesday, 11 October 2022 at 23:28:50 UTC, Adam D Ruppe wrote: I'm just eyeballing the code, is it the g_dateTimeCursor you're concerned about? That's the only one I really see there. [...] Yes! :-D getControl was the issue, I've used ref on its return value now. Thanks so much for your help! :-)
Reading and wiping notes also adding more notes
I'm trying to add a feature to my text modifying program. I take a lot of notes but I want to be able to both wipe what I've read while still adding more notes as I go. I have two text fields. The one on the left has the whole text, new stuff being added to the bottom. The one on the right has text I've been wiping as I'm reading. I want to be able to add from the whole text just the new stuff at the bottom to the right text at the bottom. - I hope I'm making sense (good exercise, trying to explain it helps me work it out by itself). Example Whole text: [I went for a walk and fell down a hole. There was a D guy on the roof. That was a tricky problem!] Read and wipe text: [There was a d guy on the roof.] Now I want to add "That was a tricky problem!" to the wipe text to get: [There was a D guy on the roof. That was a tricky problem!]
Re: Reading and wiping notes also adding more notes
On Tuesday, 18 October 2022 at 05:48:27 UTC, Ali Çehreli wrote: On 10/17/22 22:40, Joel wrote: > I have two text fields. The one on the left has the whole text, new > stuff being added to the bottom. The one on the right has text I've been > wiping as I'm reading. I think this can be modelled as a string array and an index showing where the active part starts: import std; struct Notes { string[] whole; size_t activeIndex; void add(string line) { whole ~= line; } string[] activeText() { return whole[activeIndex..$]; } void wipeText() { ++activeIndex; } } void main() { auto input = [ "I went for a walk and fell down a hole.", "There was a D guy on the roof.", "That was a tricky problem!", ]; Notes notes; // add() to add() input.each!(line => notes.add(line)); // activeText() will show the active part // wipeText() will move forward } Ali I want to have two text files, for each notes I'm reading and wiping. Keep adding to one and reading wiping and updating the other one. I want my program to process them by updating the temporary notes.
Re: Reading and wiping notes also adding more notes
On Tuesday, 18 October 2022 at 05:48:27 UTC, Ali Çehreli wrote: On 10/17/22 22:40, Joel wrote: > I have two text fields. The one on the left has the whole text, new > stuff being added to the bottom. The one on the right has text I've been > wiping as I'm reading. I think this can be modelled as a string array and an index showing where the active part starts: import std; struct Notes { string[] whole; size_t activeIndex; void add(string line) { whole ~= line; } string[] activeText() { return whole[activeIndex..$]; } void wipeText() { ++activeIndex; } } void main() { auto input = [ "I went for a walk and fell down a hole.", "There was a D guy on the roof.", "That was a tricky problem!", ]; Notes notes; // add() to add() input.each!(line => notes.add(line)); // activeText() will show the active part // wipeText() will move forward } Ali void upNotes() { string left, right; left=_editBoxMain.text.to!string; right=_editBoxRight.text.to!string; // left is the whole doc // right is the read and wipe doc // Add the new stuff at the bottom of left and append it to the right size_t chunkSize=100; string chunkText, appendText; if (right.length<100) chunkSize=right.length; // mixin(tce("chunkSize left.length right.length right[$-chunkSize..$]".split)); chunkText=left[$-chunkSize..$]; size_t l=left.length-1, r=right.length-1; while(true) { if (right[r..$]!=left[l..$]) { r-=1; l-=1; } else break; } right=right~left[r..$]; //appendText; _editBoxRight.text=right.to!dstring; }
Drawing a line code
I found some code on the net but haven't been able to get it working properly. I trying to draw with mouse (any direction). ```d void drawLine(Dot s, Dot e) { auto d=s; /+ // import std.algorithm : swap; if (s.pos.X>e.pos.X) { int ox=s.pos.Xi; s.pos=Point(e.pos.X,s.pos.Y); e.pos=Point(ox,e.pos.Y); // swap(s.pos.X, e.pos.X); } if (s.pos.Y>e.pos.Y) { int oy=s.pos.Yi; s.pos=Point(s.pos.X,e.pos.Y); e.pos=Point(e.pos.X,oy); // swap(s.pos.Y, e.pos.Y); } +/ int x0=s.pos.Xi, x1=e.pos.Xi, y0=s.pos.Yi, y1=e.pos.Yi; int dy, dx, incrE, incrNE, dt,x,y; /+ import std.algorithm : swap; if (x0>x1) swap(x0,x1); if (y0>y1) swap(y0,y1); +/ dx = x1 - x0; dy = y1 - y0; dt = 2 * (dy - dx); incrE = 2*dy; incrNE = 2*(dy - dx); x = x0; y = y0; d.setPos(s.pos); drawDot(d); while(x < x1) { if (dt <= 0) { dt += incrE; x++; } else { dt += incrNE; x++; y++; } d.setPos(Point(x,y)); drawDot(d); } } // drawLine ```
Re: Drawing a line code
On Sunday, 6 November 2022 at 11:40:40 UTC, claptrap wrote: On Sunday, 6 November 2022 at 11:22:26 UTC, Joel wrote: I found some code on the net but haven't been able to get it working properly. I trying to draw with mouse (any direction). this is the classic integer line drawing algorithm... https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm#Algorithm_for_integer_arithmetic or you could use this... https://github.com/cerjones/dg2d The algorithm is too hard for me to work out and dg2d doesn't help either. I want my code fixed up so that works from any two points.
Re: Drawing a line code
On Sunday, 6 November 2022 at 17:15:03 UTC, rikki cattermole wrote: On 07/11/2022 5:48 AM, Joel wrote: The algorithm is too hard for me to work out and dg2d doesn't help either. I want my code fixed up so that works from any two points. Its not as complex as that page initially looks. ``` plotLine(x0, y0, x1, y1) dx = abs(x1 - x0) sx = x0 < x1 ? 1 : -1 dy = -abs(y1 - y0) sy = y0 < y1 ? 1 : -1 error = dx + dy while true plot(x0, y0) if x0 == x1 && y0 == y1 break e2 = 2 * error if e2 >= dy if x0 == x1 break error = error + dy x0 = x0 + sx end if if e2 <= dx if y0 == y1 break error = error + dx y0 = y0 + sy end if end while ``` That is the pseudo code you want. Its just a matter of typing the variables to something like int. I can recommend: https://www.amazon.com/Computer-Graphics-Principles-Practice-3rd/dp/0321399528 and https://www.amazon.com/Computer-Graphics-C-Version-2nd/dp/0135309247 (The updated version should be fine too) If you wish to understand it. Ok, this is working: ```d void drawLine(Dot s, Dot e) { Dot d=s; int x0=s.pos.Xi, y0=s.pos.Yi; int x1=e.pos.Xi, y1=e.pos.Yi; int dx = abs(x1 - x0); int sx = x0 < x1 ? 1 : -1; int dy = -abs(y1 - y0); int sy = y0 < y1 ? 1 : -1; int error = dx + dy; while(true) { d.setPos(Point(x0,y0)); drawDot(d); if (x0 == x1 && y0 == y1) break; int e2 = 2 * error; if (e2 >= dy) { if (x0 == x1) break; error = error + dy; x0 = x0 + sx; } if (e2 <= dx) { if (y0 == y1) break; error = error + dx; y0 = y0 + sy; } } } //[...] void mouseDraw(ref Dot d) { int lmx=g_mx, lmy=g_my, mx,my; int mstate = SDL_GetMouseState(&mx,&my); if (mstate & SDL_BUTTON_LEFT) { if (mx>0 && my>0) { g_mx=mx/3; g_my=my/3; auto s=d, e=d; s.setPos(Point(lmx, lmy)); e.setPos(Point(g_mx, g_my)); //mixin(tce("lmx lmy g_mx g_my".split)); g_df.drawLine(s,e); } } else { if (mx>0 && my>0) { g_mx=mx/3; g_my=my/3; } } } ```
Re: Running GtkD programs on macOS
On Saturday, 30 November 2019 at 00:17:51 UTC, Mike Wey wrote: On 29-11-2019 04:40, Joel wrote: Oh, I used 'brew install gtk+3', and the test program worked, but (see below) I don't know about all that installing - is that alright? They all look like GTK+ dependencies so that would be alright/ Update: Three years to the day (from when I posted on here about it), since upgrading to macOS Ventura I've found my GTK+ programs work again! Yay. It never stopped working on my Windows computer. The DLangui hasn't been working on Windows though.
Re: Running GtkD programs on macOS
On Tuesday, 29 November 2022 at 07:17:09 UTC, Joel wrote: On Saturday, 30 November 2019 at 00:17:51 UTC, Mike Wey wrote: On 29-11-2019 04:40, Joel wrote: Oh, I used 'brew install gtk+3', and the test program worked, but (see below) I don't know about all that installing - is that alright? They all look like GTK+ dependencies so that would be alright/ Update: Three years to the day (from when I posted on here about it), since upgrading to macOS Ventura I've found my GTK+ programs work again! Yay. It never stopped working on my Windows computer. The DLangui hasn't been working on Windows though. Ops, 29 11 2019 is the day I posted about trying to use GtkD on macOS (not when I found that the window wouldn't show). It doesn't work my laptop display, just the lower resolution external screen.
Graphical progressive fill
I've been trying to fill in areas with a colour but can't work it out. I want something like the effect where it fills with diamonds. Not all at once but building up in the main program loop. # # # # # # # # # # # # # # # # # #### # # # # # ## # # #### # # # # ### # ## #
Re: Graphical progressive fill
On Monday, 12 December 2022 at 04:49:09 UTC, Siarhei Siamashka wrote: On Sunday, 11 December 2022 at 06:50:44 UTC, Joel wrote: I've been trying to fill in areas with a colour but can't work it out. I want something like the effect where it fills with diamonds. Not all at once but building up in the main program loop. I'm not sure if I understood the question correctly, but maybe https://en.wikipedia.org/wiki/Breadth-first_search approach will do the job? Basically have a queue for point coordinates. Add your starting point to it (or multiple starting points). In a loop keep extracting points from the front of the queue, paint this point with a color and add non-painted neighbors of this point to the end of the queue. Keep going until the queue is empty. Example: ```D import std; const width = 78; const height = 10; const number_of_starting_points = 5; struct point { int x, y; } void show_grid(char[][] grid) { foreach (ref row ; grid) writeln(row); writeln; } void animated_fill(char[][] grid, point[] starting_points) { auto height = grid.length; if (height == 0) return; auto width = grid[0].length; struct xpoint { int x, y, dist_from_start; } DList!xpoint queue; foreach (p ; starting_points) queue.insertBack(xpoint(p.x, p.y, 0)); int current_dist = 0; while (!queue.empty) { auto p = queue.front; queue.removeFront; if (grid[p.y][p.x] != '.') continue; // only fill the dots if (p.dist_from_start > current_dist) { show_grid(grid); current_dist = p.dist_from_start; } grid[p.y][p.x] = '#'; if (p.y + 1 < height) queue.insertBack(xpoint(p.x, p.y + 1, p.dist_from_start + 1)); if (p.y - 1 >= 0) queue.insertBack(xpoint(p.x, p.y - 1, p.dist_from_start + 1)); if (p.x + 1 < width) queue.insertBack(xpoint(p.x + 1, p.y, p.dist_from_start + 1)); if (p.x - 1 >= 0) queue.insertBack(xpoint(p.x - 1, p.y, p.dist_from_start + 1)); } show_grid(grid); } void main() { auto grid = new char[][](height, width); foreach (ref row ; grid) row[] = '.'; auto random_points = new point[](number_of_starting_points); foreach (ref p ; random_points) p = point(uniform(0, width), uniform(0, height)); animated_fill(grid, random_points); } ``` Instead of a slow DList, it's also possible to just use a regular static array and two indexes for the start and the end of the queue. With a good implementation of BFS, this array won't need to store more than `grid_width * grid_height` elements. My implementation isn't a good one, but can be improved to do it. Thanks for the help. I got it working with my crazy drawing/animation program. Though I want to be able to do stuff while it's slowly filling the areas (including more filling spots). (I might've used the second example if I was paying more attention). ```D struct Fill { Dot print; // what it draws Dot sample; // what it draws on bool wipe; struct xpoint { int x, y, dist_from_start; } DList!xpoint queue; int current_dist; void start(Dot d) { print=d; sample=g_df.sample(d.pos); if (print==sample) { g_history.updateHistory("Redundant filling (print and sample colours identcal)"); return; } queue.insertBack(xpoint(print.pos.Xi, print.pos.Yi, 0)); current_dist=0; // fillOn=true; process; } void process() { // if (queue.empty) { // fillOn=doFillDraw=false; // return; // } bool done = false; while(!queue.empty && ! done && ! g_keys[SDL_SCANCODE_ESCAPE].keyTrigger) { //Handle events on queue while(SDL_PollEvent(&gEvent)!=0) { //User requests quit if (gEvent.type == SDL_QUIT) done = true; } SDL_PumpEvents(); auto p = queue.front; queue.removeFront; sample.pos=Point(p.x, p.y); if (g_df.sample(p.x,p.y)!=sample) { continue; // only fill the dots } if (p.dist_from_start > current_dist) { if (slow) { g_df.drawTex; SDL_RenderPresent(gRenderer); SDL_Delay(20); } current_dist = p.dist_from_start; } g_df.drawDot(print, p.x,p.y); if (p.y + 1 < HEIGHT) queue.insertBack(xpoint(p.x, p.y + 1, p.dist_from_start + 1)); if (p.y - 1 >= 0) queue.insertBack(xpoint(p.x, p.y - 1, p.dist_from_start + 1)); if (p.x + 1 < WIDTH)
append - too many files
I get this error after a while (seems append doesn't close the file each time): std.file.FileException@std/file.d(836): history.txt: Too many open files ```d auto jm_addToHistory(T...)(T args) { import std.conv : text; import std.file : append; auto txt = text(args); append("history.txt", txt); return txt; } ```
Re: append - too many files
On Wednesday, 11 January 2023 at 06:00:26 UTC, Salih Dincer wrote: On Wednesday, 11 January 2023 at 02:15:13 UTC, Joel wrote: I get this error after a while (seems append doesn't close the file each time): There is no error in the function or Phobos. There may be another error on your system or depending on how you use it. Could it be that more than one program tried to open the same file? How do you use this function? SDB@79 I kinda have an update function that gets the update text, it writes it to the terminal, to a text file and returns the text (for like display on screen). Oh, looking at my code now, I was looking at the wrong function. Not to do with append. Sorry, forget about it.
Getting a total from a user defined variable
```d import std; struct Person { string name; ulong age; } void main() { auto p=[Person("Joel", 43), Person("Timothy", 40)]; writeln("Total: ", p.reduce!((a,b) => a.age+b.age)(0UL)); // how do I get the total of ages added together? } ```
Re: Getting a total from a user defined variable
On Thursday, 20 April 2023 at 21:28:48 UTC, John Chapman wrote: On Thursday, 20 April 2023 at 19:41:21 UTC, Joel wrote: // how do I get the total of ages added together? p.map!(x => x.age).sum(); Or: p.map!"a.age".sum; works too.
toLower
How come toLower works in the sort quotes, but not in the map? ```d void main() { import std; "EzraTezla" .to!(char[]) .byCodeUnit .sort!"a.toLower c.toLower) .writeln; } ``` onlineapp.d(60): Error: `toLower` matches conflicting symbols: /dlang/dmd/linux/bin64/../../src/phobos/std/uni/package.d(9819): function `std.uni.toLower` /dlang/dmd/linux/bin64/../../src/phobos/std/ascii.d(637): function `std.ascii.toLower!char.toLower` /dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(479):instantiated from here: `MapResult!(__lambda4, SortedRange!(ByCodeUnitImpl, "a.toLower>b.toLower", SortedRangeOptions.assumeSorted))` onlineapp.d(60):instantiated from here: `map!(SortedRange!(ByCodeUnitImpl, "a.toLower>b.toLower", SortedRangeOptions.assumeSorted))`
Re: toLower
On Tuesday, 15 August 2023 at 16:54:49 UTC, FeepingCreature wrote: On Tuesday, 15 August 2023 at 16:47:36 UTC, Joel wrote: [...] When you pass a string to a lambda, it's evaluated in `std.functional.unaryFun`/`binaryFun`. At that point, these modules are imported for use in string expressions: ``` import std.algorithm, std.conv, std.exception, std.math, std.range, std.string; import std.meta, std.traits, std.typecons; ``` And `std.string` itself publically imports: ``` public import std.uni : icmp, toLower, toLowerInPlace, toUpper, toUpperInPlace; ``` But does *not* import `std.ascii`! So there's no ambiguity inside the `sort` string expression between the two `toLower` functions.. How do I get it to work? I tried std.ascii.toLower. And using alias toLower=std.ascii.toLower;
Re: toLower
On Wednesday, 16 August 2023 at 05:40:09 UTC, FeepingCreature wrote: On Tuesday, 15 August 2023 at 20:09:28 UTC, Joel wrote: On Tuesday, 15 August 2023 at 16:54:49 UTC, FeepingCreature wrote: But does *not* import `std.ascii`! So there's no ambiguity inside the `sort` string expression between the two `toLower` functions.. How do I get it to work? I tried std.ascii.toLower. And using alias toLower=std.ascii.toLower; To elaborate more, `toLower` doesn't work because function-scope aliases are not considered for UFCS. ``` alias toLower = std.ascii.toLower; ... // So this does actually work: .map!toLower // but this does not, because it looks for a UFCS-capable symbol .map!(c => c.toLower) // but this does again .map!(c => toLower(c)) ``` I get an compile time error with sort after using toLower, putting in array before sort, didn’t work: ```d void main() { Import std; "EzraTezla" .to!(char[]) .byCodeUnit .map!(std.uni.toLower) .sort!"aonlineapp.d(8): Error: none of the overloads of template `std.algorithm.sorting.sort` are callable using argument types `!("a /dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/sorting.d(1925):Candidate is: `sort(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable, Range)(Range r)` with `less = "a
Re: toLower
On Thursday, 17 August 2023 at 14:14:00 UTC, bachmeier wrote: On Thursday, 17 August 2023 at 09:28:05 UTC, Joel wrote: I get an compile time error with sort after using toLower, putting in array before sort, didn’t work: ```d void main() { Import std; "EzraTezla" .to!(char[]) .byCodeUnit .map!(std.uni.toLower) .sort!"a It works for me. Modifying your code to ``` void main() { import std; "EzraTezla" .to!(char[]) .byCodeUnit .map!(std.uni.toLower) .array .sort!"acompiles and gives the expected output. https://run.dlang.io/is/85VjiL ```d void main() { import std; "EzraTezla" .to!(char[]) .byCodeUnit .map!(std.ascii.toLower) .array .sort!"astd.uni.toLower works, but not ascii. Ascii works with bycode after map, though. /Library/D/dmd/src/phobos/std/algorithm/sorting.d(1936): Error: static assert: "When using SwapStrategy.unstable, the passed Range 'char[]' must either fulfill hasSwappableElements, or hasAssignableElements, both were not the case" once.d(9):instantiated from here: `sort!("aSwapStrategy.unstable, char[])`
startsWith
```d void main() { import std.string : split; import std.algorithm.searching : startsWith; string bk="Exo"; assert(("Gen Exo Lev Num Deu Jos Judg Rut 1Sam 2Sam".split~ "1Kin 2Kin 1Chr 2Chr Ezra Neh Est Job Psa Pro Ecc Son Isa Jer".split~ "Lam Eze Dan Hos Joel Amos Oba Jon Mic Nah Hab Zep Hag Zec".split~ "Mal Mat Mar Luk Joh Act Rom 1Cor 2Cor Gal Eph Phili Col".split~ "1The 2The Titu Phile Heb Jam 1Pet 2Pet 1Joh 2Joh 3Joh Jude Rev".split) .startsWith(bk)); } ``` Why doesn't this work? canFind works though.
Key and value with ranges
```d import std; auto data=“I went for a walk, and fell down a hole.”; void main(string[] args) { int[string] dic; struct WordCnt { string word; ulong count; string toString() const { return text("Word: ", word, " - number of instances: ", count); } } WordCnt[] wc; data .map!(c => lowercase.canFind(std.uni.toLower(c)) ? c : ' ') .to!string .splitter .each!(d => dic[d]+=1); foreach(key, value; dic) wc~=WordCnt(key, value); wc.sort!"a.count>b.count".each!writeln; } ``` How can I improve this code? Like avoiding using foreach.
Re: Key and value with ranges
On Monday, 2 October 2023 at 06:19:29 UTC, Imperatorn wrote: On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; You can improve it further by inlining ```d import std; auto data = "I went for a walk, and fell down a hole."; void main(string[] args) { int[string] dic; data.split(' ').each!(w => dic[w]++); sort(dic.keys).each!(w => writeln(dic[w], " ",w)); } ``` I want the output sorted by value.
Re: Key and value with ranges
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; void main(string[] args) { int[string] dic; struct WordCnt { string word; ulong count; string toString() const { return text("Word: ", word, " - number of instances: ", count); } } WordCnt[] wc; data .map!(c => lowercase.canFind(std.uni.toLower(c)) ? c : ' ') .to!string .splitter .each!(d => dic[d]+=1); foreach(key, value; dic) wc~=WordCnt(key, value); wc.sort!"a.count>b.count".each!writeln; } ``` How can I improve this code? Like avoiding using foreach. This is what I've got so far. Is there a way to do it any better? ```d import std; auto data="I went for a walk, and fell down a hole."; void main() { int[string] aa; struct WordCnt { string word; ulong count; string toString() const { return text("Word: ", word, " - number of instances: ", count); } } WordCnt[] wc; data .map!(c => lowercase.canFind(std.uni.toLower(c)) ? c : ' ') .to!string .splitter .each!(d => aa[d]+=1); aa.each!((key, value) { wc~=WordCnt(key, value); }); wc.sort!"a.count>b.count" .each!writeln; } ```
Re: Key and value with ranges
On Monday, 2 October 2023 at 02:47:37 UTC, Joel wrote: ```d import std; auto data=“I went for a walk, and fell down a hole.”; ``` [snip] How can I improve this code? Like avoiding using foreach. This works for me: ```d import std; auto data="I went for a walk, and fell down a hole."; void main(string[] args) { if (args.length>1 && args[1].exists) data=readText(args[1]); data .toLower .map!(c => lowercase.canFind(std.uni.toLower(c)) ? c : ' ') .to!string .split .fold!((ref result, element) { result[element]+=1; return result; })(uint[string].init) .byKeyValue .array .sort!"a.value>b.value" .each!(pair => writeln("Word: ", pair.key, " - number of instances: ", pair.value)); } ```
Type constraint
I’ve got a struct that has a method that adds numbers together. I want to do something like this, static if (isInteger!T) … but it isn’t working. static if (is(T==int)) works for one integer type. ```d struct List(T) { auto addUp() If (isInteger!T) { (Add numbers) } } } ```
Re: Type constraint
On Tuesday, 3 October 2023 at 14:06:37 UTC, ryuukk_ wrote: On Tuesday, 3 October 2023 at 11:43:46 UTC, Joel wrote: I’ve got a struct that has a method that adds numbers together. I want to do something like this, static if (isInteger!T) … but it isn’t working. static if (is(T==int)) works for one integer type. ```d struct List(T) { auto addUp() If (isInteger!T) { (Add numbers) } } } ``` ```D static if (__traits(isIntegral, T)) { } else static assert(0, "type no supported"); ``` https://dlang.org/spec/traits.html#isIntegral Oh, I found, ```d static if (isIntegral!T) ``` seems to work.
T[] opIndex() Error: .. signal 11
The following program crashes, but doesn’t if I change (see title) T[] to auto. The program doesn’t even use that method/function. What’s the story? ```d // Adding program - literal functions import std; struct List(T) { class Node { T data; Node next; this(T data) { this.data=data; } } string title; size_t length; Node head; this(string title, T[] data...) { this.title=title; length=data.length; if (length) { head=new Node(data[0]); auto cur=head; data[1..$].each!((d) { cur.next=new Node(d); cur=cur.next; }); } } bool empty() { return head is null; } auto ref front() { return head.data; } void popFront() { head=head.next; } T[] opIndex() { return this.array; } auto opDollar() { return length; } } void main(string[] args) { args.popFront; List!int ints; if (args.length) { ints=List!int(args[0], args[1..$].to!(int[])); } else{ ints=List!int("Car, and Date numbers", 1979,9,3,4,5); } stdout.write(ints.title, ": "); ints.each!((i, d) { stdout.write(d, i+1
Re: Type constraint
On Tuesday, 3 October 2023 at 17:42:51 UTC, Jonathan M Davis wrote: On Tuesday, October 3, 2023 8:35:31 AM MDT Joel via Digitalmars-d-learn wrote: [...] Yeah. static if will compile in the code in that branch based on whether the condition is true, whereas if without the static will branch at runtime, with both branches being compiled in. So, if you want to be changing what code is being compiled in, you need static if, not if. if(isIntegral!T) will compile just fine, but it'll just end up being either if(true) or if(false) and the code within that branch will be compiled in regardless (and potentially result in compiler errors if it doesn't work with the type that that the template is being instantiated with). So, you usually want to use static if with compile-time tests and not if. - Jonathan M Davis I think the if without static is still static, since it's part of the function name part, or so (outside of the curly bracket scope).
Error: none of the overloads of template `once.main.each!((l)
What am I missing? ```d import std; void main() { struct DateRem { Date date; string rem; string toString() const => text(date.toSimpleString, " ", rem); } DateRem[] daterem; data .splitter('\n') .filter!(l => l.length && l[0].isDigit) .each!((l) { auto parts=l .splitter[0..3] .to!(int[]); if (parts.length==3) { daterem~=DateRem(Date(parts[2],parts[1],parts[0]), l.splitter[3..$].join(" ")); } }); daterem.each!writeln; } auto data="04 10 2023 17:28, not much 30 9 2023 21:08, very little"; ```
Safer binary reading (or writing) code
I've got this mixin thing, I think it's less typo-prone. I haven't been able to make it show the variable's name, though. Also, it should be optional whether it prints anything, (it's not hard for me to do that though). ```d // mixin(jread("width")); -> fread(&width, 1, width.sizeof, bfile); auto jread(string var) => `fread(&`~var~`, 1, `~var~`.sizeof, bfile); writeln("read var=", `~var~`);`; ```
Re: Safer binary reading (or writing) code
On Tuesday, 12 December 2023 at 09:43:39 UTC, Joel wrote: I've got this mixin thing, I think it's less typo-prone. I haven't been able to make it show the variable's name, though. Also, it should be optional whether it prints anything, (it's not hard for me to do that though). ```d // mixin(jread("width")); -> fread(&width, 1, width.sizeof, bfile); auto jread(string var) => `fread(&`~var~`, 1, `~var~`.sizeof, bfile); writeln("read var=", `~var~`);`; ``` O, got it: ```d auto jread(string var) => `fread(&`~var~`, 1, `~var~`.sizeof, bfile); writeln("read `~var~`=", `~var~`);`; ```
Re: Checking path name
On Thursday, 14 December 2023 at 08:47:49 UTC, Anonymouse wrote: On Thursday, 14 December 2023 at 03:58:37 UTC, Joel wrote: If I get user input, for example, how do I check to see if it's a valid path, like, file name. ```d // something like this: if (getUserInput.isValidPath) { ... } ``` Is that not how it works? https://dlang.org/phobos/std_path.html#isValidPath https://dlang.org/phobos/std_path.html#.isValidFilename Oh, forgot about std.path But what's the difference between path and file name?
Re: macOS Sonoma Linker Issue
On Wednesday, 4 October 2023 at 11:01:08 UTC, Johan wrote: On Tuesday, 3 October 2023 at 23:55:05 UTC, confuzzled wrote: [...] Try passing `-ld_classic` to the linker. (`dmd -L-ld_classic`) https://github.com/ldc-developers/ldc/issues/4501#issuecomment-1738295459 -Johan I've been holding off installing Sonoma, because of this. How does one use DUB with the linker fix?
Group dots not working
The dots are supposed to keep moving till they hit something then change direction. Using DotsLogicType.solid the move at first, but then stop moving once they hit something. What supposed to happen: First they check left or right (depending on the dir.x is negative or positive). If no dots hit anything then move the whole dot group, otherwise change direction x variable. Do the same again, but with up and down. ```d module freedots; import jart; struct Dot { Vector2 pos, dir; Color col; Vector2 wpos; bool hit; bool hitx, hity; // old Vector2 logic(in DotsLogicType dotsLogicType, int hrd, ref char[][] hitMap, in RenderTexture canvas) { Vector2 result; final switch(dotsLogicType) with(DotsLogicType) { case none: break; case solid: // mixin(tce("hrd dir.x dir.y".split)); // look horrisontal if (hrd==0) if (pos.x+dir.x>=canvas.texture.width || pos.x+dir.x<0 || hitMap[cast(size_t)(pos.x+dir.x)][cast(size_t)pos.y]=='#') { hit=true; } // look virtical if (hrd==1) if (pos.y+dir.y>=canvas.texture.height || pos.y+dir.y<0 || hitMap[cast(size_t)pos.x][cast(size_t)(pos.y+dir.y)]=='#') { hit=true; } break; case fold: if (pos.x+dir.x>=canvas.texture.width || pos.x+dir.x<0 || hitMap[cast(size_t)(pos.x+dir.x)][cast(size_t)pos.y]=='#') { dir.x*=-1; } else pos.x+=dir.x; if (pos.y+dir.y>=canvas.texture.height || pos.y+dir.y<0 || hitMap[cast(size_t)pos.x][cast(size_t)(pos.y+dir.y)]=='#') { dir.y*=-1; } else pos.y+=dir.y; break; } return result; } void draw() { DrawRectangleV(Vector2(cast(int)pos.x, cast(int)pos.y)*3, Vector2(3,3), col); } } struct DotCnt { Dot[] dots; static DotsLogicType dotsLogicType=DotsLogicType.none; void clearDotsHitMap(ref char[][] hitMap) { foreach(ref d; dots) { hitMap[cast(size_t)d.pos.x][cast(size_t)d.pos.y]=' '; } } void setDotsHitMap(ref char[][] hitMap) { foreach(ref d; dots) { hitMap[cast(size_t)d.pos.x][cast(size_t)d.pos.y]='#'; } } void logic(in RenderTexture canvas, ref char[][] hitMap) { final switch(dotsLogicType) with(DotsLogicType) { case none: setDotsHitMap(hitMap); break; case solid: clearDotsHitMap(hitMap); foreach(hrd; 0..2) { Vector2 mdir; bool hit; // go through dots looking foreach(ref d; dots) { mdir=(hrd==0 ? Vector2(d.dir.x,0) : Vector2(0,d.dir.y)); d.logic(DotsLogicType.solid, hrd, hitMap, canvas); if (d.hit) { hit=true; break; } } if (! hit) foreach(ref d; dots) { d.pos+=mdir; } if (hit) foreach(ref d; dots) { if (hrd==0) d.dir.x=-mdir.x; if (hrd==1) d.dir.y=-mdir.y; mixin(tce("hrd mdir d.pos d.dir".split)); } } // for loop h and v setDotsHitMap(hitMap); break; case fold: foreach(ref d; dots) d.logic(DotsLogicType.fold, 0, hitMap, canvas); break; } } void draw() { foreach(ref d; dots) d.draw; } void dotifyFrmTex(in PointerNSelecter pntsel, Texture2D tex, bool flip=false) { auto ds=buildXDollarsFromTex(tex, flip); foreach(y; 0..tex.height) foreach(x; 0..tex.width) if (ds[x][y].a!=0) dots~=Dot(pntsel.pos+Vector2(x,y), Vector2(1,1), ds[x][y]); } } ``` Here's YouTube video that gives an idea of what my grouped dots can do. https://youtu.be/t5EYeV4BYzU?si=bcpGYwYIX2ecfa9Q
Re: Group dots not working
On Wednesday, 20 December 2023 at 01:45:57 UTC, Joel wrote: The dots are supposed to keep moving till they hit something then change direction. [...] Oh, I found the problem, I wasn't resetting the hit bool variable.
Setting field of struct object
I've been watching a video (YouTube - "Pipeline-oriented programming - Scott Wlaschin - NDC Porto 2023") with something like the following code. This only sets the first method call, so I'm wanting to know how to make this work, for the subsequent methods. ```d import std; struct Person { string name, email; ulong age; auto withName(string name) { this.name=name; return this; } auto withEmail(string email) { this.email=email; return this; } auto withAge(ulong age) { this.age=age; return this; } } void main() { Person p; p.withName("Tom").withEmail("joel...@gmail.com").withAge(44); writeln(p); } ```
Re: Setting field of struct object
On Monday, 22 January 2024 at 08:27:36 UTC, Joel wrote: I've been watching a video (YouTube - "Pipeline-oriented programming - Scott Wlaschin - NDC Porto 2023") with something like the following code. This only sets the first method call, so I'm wanting to know how to make this work, for the subsequent methods. ```d import std; struct Person { string name, email; ulong age; auto withName(string name) { this.name=name; return this; } auto withEmail(string email) { this.email=email; return this; } auto withAge(ulong age) { this.age=age; return this; } } void main() { Person p; p.withName("Tom").withEmail("joel...@gmail.com").withAge(44); writeln(p); } ``` I've lost interest in the video, looks like horrible syntax (F#).
Re: Setting field of struct object
On Monday, 22 January 2024 at 08:54:54 UTC, zjh wrote: On Monday, 22 January 2024 at 08:27:36 UTC, Joel wrote: ```d import std; struct Person { string name, email; ulong age; auto withName(string name) { this.name=name; return this; } auto withEmail(string email) { this.email=email; return this; } auto withAge(ulong age) { this.age=age; return this; } } void main() { Person p; p.withName("Tom").withEmail("joel...@gmail.com").withAge(44); writeln(p); } ``` VS:`C++` ```d struct Person { string name, email; ulong age; } Person a{"n","email",33}; ``` What about in D: auto a=Person(“n”, “email”, 33);
Learning delegates
I'm trying to understand delegates. Is there any good ways I can get a better understanding of them?
Name change weird
I edited one of my librarys and found my programs crashing. At first, I couldn't find what was wrong but used GitHub to review my changes. I found an enum[0] that had a name change - that my programs weren't even using. All the change that was from 'enum g_Draw {text, input}' to 'enum g_draw {text, input}' (just changed the D to lowercase). I fixed it by making the D uppercase again - D Programming Language (code-d) marks it as not the right style. https://github.com/joelcnz [0] JecLib - base.d
Re: Name change weird
On Friday, 13 September 2019 at 05:39:06 UTC, Joel wrote: I edited one of my librarys and found my programs crashing. At first, I couldn't find what was wrong but used GitHub to review my changes. I found an enum[0] that had a name change - that my programs weren't even using. All the change that was from 'enum g_Draw {text, input}' to 'enum g_draw {text, input}' (just changed the D to lowercase). I fixed it by making the D uppercase again - D Programming Language (code-d) marks it as not the right style. https://github.com/joelcnz [0] JecLib - base.d Actually, forget about the above. It's still crashing in run time. jex(2204,0x75356000) malloc: Incorrect checksum for freed object 0x7ffc9368cdf8: probably modified after being freed. Corrupt value: 0x7ffc9368000d jex(2204,0x75356000) malloc: *** set a breakpoint in malloc_error_break to debug Program exited with code -6 Also get: Program exited with code -11 Having this problem since documenting (eg /// discription) some of my code.
Re: Name change weird
On Friday, 13 September 2019 at 05:57:53 UTC, Joel wrote: On Friday, 13 September 2019 at 05:39:06 UTC, Joel wrote: [...] Actually, forget about the above. It's still crashing in run time. jex(2204,0x75356000) malloc: Incorrect checksum for freed object 0x7ffc9368cdf8: probably modified after being freed. Corrupt value: 0x7ffc9368000d jex(2204,0x75356000) malloc: *** set a breakpoint in malloc_error_break to debug Program exited with code -6 Also get: Program exited with code -11 Having this problem since documenting (eg /// discription) some of my code. I'm using DSFML 2.1.1 on macOS 10.14.6 DMD 2.087.1 (home brew). I have upgraded macOS recently - I don't know if that's it. I haven't been able to get a much newer version DSFML to work.
Re: Bug with profiling GC with multiple threads/fibers
On Sunday, 21 April 2019 at 16:20:51 UTC, WebFreak001 wrote: I'm trying to GC profile serve-d which uses a lot of fibers potentially also across some threads and some threads doing some dedicated work, however -profile=gc doesn't seem to work properly. It logs `shared static this` calls and some methods, however none of the actual stuff is in there (and the total bytes allocated is way too small) [...] I don't know a fix. On my macOS computer, I close serve-d thread when it's using too much CPU, I also knock off spindump for the same reason.
Re: Name change weird
On Friday, 13 September 2019 at 06:07:57 UTC, Joel wrote: On Friday, 13 September 2019 at 05:57:53 UTC, Joel wrote: On Friday, 13 September 2019 at 05:39:06 UTC, Joel wrote: [...] Actually, forget about the above. It's still crashing in run time. jex(2204,0x75356000) malloc: Incorrect checksum for freed object 0x7ffc9368cdf8: probably modified after being freed. Corrupt value: 0x7ffc9368000d jex(2204,0x75356000) malloc: *** set a breakpoint in malloc_error_break to debug Program exited with code -6 Also get: Program exited with code -11 Having this problem since documenting (eg /// discription) some of my code. I'm using DSFML 2.1.1 on macOS 10.14.6 DMD 2.087.1 (home brew). I have upgraded macOS recently - I don't know if that's it. I haven't been able to get a much newer version DSFML to work. I think it's the macOS update. Programs that ran before, now crash, not my DLangUI ones. Seems to be with input handling using the DSFML library, I have a program that has graphics and audio, but not looking for keyboard input - that runs properly.
Re: Name change weird
On Friday, 13 September 2019 at 09:54:58 UTC, Kagamin wrote: Maybe you upgraded SFML and now binding doesn't match? I didn't touch SFML dylibs. I guess I could try recompling them. It's a bit late here in New Zealand, though.
Re: Name change weird
On Friday, 13 September 2019 at 10:02:35 UTC, Joel wrote: On Friday, 13 September 2019 at 09:54:58 UTC, Kagamin wrote: Maybe you upgraded SFML and now binding doesn't match? I didn't touch SFML dylibs. I guess I could try recompling them. It's a bit late here in New Zealand, though. I tried recompiling and it didn't work at first. But compiled by recloning with git. Still have the same fatal problem. My platform game plays a popping sound over and over (which would go once at program launch before).
Re: Name change weird
On Friday, 13 September 2019 at 12:20:48 UTC, H. S. Teoh wrote: On Fri, Sep 13, 2019 at 05:57:53AM +, Joel via Digitalmars-d-learn wrote: [...] jex(2204,0x75356000) malloc: Incorrect checksum for freed object 0x7ffc9368cdf8: probably modified after being freed. Corrupt value: 0x7ffc9368000d jex(2204,0x75356000) malloc: *** set a breakpoint in malloc_error_break to debug Program exited with code -6 Also get: Program exited with code -11 [...] This looks like a memory corruption bug. Possibly it was masked before, but due to recent changes in the compiler / druntime, the bug got exposed. T Yeah, input handling would crash in the past, too, but own if you switched away from the program and started doing something else.
serve-d and spindump
On my macOS 10.14.6 computer, I close serve-d thread when it's using too much CPU, I also knock off spindump for the same reason. I get artifacts and junk that flash on my screen - I don't know if that's connected to removing those or not. Does anyone else have these problems? I always have Visual Code running for D programming. I found an old solitary post[0] about it, or so. [0] Bug with profiling GC with multiple threads/fibers
Re: serve-d and spindump
On Saturday, 14 September 2019 at 10:14:19 UTC, psyscout wrote: On Friday, 13 September 2019 at 23:47:00 UTC, Joel wrote: [...] I had a similar issue with crazy CPU consumption when I used VS Code. The root cause for me was "autosave" and "build on save" settings turned on simultaneously. Basically, it was trying to build the entire project every time save happened, and it was frequent enough to overwhelm the CPU. The fix was in: File=>Preferences=>Settings, Then extensions=>D:Enable Dub Linting, have to be disabled (unchecked). Hopefully, this helps. Thanks psyscout - I'm now trying that. On my machine, I used [command]+[,] to get to settings.
Input engine
What is a good keyboard input handler or so? Just need one that picks up that a key is down, but not like a word processor.
Re: Input engine
On Sunday, 15 September 2019 at 10:52:43 UTC, rikki cattermole wrote: On 15/09/2019 12:16 PM, Joel wrote: What is a good keyboard input handler or so? Just need one that picks up that a key is down, but not like a word processor. Are you referring to when you hold down a key and multiple characters gets added to the text area? If so, this feature is called auto-repeat and is implemented by the kernel on input from keyboard. This is easily detected for Windows and can be disabled with X11. Windowing libraries like GLFW offer telling you if an event was an auto-repeat GLFW_REPEAT[0]. SDL[1] has it too under the repeat field, and so does Allegro in the event ALLEGRO_EVENT_KEY_CHAR[2]. If you have a windowing library that forces auto-repeat on you, then you can use a map (with a lookup table to optimize for ASCII as that will be mostly what you will get with it) to check if the key is currently down. If you have a windowing library that forces auto-repeat to be off, then you can use a map (with a lookup table to optimize for ASCII) and then use a timer and trigger your own internal to program auto repeat event. [0] https://www.glfw.org/docs/latest/group__input.html [1] https://wiki.libsdl.org/SDL_KeyboardEvent [2] https://www.allegro.cc/manual/5/ALLEGRO_EVENT I was using DSFML 2.1.1[0] for keyboard input, but with the last macOS update, it just crashes my programs, (it was unstable anyway). I have my own wrapper[0] for handling key pressers. I just need to know when (a) key(s) is/are down (and what key(s)). I still want to use DSFML for other stuff (like graphics). I've had the whole macOS crash, with trying to get Allegro working on it with code that works on Windows OS. I haven't got any SDL program working - DLangUI programs compile and work though. [0] https://code.dlang.org/packages/dsfml [1] https://github.com/joelcnz/JecLib
Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)
On Friday, 11 October 2019 at 11:38:27 UTC, Jacob Carlborg wrote: On 2019-10-10 20:12, Robert M. Münch wrote: I have two project I want to compile and both times get this error: Undefined symbols for architecture x86_64: "_dyld_enumerate_tlv_storage", referenced from: __d_dyld_getTLSRange in libphobos2.a(osx_tls.o) I'm wondering where this comes from as I didn't see it in the past. Any idea? Any D application needs to be compiled with DMD 2.087.1 or later or the corresponding version of LDC to be able to run on macOS Catalina. That includes DMD itself. The oldest version of DMD that runs on Catalina is 2.088.0, since any given version of DMD is compiled with the previous version. That means that all D applications out there for macOS needs to be recompiled. I get this since Catalina: Joel-Computer:VacSpace joelchristensen$ dub Failed to invoke the compiler dmd to determine the build platform: dyld: lazy symbol binding failed: Symbol not found: _dyld_enumerate_tlv_storage Referenced from: /usr/local/bin/dmd Expected in: /usr/lib/libSystem.B.dylib dyld: Symbol not found: _dyld_enumerate_tlv_storage Referenced from: /usr/local/bin/dmd Expected in: /usr/lib/libSystem.B.dylib Joel-Computer:VacSpace joelchristensen$ I use Home Brew (brew upgrade dmd, and brew upgrade dub) Brew is only up to 2.087.1 at the moment - John Colvin seems to be the man that mantains dmd with brew.
Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)
On Monday, 14 October 2019 at 18:49:04 UTC, Jacob Carlborg wrote: On 2019-10-14 07:36, Joel wrote: I use Home Brew (brew upgrade dmd, and brew upgrade dub) Brew is only up to 2.087.1 at the moment - John Colvin seems to be the man that mantains dmd with brew. You can use DVM [1] to install the latest version of DMD. [1] https://github.com/jacob-carlborg/dvm I started an issue for DVM under: 'macOS Cataline'
Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)
On Monday, 14 October 2019 at 18:49:04 UTC, Jacob Carlborg wrote: On 2019-10-14 07:36, Joel wrote: I use Home Brew (brew upgrade dmd, and brew upgrade dub) Brew is only up to 2.087.1 at the moment - John Colvin seems to be the man that mantains dmd with brew. You can use DVM [1] to install the latest version of DMD. [1] https://github.com/jacob-carlborg/dvm I added an issue for DVM under: 'macOS Cataline'
Uninstalling DMG file
How would I go about uninstalling D's DMG file, (as I'm weary of installing it)? I usually, use Home Brew, but the lastest on that doesn't work (macOS Catalina). I guess I can just wipe off the executable files that DMG produces, aye?
Re: Uninstalling DMG file
On Wednesday, 16 October 2019 at 02:30:58 UTC, Joel wrote: How would I go about uninstalling D's DMG file, (as I'm weary of installing it)? I usually, use Home Brew, but the lastest on that doesn't work (macOS Catalina). I guess I can just wipe off the executable files that DMG produces, aye? Ok, I've installed the latest (2.088.1) dmg file. It has an uninstall file in there. Everything seems to be working again - yay!
Program run fails on Windows
I have DLangUI program that works on macOS, but only compiles Windows. It returns -1. Is there a gotcha? It doesn't ask for any DLL's. Windows 10 Pro
Re: Program run fails on Windows
On Wednesday, 30 October 2019 at 03:56:40 UTC, Joel wrote: I have DLangUI program that works on macOS, but only compiles Windows. It returns -1. Is there a gotcha? It doesn't ask for any DLL's. Windows 10 Pro I got programs to compile and run with bindbc-sdl, for example.
Unexpected result with std.conv.to
I made a feature that converts, say, [9:59am] -> [10:00am] to 1 minute. but found '9'.to!int = 57 (not 9). Doesn't seem right... I'm guessing that's standard though, same with ldc.
Re: Unexpected result with std.conv.to
On Friday, 15 November 2019 at 04:26:58 UTC, Jon Degenhardt wrote: On Friday, 15 November 2019 at 03:51:04 UTC, Joel wrote: I made a feature that converts, say, [9:59am] -> [10:00am] to 1 minute. but found '9'.to!int = 57 (not 9). Doesn't seem right... I'm guessing that's standard though, same with ldc. Use a string or char[] array. e.g. writeln("9".to!int) => 9. With a single 'char' what is being produced is the ascii value of the character. Thanks, Jon Degenhardt. I did work it out.
Parsing with dxml
I can only parse one row successfully. I tried increasing the popFronts, till it said I'd gone off the end. Running ./app core.exception.AssertError@../../../../.dub/packages/dxml-0.4.1/dxml/source/dxml/parser.d(1457): text cannot be called with elementEnd ??:? _d_assert_msg [0x104b3981a] ../../JMiscLib/source/jmisc/base.d:161 pure @property @safe immutable(char)[] dxml.parser.EntityRange!(dxml.parser.Config(1, 1, 1, 1), immutable(char)[]).EntityRange.Entity.text() [0x104b2297b] source/app.d:26 _Dmain [0x104aeb46e] Program exited with code 1 ``` http://www.w3.org/2001/XMLSchema-instance";> 01001001 1 1 1 In the beginning God created the heavens and the earth. 01001002 1 1 2 And the earth was waste and void; and darkness was upon the face of the deep: and the Spirit of God moved upon the face of the waters. ``` ```d void main() { import std.stdio; import std.file : readText; import dxml.parser; import std.conv : to; struct Verse { string id; int b, c, v; string t; } auto range = parseXML!simpleXML(readText("xmltest.xml")); // simpleXML skips comments void pops(int c) { foreach(_; 0 .. c) range.popFront(); } pops(3); Verse[] vers; foreach(_; 0 .. 2) { Verse ver; ver.id = range.front.text; pops(3); ver.b = range.front.text.to!int; pops(3); ver.c = range.front.text.to!int; pops(3); ver.v = range.front.text.to!int; pops(3); ver.t = range.front.text; with(ver) vers ~= Verse(id,b,c,v,t); pops(2); } foreach(verse; vers) with(verse) writeln(id, " Book: ", b, " ", c, ":", v, " -> ", t); } ```
Re: Parsing with dxml
On Monday, 18 November 2019 at 06:44:43 UTC, Joel wrote: with(ver) vers ~= Verse(id,b,c,v,t); Or, vers ~= ver;
Re: Parsing with dxml
On Tuesday, 19 November 2019 at 02:45:29 UTC, Jonathan M Davis wrote: On Sunday, November 17, 2019 11:44:43 PM MST Joel via Digitalmars-d-learn wrote: [...] You need to be checking the type of the entity before you call either name or text on it, because not all entities have a name, and not all entities have text - e.g. is an EntityType.elementStart, so it has a name (which is "field"), but it doesn't have text, whereas the 01001001 between the and tags has no name but does have text, because it's an EntityType.text. If you call name or text without verifying the type first, then you're almost certainly going to get an assertion failure at some point (assuming that you don't compile with -release anyway), since you're bound to end up with an entity that you don't expect at some point (either because you were wrong about where you were in the document, or because the document didn't match the layout that was expected). [...] Thanks for taking the time to reply. I have had another xml Bible version text in the past [1]. It had a different format. And Adam Ruppe helped me by writing code that worked (with just one tweak). I think I want another example that I can just paste into my program, using the same structs as the last xml version (see link). [1] https://forum.dlang.org/thread/j7ljs5$24r2$1...@digitalmars.com
Re: Parsing with dxml
On Tuesday, 19 November 2019 at 04:43:31 UTC, Joel wrote: On Tuesday, 19 November 2019 at 02:45:29 UTC, Jonathan M Davis wrote: [...] Thanks for taking the time to reply. I have had another xml Bible version text in the past [1]. It had a different format. And Adam Ruppe helped me by writing code that worked (with just one tweak). I think I want another example that I can just paste into my program, using the same structs as the last xml version (see link). [1] https://forum.dlang.org/thread/j7ljs5$24r2$1...@digitalmars.com -class's (not structs)
Re: Parsing with dxml
On Tuesday, 19 November 2019 at 14:20:39 UTC, Kagamin wrote: On Monday, 18 November 2019 at 06:44:43 UTC, Joel wrote: ``` http://www.w3.org/2001/XMLSchema-instance";> ``` You're missing a closing tag. I can store the ASV Bible in an array (I check for if the last book, chapter, and verse number instead of a closing tag). But I haven't figured out how to get it into the class's setup I've got.
Re: Parsing with dxml
On Wednesday, 20 November 2019 at 00:07:53 UTC, Joel wrote: On Tuesday, 19 November 2019 at 14:20:39 UTC, Kagamin wrote: On Monday, 18 November 2019 at 06:44:43 UTC, Joel wrote: ``` http://www.w3.org/2001/XMLSchema-instance";> ``` You're missing a closing tag. I can store the ASV Bible in an array (I check for if the last book, chapter, and verse number instead of a closing tag). But I haven't figured out how to get it into the class's setup I've got. Ok, got it working. Though didn't use any xml tools, just split the xml file into lines, and went from there. I used my trace function in a mixin for tracing what was happening, from simple code I reuse in my programs - I shows the variable and its value without having to write the variable twice. ``` g_bible = new Bible; int b, c, v; size_t j; break0: do { b = verses[j].b; g_bible.m_books ~= new Book(bookNames[b-1]); version(asvtrace) mixin(trace("g_bible.m_books[$-1].m_bookTitle")); do { c = verses[j].c; g_bible.m_books[$-1].m_chapters ~= new Chapter(c.to!string); version(asvtrace) mixin(trace("j g_bible.m_books[$-1].m_chapters[$-1].m_chapterTitle".split)); do { v = verses[j].v; g_bible.m_books[$-1].m_chapters[$-1].m_verses ~= new Verse(v.to!string); g_bible.m_books[$-1].m_chapters[$-1].m_verses[$-1].verse = verses[j].t; version(asvtrace) mixin(trace(("j g_bible.m_books[$-1].m_chapters[$-1].m_verses[$-1].m_verseTitle" ~ " g_bible.m_books[$-1].m_chapters[$-1].m_verses[$-1].verse").split)); j += 1; if (j == verses.length) break break0; } while(verses[j].v != 1); } while(verses[j+1].c != 1); } while(true); ```
Running GtkD programs on macOS
I've used dub alright, but don't know how to install the dylib files: object.Exception@../../../../.dub/packages/gtk-d-3.9.0/gtk-d/generated/gtkd/gtkd/Loader.d(125): Library load failed (libatk-1.0.0.dylib): dlopen(libatk-1.0.0.dylib, 258): image not found What's a good way to fix this problem?
Re: Running GtkD programs on macOS
On Friday, 29 November 2019 at 08:22:09 UTC, Joel wrote: I've used dub alright, but don't know how to install the dylib files: object.Exception@../../../../.dub/packages/gtk-d-3.9.0/gtk-d/generated/gtkd/gtkd/Loader.d(125): Library load failed (libatk-1.0.0.dylib): dlopen(libatk-1.0.0.dylib, 258): image not found What's a good way to fix this problem? Oh, I used 'brew install gtk+3', and the test program worked, but (see below) I don't know about all that installing - is that alright? Joel-Computer:GtkD joelchristensen$ brew install gtk+3 ==> Installing dependencies for gtk+3: gettext, gdbm, openssl@1.1, readline, sqlite, xz, python, glib, atk, libtiff, gdk-pixbuf, gsettings-desktop-schemas, hicolor-icon-theme, libepoxy, fontconfig, lzo, pixman, cairo, fribidi, graphite2, icu4c, harfbuzz and pango ==> Installing gtk+3 dependency: gettext ==> Downloading https://homebrew.bintray.com/bottles/gettext-0.20.1.catalina.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/10/107d7f386fbeea6979f9376cdbbcf3f60943caaad61bdc754d3019ce625dffe6?__gda__=exp=1575016927~hmac=1f2f6b107535855972ea31d612cdd1bcb0b29049b0c57abc49893f176a5cd205&response-content-di 100.0% ==> Pouring gettext-0.20.1.catalina.bottle.tar.gz ==> Caveats gettext is keg-only, which means it was not symlinked into /usr/local, because macOS provides the BSD gettext library & some software gets confused if both are in the library path. If you need to have gettext first in your PATH run: echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.zshrc For compilers to find gettext you may need to set: export LDFLAGS="-L/usr/local/opt/gettext/lib" export CPPFLAGS="-I/usr/local/opt/gettext/include" ==> Summary 🍺 /usr/local/Cellar/gettext/0.20.1: 1,893 files, 18.4MB ==> Installing gtk+3 dependency: gdbm ==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.1.catalina.bottle.1.tar.gz 100.0% ==> Pouring gdbm-1.18.1.catalina.bottle.1.tar.gz 🍺 /usr/local/Cellar/gdbm/1.18.1: 20 files, 602.8KB ==> Installing gtk+3 dependency: openssl@1.1 ==> Downloading https://homebrew.bintray.com/bottles/open...@1.1-1.1.1d.catalina.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/d7/d7f992ebfd78f80828051f6dc6a1a99aed405f86b0f39ea651fd0afeadd1b0f4?__gda__=exp=1575016937~hmac=5f2ce786f74315c4cdd29cf182505c91b4674ea63dcbd3582441367ea9f101ad&response-content-di 100.0% ==> Pouring open...@1.1-1.1.1d.catalina.bottle.tar.gz ==> Caveats A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because openssl/libressl is provided by macOS so don't link an incompatible version. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" For pkg-config to find openssl@1.1 you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig" ==> Summary 🍺 /usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB ==> Installing gtk+3 dependency: readline ==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.1.catalina.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/ab/ab3c966f4cae7d0f3ecc5688bb989820c3261f5ed547a08c84186ba7f53bdd9c?__gda__=exp=1575016950~hmac=ad277b652e65c3cb8d94e94d22db1d3f5c7f563b2bf9b1d1fb745c9318673a32&response-content-di 100.0% ==> Pouring readline-8.0.1.catalina.bottle.tar.gz ==> Caveats readline is keg-only, which means it was not symlinked into /usr/local, because macOS provides the BSD libedit library, which shadows libreadline. In order to prevent conflicts when programs look for libreadline we are defaulting this GNU Readline installation to keg-only. For compilers to find readline you may need to set: export LDFLAGS="-L/usr/local/opt/readline/lib" export CPPFLAGS="-I/usr/local/opt/readline/include" For pkg-config to find readline you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig" ==> Summary 🍺 /usr/local/Cellar/readline/8.0.1: 48 files, 1.5MB ==> Installing gtk+3 dependency: sqlite ==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.30.1.catalina.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/38/38c39121f7634ec563bb201b483f66cf567dfe61e02624ffb06f620f11158ab1?__gda__=exp=1575016952~hmac=397e8214ce6d53e8e7ccb6d939004d
What could this be?
I'm gotten stuck with this error - "..is not visible from module.."
Re: What could this be?
On Monday, 11 May 2020 at 11:37:40 UTC, Simen Kjærås wrote: On Monday, 11 May 2020 at 11:20:51 UTC, Joel wrote: I'm gotten stuck with this error - "..is not visible from module.." Without some code it's hard to say exactly, but this generally means you're referencing a private symbol in a different module: module foo; private struct S {} module bar; import foo; foo.S s; // foo.S is not visible from module bar -- Simen Thanks Simen.
link error on Windows
I think is works with older versions of DMD. D:\jpro\dpro2\SpellIt>dub Performing "debug" build using D:\jpro\dmd2\windows\bin\dmd.exe for x86_64. bindbc-loader 0.3.0: target for configuration "noBC" is up to date. bindbc-sdl 0.18.0: target for configuration "dynamic" is up to date. spellit ~master: building configuration "application"... ..\arsdLib\source\arsd\terminal.d(3657,5): Deprecation: variable idx is shadowing variable arsd.terminal.ScrollbackBuffer.drawInto.idx. Rename the foreach variable. Linking... lld-link: error: undefined symbol: _D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv referenced by D:\jpro\dmd2\windows\bin\..\..\src\phobos\std\format.d:7088 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_D3std6format__T10printFloatTfTaZQrFNaNfNkAafSQBsQBr__T10FormatSpecTaZQpEQCtQCs12RoundingModeZQCa) referenced by D:\jpro\dmd2\windows\bin\..\..\src\phobos\std\uni.d:6291 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_D3std3uni__T16UnicodeSetParserTSQBf5regex8internal6parser__T6ParserTAyaTSQCuQBpQBmQBg7CodeGenZQBiZQDi13parseCharTermMFNfZSQEr8typecons__T5TupleTSQFoQFn__T13InversionListTSQGoQGn8GcPolicyZQBhTEQHjQHi__TQHhTQGsZQHp8OperatorZQDh) referenced by D:\jpro\dpro2\SpellIt\..\JecsdlLib\source\jecsdl\draw.d:47 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_D6jecsdl4draw10JRectangleQrMFZv) referenced by D:\jpro\dpro2\SpellIt\..\JecsdlLib\source\jecsdl\lettermanager.d:650 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_D6jecsdl13lettermanager13LetterManager7doInputMFKbZa) referenced by D:\jpro\dpro2\SpellIt\..\arsdLib\source\arsd\dom.d:5988 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_D4arsd3dom13parseSelectorFAAyabZSQBgQBe17SelectorComponent) referenced by D:\jpro\dpro2\SpellIt\..\arsdLib\source\arsd\terminal.d:1770 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_D4arsd8terminal20RealTimeConsoleInput11injectEventMFSQCaQBy10InputEventEQCtQCrQCl17InjectionPositionZv) referenced by D:\jpro\dpro2\SpellIt\..\arsdLib\source\arsd\terminal.d:3718 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_D4arsd8terminal16ScrollbackBuffer11handleEventMFSQBwQBu10InputEventZb) referenced by D:\jpro\dpro2\SpellIt\source\app.d:188 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_Dmain) referenced by D:\jpro\dpro2\SpellIt\source\app.d:185 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_Dmain) referenced by D:\jpro\dpro2\SpellIt\source\projectetc.d:307 .dub\build\application-debug-windows-x86_64-dmd_2092-8E7B763C2C746F27EB489566C5B583AE\spellit.obj:(_D10projectetc10ProjectEtc11showTheWordMFZv) referenced 1 more times Error: linker exited with status 1 D:\jpro\dmd2\windows\bin\dmd.exe failed with exit code 1.
Re: link error on Windows
I tried with DMD32 D Compiler v2.088.1-dirty, and it compiled and created an exe file, but not run (msvcr100.dll not found - and tried to find it on the net without success).
Compile and run programs off USB drive
With Windows OS. How would I use my USB drive to compile and run (with 64-bit too)? So far I made a bat file that adds D to %PATH%. There's no zip file of DMD to download, and I didn't get the 7z to work (even with the 7z program?!) - last time I tried. With 64-bit, I don't see what to do there .. edp.bat set PATH=\jpro\dmd2\windows\bin;\jpro\dpro2\Windows\dlls;%PATH% cd jpro\dpro2
Re: link error on Windows
On Wednesday, 20 May 2020 at 09:31:38 UTC, Nathan S. wrote: On Tuesday, 19 May 2020 at 04:54:38 UTC, Joel wrote: I tried with DMD32 D Compiler v2.088.1-dirty, and it compiled and created an exe file, but not run (msvcr100.dll not found - and tried to find it on the net without success). DMD 2.089 changed the default linking options. I bet an up-to-date DMD will also work if you invoke it as "dmd -m32mscoff". It should also work if you build it in 64-bit mode. Thanks Nathan. Got it to work using 64-bit. :)
Re: Compile and run programs off USB drive
On Thursday, 21 May 2020 at 06:23:10 UTC, Joel wrote: With Windows OS. How would I use my USB drive to compile and run (with 64-bit too)? So far I made a bat file that adds D to %PATH%. There's no zip file of DMD to download, and I didn't get the 7z to work (even with the 7z program?!) - last time I tried. With 64-bit, I don't see what to do there .. edp.bat set PATH=\jpro\dmd2\windows\bin;\jpro\dpro2\Windows\dlls;%PATH% cd jpro\dpro2 Nevermind, I got it working just edited the bat file putting bin64 instead of bin. :)
unit test that show more than one failure
I've tired different unit test libraries, but they jump out on errors instead of just adding to failed numbers. I'm thinking like this: ``` @("dummy"); unittset { 0.shouldEqual(0); 1.shouldEqual(2); 2.shouldEqual(3); } ``` Test: dummy test passed line 10: 0 is equal to 0 test failed line 11: 1 is not equal to 2 test failed line 12: 2 is not equal to 3 1 passed 2 failed The unit tests I tried would jump out on the first failure.
Re: unit test that show more than one failure
On Tuesday, 16 June 2020 at 07:39:20 UTC, Luis wrote: On Tuesday, 16 June 2020 at 06:19:51 UTC, Joel wrote: [...] I understand that where the trivial test code is placed, must be something more complex being tested. @("dummy test 1"); unittest { /// Some test code that runs fine } @("dummy test 2"); unittest { /// Some test code that fails } @("dummy test 3"); unittest { /// Some test code that runs fine } Does (with Silly) : ✓ app dummy test 1 ✗ app dummy test 2 ✓ app dummy test 3 Summary: 2 passed, 1 failed in XX ms If you literary expects that some test runner do what you write... sorry but you will never find it on ANY language (that I know). Oh, that's what it is (one UDA a test). Thanks guys.
Linking lib files
Using Windows 10. In my dub.json file I have: "lflags" : ["+..\\DAllegro5\\lib\\"], But I get: Linking... lld-link: error: could not open '+..\DAllegro5\lib\': no such file or directory lld-link: error: could not open 'allegro.lib': no such file or directory ... lld-link: error: could not open 'allegro_audio.lib': no such file or directory Error: linker exited with status 1 It was working on another computer. I'm doing it strait off a flash drive, (I've tried it on computer drive with no difference).
Cannot call @system funciton (stdout)
../../JMiscLib/source/jmisc/base.d(176,2): Error: @safe function jmisc.base.upDateStatus!string.upDateStatus cannot call @system function std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal /Library/D/dmd/src/phobos/std/stdio.d(4837,20): std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal is declared here I got around it by avoiding 'stdout'.
Re: Cannot call @system funciton (stdout)
On Sunday, 16 August 2020 at 18:13:07 UTC, Anonymouse wrote: On Sunday, 16 August 2020 at 10:07:02 UTC, Simen Kjærås wrote: On Saturday, 15 August 2020 at 23:59:36 UTC, Joel wrote: [...] First, what's wrong with using writeln and friends instead of directly mucking about with stdout? :p Just as a drive-by comment, the main stdio thing I came across that I couldn't do from within @safe was stdout.flush(), which I need to call manually for Cygwin terminals and some terminals embedded in editors (vscode). If someone knows why, please tell me. Yeah, that's probably the only thing I've used 'stdout' for so far - flush.
Re: Linking lib files
On Saturday, 4 July 2020 at 01:15:03 UTC, Joel wrote: Using Windows 10. In my dub.json file I have: "lflags" : ["+..\\DAllegro5\\lib\\"], But I get: Linking... lld-link: error: could not open '+..\DAllegro5\lib\': no such file or directory lld-link: error: could not open 'allegro.lib': no such file or directory ... lld-link: error: could not open 'allegro_audio.lib': no such file or directory Error: linker exited with status 1 It was working on another computer. I'm doing it strait off a flash drive, (I've tried it on computer drive with no difference). Got it working, using an old dub version. I haven't been using allegro, I had trouble trying it with macOS, (my main system).
C++ code to D (multi dem 3d mesh)
``` struct vec3d { float x, y, z; } struct triangle { vec3d[3] p; } struct mesh { triangle[] tris; } // This here meshCube.tris = { // SOUTH { 0.0f, 0.0f, 0.0f,0.0f, 1.0f, 0.0f,1.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 0.0f,1.0f, 1.0f, 0.0f,1.0f, 0.0f, 0.0f }, // EAST { 1.0f, 0.0f, 0.0f,1.0f, 1.0f, 0.0f,1.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 0.0f,1.0f, 1.0f, 1.0f,1.0f, 0.0f, 1.0f }, // NORTH { 1.0f, 0.0f, 1.0f,1.0f, 1.0f, 1.0f,0.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 1.0f,0.0f, 1.0f, 1.0f,0.0f, 0.0f, 1.0f }, // WEST { 0.0f, 0.0f, 1.0f,0.0f, 1.0f, 1.0f,0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f,0.0f, 1.0f, 0.0f,0.0f, 0.0f, 0.0f }, // TOP { 0.0f, 1.0f, 0.0f,0.0f, 1.0f, 1.0f,1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 0.0f,1.0f, 1.0f, 1.0f,1.0f, 1.0f, 0.0f }, // BOTTOM { 1.0f, 0.0f, 1.0f,0.0f, 0.0f, 1.0f,0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 1.0f,0.0f, 0.0f, 0.0f,1.0f, 0.0f, 0.0f }, }; ``` See: https://youtu.be/ih20l3pJoeU https://github.com/OneLoneCoder/videos/blob/master/OneLoneCoder_olcEngine3D_Part1.cpp
Re: C++ code to D (multi dem 3d mesh)
On Monday, 26 October 2020 at 23:38:22 UTC, Joel wrote: ``` struct vec3d { float x, y, z; } struct triangle { vec3d[3] p; } struct mesh { triangle[] tris; } // This here meshCube.tris = { // SOUTH { 0.0f, 0.0f, 0.0f,0.0f, 1.0f, 0.0f,1.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 0.0f,1.0f, 1.0f, 0.0f,1.0f, 0.0f, 0.0f }, // EAST { 1.0f, 0.0f, 0.0f,1.0f, 1.0f, 0.0f,1.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 0.0f,1.0f, 1.0f, 1.0f,1.0f, 0.0f, 1.0f }, // NORTH { 1.0f, 0.0f, 1.0f,1.0f, 1.0f, 1.0f,0.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 1.0f,0.0f, 1.0f, 1.0f,0.0f, 0.0f, 1.0f }, // WEST { 0.0f, 0.0f, 1.0f,0.0f, 1.0f, 1.0f,0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f,0.0f, 1.0f, 0.0f,0.0f, 0.0f, 0.0f }, // TOP { 0.0f, 1.0f, 0.0f,0.0f, 1.0f, 1.0f,1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 0.0f,1.0f, 1.0f, 1.0f,1.0f, 1.0f, 0.0f }, // BOTTOM { 1.0f, 0.0f, 1.0f,0.0f, 0.0f, 1.0f,0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 1.0f,0.0f, 0.0f, 0.0f,1.0f, 0.0f, 0.0f }, }; ``` See: https://youtu.be/ih20l3pJoeU https://github.com/OneLoneCoder/videos/blob/master/OneLoneCoder_olcEngine3D_Part1.cpp This is what I came up with: meshCube.tris = // south [triangle(vec3d(0f,0f,0f)), triangle(vec3d(0f,1f,0f)), triangle(vec3d(1f,1f,0f)), triangle(vec3d(0f,0f,0f)), triangle(vec3d(1f,1f,0f)), triangle(vec3d(1f,0f,0f)), // east triangle(vec3d(1f,0f,0f)), triangle(vec3d(1f,1f,0f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(1f,0f,0f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(1f,0f,1f)), // north triangle(vec3d(1f,0f,1f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(0f,1f,1f)), triangle(vec3d(1f,0f,1f)), triangle(vec3d(0f,1f,1f)), triangle(vec3d(0f,0f,1f)), // west triangle(vec3d(0f,0f,1f)), triangle(vec3d(0f,1f,1f)), triangle(vec3d(0f,1f,0f)), triangle(vec3d(0f,0f,1f)), triangle(vec3d(0f,1f,0f)), triangle(vec3d(0f,0f,0f)), // top triangle(vec3d(0f,1f,0f)), triangle(vec3d(0f,1f,1f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(0f,1f,0f)), triangle(vec3d(1f,1f,1f)), triangle(vec3d(1f,1f,0f)), // bottom triangle(vec3d(1f,0f,1f)), triangle(vec3d(0f,0f,1f)), triangle(vec3d(0f,0f,0f)), triangle(vec3d(1f,0f,1f)), triangle(vec3d(0f,0f,0f)), triangle(vec3d(1f,0f,0f))];
Re: C++ code to D (multi dem 3d mesh)
On Tuesday, 27 October 2020 at 07:17:46 UTC, Imperatorn wrote: On Monday, 26 October 2020 at 23:38:22 UTC, Joel wrote: ``` struct vec3d { float x, y, z; } [...] It's not really clear what your question is. I'm trying to convert from C++ code to D code, see where I've put '// This here' - with all the data. I found one way. I think I've thought of another way too.
Re: C++ code to D (multi dem 3d mesh)
On Tuesday, 27 October 2020 at 08:14:28 UTC, Imperatorn wrote: On Tuesday, 27 October 2020 at 07:32:30 UTC, Joel wrote: On Tuesday, 27 October 2020 at 07:17:46 UTC, Imperatorn wrote: On Monday, 26 October 2020 at 23:38:22 UTC, Joel wrote: ``` struct vec3d { float x, y, z; } [...] It's not really clear what your question is. I'm trying to convert from C++ code to D code, see where I've put '// This here' - with all the data. I found one way. I think I've thought of another way too. Ok, some steps have to be done manually. Just wanted to share some links that might be interesting when converting in the future: https://github.com/lhamot/CPP2D https://github.com/jacob-carlborg/dstep https://github.com/atilaneves/dpp http://www.swig.org/Doc4.0/D.html https://dlang.org/htod.html Thanks, I've bookmarked this.
Updating to newer files with different disk formats
I found using timeLastModified from macOS drive to ExFat, macOS has higher precision than ExFat[0], so a different number. My little program lists the files to update, but I get files to update still, after updating them, because of the differences with the disk formats. [0] from time: 2020-Nov-06 13:29:30.5897005, to time: 2020-Nov-06 13:29:30.58 Potential copy("/Users/joelchristensen/jpro/dpro2/AbcKids/LettersO/d.wav","/Volumes/PNY480/jpro/dpro2/AbcKids/LettersO/d.wav");
GtkD on macOS Monterey
My GtkD programs compile and run (on Monterey - works on earlier versions), but not GUI displayed?! I asked on the GtkD forum, but they said about not having a mac or something.
Re: GtkD on macOS Monterey
On Wednesday, 16 February 2022 at 15:54:26 UTC, Ron Tarrant wrote: On Monday, 14 February 2022 at 00:39:30 UTC, Joel wrote: My GtkD programs compile and run (on Monterey - works on earlier versions), but not GUI displayed?! I asked on the GtkD forum, but they said about not having a mac or something. Check this out: https://gitlab.gnome.org/GNOME/gtk/-/issues/4342 It may shed some light for you. Thanks for your reply, but it's not the same issue though. I don't have an M1 computer, (I've tried M1 though, and could do even less on it, just terminal programs, not the multimedia stuff I use).
wstring double quotes to string double quotes
I have a program that uses string double quotes, but copies from wstring double quotes. The wstring double quotes are in string type (sourceTxt is a string with wstring double quotes). The following code crashes with an array.d(2211): Range violation error: import std.conv : to; import std.string : replace; auto sourceTxtW = sourceTxt.to!wstring; sourceTxtW.replace("”", `"`); auto sourceTxtR = sourceTxtW.to!string; sourceLines = sourceTxtR.split("\n");
Re: wstring double quotes to string double quotes
On Thursday, 19 April 2018 at 21:57:28 UTC, Adam D. Ruppe wrote: On Thursday, 19 April 2018 at 21:53:52 UTC, Joel wrote: I have a program that uses string double quotes, but copies from wstring double quotes. The wstring double quotes are in string type (sourceTxt is a string with wstring double quotes). quotes are quotes, you don't need to convert to wstring here. I really don't think it should be throwing that error regardless... but you also should be able to just do string[] sourceLines = sourceTxt.replace("”", `"`).split("\n"); and skip the wstring part entirely. That worked! Thanks Adam.
Re: wstring double quotes to string double quotes
On Friday, 20 April 2018 at 02:46:14 UTC, Jonathan M Davis wrote: On Thursday, April 19, 2018 23:24:05 Joel via Digitalmars-d-learn wrote: On Thursday, 19 April 2018 at 21:57:28 UTC, Adam D. Ruppe wrote: > [...] That worked! Thanks Adam. Given that these functions really shouldn't be throw RangeErrors, please create a bug report with example code that can someone can just run to reproduce the issue (your example isn't runnable as-is). That way, the bug can be fixed. Otherwise, it's probably just going to be lost, and someone else may hit it in the future. Thanks. https://issues.dlang.org - Jonathan M Davis Done.
Home Brew dmd update 2.082
It's been a over a month, and there still isn't an update for dmd 2.082 on macOS using Home Brew?! I get this (with 'brew upgrade dmd'): Error: dmd 2.081.2 already installed
File .. byLine
I can't seem to get this to work! ``` foreach(line; File("help.txt").byLine) { writeln(line.stripLeft); ``` With the code above, I get this compile error: source/app.d(360,36): Error: template std.algorithm.mutation.stripLeft cannot deduce function from argument types !()(char[]), candidates are: /usr/local/opt/dmd/include/dlang/dmd/std/algorithm/mutation.d(2602,7): std.algorithm.mutation.stripLeft(Range, E)(Range range, E element) if (isInputRange!Range && is(typeof(range.front == element) : bool)) /usr/local/opt/dmd/include/dlang/dmd/std/algorithm/mutation.d(2610,7): std.algorithm.mutation.stripLeft(alias pred, Range)(Range range) if (isInputRange!Range && is(typeof(pred(range.front)) : bool)) I just want to use each 'line' variable as a string?! I've tried 'byLineCopy', and 'line.to!string'. I've looked at documentation.
Re: File .. byLine
On Monday, 3 December 2018 at 06:55:50 UTC, Nicholas Wilson wrote: On Monday, 3 December 2018 at 06:09:21 UTC, Joel wrote: [...] https://run.dlang.io/is/h0ArAB works for me. If you want it as a string not char[] then byLineCopy should work, if not just `.idup` `line`. Oh, I was using std.algorithm's 'stripLeft' instead of std.string's 'stripLeft'.
dub getting stuck
macOS 10.13.6 dmd 2.085.0 dub 1.3.0 { "name": "server", "targetType": "executable", "description": "A testing D application.", "sourcePaths" : ["source"], "dependencies": { "vibe-d" : "~>0.8.0" } } void main() { import vibe.d; listenHTTP(":8080", (req, res) { res.writeBody("Hello, World: " ~ req.path); }); runApplication(); } dub -v .. Sub package vibe-d:diet doesn't exist in vibe-d 0.8.1-alpha.1. (gets as far as that line?!) On another program, it gets stuck in a completely different situation.
Re: dub getting stuck
On Sunday, 17 March 2019 at 09:04:37 UTC, Eugene Wissner wrote: On Sunday, 17 March 2019 at 07:20:47 UTC, Joel wrote: macOS 10.13.6 dmd 2.085.0 dub 1.3.0 [snip] dub 1.3.0 is something old. Is it reproducable with a newer version? Can one safely update dub by it's self (Home Brew), when it comes with DMD (Home Brew also)? Otherwise can be related: https://github.com/dlang/dub/issues/1345 https://github.com/dlang/dub/issues/1001
Re: dub getting stuck
On Monday, 18 March 2019 at 20:25:14 UTC, Joel wrote: On Sunday, 17 March 2019 at 09:04:37 UTC, Eugene Wissner wrote: On Sunday, 17 March 2019 at 07:20:47 UTC, Joel wrote: macOS 10.13.6 dmd 2.085.0 dub 1.3.0 [snip] dub 1.3.0 is something old. Is it reproducable with a newer version? Can one safely update dub by it's self (Home Brew), when it comes with DMD (Home Brew also)? Well, I went ahead and updated dub. Looks like it's working now. Yay! Otherwise can be related: https://github.com/dlang/dub/issues/1345 https://github.com/dlang/dub/issues/1001
macOS Mojave compatiblity
I've ordered a new computer, and it has Mojave OS. It's 64 bit only, so I'm wondering what difference would that make with things like with C bindings and stuff. For example would https://code.dlang.org/packages/dsfml and https://code.dlang.org/packages/dlangui librarys work?